Changeset 262
- Timestamp:
- 03/19/10 14:54:36 (14 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java
r207 r262 15 15 List<ComponentDescription> getComponentDescriptions(); 16 16 17 ComponentDescription getComponentDescription(String id); 18 17 19 List<ProfileDescription> getProfileDescriptions(); 20 21 ProfileDescription getProfileDescription(String id); 18 22 19 23 CMDComponentSpec getMDProfile(String id); -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistryImpl.java
r253 r262 166 166 return result; 167 167 } 168 169 public ComponentDescription getComponentDescription(String id) { 170 return componentDescriptions.get(id); 171 } 168 172 169 173 public CMDComponentSpec getMDProfile(String profileId) { … … 239 243 Collections.sort(result, ProfileDescription.COMPARE_ON_NAME); 240 244 return result; 245 } 246 247 public ProfileDescription getProfileDescription(String id) { 248 return profileDescriptions.get(id); 241 249 } 242 250 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r208 r262 99 99 return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build(); 100 100 } catch (UserUnauthorizedException e) { 101 LOG.info("Component with id: " + componentId + " deletion failed: " +e.getMessage());101 LOG.info("Component with id: " + componentId + " deletion failed: " + e.getMessage()); 102 102 return Response.serverError().status(Status.UNAUTHORIZED).build(); 103 103 } … … 109 109 @Path("/components/{componentId}/{rawType}") 110 110 @Produces( { MediaType.TEXT_XML, MediaType.APPLICATION_XML }) 111 public StringgetRegisteredComponentRawType(@PathParam("componentId") String componentId, @PathParam("rawType") String rawType) {111 public Response getRegisteredComponentRawType(@PathParam("componentId") String componentId, @PathParam("rawType") String rawType) { 112 112 LOG.info("Component with id: " + componentId + " and rawType:" + rawType + " is requested."); 113 113 String result = ""; 114 ComponentDescription desc = registry.getComponentDescription(componentId); 115 if (desc == null) { 116 throw new WebApplicationException(Response.serverError().entity("Requested component does not exist").build()); 117 } 118 String fileName = desc.getName() + "." + rawType; 114 119 if ("xml".equalsIgnoreCase(rawType)) { 115 120 result = registry.getMDComponentAsXml(componentId); … … 120 125 "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build()); 121 126 } 122 return result;127 return createDownloadResponse(result, fileName); 123 128 } 124 129 … … 145 150 return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build(); 146 151 } catch (UserUnauthorizedException e) { 147 LOG.info("Profile with id: " + profileId + " deletion failed: " +e.getMessage());152 LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage()); 148 153 return Response.serverError().status(Status.UNAUTHORIZED).build(); 149 154 } … … 155 160 @Path("/profiles/{profileId}/{rawType}") 156 161 @Produces( { MediaType.TEXT_XML, MediaType.APPLICATION_XML }) 157 public StringgetRegisteredProfileRawType(@PathParam("profileId") String profileId, @PathParam("rawType") String rawType) {162 public Response getRegisteredProfileRawType(@PathParam("profileId") String profileId, @PathParam("rawType") String rawType) { 158 163 LOG.info("Profile with id: " + profileId + " and rawType:" + rawType + " is requested."); 159 164 String result = ""; 165 ProfileDescription desc = registry.getProfileDescription(profileId); 166 if (desc == null) { 167 throw new WebApplicationException(Response.serverError().entity("Requested component does not exist").build()); 168 } 169 String fileName = desc.getName() + "." + rawType; 160 170 if ("xml".equalsIgnoreCase(rawType)) { 161 171 result = registry.getMDProfileAsXml(profileId); … … 166 176 "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build()); 167 177 } 168 return result; 178 return createDownloadResponse(result, fileName); 179 180 } 181 182 private Response createDownloadResponse(String result, String fileName) { 183 //Making response so it triggers browsers native save as dialog. 184 Response response = Response.ok().type("application/x-download").header("Content-Disposition", "attachment; filename=" + fileName) 185 .entity(result).build(); 186 return response; 187 169 188 } 170 189 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/ComponentRegistryImplTest.java
r207 r262 22 22 import clarin.cmdi.componentregistry.model.ProfileDescription; 23 23 import clarin.cmdi.componentregistry.rest.DummyPrincipal; 24 import clarin.cmdi.componentregistry.rest. TestHelper;24 import clarin.cmdi.componentregistry.rest.RegistryTestHelper; 25 25 26 26 public class ComponentRegistryImplTest { … … 39 39 assertEquals(0, register.getProfileDescriptions().size()); 40 40 41 CMDComponentSpec testProfile = TestHelper.getTestProfile();41 CMDComponentSpec testProfile = RegistryTestHelper.getTestProfile(); 42 42 assertNull(testProfile.getHeader().getID()); 43 43 assertNull(testProfile.getHeader().getName()); … … 68 68 assertEquals(0, register.getProfileDescriptions().size()); 69 69 70 CMDComponentSpec testComponent = TestHelper.getTestComponent();70 CMDComponentSpec testComponent = RegistryTestHelper.getTestComponent(); 71 71 assertNull(testComponent.getHeader().getID()); 72 72 assertNull(testComponent.getHeader().getName()); … … 103 103 assertEquals(0, register.getComponentDescriptions().size()); 104 104 assertEquals(0, register.getProfileDescriptions().size()); 105 register.registerMDProfile(description, TestHelper.getTestProfile());105 register.registerMDProfile(description, RegistryTestHelper.getTestProfile()); 106 106 assertEquals(0, register.getComponentDescriptions().size()); 107 107 assertEquals(1, register.getProfileDescriptions().size()); … … 130 130 assertEquals(0, register.getComponentDescriptions().size()); 131 131 assertEquals(0, register.getProfileDescriptions().size()); 132 register.registerMDProfile(description, TestHelper.getTestProfile());132 register.registerMDProfile(description, RegistryTestHelper.getTestProfile()); 133 133 description = new ProfileDescription(); 134 134 description.setName("Aap2"); 135 135 String id2 = "Aap2" + System.currentTimeMillis(); 136 136 description.setId(id2); 137 register.registerMDProfile(description, TestHelper.getTestProfile());137 register.registerMDProfile(description, RegistryTestHelper.getTestProfile()); 138 138 139 139 assertEquals(0, register.getComponentDescriptions().size()); … … 172 172 173 173 String id = "profile1"; 174 ProfileDescription description = TestHelper.addProfile(register, id, profileContent);174 ProfileDescription description = RegistryTestHelper.addProfile(register, id, profileContent); 175 175 176 176 String xsd = register.getMDProfileAsXsd(description.getId()); … … 194 194 compContent += "</CMD_ComponentSpec>\n"; 195 195 196 ComponentDescription compDesc = TestHelper.addComponent(register, compId, compContent);196 ComponentDescription compDesc = RegistryTestHelper.addComponent(register, compId, compContent); 197 197 198 198 String profileContent = ""; … … 206 206 207 207 String id = "profile1"; 208 ProfileDescription description = TestHelper.addProfile(register, id, profileContent);208 ProfileDescription description = RegistryTestHelper.addProfile(register, id, profileContent); 209 209 210 210 String xsd = register.getMDProfileAsXsd(description.getId()); … … 226 226 compContent += " </CMD_Component>\n"; 227 227 compContent += "</CMD_ComponentSpec>\n"; 228 ComponentDescription compDesc1 = TestHelper.addComponent(register, "component1", compContent);228 ComponentDescription compDesc1 = RegistryTestHelper.addComponent(register, "component1", compContent); 229 229 230 230 compContent = ""; … … 238 238 compContent += " </CMD_Component>\n"; 239 239 compContent += "</CMD_ComponentSpec>\n"; 240 ComponentDescription compDesc2 = TestHelper.addComponent(register, "component2", compContent);240 ComponentDescription compDesc2 = RegistryTestHelper.addComponent(register, "component2", compContent); 241 241 242 242 compContent = ""; … … 253 253 compContent += " </CMD_Component>\n"; 254 254 compContent += "</CMD_ComponentSpec>\n"; 255 ComponentDescription compDesc3 = TestHelper.addComponent(register, "component3", compContent);255 ComponentDescription compDesc3 = RegistryTestHelper.addComponent(register, "component3", compContent); 256 256 257 257 String xsd = register.getMDComponentAsXsd(compDesc3.getId()); … … 272 272 description.setCreatorName(PRINCIPAL.getName()); 273 273 description.setDescription("MyDescription"); 274 CMDComponentSpec testProfile = TestHelper.getTestProfile();274 CMDComponentSpec testProfile = RegistryTestHelper.getTestProfile(); 275 275 276 276 register.registerMDProfile(description, testProfile); … … 301 301 description.setCreatorName(PRINCIPAL.getName()); 302 302 description.setDescription("MyDescription"); 303 CMDComponentSpec testProfile = TestHelper.getTestProfile();303 CMDComponentSpec testProfile = RegistryTestHelper.getTestProfile(); 304 304 305 305 register.registerMDComponent(description, testProfile); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r207 r262 215 215 public void testRegisterProfile() throws Exception { 216 216 FormDataMultiPart form = new FormDataMultiPart(); 217 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, TestHelper.getTestProfileContent(),217 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getTestProfileContent(), 218 218 MediaType.APPLICATION_OCTET_STREAM_TYPE); 219 219 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1"); … … 235 235 public void testRegisterComponent() throws Exception { 236 236 FormDataMultiPart form = new FormDataMultiPart(); 237 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, TestHelper.getComponentTestContent(),237 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(), 238 238 MediaType.APPLICATION_OCTET_STREAM_TYPE); 239 239 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ComponentTest1"); … … 302 302 public void testRegisterComponentAsProfile() throws Exception { 303 303 FormDataMultiPart form = new FormDataMultiPart(); 304 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, TestHelper.getComponentTestContent(),304 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, RegistryTestHelper.getComponentTestContent(), 305 305 MediaType.APPLICATION_OCTET_STREAM_TYPE); 306 306 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "t"); … … 318 318 registryDir = ComponentRegistryImplTest.createTempRegistryDir(); 319 319 testRegistry = ComponentRegistryImplTest.getTestRegistry(registryDir); 320 TestHelper.addProfile(testRegistry, ComponentRegistry.REGISTRY_ID + "profile1");321 TestHelper.addProfile(testRegistry, ComponentRegistry.REGISTRY_ID + "profile2");322 TestHelper.addComponent(testRegistry, ComponentRegistry.REGISTRY_ID + "component1");323 TestHelper.addComponent(testRegistry, ComponentRegistry.REGISTRY_ID + "component2");320 RegistryTestHelper.addProfile(testRegistry, ComponentRegistry.REGISTRY_ID + "profile1"); 321 RegistryTestHelper.addProfile(testRegistry, ComponentRegistry.REGISTRY_ID + "profile2"); 322 RegistryTestHelper.addComponent(testRegistry, ComponentRegistry.REGISTRY_ID + "component1"); 323 RegistryTestHelper.addComponent(testRegistry, ComponentRegistry.REGISTRY_ID + "component2"); 324 324 } 325 325 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/MDValidatorTest.java
r127 r262 97 97 assertTrue(validator.getErrorMessages().get(1).startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR)); 98 98 99 TestHelper.addComponent(testRegistry, id1);99 RegistryTestHelper.addComponent(testRegistry, id1); 100 100 validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, testRegistry); 101 101 assertFalse(validator.validate()); … … 103 103 assertTrue(validator.getErrorMessages().get(0).startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR)); 104 104 105 TestHelper.addComponent(testRegistry, id2);105 RegistryTestHelper.addComponent(testRegistry, id2); 106 106 validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, testRegistry); 107 107 assertTrue("component is registered should be valid now", validator.validate()); … … 130 130 assertTrue(validator.getErrorMessages().get(0).startsWith(MDValidator.COMPONENT_NOT_REGISTERED_ERROR)); 131 131 132 TestHelper.addComponent(testRegistry, id1);132 RegistryTestHelper.addComponent(testRegistry, id1); 133 133 validator = new MDValidator(new ByteArrayInputStream(content.getBytes()), desc, testRegistry); 134 134 assertTrue(validator.validate()); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java
r207 r262 19 19 * 20 20 */ 21 public final class TestHelper {21 public final class RegistryTestHelper { 22 22 23 private TestHelper() {23 private RegistryTestHelper() { 24 24 } 25 25 … … 71 71 72 72 public static ProfileDescription addProfile(ComponentRegistry testRegistry, String id) throws ParseException, JAXBException { 73 return addProfile(testRegistry, id, TestHelper.getTestProfileContent());73 return addProfile(testRegistry, id, RegistryTestHelper.getTestProfileContent()); 74 74 } 75 75
Note: See TracChangeset
for help on using the changeset viewer.