Changeset 1993 for ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AdminRegistryTest.java
- Timestamp:
- 06/18/12 15:24:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AdminRegistryTest.java
r1603 r1993 17 17 import clarin.cmdi.componentregistry.ComponentRegistry; 18 18 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 19 import clarin.cmdi.componentregistry.ComponentStatus; 19 20 import clarin.cmdi.componentregistry.DeleteFailedException; 20 21 import clarin.cmdi.componentregistry.frontend.CMDItemInfo; … … 28 29 @RunWith(SpringJUnit4ClassRunner.class) 29 30 @ContextConfiguration(locations = {"/applicationContext.xml"}) 30 public class AdminRegistryTest 31 31 public class AdminRegistryTest { 32 32 33 @Autowired 33 34 private ComponentDescriptionDao componentDescriptionDao; … … 37 38 private ComponentRegistryFactory componentRegistryFactory; 38 39 private static final Principal PRINCIPAL_ADMIN = DummyPrincipal.DUMMY_ADMIN_PRINCIPAL; 39 40 40 @Autowired 41 41 private JdbcTemplate jdbcTemplate; 42 42 43 43 @Before 44 44 public void init() { … … 48 48 @Test 49 49 public void testForceUpdate() throws Exception { 50 51 52 53 54 55 56 57 58 59 50 ComponentRegistry testRegistry = componentRegistryFactory.getPublicRegistry(); 51 String content1 = ""; 52 content1 += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 53 content1 += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 54 content1 += " <Header/>\n"; 55 content1 += " <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n"; 56 content1 += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 57 content1 += " </CMD_Component>\n"; 58 content1 += "</CMD_ComponentSpec>\n"; 59 ComponentDescription compDesc1 = RegistryTestHelper.addComponent(testRegistry, "XXX1", content1); 60 60 61 62 63 64 65 66 67 68 69 70 61 String content2 = ""; 62 content2 += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 63 content2 += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 64 content2 += " <Header/>\n"; 65 content2 += " <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 66 content2 += " <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 67 content2 += " </CMD_Component>\n"; 68 content2 += " </CMD_Component>\n"; 69 content2 += "</CMD_ComponentSpec>\n"; 70 ProfileDescription profileDesc = RegistryTestHelper.addProfile(testRegistry, "YYY1", content2); 71 71 72 AdminRegistry adminReg = new AdminRegistry(); 73 adminReg.setComponentRegistryFactory(componentRegistryFactory); 74 adminReg.setComponentDescriptionDao(componentDescriptionDao); 75 adminReg.setProfileDescriptionDao(profileDescriptionDao); 76 CMDItemInfo fileInfo = new CMDItemInfo(); 77 fileInfo.setForceUpdate(false); 78 fileInfo.setDataNode(new DisplayDataNode(compDesc1.getName(), false, compDesc1, true)); 79 fileInfo.setContent(content1); 80 try { 81 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); 82 fail(); 83 } catch (SubmitFailedException e) {} 84 fileInfo.setForceUpdate(true); 85 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); //Component needs to be forced because they can be used by other profiles/components 72 AdminRegistry adminReg = new AdminRegistry(); 73 adminReg.setComponentRegistryFactory(componentRegistryFactory); 74 adminReg.setComponentDescriptionDao(componentDescriptionDao); 75 adminReg.setProfileDescriptionDao(profileDescriptionDao); 76 CMDItemInfo fileInfo = new CMDItemInfo(); 77 fileInfo.setForceUpdate(false); 78 fileInfo.setDataNode(new DisplayDataNode(compDesc1.getName(), false, compDesc1, ComponentStatus.PUBLIC)); 79 fileInfo.setContent(content1); 80 try { 81 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); 82 fail(); 83 } catch (SubmitFailedException e) { 84 } 85 fileInfo.setForceUpdate(true); 86 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); //Component needs to be forced because they can be used by other profiles/components 86 87 87 88 89 90 91 92 93 94 95 96 97 98 88 assertEquals(1, testRegistry.getComponentDescriptions().size()); 89 try { 90 fileInfo.setForceUpdate(false); 91 adminReg.delete(fileInfo, PRINCIPAL_ADMIN); 92 fail(); 93 } catch (SubmitFailedException e) { 94 assertTrue(e.getCause() instanceof DeleteFailedException); 95 } 96 assertEquals(1, testRegistry.getComponentDescriptions().size()); 97 fileInfo.setForceUpdate(true); 98 adminReg.delete(fileInfo, PRINCIPAL_ADMIN); 99 assertEquals(0, testRegistry.getComponentDescriptions().size()); 99 100 100 101 102 fileInfo.setDataNode(new DisplayDataNode(profileDesc.getName(), false, profileDesc, true));103 104 101 assertEquals(1, testRegistry.getProfileDescriptions().size()); 102 fileInfo.setForceUpdate(false); 103 fileInfo.setDataNode(new DisplayDataNode(profileDesc.getName(), false, profileDesc, ComponentStatus.PUBLIC)); 104 adminReg.delete(fileInfo, PRINCIPAL_ADMIN); //Profile do not need to be forced they cannot be used by other profiles 105 assertEquals(0, testRegistry.getProfileDescriptions().size()); 105 106 } 106 107 }
Note: See TracChangeset
for help on using the changeset viewer.