Changeset 5550
- Timestamp:
- 08/12/14 14:59:10 (10 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java
r5549 r5550 213 213 * @throws DeleteFailedException 214 214 */ 215 public void deleteComment(String commentId) throws IOException, ComponentRegistryException,UserUnauthorizedException,215 public void deleteComment(String commentId) throws IOException, UserUnauthorizedException, 216 216 DeleteFailedException, ItemNotFoundException; 217 217 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r5549 r5550 284 284 return comment; 285 285 } else { 286 // Comment exists in DB, but profile is not in this registry 287 throw new ComponentRegistryException("Comment " + commentId + " cannot be found in specified registry"); 286 throw new ComponentRegistryException("Comment " + commentId + "for the profile "+profileId); 288 287 } 289 288 } catch (DataAccessException ex) { … … 323 322 return comment; 324 323 } else { 325 // Comment does not exists in DB or component is not in this 326 // registry 327 throw new ComponentRegistryException("Comment " + commentId 328 + " cannot be found in specified registry for specified component"); 324 throw new ComponentRegistryException("Comment " + commentId + "for the profile "+componentId); 329 325 } 330 326 } catch (DataAccessException ex) { … … 809 805 810 806 @Override 811 public void deleteComment(String commentId) throws IOException, ComponentRegistryException,807 public void deleteComment(String commentId) throws IOException, 812 808 UserUnauthorizedException, DeleteFailedException, ItemNotFoundException { 813 809 try { … … 822 818 } else { 823 819 // Comment exists in DB, but component is not in this registry 824 throw new ComponentRegistryException("Comment " + commentId + " cannot be found in specified registry");820 throw new ItemNotFoundException("Comment " + commentId + " cannot be found in specified registry"); 825 821 } 826 822 } catch (DataAccessException ex) { -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r5549 r5550 28 28 import clarin.cmdi.componentregistry.rss.RssCreatorDescriptions; 29 29 import com.google.common.collect.Lists; 30 import com.sun.jersey.api.client.ClientResponse; 31 import com.sun.jersey.api.client.UniformInterfaceException; 30 32 31 33 import com.sun.jersey.api.core.InjectParam; … … 311 313 } 312 314 }; 315 return createDownloadResponse(result, fileName); 313 316 } else if ("xsd".equalsIgnoreCase(rawType)) { 314 317 result = new StreamingOutput() { … … 344 347 } 345 348 }; 349 return createDownloadResponse(result, fileName); 346 350 } else { 347 throw new WebApplicationException(Response 348 .serverError() 349 .entity("unsupported rawType: " + rawType 350 + " (only xml or xsd are supported)").build()); 351 return Response.status(Status.NOT_FOUND).entity("Usupported raw type "+rawType).build(); 351 352 } 352 return createDownloadResponse(result, fileName);353 353 354 354 355 } catch (UserUnauthorizedException e2) { … … 876 877 .build(); 877 878 } catch (ItemNotFoundException e) { 878 LOG.warn("Profile with id " + profileId + " is not found.", 879 e); 879 LOG.warn("Profile with id " + profileId + " is not found."); 880 880 return Response.serverError().status(Status.NOT_FOUND) 881 881 .build(); … … 931 931 return Response.serverError().status(Status.FORBIDDEN) 932 932 .entity("" + e.getMessage()).build(); 933 } catch (ComponentRegistryException e) { 934 LOG.info("Could not retrieve component", e); 933 } 934 catch (ComponentRegistryException e) { 935 LOG.info("Could not find comment "+commentId+ " for "+profileId); 935 936 return Response.serverError().status(Status.INTERNAL_SERVER_ERROR) 936 937 .build(); 937 } catch (IOException e) { 938 } 939 catch (IOException e) { 938 940 LOG.error("Comment with id: " + commentId + " deletion failed.", e); 939 941 return Response.serverError().status(Status.INTERNAL_SERVER_ERROR) … … 983 985 return Response.serverError().status(Status.FORBIDDEN) 984 986 .entity("" + e.getMessage()).build(); 985 } catch (ComponentRegistryException e) { 986 LOG.info("Could not retrieve component ", e);987 } catch (ComponentRegistryException e) { 988 LOG.info("Could not retrieve component "+componentId+" for the component "+componentId); 987 989 return Response.serverError().status(Status.INTERNAL_SERVER_ERROR) 988 990 .build(); … … 1012 1014 public Response getRegisteredProfileRawType( 1013 1015 @PathParam("profileId") final String profileId, 1014 @PathParam("rawType") String rawType) throws ComponentRegistryException {1016 @PathParam("rawType") String rawType) throws ComponentRegistryException, IllegalArgumentException { 1015 1017 1016 1018 … … 1064 1066 }; 1065 1067 } else { 1066 throw new WebApplicationException(Response 1067 .serverError() 1068 .entity("unsupported rawType: " + rawType 1069 + " (only xml or xsd are supported)").build()); 1068 return Response.status(Status.NOT_FOUND).entity("Unsupported raw type "+rawType).build(); 1070 1069 } 1071 1070 return createDownloadResponse(result, fileName); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r5549 r5550 24 24 import java.util.Date; 25 25 import java.util.List; 26 import javax.ws.rs.WebApplicationException; 26 27 27 28 import javax.ws.rs.core.MediaType; … … 40 41 * Launches a servlet container environment and performs HTTP calls to the 41 42 * {@link ComponentRegistryRestService} 42 * 43 * 43 44 * @author george.georgovassilis@mpi.nl 44 * 45 * 45 46 */ 46 public class ComponentRegistryRestServiceTest extends 47 ComponentRegistryRestServiceTestCase { 47 public class ComponentRegistryRestServiceTest extends ComponentRegistryRestServiceTestCase { 48 48 49 49 @Autowired … … 57 57 @Before 58 58 public void init() { 59 60 61 59 ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate); 60 createUserRecord(); 61 baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS); 62 62 } 63 63 64 64 private String expectedUserId(String principal) { 65 return getUserDao().getByPrincipalName(principal).getId().toString(); 66 } 67 65 return getUserDao().getByPrincipalName(principal).getId().toString(); 66 } 68 67 private ComponentDescription component1; 69 68 private ComponentDescription component2; 70 69 private ProfileDescription profile1; 71 70 private ProfileDescription profile2; 72 73 71 private ComponentDescription component3; 74 72 private ProfileDescription profile3; 75 76 73 private Comment profile1Comment1; 77 74 private Comment profile1Comment2; 78 75 private Comment component1Comment3; 79 76 private Comment component1Comment4; 80 81 77 private Comment profile3Comment5; 82 78 private Comment component3Comment7; 83 79 84 80 private void fillUpPublicItems() throws Exception { 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 } 105 81 82 profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true); 83 profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true); 84 component1 = RegistryTestHelper.addComponent(baseRegistry, 85 "component2", true); 86 component2 = RegistryTestHelper.addComponent(baseRegistry, 87 "component1", true); 88 profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2", 89 ProfileDescription.PROFILE_PREFIX + "profile1", 90 "JUnit@test.com"); 91 profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1", 92 ProfileDescription.PROFILE_PREFIX + "profile1", 93 "JUnit@test.com"); 94 component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3", 95 ComponentDescription.COMPONENT_PREFIX + "component1", 96 "JUnit@test.com"); 97 component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4", 98 ComponentDescription.COMPONENT_PREFIX + "component1", 99 "JUnit@test.com"); 100 } 101 106 102 private void fillUpPrivateItems() throws Exception { 107 108 109 110 111 112 113 114 115 116 } 117 118 @Test //ok103 profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false); 104 component3 = RegistryTestHelper.addComponent(baseRegistry, 105 "component3", false); 106 profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5", 107 ProfileDescription.PROFILE_PREFIX + "profile3", 108 "JUnit@test.com"); 109 component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7", 110 ComponentDescription.COMPONENT_PREFIX + "component3", 111 "JUnit@test.com"); 112 } 113 114 @Test 119 115 public void testGetPublicProfiles() throws Exception { 120 121 fillUpPublicItems(); 122 123 RegistryTestHelper.addProfile(baseRegistry, "PROFILE2", true); 124 List<ProfileDescription> response = this.getAuthenticatedResource(getResource() 125 .path("/registry/profiles")).accept(MediaType.APPLICATION_XML) 126 .get(PROFILE_LIST_GENERICTYPE); 127 assertEquals(3, response.size()); 128 response = this.getAuthenticatedResource(getResource() 129 .path("/registry/profiles")) 130 .accept(MediaType.APPLICATION_JSON) 131 .get(PROFILE_LIST_GENERICTYPE); 132 assertEquals(3, response.size()); 133 assertEquals("profile1", response.get(0).getName()); 134 assertEquals("PROFILE2", response.get(1).getName()); 135 assertEquals("profile2", response.get(2).getName()); 116 117 System.out.println("testGetPublicProfiles"); 118 119 fillUpPublicItems(); 120 121 RegistryTestHelper.addProfile(baseRegistry, "PROFILE2", true); 122 List<ProfileDescription> response = this.getAuthenticatedResource(getResource() 123 .path("/registry/profiles")).accept(MediaType.APPLICATION_XML) 124 .get(PROFILE_LIST_GENERICTYPE); 125 assertEquals(3, response.size()); 126 response = this.getAuthenticatedResource(getResource() 127 .path("/registry/profiles")) 128 .accept(MediaType.APPLICATION_JSON) 129 .get(PROFILE_LIST_GENERICTYPE); 130 assertEquals(3, response.size()); 131 assertEquals("profile1", response.get(0).getName()); 132 assertEquals("PROFILE2", response.get(1).getName()); 133 assertEquals("profile2", response.get(2).getName()); 136 134 } 137 135 138 136 @Test //ok 139 137 public void testGetPublicComponents() throws Exception { 140 141 fillUpPublicItems(); 142 138 139 System.out.println("testGetPublicComponents"); 140 141 fillUpPublicItems(); 142 143 143 RegistryTestHelper.addComponent(baseRegistry, "COMPONENT2", true); 144 145 146 147 148 149 150 151 152 153 154 155 144 List<ComponentDescription> response = this.getAuthenticatedResource(getResource() 145 .path("/registry/components")).accept(MediaType.APPLICATION_XML) 146 .get(COMPONENT_LIST_GENERICTYPE); 147 assertEquals(3, response.size()); 148 response = this.getAuthenticatedResource(getResource() 149 .path("/registry/components")) 150 .accept(MediaType.APPLICATION_JSON) 151 .get(COMPONENT_LIST_GENERICTYPE); 152 assertEquals(3, response.size()); 153 assertEquals("component1", response.get(0).getName()); 154 assertEquals("COMPONENT2", response.get(1).getName()); 155 assertEquals("component2", response.get(2).getName()); 156 156 } 157 157 158 158 @Test //ok 159 159 public void testGetUserComponents() throws Exception { 160 160 161 System.out.println("testGetUserComponents"); 162 161 163 fillUpPrivateItems(); 162 163 164 165 164 165 List<ComponentDescription> response = this.getUserComponents(); 166 assertEquals(1, response.size()); 167 166 168 //// 167 168 fillUpPublicItems(); 169 170 171 172 173 174 175 176 177 169 170 fillUpPublicItems(); 171 response = getAuthenticatedResource(getResource().path("/registry/components")).accept( 172 MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE); 173 assertEquals("Get public components", 2, response.size()); 174 175 ClientResponse cResponse = getResource().path("/registry/components") 176 .queryParam(REGISTRY_SPACE_PARAM, "private") 177 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); 178 assertEquals("Trying to get userspace without credentials", 401, 179 cResponse.getStatus()); 178 180 } 179 181 180 182 @Test //ok 181 183 public void testGetPublicComponent() throws Exception { 182 183 fillUpPublicItems(); 184 184 185 System.out.println("testGetPublicComponents"); 186 187 fillUpPublicItems(); 188 185 189 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 190 String id2 = ComponentDescription.COMPONENT_PREFIX + "component2"; 191 CMDComponentSpec component = this.getAuthenticatedResource(getResource() 192 .path("/registry/components/" + id)) 193 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 194 assertNotNull(component); 195 assertEquals("Access", component.getCMDComponent().getName()); 196 197 198 component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id2)) 199 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 200 assertNotNull(component); 201 assertEquals("Access", component.getCMDComponent().getName()); 202 assertEquals(id2, component.getHeader().getID()); 203 assertEquals("component2", component.getHeader().getName()); 204 assertEquals("Test Description", component.getHeader().getDescription()); 201 205 } 202 206 203 207 @Test // ok 204 208 public void testGetCommentsInPublicProfile() throws Exception { 205 206 fillUpPublicItems(); 207 208 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 209 RegistryTestHelper.addComment(baseRegistry, "COMMENT1", id, 210 "JUnit@test.com"); 211 List<Comment> response = this.getAuthenticatedResource(getResource() 212 .path("/registry/profiles/" + id + "/comments/")) 213 .accept(MediaType.APPLICATION_XML) 214 .get(COMMENT_LIST_GENERICTYPE); 215 assertEquals(3, response.size()); 216 217 response = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id + "/comments")) 218 .accept(MediaType.APPLICATION_JSON) 219 .get(COMMENT_LIST_GENERICTYPE); 220 assertEquals(3, response.size()); 221 assertEquals("comment2", response.get(0).getComment()); 222 assertEquals("comment1", response.get(1).getComment()); 223 assertEquals("COMMENT1", response.get(2).getComment()); 224 225 assertEquals("Database test user", response.get(0).getUserName()); 209 210 System.out.println("testGetCommentsInPublicPrfile"); 211 212 fillUpPublicItems(); 213 214 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 215 RegistryTestHelper.addComment(baseRegistry, "COMMENT1", id, 216 "JUnit@test.com"); 217 List<Comment> response = this.getAuthenticatedResource(getResource() 218 .path("/registry/profiles/" + id + "/comments/")) 219 .accept(MediaType.APPLICATION_XML) 220 .get(COMMENT_LIST_GENERICTYPE); 221 assertEquals(3, response.size()); 222 223 response = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id + "/comments")) 224 .accept(MediaType.APPLICATION_JSON) 225 .get(COMMENT_LIST_GENERICTYPE); 226 assertEquals(3, response.size()); 227 assertEquals("comment2", response.get(0).getComment()); 228 assertEquals("comment1", response.get(1).getComment()); 229 assertEquals("COMMENT1", response.get(2).getComment()); 230 231 assertEquals("Database test user", response.get(0).getUserName()); 226 232 } 227 233 228 234 @Test // ok 229 235 public void testGetCommentsInPubliComponent() throws Exception { 230 fillUpPublicItems(); 231 232 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 233 RegistryTestHelper.addComment(baseRegistry, "COMMENT2", id, 234 "JUnit@test.com"); 235 List<Comment> response = this.getAuthenticatedResource(getResource() 236 .path("/registry/components/" + id + "/comments/")) 237 .accept(MediaType.APPLICATION_XML) 238 .get(COMMENT_LIST_GENERICTYPE); 239 assertEquals(3, response.size()); 240 response = this.getAuthenticatedResource(getResource() 241 .path("/registry/components/" + id + "/comments")) 242 .accept(MediaType.APPLICATION_JSON) 243 .get(COMMENT_LIST_GENERICTYPE); 244 assertEquals(3, response.size()); 245 assertEquals("comment3", response.get(0).getComment()); 246 assertEquals("comment4", response.get(1).getComment()); 247 assertEquals("COMMENT2", response.get(2).getComment()); 248 249 assertEquals("Database test user", response.get(0).getUserName()); 236 237 System.out.println("testGetCoomentsInPublicComponent"); 238 239 fillUpPublicItems(); 240 241 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 242 RegistryTestHelper.addComment(baseRegistry, "COMMENT2", id, 243 "JUnit@test.com"); 244 List<Comment> response = this.getAuthenticatedResource(getResource() 245 .path("/registry/components/" + id + "/comments/")) 246 .accept(MediaType.APPLICATION_XML) 247 .get(COMMENT_LIST_GENERICTYPE); 248 assertEquals(3, response.size()); 249 response = this.getAuthenticatedResource(getResource() 250 .path("/registry/components/" + id + "/comments")) 251 .accept(MediaType.APPLICATION_JSON) 252 .get(COMMENT_LIST_GENERICTYPE); 253 assertEquals(3, response.size()); 254 assertEquals("comment3", response.get(0).getComment()); 255 assertEquals("comment4", response.get(1).getComment()); 256 assertEquals("COMMENT2", response.get(2).getComment()); 257 258 assertEquals("Database test user", response.get(0).getUserName()); 250 259 } 251 260 252 261 @Test // ok 253 262 public void testGetSpecifiedCommentInPublicComponent() throws Exception { 254 255 fillUpPublicItems(); 256 257 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 258 Comment comment = this.getAuthenticatedResource(getResource() 259 .path("/registry/components/" + id + "/comments/"+component1Comment3.getId())) 260 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 261 assertNotNull(comment); 262 assertEquals("comment3", comment.getComment()); 263 assertEquals(component1Comment3.getId(), comment.getId()); 264 comment = this.getAuthenticatedResource(getResource() 265 .path("/registry/components/" + id + "/comments/"+component1Comment4.getId())) 266 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 267 assertNotNull(comment); 268 assertEquals("comment4", comment.getComment()); 269 assertEquals(component1Comment4.getId(), comment.getId()); 270 assertEquals(id, comment.getComponentId()); 263 264 System.out.println("testSpecifiedCommentInPublicComponent"); 265 266 fillUpPublicItems(); 267 268 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 269 Comment comment = this.getAuthenticatedResource(getResource() 270 .path("/registry/components/" + id + "/comments/" + component1Comment3.getId())) 271 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 272 assertNotNull(comment); 273 assertEquals("comment3", comment.getComment()); 274 assertEquals(component1Comment3.getId(), comment.getId()); 275 comment = this.getAuthenticatedResource(getResource() 276 .path("/registry/components/" + id + "/comments/" + component1Comment4.getId())) 277 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 278 assertNotNull(comment); 279 assertEquals("comment4", comment.getComment()); 280 assertEquals(component1Comment4.getId(), comment.getId()); 281 assertEquals(id, comment.getComponentId()); 271 282 } 272 283 273 284 @Test //ok 274 285 public void testGetSpecifiedCommentInPublicProfile() throws Exception { 275 276 fillUpPublicItems(); 277 278 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 279 Comment comment = this.getAuthenticatedResource(getResource() 280 .path("/registry/profiles/" + id + "/comments/"+profile1Comment2.getId())) 281 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 282 assertNotNull(comment); 283 assertEquals("comment2", comment.getComment()); 284 assertEquals(profile1Comment2.getId(), comment.getId()); 285 286 comment = this.getAuthenticatedResource(getResource() 287 .path("/registry/profiles/" + id + "/comments/"+profile1Comment1.getId())) 286 287 System.out.println("testGetSpecifiedCoomentInPublicProfile"); 288 289 fillUpPublicItems(); 290 291 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 292 Comment comment = this.getAuthenticatedResource(getResource() 293 .path("/registry/profiles/" + id + "/comments/" + profile1Comment2.getId())) 288 294 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 289 assertNotNull(comment); 290 assertEquals("comment1", comment.getComment()); 291 assertEquals(profile1Comment1.getId(), comment.getId()); 292 assertEquals(id, comment.getComponentId()); 295 assertNotNull(comment); 296 assertEquals("comment2", comment.getComment()); 297 assertEquals(profile1Comment2.getId(), comment.getId()); 298 299 comment = this.getAuthenticatedResource(getResource() 300 .path("/registry/profiles/" + id + "/comments/" + profile1Comment1.getId())) 301 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 302 assertNotNull(comment); 303 assertEquals("comment1", comment.getComment()); 304 assertEquals(profile1Comment1.getId(), comment.getId()); 305 assertEquals(id, comment.getComponentId()); 293 306 } 294 307 295 308 @Test //ok 296 309 public void testDeleteCommentFromPublicComponent() throws Exception { 297 298 fillUpPublicItems(); 299 300 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 301 String id2 = ComponentDescription.COMPONENT_PREFIX + "component2"; 302 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 303 "/registry/components/" + id + "/comments")).get( 304 COMMENT_LIST_GENERICTYPE); 305 assertEquals(2, comments.size()); 306 Comment aComment = this.getAuthenticatedResource(getResource().path( 307 "/registry/components/" + id + "/comments/"+component1Comment3.getId())) 308 .get(Comment.class); 309 assertNotNull(aComment); 310 311 // Try to delete from other component 312 ClientResponse response = getAuthenticatedResource( 313 "/registry/components/" + id2 + "/comments/"+component1Comment4.getId()).delete( 314 ClientResponse.class); 315 assertEquals(500, response.getStatus()); 316 // Delete from correct component 317 response = getAuthenticatedResource( 318 "/registry/components/" + id + "/comments/"+component1Comment3.getId()).delete( 319 ClientResponse.class); 320 assertEquals(200, response.getStatus()); 321 322 comments = this.getAuthenticatedResource(getResource().path( 323 "/registry/components/" + id + "/comments/")).get( 324 COMMENT_LIST_GENERICTYPE); 325 assertEquals(1, comments.size()); 326 327 response = getAuthenticatedResource( 328 "/registry/components/" + id + "/comments/"+component1Comment4.getId()).delete( 329 ClientResponse.class); 330 assertEquals(200, response.getStatus()); 331 332 comments = this.getAuthenticatedResource(getResource().path( 333 "/registry/components/" + id + "/comments")).get( 334 COMMENT_LIST_GENERICTYPE); 335 assertEquals(0, comments.size()); 310 311 System.out.println("testDeleteCommentFromPublicComponent"); 312 313 fillUpPublicItems(); 314 315 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 316 String id2 = ComponentDescription.COMPONENT_PREFIX + "component2"; 317 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 318 "/registry/components/" + id + "/comments")).get( 319 COMMENT_LIST_GENERICTYPE); 320 assertEquals(2, comments.size()); 321 Comment aComment = this.getAuthenticatedResource(getResource().path( 322 "/registry/components/" + id + "/comments/" + component1Comment3.getId())) 323 .get(Comment.class); 324 assertNotNull(aComment); 325 326 // Try to delete from other component 327 ClientResponse response = getAuthenticatedResource( 328 "/registry/components/" + id2 + "/comments/" + component1Comment4.getId()).delete( 329 ClientResponse.class); 330 assertEquals(500, response.getStatus()); 331 // Delete from correct component 332 response = getAuthenticatedResource( 333 "/registry/components/" + id + "/comments/" + component1Comment3.getId()).delete( 334 ClientResponse.class); 335 assertEquals(200, response.getStatus()); 336 337 comments = this.getAuthenticatedResource(getResource().path( 338 "/registry/components/" + id + "/comments/")).get( 339 COMMENT_LIST_GENERICTYPE); 340 assertEquals(1, comments.size()); 341 342 response = getAuthenticatedResource( 343 "/registry/components/" + id + "/comments/" + component1Comment4.getId()).delete( 344 ClientResponse.class); 345 assertEquals(200, response.getStatus()); 346 347 comments = this.getAuthenticatedResource(getResource().path( 348 "/registry/components/" + id + "/comments")).get( 349 COMMENT_LIST_GENERICTYPE); 350 assertEquals(0, comments.size()); 336 351 } 337 352 338 353 @Test 339 354 public void testManipulateCommentFromPublicComponent() throws Exception { 340 341 fillUpPublicItems(); 342 343 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 344 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 345 + "component1/comments")).get(COMMENT_LIST_GENERICTYPE); 346 assertEquals(2, comments.size()); 347 Comment aComment = this.getAuthenticatedResource(getResource().path( 348 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 349 + "component1/comments/"+component1Comment3.getId())).get(Comment.class); 350 assertNotNull(aComment); 351 352 Form manipulateForm = new Form(); 353 manipulateForm.add("method", "delete"); 354 355 // Try to delete from other component 356 ClientResponse response = getAuthenticatedResource( 357 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 358 + "component1/comments/"+component1Comment3.getId()).post(ClientResponse.class, 359 manipulateForm); 360 assertEquals(200, response.getStatus()); 361 362 comments = this.getAuthenticatedResource(getResource().path( 363 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 364 + "component1/comments/")).get(COMMENT_LIST_GENERICTYPE); 365 assertEquals(1, comments.size()); 355 356 System.out.println("testManipulateCommentFromPublicComponent"); 357 358 fillUpPublicItems(); 359 360 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 361 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 362 + "component1/comments")).get(COMMENT_LIST_GENERICTYPE); 363 assertEquals(2, comments.size()); 364 Comment aComment = this.getAuthenticatedResource(getResource().path( 365 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 366 + "component1/comments/" + component1Comment3.getId())).get(Comment.class); 367 assertNotNull(aComment); 368 369 Form manipulateForm = new Form(); 370 manipulateForm.add("method", "delete"); 371 372 // Try to delete from other component 373 ClientResponse response = getAuthenticatedResource( 374 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 375 + "component1/comments/" + component1Comment3.getId()).post(ClientResponse.class, 376 manipulateForm); 377 assertEquals(200, response.getStatus()); 378 379 comments = this.getAuthenticatedResource(getResource().path( 380 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 381 + "component1/comments/")).get(COMMENT_LIST_GENERICTYPE); 382 assertEquals(1, comments.size()); 366 383 } 367 384 368 385 @Test 369 386 public void testDeleteCommentFromPublicProfile() throws Exception { 370 371 fillUpPublicItems(); 372 373 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 374 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 375 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 376 assertEquals(2, comments.size()); 377 Comment aComment = this.getAuthenticatedResource(getResource().path( 378 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 379 + "profile1/comments/"+profile1Comment1.getId())).get(Comment.class); 380 assertNotNull(aComment); 381 382 // Try to delete from other profile 383 ClientResponse response = getAuthenticatedResource( 384 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 385 + "profile2/comments/9999").delete(ClientResponse.class); 386 assertEquals(500, response.getStatus()); 387 // Delete from correct profile 388 response = getAuthenticatedResource( 389 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 390 + "profile1/comments/"+profile1Comment1.getId()).delete(ClientResponse.class); 391 assertEquals(200, response.getStatus()); 392 393 comments = this.getAuthenticatedResource(getResource().path( 394 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 395 + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE); 396 assertEquals(1, comments.size()); 397 398 response = getAuthenticatedResource( 399 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 400 + "profile1/comments/"+profile1Comment2.getId()).delete(ClientResponse.class); 401 assertEquals(200, response.getStatus()); 402 403 comments = this.getAuthenticatedResource(getResource().path( 404 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 405 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 406 assertEquals(0, comments.size()); 387 388 System.out.println("testDeleteCommentFromPublicProfile"); 389 390 fillUpPublicItems(); 391 392 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 393 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 394 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 395 assertEquals(2, comments.size()); 396 Comment aComment = this.getAuthenticatedResource(getResource().path( 397 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 398 + "profile1/comments/" + profile1Comment1.getId())).get(Comment.class); 399 assertNotNull(aComment); 400 401 // Try to delete from other profile 402 ClientResponse response = getAuthenticatedResource( 403 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 404 + "profile2/comments/9999").delete(ClientResponse.class); 405 assertEquals(500, response.getStatus()); 406 // Delete from correct profile 407 response = getAuthenticatedResource( 408 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 409 + "profile1/comments/" + profile1Comment1.getId()).delete(ClientResponse.class); 410 assertEquals(200, response.getStatus()); 411 412 comments = this.getAuthenticatedResource(getResource().path( 413 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 414 + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE); 415 assertEquals(1, comments.size()); 416 417 response = getAuthenticatedResource( 418 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 419 + "profile1/comments/" + profile1Comment2.getId()).delete(ClientResponse.class); 420 assertEquals(200, response.getStatus()); 421 422 comments = this.getAuthenticatedResource(getResource().path( 423 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 424 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 425 assertEquals(0, comments.size()); 407 426 } 408 427 409 428 @Test 410 429 public void testManipulateCommentFromPublicProfile() throws Exception { 411 412 fillUpPublicItems(); 413 414 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 415 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 416 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 417 assertEquals(2, comments.size()); 418 Comment aComment = this.getAuthenticatedResource(getResource().path( 419 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 420 + "profile1/comments/"+profile1Comment2.getId())).get(Comment.class); 421 assertNotNull(aComment); 422 423 Form manipulateForm = new Form(); 424 manipulateForm.add("method", "delete"); 425 // Delete from correct profile 426 ClientResponse response = getAuthenticatedResource( 427 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 428 + "profile1/comments/"+profile1Comment2.getId()).post(ClientResponse.class, 429 manipulateForm); 430 assertEquals(200, response.getStatus()); 431 432 comments = this.getAuthenticatedResource(getResource().path( 433 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 434 + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE); 435 assertEquals(1, comments.size()); 430 431 System.out.println("testManipulatreCommentFromPublicProfile"); 432 433 fillUpPublicItems(); 434 435 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 436 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 437 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 438 assertEquals(2, comments.size()); 439 Comment aComment = this.getAuthenticatedResource(getResource().path( 440 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 441 + "profile1/comments/" + profile1Comment2.getId())).get(Comment.class); 442 assertNotNull(aComment); 443 444 Form manipulateForm = new Form(); 445 manipulateForm.add("method", "delete"); 446 // Delete from correct profile 447 ClientResponse response = getAuthenticatedResource( 448 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 449 + "profile1/comments/" + profile1Comment2.getId()).post(ClientResponse.class, 450 manipulateForm); 451 assertEquals(200, response.getStatus()); 452 453 comments = this.getAuthenticatedResource(getResource().path( 454 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 455 + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE); 456 assertEquals(1, comments.size()); 436 457 } 437 458 438 459 @Test 439 460 public void testDeletePublicComponent() throws Exception { 440 441 fillUpPublicItems(); 442 443 List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( 444 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); 445 assertEquals(2, components.size()); 446 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 447 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 448 + "component1")).get(CMDComponentSpec.class); 449 assertNotNull(profile); 450 ClientResponse response = getAuthenticatedResource( 451 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 452 + "component1").delete(ClientResponse.class); 453 assertEquals(200, response.getStatus()); 454 455 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 456 COMPONENT_LIST_GENERICTYPE); 457 assertEquals(1, components.size()); 458 459 response = getAuthenticatedResource( 460 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 461 + "component2").delete(ClientResponse.class); 462 assertEquals(200, response.getStatus()); 463 464 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 465 COMPONENT_LIST_GENERICTYPE); 466 assertEquals(0, components.size()); 467 468 response = getAuthenticatedResource( 469 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 470 + "component1").delete(ClientResponse.class); 471 assertEquals(200, response.getStatus()); 461 462 System.out.println("testDeletePublicComponent"); 463 464 fillUpPublicItems(); 465 466 List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( 467 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); 468 assertEquals(2, components.size()); 469 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 470 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 471 + "component1")).get(CMDComponentSpec.class); 472 assertNotNull(profile); 473 ClientResponse response = getAuthenticatedResource( 474 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 475 + "component1").delete(ClientResponse.class); 476 assertEquals(200, response.getStatus()); 477 478 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 479 COMPONENT_LIST_GENERICTYPE); 480 assertEquals(1, components.size()); 481 482 response = getAuthenticatedResource( 483 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 484 + "component2").delete(ClientResponse.class); 485 assertEquals(200, response.getStatus()); 486 487 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 488 COMPONENT_LIST_GENERICTYPE); 489 assertEquals(0, components.size()); 490 491 response = getAuthenticatedResource( 492 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 493 + "component1").delete(ClientResponse.class); 494 assertEquals(200, response.getStatus()); 472 495 } 473 496 474 497 @Test 475 498 public void testDeletePublicComponentStillUsed() throws Exception { 476 477 fillUpPublicItems(); 478 499 500 System.out.println("testDeletePublicComponentStillUsed"); 501 502 fillUpPublicItems(); 503 479 504 String content = ""; 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 baseRegistry, "YYY1", content,true);502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 505 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 506 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 507 content += " <Header/>\n"; 508 content += " <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n"; 509 content += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 510 content += " </CMD_Component>\n"; 511 content += "</CMD_ComponentSpec>\n"; 512 ComponentDescription compDesc1 = RegistryTestHelper.addComponent( 513 baseRegistry, "XXX1", content, true); 514 515 content = ""; 516 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 517 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 518 content += " <Header/>\n"; 519 content += " <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 520 content += " <CMD_Component ComponentId=\"" + compDesc1.getId() 521 + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 522 content += " </CMD_Component>\n"; 523 content += " </CMD_Component>\n"; 524 content += "</CMD_ComponentSpec>\n"; 525 ComponentDescription compDesc2 = RegistryTestHelper.addComponent( 526 baseRegistry, "YYY1", content, true); 527 528 content = ""; 529 content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 530 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 531 content += " <Header/>\n"; 532 content += " <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 533 content += " <CMD_Component ComponentId=\"" + compDesc1.getId() 534 + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 535 content += " </CMD_Component>\n"; 536 content += " </CMD_Component>\n"; 537 content += "</CMD_ComponentSpec>\n"; 538 ProfileDescription profile = RegistryTestHelper.addProfile( 539 baseRegistry, "TestProfile3", content, true); 540 541 List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( 542 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); 543 assertEquals(4, components.size()); 544 545 ClientResponse response = getAuthenticatedResource( 546 "/registry/components/" + compDesc1.getId()).delete( 547 ClientResponse.class); 548 assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus()); 549 assertEquals( 550 "Component is still in use by other components or profiles. Request component usage for details.", 551 response.getEntity(String.class)); 552 553 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 554 COMPONENT_LIST_GENERICTYPE); 555 assertEquals(4, components.size()); 556 557 response = getAuthenticatedResource( 558 "/registry/profiles/" + profile.getId()).delete( 559 ClientResponse.class); 560 assertEquals(200, response.getStatus()); 561 response = getAuthenticatedResource( 562 "/registry/components/" + compDesc2.getId()).delete( 563 ClientResponse.class); 564 assertEquals(200, response.getStatus()); 565 response = getAuthenticatedResource( 566 "/registry/components/" + compDesc1.getId()).delete( 567 ClientResponse.class); 568 assertEquals(200, response.getStatus()); 569 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 570 COMPONENT_LIST_GENERICTYPE); 571 assertEquals(2, components.size()); 547 572 } 548 573 549 574 @Test 550 575 public void testManipulatePublicComponent() throws Exception { 551 552 fillUpPublicItems(); 553 554 List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( 555 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); 556 assertEquals(2, components.size()); 557 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 558 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 559 + "component1")).get(CMDComponentSpec.class); 560 assertNotNull(profile); 561 562 Form manipulateForm = new Form(); 563 manipulateForm.add("method", "delete"); 564 565 ClientResponse response = getAuthenticatedResource( 566 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 567 + "component1").post(ClientResponse.class, 568 manipulateForm); 569 assertEquals(200, response.getStatus()); 570 571 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 572 COMPONENT_LIST_GENERICTYPE); 573 assertEquals(1, components.size()); 574 575 response = getAuthenticatedResource( 576 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 577 + "component2").post(ClientResponse.class, 578 manipulateForm); 579 assertEquals(200, response.getStatus()); 576 577 System.out.println("testManipulatePublicComponent"); 578 579 fillUpPublicItems(); 580 581 List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( 582 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); 583 assertEquals(2, components.size()); 584 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 585 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 586 + "component1")).get(CMDComponentSpec.class); 587 assertNotNull(profile); 588 589 Form manipulateForm = new Form(); 590 manipulateForm.add("method", "delete"); 591 592 ClientResponse response = getAuthenticatedResource( 593 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 594 + "component1").post(ClientResponse.class, 595 manipulateForm); 596 assertEquals(200, response.getStatus()); 597 598 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 599 COMPONENT_LIST_GENERICTYPE); 600 assertEquals(1, components.size()); 601 602 response = getAuthenticatedResource( 603 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 604 + "component2").post(ClientResponse.class, 605 manipulateForm); 606 assertEquals(200, response.getStatus()); 580 607 } 581 608 582 609 @Test 583 610 public void testGetRegisteredProfile() throws Exception { 584 585 fillUpPublicItems(); 586 587 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 588 String id2 = ProfileDescription.PROFILE_PREFIX + "profile2"; 589 CMDComponentSpec profile = this.getAuthenticatedResource(getResource() 590 .path("/registry/profiles/" + id)) 591 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 592 assertNotNull(profile); 593 assertEquals("Actor", profile.getCMDComponent().getName()); 594 profile = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id2)) 595 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 596 assertNotNull(profile); 597 assertEquals("Actor", profile.getCMDComponent().getName()); 598 599 assertEquals(id2, profile.getHeader().getID()); 600 assertEquals("profile2", profile.getHeader().getName()); 601 assertEquals("Test Description", profile.getHeader().getDescription()); 602 603 try { 604 profile = this.getAuthenticatedResource(getResource() 605 .path("/registry/profiles/" 606 + ProfileDescription.PROFILE_PREFIX + "profileXXXX")) 607 .accept(MediaType.APPLICATION_XML) 608 .get(CMDComponentSpec.class); 609 fail("Exception should have been thrown resource does not exist, HttpStatusCode 404"); 610 } catch (UniformInterfaceException e) { 611 assertEquals(404, e.getResponse().getStatus()); 612 } 613 } 614 615 @Test 616 public void testGetRegisteredProfileRawData() throws Exception { 617 618 fillUpPublicItems(); 619 620 String profile = this.getAuthenticatedResource(getResource() 621 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 622 + "profile1/xsd")).accept(MediaType.TEXT_XML) 623 .get(String.class).trim(); 624 assertTrue(profile 625 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); 626 assertTrue(profile.endsWith("</xs:schema>")); 627 628 profile = this.getAuthenticatedResource(getResource() 629 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 630 + "profile1/xml")).accept(MediaType.TEXT_XML) 631 .get(String.class).trim(); 632 assertTrue(profile 633 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); 634 assertTrue(profile.endsWith("</CMD_ComponentSpec>")); 635 assertTrue(profile.contains("xsi:schemaLocation")); 636 637 try { 638 this.getAuthenticatedResource(getResource() 639 .path("/registry/components/" 640 + ComponentDescription.COMPONENT_PREFIX 641 + "component1/xsl")).accept(MediaType.TEXT_XML) 642 .get(String.class); 643 fail("Should have thrown exception, unsupported path parameter"); 644 } catch (UniformInterfaceException e) {// server error 645 } 611 612 System.out.println("testGetRegisteredProfile"); 613 614 fillUpPublicItems(); 615 616 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 617 String id2 = ProfileDescription.PROFILE_PREFIX + "profile2"; 618 CMDComponentSpec profile = this.getAuthenticatedResource(getResource() 619 .path("/registry/profiles/" + id)) 620 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 621 assertNotNull(profile); 622 assertEquals("Actor", profile.getCMDComponent().getName()); 623 profile = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id2)) 624 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 625 assertNotNull(profile); 626 assertEquals("Actor", profile.getCMDComponent().getName()); 627 628 assertEquals(id2, profile.getHeader().getID()); 629 assertEquals("profile2", profile.getHeader().getName()); 630 assertEquals("Test Description", profile.getHeader().getDescription()); 631 632 try { 633 profile = this.getAuthenticatedResource(getResource() 634 .path("/registry/profiles/" 635 + ProfileDescription.PROFILE_PREFIX + "profileXXXX")) 636 .accept(MediaType.APPLICATION_XML) 637 .get(CMDComponentSpec.class); 638 fail("Exception should have been thrown resource does not exist, HttpStatusCode 404"); 639 } catch (UniformInterfaceException e) { 640 assertEquals(404, e.getResponse().getStatus()); 641 } 642 } 643 644 @Test 645 public void testGetRegisteredProfileRawData() { 646 647 System.out.println("testGetRegisteredProfileRawData"); 648 649 try { 650 fillUpPublicItems(); 651 } catch (Exception e) { 652 System.out.println("test fails due to exception: " + e.getMessage()); 653 return; 654 } 655 656 String profile = this.getAuthenticatedResource(getResource() 657 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 658 + "profile1/xsd")).accept(MediaType.TEXT_XML) 659 .get(String.class).trim(); 660 assertTrue(profile 661 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); 662 assertTrue(profile.endsWith("</xs:schema>")); 663 664 profile = this.getAuthenticatedResource(getResource() 665 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 666 + "profile1/xml")).accept(MediaType.TEXT_XML) 667 .get(String.class).trim(); 668 assertTrue(profile 669 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); 670 assertTrue(profile.endsWith("</CMD_ComponentSpec>")); 671 assertTrue(profile.contains("xsi:schemaLocation")); 672 673 674 ClientResponse respie = this.getAuthenticatedResource(getResource() 675 .path("/registry/profiles/" 676 + ProfileDescription.PROFILE_PREFIX 677 + "profile1/xsl")).accept(MediaType.TEXT_XML).head(); 678 assertEquals(404, respie.getStatus()); 646 679 } 647 680 648 681 // 649 682 @Test 650 public void testPrivateProfileXsd() throws Exception { 651 652 fillUpPublicItems(); 653 654 FormDataMultiPart form = createFormData(RegistryTestHelper 655 .getTestProfileContent()); 656 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam( 657 REGISTRY_SPACE_PARAM, "private")).type( 658 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 659 form); 660 assertTrue(response.isProfile()); 661 assertEquals(1, getUserProfiles().size()); 662 BaseDescription desc = response.getDescription(); 663 String profile = this.getAuthenticatedResource(getResource() 664 .path("/registry/profiles/" + desc.getId() + "/xsd")) 665 .accept(MediaType.TEXT_XML).get(String.class).trim(); 666 assertTrue(profile 667 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); 668 assertTrue(profile.endsWith("</xs:schema>")); 683 public void testPrivateProfileXsd() { 684 685 System.out.println("testPrivateProfileXsd"); 686 687 try { 688 fillUpPublicItems(); 689 } catch (Exception e) { 690 System.out.println("test fails due to exception: " + e.getMessage()); 691 return; 692 } 693 694 FormDataMultiPart form = createFormData(RegistryTestHelper 695 .getTestProfileContent()); 696 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam( 697 REGISTRY_SPACE_PARAM, "private")).type( 698 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 699 form); 700 assertTrue(response.isProfile()); 701 assertEquals(1, getUserProfiles().size()); 702 BaseDescription desc = response.getDescription(); 703 String profile = this.getAuthenticatedResource(getResource() 704 .path("/registry/profiles/" + desc.getId() + "/xsd")) 705 .accept(MediaType.TEXT_XML).get(String.class).trim(); 706 assertTrue(profile 707 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); 708 assertTrue(profile.endsWith("</xs:schema>")); 669 709 } 670 710 671 711 @Test 672 712 public void testPrivateComponentXsd() throws Exception { 673 674 fillUpPublicItems(); 675 676 FormDataMultiPart form = createFormData(RegistryTestHelper 677 .getComponentTestContent()); 678 RegisterResponse response = getAuthenticatedResource( 679 getResource().path("/registry/components").queryParam( 680 REGISTRY_SPACE_PARAM, "private")).type( 681 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 682 form); 683 assertFalse(response.isProfile()); 684 assertEquals(1, getUserComponents().size()); 685 BaseDescription desc = response.getDescription(); 686 String profile = this.getAuthenticatedResource(getResource() 687 .path("/registry/components/" + desc.getId() + "/xsd")) 688 .accept(MediaType.TEXT_XML).get(String.class).trim(); 689 assertTrue(profile 690 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); 691 assertTrue(profile.endsWith("</xs:schema>")); 713 714 System.out.println("testPrivateComponentXsd"); 715 716 fillUpPublicItems(); 717 718 FormDataMultiPart form = createFormData(RegistryTestHelper 719 .getComponentTestContent()); 720 RegisterResponse response = getAuthenticatedResource( 721 getResource().path("/registry/components").queryParam( 722 REGISTRY_SPACE_PARAM, "private")).type( 723 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 724 form); 725 assertFalse(response.isProfile()); 726 assertEquals(1, getUserComponents().size()); 727 BaseDescription desc = response.getDescription(); 728 String profile = this.getAuthenticatedResource(getResource() 729 .path("/registry/components/" + desc.getId() + "/xsd")) 730 .accept(MediaType.TEXT_XML).get(String.class).trim(); 731 assertTrue(profile 732 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); 733 assertTrue(profile.endsWith("</xs:schema>")); 692 734 } 693 735 694 736 @Test 695 737 public void testDeleteRegisteredProfile() throws Exception { 696 697 fillUpPublicItems(); 698 699 List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path( 700 "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE); 701 assertEquals(2, profiles.size()); 702 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 703 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 704 + "profile1")).get(CMDComponentSpec.class); 705 assertNotNull(profile); 706 707 ClientResponse response = getAuthenticatedResource( 708 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 709 + "profile1").delete(ClientResponse.class); 710 assertEquals(200, response.getStatus()); 711 712 profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( 713 PROFILE_LIST_GENERICTYPE); 714 assertEquals(1, profiles.size()); 715 716 response = getAuthenticatedResource( 717 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 718 + "profile2").delete(ClientResponse.class); 719 assertEquals(200, response.getStatus()); 720 721 profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( 722 PROFILE_LIST_GENERICTYPE); 723 assertEquals(0, profiles.size()); 724 725 response = getAuthenticatedResource( 726 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 727 + "profile1").delete(ClientResponse.class); 728 assertEquals(404, response.getStatus()); 738 739 System.out.println("testDeleteRegistredProfile"); 740 741 fillUpPublicItems(); 742 743 List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path( 744 "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE); 745 assertEquals(2, profiles.size()); 746 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 747 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 748 + "profile1")).get(CMDComponentSpec.class); 749 assertNotNull(profile); 750 751 ClientResponse response = getAuthenticatedResource( 752 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 753 + "profile1").delete(ClientResponse.class); 754 assertEquals(200, response.getStatus()); 755 756 profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( 757 PROFILE_LIST_GENERICTYPE); 758 assertEquals(1, profiles.size()); 759 760 response = getAuthenticatedResource( 761 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 762 + "profile2").delete(ClientResponse.class); 763 assertEquals(200, response.getStatus()); 764 765 profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( 766 PROFILE_LIST_GENERICTYPE); 767 assertEquals(0, profiles.size()); 768 769 response = getAuthenticatedResource( 770 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 771 + "profile1").delete(ClientResponse.class); 772 assertEquals(404, response.getStatus()); 729 773 } 730 774 731 775 @Test 732 776 public void testManipulateRegisteredProfile() throws Exception { 733 734 fillUpPublicItems(); 735 736 List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path( 737 "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE); 738 assertEquals(2, profiles.size()); 739 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 740 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 741 + "profile1")).get(CMDComponentSpec.class); 742 assertNotNull(profile); 743 744 Form manipulateForm = new Form(); 745 manipulateForm.add("method", "delete"); 746 747 ClientResponse response = getAuthenticatedResource( 748 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 749 + "profile1") 750 .post(ClientResponse.class, manipulateForm); 751 assertEquals(200, response.getStatus()); 752 753 profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( 754 PROFILE_LIST_GENERICTYPE); 755 assertEquals(1, profiles.size()); 756 757 response = getAuthenticatedResource( 758 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 759 + "profile2") 760 .post(ClientResponse.class, manipulateForm); 761 assertEquals(200, response.getStatus()); 777 778 System.out.println("testManipulateRegisteredProfile"); 779 780 fillUpPublicItems(); 781 782 List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path( 783 "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE); 784 assertEquals(2, profiles.size()); 785 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 786 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 787 + "profile1")).get(CMDComponentSpec.class); 788 assertNotNull(profile); 789 790 Form manipulateForm = new Form(); 791 manipulateForm.add("method", "delete"); 792 793 ClientResponse response = getAuthenticatedResource( 794 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 795 + "profile1") 796 .post(ClientResponse.class, manipulateForm); 797 assertEquals(200, response.getStatus()); 798 799 profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( 800 PROFILE_LIST_GENERICTYPE); 801 assertEquals(1, profiles.size()); 802 803 response = getAuthenticatedResource( 804 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 805 + "profile2") 806 .post(ClientResponse.class, manipulateForm); 807 assertEquals(200, response.getStatus()); 762 808 } 763 809 764 810 @Test 765 811 public void testGetRegisteredComponentRawData() throws Exception { 766 767 fillUpPublicItems(); 768 769 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 770 String component = this.getAuthenticatedResource(getResource() 771 .path("/registry/components/" + id + "/xsd")) 772 .accept(MediaType.TEXT_XML).get(String.class).trim(); 773 assertTrue(component 774 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); 775 assertTrue(component.endsWith("</xs:schema>")); 776 777 component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id + "/xml")) 778 .accept(MediaType.TEXT_XML).get(String.class).trim(); 779 assertTrue(component 780 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); 781 assertTrue(component.endsWith("</CMD_ComponentSpec>")); 782 assertTrue(component.contains("xsi:schemaLocation")); 783 784 try { 785 this.getAuthenticatedResource(getResource() 786 .path("/registry/components/" 787 + ComponentDescription.COMPONENT_PREFIX 788 + "component1/jpg")).accept(MediaType.TEXT_XML) 789 .get(String.class); 790 fail("Should have thrown exception, unsopported path parameter"); 791 } catch (UniformInterfaceException e) { 792 } 812 813 System.out.println("testGetRegisteredComponentRawData"); 814 815 fillUpPublicItems(); 816 817 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 818 String component = this.getAuthenticatedResource(getResource() 819 .path("/registry/components/" + id + "/xsd")) 820 .accept(MediaType.TEXT_XML).get(String.class).trim(); 821 assertTrue(component 822 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); 823 assertTrue(component.endsWith("</xs:schema>")); 824 825 component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id + "/xml")) 826 .accept(MediaType.TEXT_XML).get(String.class).trim(); 827 assertTrue(component 828 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); 829 assertTrue(component.endsWith("</CMD_ComponentSpec>")); 830 assertTrue(component.contains("xsi:schemaLocation")); 831 832 ClientResponse respie = this.getAuthenticatedResource(getResource() 833 .path("/registry/components/" 834 + ComponentDescription.COMPONENT_PREFIX 835 + "component1/jpg")).accept(MediaType.TEXT_XML) 836 .head(); 837 assertEquals(404, respie.getStatus()); 793 838 } 794 839 795 840 @Test 796 841 public void testRegisterProfile() throws Exception { 797 798 fillUpPublicItems(); 799 800 FormDataMultiPart form = new FormDataMultiPart(); 801 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 802 RegistryTestHelper.getTestProfileContent(), 803 MediaType.APPLICATION_OCTET_STREAM_TYPE); 804 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, 805 "ProfileTest1"); 806 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, 807 "TestDomain"); 808 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 809 "My Test Profile"); 810 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, 811 "My Test Group"); 812 RegisterResponse response = getAuthenticatedResource( 813 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 814 RegisterResponse.class, form); 815 assertTrue(response.isProfile()); 816 assertTrue(response.isInUserSpace()); 817 ProfileDescription profileDesc = (ProfileDescription) response 818 .getDescription(); 819 assertNotNull(profileDesc); 820 assertEquals("ProfileTest1", profileDesc.getName()); 821 assertEquals("My Test Profile", profileDesc.getDescription()); 822 assertEquals("TestDomain", profileDesc.getDomainName()); 823 assertEquals("My Test Group", profileDesc.getGroupName()); 824 assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId()); 825 assertEquals("Database test user", profileDesc.getCreatorName()); 826 assertTrue(profileDesc.getId().startsWith( 827 ComponentRegistry.REGISTRY_ID + "p_")); 828 assertNotNull(profileDesc.getRegistrationDate()); 829 assertEquals( 830 "http://localhost:9998/registry/profiles/" 831 + profileDesc.getId(), profileDesc.getHref()); 842 843 System.out.println("testRegisterProfile"); 844 845 fillUpPublicItems(); 846 847 FormDataMultiPart form = new FormDataMultiPart(); 848 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 849 RegistryTestHelper.getTestProfileContent(), 850 MediaType.APPLICATION_OCTET_STREAM_TYPE); 851 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, 852 "ProfileTest1"); 853 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, 854 "TestDomain"); 855 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 856 "My Test Profile"); 857 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, 858 "My Test Group"); 859 RegisterResponse response = getAuthenticatedResource( 860 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 861 RegisterResponse.class, form); 862 assertTrue(response.isProfile()); 863 assertTrue(response.isInUserSpace()); 864 ProfileDescription profileDesc = (ProfileDescription) response 865 .getDescription(); 866 assertNotNull(profileDesc); 867 assertEquals("ProfileTest1", profileDesc.getName()); 868 assertEquals("My Test Profile", profileDesc.getDescription()); 869 assertEquals("TestDomain", profileDesc.getDomainName()); 870 assertEquals("My Test Group", profileDesc.getGroupName()); 871 assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId()); 872 assertEquals("Database test user", profileDesc.getCreatorName()); 873 assertTrue(profileDesc.getId().startsWith( 874 ComponentRegistry.REGISTRY_ID + "p_")); 875 assertNotNull(profileDesc.getRegistrationDate()); 876 assertEquals( 877 "http://localhost:9998/registry/profiles/" 878 + profileDesc.getId(), profileDesc.getHref()); 832 879 } 833 880 834 881 @Test 835 882 public void testPublishProfile() throws Exception { 836 883 884 System.out.println("testPublishProfile"); 885 837 886 fillUpPrivateItems(); 838 887 fillUpPublicItems(); 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 888 889 assertEquals("user registered profiles", 1, getUserProfiles().size()); 890 assertEquals("public registered profiles", 2, getPublicProfiles() 891 .size()); 892 FormDataMultiPart form = createFormData( 893 RegistryTestHelper.getTestProfileContent(), "Unpublished"); 894 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type( 895 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 896 form); 897 assertTrue(response.isProfile()); 898 BaseDescription desc = response.getDescription(); 899 assertEquals("Unpublished", desc.getDescription()); 900 assertEquals(2, getUserProfiles().size()); 901 assertEquals(2, getPublicProfiles().size()); 902 form = createFormData( 903 RegistryTestHelper.getTestProfileContent("publishedName"), 904 "Published"); 905 response = getAuthenticatedResource(getResource().path( 906 "/registry/profiles/" + desc.getId() + "/publish")) 907 .type(MediaType.MULTIPART_FORM_DATA).post( 908 RegisterResponse.class, form); 909 910 assertEquals(1, getUserProfiles().size()); 911 List<ProfileDescription> profiles = getPublicProfiles(); 912 assertEquals(3, profiles.size()); 913 ProfileDescription profileDescription = profiles.get(2); 914 assertNotNull(profileDescription.getId()); 915 assertEquals(desc.getId(), profileDescription.getId()); 916 assertEquals("http://localhost:9998/registry/profiles/" + desc.getId(), 917 profileDescription.getHref()); 918 assertEquals("Published", profileDescription.getDescription()); 919 CMDComponentSpec spec = getPublicSpec(profileDescription); 920 assertEquals("publishedName", spec.getCMDComponent().getName()); 872 921 } 873 922 874 923 private CMDComponentSpec getPublicSpec(BaseDescription desc) { 875 876 877 878 879 880 881 924 if (desc.isProfile()) { 925 return this.getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId())) 926 .get(CMDComponentSpec.class); 927 } else { 928 return this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())) 929 .get(CMDComponentSpec.class); 930 } 882 931 } 883 932 884 933 @Test 885 934 public void testPublishRegisteredComponent() throws Exception { 886 935 936 System.out.println("testPublishRegisteredComponent"); 937 887 938 fillUpPrivateItems(); 888 939 fillUpPublicItems(); 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 940 941 assertEquals(1, getUserComponents().size()); 942 assertEquals(2, getPublicComponents().size()); 943 944 FormDataMultiPart form = createFormData( 945 RegistryTestHelper.getComponentTestContent(), "Unpublished"); 946 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type( 947 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 948 form); 949 assertFalse(response.isProfile()); 950 BaseDescription desc = response.getDescription(); 951 assertEquals("Unpublished", desc.getDescription()); 952 assertEquals(2, getUserComponents().size()); 953 assertEquals(2, getPublicComponents().size()); 954 form = createFormData( 955 RegistryTestHelper.getComponentTestContentAsStream("publishedName"), 956 "Published"); 957 response = getAuthenticatedResource(getResource().path( 958 "/registry/components/" + desc.getId() + "/publish")) 959 .type(MediaType.MULTIPART_FORM_DATA).post( 960 RegisterResponse.class, form); 961 962 assertEquals(1, getUserComponents().size()); 963 List<ComponentDescription> components = getPublicComponents(); 964 assertEquals(3, components.size()); 965 ComponentDescription componentDescription = components.get(2); 966 assertNotNull(componentDescription.getId()); 967 assertEquals(desc.getId(), componentDescription.getId()); 968 assertEquals( 969 "http://localhost:9998/registry/components/" + desc.getId(), 970 componentDescription.getHref()); 971 assertEquals("Published", componentDescription.getDescription()); 972 CMDComponentSpec spec = getPublicSpec(componentDescription); 973 assertEquals("publishedName", spec.getCMDComponent().getName()); 923 974 } 924 975 … … 926 977 @Test 927 978 public void testRegisterUserspaceProfile() throws Exception { 928 979 980 System.out.println("testRegisterUserspacProfile"); 981 929 982 fillUpPrivateItems(); 930 983 fillUpPublicItems(); 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 984 985 List<ProfileDescription> profiles = getUserProfiles(); 986 assertEquals("user registered profiles", 1, profiles.size()); 987 assertEquals("public registered profiles", 2, getPublicProfiles() 988 .size()); 989 FormDataMultiPart form = createFormData(RegistryTestHelper 990 .getTestProfileContent()); 991 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type( 992 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 993 form); 994 assertTrue(response.isProfile()); 995 assertTrue(response.isInUserSpace()); 996 ProfileDescription profileDesc = (ProfileDescription) response 997 .getDescription(); 998 assertNotNull(profileDesc); 999 assertEquals("Test1", profileDesc.getName()); 1000 assertEquals("My Test", profileDesc.getDescription()); 1001 assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId()); 1002 assertEquals("Database test user", profileDesc.getCreatorName()); 1003 assertTrue(profileDesc.getId().startsWith( 1004 ComponentRegistry.REGISTRY_ID + "p_")); 1005 assertNotNull(profileDesc.getRegistrationDate()); 1006 assertEquals( 1007 "http://localhost:9998/registry/profiles/" 1008 + profileDesc.getId(), 1009 profileDesc.getHref()); 1010 1011 profiles = getUserProfiles(); 1012 assertEquals(2, profiles.size()); 1013 assertEquals(2, getPublicProfiles().size()); 1014 1015 // Try to post unauthenticated 1016 ClientResponse cResponse = getResource().path("/registry/profiles") 1017 .type(MediaType.MULTIPART_FORM_DATA) 1018 .post(ClientResponse.class, form); 1019 assertEquals(401, cResponse.getStatus()); 1020 1021 1022 1023 CMDComponentSpec spec = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId()) 1024 .queryParam(REGISTRY_SPACE_PARAM, "private")).accept( 1025 MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 1026 assertNotNull(spec); 1027 1028 cResponse = this.getAuthenticatedResource(getResource() 1029 .path("/registry/profiles/" + profileDesc.getId() + "/xsd")) 1030 .accept(MediaType.TEXT_XML).get(ClientResponse.class); 1031 assertEquals(200, cResponse.getStatus()); 1032 String profile = cResponse.getEntity(String.class); 1033 assertTrue(profile.length() > 0); 1034 1035 profile = getAuthenticatedResource(getResource().path( 1036 "/registry/profiles/" + profileDesc.getId() + "/xml")) 1037 .accept(MediaType.TEXT_XML).get(String.class); 1038 assertTrue(profile.length() > 0); 1039 1040 cResponse = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId()) 1041 .queryParam(REGISTRY_SPACE_PARAM, "private")).delete( 1042 ClientResponse.class); 1043 assertEquals(200, cResponse.getStatus()); 1044 1045 profiles = getUserProfiles(); 1046 assertEquals(1, profiles.size()); 994 1047 } 995 1048 996 1049 private List<ProfileDescription> getPublicProfiles() { 997 998 1050 return getAuthenticatedResource("/registry/profiles").accept( 1051 MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); 999 1052 } 1000 1053 1001 1054 private List<ProfileDescription> getUserProfiles() { 1002 1003 1004 1055 return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam( 1056 REGISTRY_SPACE_PARAM, "private")).accept( 1057 MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); 1005 1058 } 1006 1059 1007 1060 private FormDataMultiPart createFormData(Object content) { 1008 1061 return createFormData(content, "My Test"); 1009 1062 } 1010 1063 1011 1064 private FormDataMultiPart createFormData(Object content, String description) { 1012 1013 1014 1015 1016 1017 1018 1019 1020 1065 FormDataMultiPart form = new FormDataMultiPart(); 1066 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content, 1067 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1068 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1"); 1069 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 1070 description); 1071 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain"); 1072 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); 1073 return form; 1021 1074 } 1022 1075 1023 1076 @Test 1024 1077 public void testRegisterWithUserComponents() throws Exception { 1078 1079 System.out.println("testRegisterWithUserComponents"); 1080 1025 1081 fillUpPrivateItems(); 1026 1082 1027 1083 // kid component, not public 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1084 String content = ""; 1085 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 1086 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 1087 content += " <Header/>\n"; 1088 content += " <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n"; 1089 content += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 1090 content += " </CMD_Component>\n"; 1091 content += "</CMD_ComponentSpec>\n"; 1092 ComponentDescription compDesc1 = RegistryTestHelper.addComponent( 1093 baseRegistry, "XXX1", content, false); 1038 1094 1039 1095 // a containing component, referring to the kid (which is not public, so the containing component cannot be registered 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1096 content = ""; 1097 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 1098 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 1099 content += " <Header/>\n"; 1100 content += " <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 1101 content += " <CMD_Component ComponentId=\"" + compDesc1.getId() 1102 + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 1103 content += " </CMD_Component>\n"; 1104 content += " </CMD_Component>\n"; 1105 content += "</CMD_ComponentSpec>\n"; 1106 FormDataMultiPart form = createFormData(content); 1107 RegisterResponse response = getAuthenticatedResource( 1108 "/registry/components").type(MediaType.MULTIPART_FORM_DATA) 1109 .post(RegisterResponse.class, form); 1054 1110 // we first alway register in a private space, so reference to a private component should work 1055 1111 assertTrue(response.isRegistered()); 1056 1112 1057 1113 1058 1114 /// profiles /// 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1115 content = ""; 1116 content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 1117 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 1118 content += " <Header/>\n"; 1119 content += " <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 1120 content += " <CMD_Component ComponentId=\"" + compDesc1.getId() 1121 + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 1122 content += " </CMD_Component>\n"; 1123 content += " </CMD_Component>\n"; 1124 content += "</CMD_ComponentSpec>\n"; 1125 1126 form = createFormData(content); 1127 response = getAuthenticatedResource("/registry/profiles").type( 1128 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 1129 form); 1130 assertTrue(response.isRegistered()); 1075 1131 1076 1132 } … … 1078 1134 @Test 1079 1135 public void testRegisterUserspaceComponent() throws Exception { 1080 1136 1137 System.out.println("testREgisterUserspaceComponent"); 1138 1081 1139 fillUpPrivateItems(); 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1140 1141 List<ComponentDescription> components = getUserComponents(); 1142 assertEquals("user registered components", 1, components.size()); 1143 assertEquals("public registered components", 0, getPublicComponents() 1144 .size()); 1145 FormDataMultiPart form = createFormData(RegistryTestHelper 1146 .getComponentTestContent()); 1147 1148 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type( 1149 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 1150 form); 1151 assertTrue(response.isRegistered()); 1152 assertFalse(response.isProfile()); 1153 assertTrue(response.isInUserSpace()); 1154 ComponentDescription desc = (ComponentDescription) response 1155 .getDescription(); 1156 assertNotNull(desc); 1157 assertEquals("Test1", desc.getName()); 1158 assertEquals("My Test", desc.getDescription()); 1159 assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId()); 1160 assertEquals("Database test user", desc.getCreatorName()); 1161 assertEquals("TestGroup", desc.getGroupName()); 1162 assertTrue(desc.getId() 1163 .startsWith(ComponentRegistry.REGISTRY_ID + "c_")); 1164 assertNotNull(desc.getRegistrationDate()); 1165 String url = getResource().getUriBuilder().build().toString(); 1166 assertEquals(url + "registry/components/" + desc.getId(), desc.getHref()); 1167 1168 components = getUserComponents(); 1169 assertEquals(2, components.size()); 1170 assertEquals(0, getPublicComponents().size()); 1171 1172 // Try to post unauthenticated 1173 ClientResponse cResponse = getResource().path("/registry/components") 1174 .type(MediaType.MULTIPART_FORM_DATA) 1175 .post(ClientResponse.class, form); 1176 assertEquals(401, cResponse.getStatus()); 1177 1178 // Try to get 1179 cResponse = this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())) 1180 .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); 1181 1182 assertEquals(200, cResponse.getStatus()); 1183 CMDComponentSpec spec = getUserComponent(desc); 1184 assertNotNull(spec); 1185 1186 cResponse = this.getAuthenticatedResource(getResource() 1187 .path("/registry/components/" + desc.getId() + "/xsd")) 1188 .accept(MediaType.TEXT_XML).get(ClientResponse.class); 1189 assertEquals(200, cResponse.getStatus()); 1190 String result = cResponse.getEntity(String.class); 1191 assertTrue(result.length() > 0); 1192 1193 result = getAuthenticatedResource(getResource().path( 1194 "/registry/components/" + desc.getId() + "/xml")) 1195 .accept(MediaType.TEXT_XML).get(String.class); 1196 assertTrue(result.length() > 0); 1197 1198 cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())).delete( 1199 ClientResponse.class); 1200 assertEquals(200, cResponse.getStatus()); 1201 1202 components = getUserComponents(); 1203 assertEquals(1, components.size()); 1146 1204 } 1147 1205 // 1206 1148 1207 @Test 1149 1208 public void testCreatePrivateComponentWithRecursion() throws Exception { 1150 1209 1210 System.out.println("testCreatePrivateComponentWithRecursion"); 1211 1151 1212 fillUpPrivateItems(); 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1213 // Create new componet 1214 FormDataMultiPart form = createFormData(RegistryTestHelper 1215 .getComponentTestContent()); 1216 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type( 1217 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1218 assertEquals(ClientResponse.Status.OK.getStatusCode(), 1219 cResponse.getStatus()); 1220 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 1221 assertTrue(response.isRegistered()); 1222 ComponentDescription desc = (ComponentDescription) response 1223 .getDescription(); 1224 1225 // Re-define with self-recursion 1226 String compContent = ""; 1227 compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 1228 compContent += "\n"; 1229 compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 1230 compContent += " xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n"; 1231 compContent += " \n"; 1232 compContent += " <Header/>\n"; 1233 compContent += " \n"; 1234 compContent += " <CMD_Component name=\"Nested\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n"; 1235 compContent += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 1236 compContent += " <CMD_Component ComponentId=\"" 1237 + desc.getId() 1238 + "\" name=\"Recursive\" CardinalityMin=\"1\" CardinalityMax=\"1\" />\n"; 1239 compContent += " </CMD_Component>\n"; 1240 compContent += "\n"; 1241 compContent += "</CMD_ComponentSpec>\n"; 1242 1243 // Update component 1244 form = createFormData( 1245 RegistryTestHelper.getComponentContentAsStream(compContent), 1246 "UPDATE DESCRIPTION!"); 1247 cResponse = getAuthenticatedResource(getResource().path( 1248 "/registry/components/" + desc.getId() + "/update")).type( 1249 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1250 assertEquals(ClientResponse.Status.OK.getStatusCode(), 1251 cResponse.getStatus()); 1252 response = cResponse.getEntity(RegisterResponse.class); 1253 assertFalse("Recursive definition should fail", response.isRegistered()); 1254 assertEquals("There should be an error message for the recursion", 1, 1255 response.getErrors().size()); 1256 assertTrue( 1257 "There error message should specify the point of recursion", 1258 response.getErrors().get(0) 1259 .contains("already contains " + desc.getId())); 1199 1260 1200 1261 } … … 1202 1263 @Test 1203 1264 public void testUpdatePrivateComponent() throws Exception { 1204 1265 1266 System.out.println("testUpdatePrivateComponent"); 1267 1205 1268 fillUpPrivateItems(); 1206 1207 1208 1209 1210 1211 1269 1270 List<ComponentDescription> components = getUserComponents(); 1271 assertEquals("user registered components", 1, components.size()); 1272 assertEquals("public registered components", 0, getPublicComponents() 1273 .size()); 1274 1212 1275 // first, post a component to update 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1276 FormDataMultiPart form = createFormData(RegistryTestHelper 1277 .getComponentTestContent()); 1278 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type( 1279 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1280 assertEquals(ClientResponse.Status.OK.getStatusCode(), 1281 cResponse.getStatus()); 1282 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 1283 assertTrue(response.isRegistered()); 1284 assertFalse(response.isProfile()); 1285 assertTrue(response.isInUserSpace()); 1286 ComponentDescription desc = (ComponentDescription) response 1287 .getDescription(); 1288 assertNotNull(desc); 1289 assertEquals("Test1", desc.getName()); 1290 assertEquals("My Test", desc.getDescription()); 1291 Date firstDate = desc.getRegistrationDate(); 1292 CMDComponentSpec spec = getUserComponent(desc); 1293 assertNotNull(spec); 1294 assertEquals("Access", spec.getCMDComponent().getName()); 1295 components = getUserComponents(); 1296 assertEquals(2, components.size()); 1297 assertEquals(0, getPublicComponents().size()); 1298 1299 // second, now update 1300 form = createFormData( 1301 RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"), 1302 "UPDATE DESCRIPTION!"); 1303 cResponse = getAuthenticatedResource(getResource().path( 1304 "/registry/components/" + desc.getId() + "/update") 1305 .queryParam(REGISTRY_SPACE_PARAM, "private")).type( 1306 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1307 assertEquals(ClientResponse.Status.OK.getStatusCode(), 1308 cResponse.getStatus()); 1309 response = cResponse.getEntity(RegisterResponse.class); 1310 assertTrue(response.isRegistered()); 1311 assertFalse(response.isProfile()); 1312 assertTrue(response.isInUserSpace()); 1313 desc = (ComponentDescription) response.getDescription(); 1314 assertNotNull(desc); 1315 assertEquals("Test1", desc.getName()); 1316 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 1317 Date secondDate = desc.getRegistrationDate(); 1318 assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); 1319 1320 spec = getUserComponent(desc); 1321 assertNotNull(spec); 1322 assertEquals("TESTNAME", spec.getCMDComponent().getName()); 1323 components = getUserComponents(); 1324 assertEquals(2, components.size()); 1325 assertEquals(0, getPublicComponents().size()); 1263 1326 } 1264 1327 1265 1328 @Test 1266 1329 public void testUpdatePrivateProfile() throws Exception { 1267 1330 1331 System.out.println("testUpdatePrivateProfile"); 1332 1268 1333 fillUpPrivateItems(); 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1334 1335 List<ProfileDescription> profiles = getUserProfiles(); 1336 assertEquals(1, profiles.size()); 1337 assertEquals(0, getPublicProfiles().size()); 1338 1339 FormDataMultiPart form = createFormData(RegistryTestHelper 1340 .getTestProfileContent()); 1341 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles")).type( 1342 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1343 assertEquals(ClientResponse.Status.OK.getStatusCode(), 1344 cResponse.getStatus()); 1345 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 1346 assertTrue(response.isRegistered()); 1347 assertTrue(response.isProfile()); 1348 assertTrue(response.isInUserSpace()); 1349 ProfileDescription desc = (ProfileDescription) response 1350 .getDescription(); 1351 assertNotNull(desc); 1352 assertEquals("Test1", desc.getName()); 1353 assertEquals("My Test", desc.getDescription()); 1354 assertEquals("TestGroup", desc.getGroupName()); 1355 Date firstDate = desc.getRegistrationDate(); 1356 CMDComponentSpec spec = getUserProfile(desc); 1357 assertNotNull(spec); 1358 assertEquals("Actor", spec.getCMDComponent().getName()); 1359 profiles = getUserProfiles(); 1360 assertEquals(2, profiles.size()); 1361 assertEquals(0, getPublicComponents().size()); 1362 1363 // Now update 1364 form = createFormData( 1365 RegistryTestHelper.getTestProfileContent("TESTNAME"), 1366 "UPDATE DESCRIPTION!"); 1367 cResponse = getAuthenticatedResource(getResource().path( 1368 "/registry/profiles/" + desc.getId() + "/update")).type( 1369 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1370 assertEquals(ClientResponse.Status.OK.getStatusCode(), 1371 cResponse.getStatus()); 1372 response = cResponse.getEntity(RegisterResponse.class); 1373 assertTrue(response.isRegistered()); 1374 assertTrue(response.isProfile()); 1375 assertTrue(response.isInUserSpace()); 1376 desc = (ProfileDescription) response.getDescription(); 1377 assertNotNull(desc); 1378 assertEquals("Test1", desc.getName()); 1379 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 1380 Date secondDate = desc.getRegistrationDate(); 1381 assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); 1382 1383 spec = getUserProfile(desc); 1384 assertNotNull(spec); 1385 assertEquals("TESTNAME", spec.getCMDComponent().getName()); 1386 profiles = getUserProfiles(); 1387 assertEquals(2, profiles.size()); 1388 assertEquals(0, getPublicComponents().size()); 1324 1389 } 1325 1390 1326 1391 private CMDComponentSpec getUserComponent(ComponentDescription desc) { 1327 1328 1329 1392 return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()) 1393 .queryParam(REGISTRY_SPACE_PARAM, "private")).accept( 1394 MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 1330 1395 } 1331 1396 1332 1397 private CMDComponentSpec getUserProfile(ProfileDescription desc) { 1333 1334 1335 1398 return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()) 1399 .queryParam(REGISTRY_SPACE_PARAM, "private")).accept( 1400 MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 1336 1401 } 1337 1402 1338 1403 private List<ComponentDescription> getPublicComponents() { 1339 1340 1404 return getAuthenticatedResource("/registry/components").accept( 1405 MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); 1341 1406 } 1342 1407 1343 1408 private List<ComponentDescription> getUserComponents() { 1344 1345 1346 1409 return getAuthenticatedResource(getResource().path("/registry/components").queryParam( 1410 REGISTRY_SPACE_PARAM, "private")).accept( 1411 MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); 1347 1412 } 1348 1413 1349 1414 @Test 1350 1415 public void testRegisterComponent() throws Exception { 1351 1416 1417 System.out.println("testRegisterComponent"); 1418 1352 1419 fillUpPrivateItems(); 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1420 1421 FormDataMultiPart form = new FormDataMultiPart(); 1422 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1423 RegistryTestHelper.getComponentTestContent(), 1424 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1425 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, 1426 "ComponentTest1"); 1427 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 1428 "My Test Component"); 1429 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, 1430 "TestDomain"); 1431 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); 1432 RegisterResponse response = getAuthenticatedResource( 1433 "/registry/components").type(MediaType.MULTIPART_FORM_DATA) 1434 .post(RegisterResponse.class, form); 1435 assertTrue(response.isRegistered()); 1436 assertFalse(response.isProfile()); 1437 assertTrue(response.isInUserSpace()); 1438 ComponentDescription desc = (ComponentDescription) response 1439 .getDescription(); 1440 assertNotNull(desc); 1441 assertEquals("ComponentTest1", desc.getName()); 1442 assertEquals("My Test Component", desc.getDescription()); 1443 assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId()); 1444 assertEquals("Database test user", desc.getCreatorName()); 1445 assertEquals("TestGroup", desc.getGroupName()); 1446 assertEquals("TestDomain", desc.getDomainName()); 1447 assertTrue(desc.getId() 1448 .startsWith(ComponentRegistry.REGISTRY_ID + "c_")); 1449 assertNotNull(desc.getRegistrationDate()); 1450 String url = getResource().getUriBuilder().build().toString(); 1451 assertEquals(url + "registry/components/" + desc.getId(), 1452 desc.getHref()); 1386 1453 } 1387 1454 1388 1455 @Test 1389 1456 public void testRegisterComment() throws Exception { 1390 1391 fillUpPublicItems(); 1392 1393 FormDataMultiPart form = new FormDataMultiPart(); 1394 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1395 RegistryTestHelper.getCommentTestContent(), 1396 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1397 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 1398 CommentResponse response = getAuthenticatedResource( 1399 "/registry/profiles/" + id + "/comments").type( 1400 MediaType.MULTIPART_FORM_DATA) 1401 .post(CommentResponse.class, form); 1402 assertTrue(response.isRegistered()); 1403 assertFalse(response.isInUserSpace()); 1404 Comment comment = response.getComment(); 1405 assertNotNull(comment); 1406 assertEquals("Actual", comment.getComment()); 1407 assertEquals("Database test user", comment.getUserName()); 1408 Assert.notNull(comment.getCommentDate()); 1409 Assert.hasText(comment.getId()); 1410 1411 // User id should not be serialized! 1412 assertEquals(0, comment.getUserId()); 1457 1458 System.out.println("testRegisterComponent"); 1459 1460 fillUpPublicItems(); 1461 1462 FormDataMultiPart form = new FormDataMultiPart(); 1463 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1464 RegistryTestHelper.getCommentTestContent(), 1465 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1466 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 1467 CommentResponse response = getAuthenticatedResource( 1468 "/registry/profiles/" + id + "/comments").type( 1469 MediaType.MULTIPART_FORM_DATA) 1470 .post(CommentResponse.class, form); 1471 assertTrue(response.isRegistered()); 1472 assertFalse(response.isInUserSpace()); 1473 Comment comment = response.getComment(); 1474 assertNotNull(comment); 1475 assertEquals("Actual", comment.getComment()); 1476 assertEquals("Database test user", comment.getUserName()); 1477 Assert.notNull(comment.getCommentDate()); 1478 Assert.hasText(comment.getId()); 1479 1480 // User id should not be serialized! 1481 assertEquals(0, comment.getUserId()); 1413 1482 } 1414 1483 … … 1416 1485 public void testRegisterCommentToNonExistent() throws Exception { 1417 1486 fillUpPublicItems(); 1418 1419 1420 1421 1422 1423 1424 1425 1426 1487 1488 FormDataMultiPart form = new FormDataMultiPart(); 1489 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1490 RegistryTestHelper.getCommentTestContent(), 1491 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1492 ClientResponse cResponse = getAuthenticatedResource( 1493 "/registry/profiles/clarin.eu:cr1:profile99/comments").type( 1494 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1495 assertEquals(404, cResponse.getStatus()); 1427 1496 } 1428 1497 1429 1498 @Test 1430 1499 public void testRegisterCommentUnauthenticated() throws Exception { 1431 fillUpPublicItems(); 1432 1433 FormDataMultiPart form = new FormDataMultiPart(); 1434 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1435 RegistryTestHelper.getCommentTestContent(), 1436 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1437 ClientResponse cResponse = getResource() 1438 .path("/registry/profiles/clarin.eu:cr1:profile1/comments") 1439 .type(MediaType.MULTIPART_FORM_DATA) 1440 .post(ClientResponse.class, form); 1441 assertEquals(401, cResponse.getStatus()); 1500 1501 System.out.println("testREgisterCommentUnauthentified"); 1502 1503 fillUpPublicItems(); 1504 1505 FormDataMultiPart form = new FormDataMultiPart(); 1506 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1507 RegistryTestHelper.getCommentTestContent(), 1508 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1509 ClientResponse cResponse = getResource() 1510 .path("/registry/profiles/clarin.eu:cr1:profile1/comments") 1511 .type(MediaType.MULTIPART_FORM_DATA) 1512 .post(ClientResponse.class, form); 1513 assertEquals(401, cResponse.getStatus()); 1442 1514 } 1443 1515 1444 1516 @Test 1445 1517 public void testRegisterProfileInvalidData() throws Exception { 1518 System.out.println("testRegisterProfileInvalidData"); 1446 1519 fillUpPrivateItems(); 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1520 FormDataMultiPart form = new FormDataMultiPart(); 1521 String notAValidProfile = "<CMD_ComponentSpec> </CMD_ComponentSpec>"; 1522 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1523 new ByteArrayInputStream(notAValidProfile.getBytes()), 1524 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1525 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, 1526 "ProfileTest1"); 1527 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "Domain"); 1528 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "Group"); 1529 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 1530 "My Test Profile"); 1531 RegisterResponse postResponse = getAuthenticatedResource( 1532 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 1533 RegisterResponse.class, form); 1534 assertTrue(postResponse.isProfile()); 1535 assertFalse(postResponse.isRegistered()); 1536 assertEquals(1, postResponse.getErrors().size()); 1537 assertTrue(postResponse.getErrors().get(0).contains("isProfile")); 1465 1538 } 1466 1539 … … 1468 1541 * Two elements on the same level with the same name violates schematron 1469 1542 * rule, and should fail validation 1470 * 1543 * 1471 1544 * @throws Exception 1472 1545 */ 1473 1546 @Test 1474 1547 public void testRegisterInvalidProfile() throws Exception { 1548 System.out.println("testRegisterInvalidProfile"); 1475 1549 fillUpPrivateItems(); 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1550 FormDataMultiPart form = new FormDataMultiPart(); 1551 String profileContent = ""; 1552 profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 1553 profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 1554 profileContent += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 1555 profileContent += " <Header />\n"; 1556 profileContent += " <CMD_Component name=\"ProfileTest1\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n"; 1557 profileContent += " <CMD_Element name=\"Age\">\n"; 1558 profileContent += " <ValueScheme>\n"; 1559 profileContent += " <pattern>[23][0-9]</pattern>\n"; 1560 profileContent += " </ValueScheme>\n"; 1561 profileContent += " </CMD_Element>\n"; 1562 profileContent += " <CMD_Element name=\"Age\">\n"; 1563 profileContent += " <ValueScheme>\n"; 1564 profileContent += " <pattern>[23][0-9]</pattern>\n"; 1565 profileContent += " </ValueScheme>\n"; 1566 profileContent += " </CMD_Element>\n"; 1567 profileContent += " </CMD_Component>\n"; 1568 profileContent += "</CMD_ComponentSpec>\n"; 1569 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1570 RegistryTestHelper.getComponentContentAsStream(profileContent), 1571 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1572 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, 1573 "ProfileTest1"); 1574 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, 1575 "TestDomain"); 1576 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 1577 "My Test Profile"); 1578 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, 1579 "My Test Group"); 1580 RegisterResponse response = getAuthenticatedResource( 1581 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 1582 RegisterResponse.class, form); 1583 assertFalse( 1584 "Subsequent elements should not be allowed to have the same name", 1585 response.isRegistered()); 1586 assertTrue(response.getErrors().get(0) 1587 .contains(MDValidator.PARSE_ERROR)); 1514 1588 } 1515 1589 1516 1590 @Test 1517 1591 public void testRegisterProfileInvalidDescriptionAndContent() 1518 throws Exception { 1592 throws Exception { 1593 System.out.println("testRegisterProfileInvalidDescriptionAndContent"); 1519 1594 fillUpPrivateItems(); 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1595 FormDataMultiPart form = new FormDataMultiPart(); 1596 String profileContent = ""; 1597 profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 1598 profileContent += "<CMD_ComponentSpec> \n"; // No isProfile attribute 1599 profileContent += " <Header />\n"; 1600 profileContent += " <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n"; 1601 profileContent += " <AttributeList>\n"; 1602 profileContent += " <Attribute>\n"; 1603 profileContent += " <Name>Name</Name>\n"; 1604 profileContent += " <Type>string</Type>\n"; 1605 profileContent += " </Attribute>\n"; 1606 profileContent += " </AttributeList>\n"; 1607 profileContent += " </CMD_Component>\n"; 1608 profileContent += "</CMD_ComponentSpec>\n"; 1609 form.field("data", new ByteArrayInputStream(profileContent.getBytes()), 1610 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1611 form.field("name", "");// Empty name so invalid 1612 form.field("description", "My Test Profile"); 1613 RegisterResponse response = getAuthenticatedResource( 1614 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 1615 RegisterResponse.class, form); 1616 assertFalse(response.isRegistered()); 1617 assertEquals(2, response.getErrors().size()); 1618 assertNotNull(response.getErrors().get(0)); 1619 assertEquals(MDValidator.PARSE_ERROR, response.getErrors().get(1) 1620 .substring(0, MDValidator.PARSE_ERROR.length())); 1546 1621 } 1547 1622 1548 1623 @Test 1549 1624 public void testRegisterLargeProfile() throws Exception { 1625 System.out.println("testRegisterLargeProfile"); 1550 1626 //fillUpPrivateItems(); not necessary 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1627 FormDataMultiPart form = new FormDataMultiPart(); 1628 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1629 RegistryTestHelper.getLargeProfileContent(), 1630 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1631 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, 1632 "ProfileTest1"); 1633 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, 1634 "TestDomain"); 1635 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 1636 "My Test Profile"); 1637 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, 1638 "My Test Group"); 1639 ClientResponse response = getAuthenticatedResource("/registry/profiles") 1640 .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, 1641 form); 1642 assertEquals(200, response.getStatus()); 1567 1643 } 1568 1644 1569 1645 @Test 1570 1646 public void testRegisterComponentAsProfile() throws Exception { 1647 System.out.println("tesRegisterComponentAsProfile"); 1571 1648 //fillUpPrivateItems();; not necessary 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1649 FormDataMultiPart form = new FormDataMultiPart(); 1650 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1651 RegistryTestHelper.getComponentTestContent(), 1652 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1653 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "t"); 1654 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "domain"); 1655 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 1656 "My Test"); 1657 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "My Group"); 1658 RegisterResponse response = getAuthenticatedResource( 1659 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 1660 RegisterResponse.class, form); 1661 assertFalse(response.isRegistered()); 1662 assertTrue(response.isProfile()); 1663 assertEquals(1, response.getErrors().size()); 1664 assertEquals(MDValidator.MISMATCH_ERROR, response.getErrors().get(0)); 1588 1665 } 1589 1666 … … 1593 1670 * "nodel-L", "node-R", "leaf-LL", "leaf-LM", "leaf-LR", "leaf-RL", 1594 1671 * "leaf-RM", "leaf-RR" 1595 * 1672 * 1596 1673 * @throws Exception 1597 1674 */ 1598 1675 @Test 1599 1676 public void testSetFilenamesToNull() throws Exception { 1600 1601 // helper assists in generating a test component 1602 CMDComponentSetFilenamesToNullTestRunner helper = new CMDComponentSetFilenamesToNullTestRunner(); 1603 1604 // making an (up to ternary) tree of test components 1605 // inductive explaination of the variable names, an example: leaf-LM is 1606 // the middle child of the nodeL 1607 // the filename is this leaf is "leaf-LM" 1608 1609 // making children of the node L 1610 CMDComponentType leafLR = helper.makeTestComponent("leaf-LR", null); 1611 CMDComponentType leafLM = helper.makeTestComponent("leaf-LM", null); 1612 CMDComponentType leafLL = helper.makeTestComponent("leaf-LL", null); 1613 1614 // making node L 1615 List<CMDComponentType> nodeLchild = (new ArrayList<CMDComponentType>()); 1616 nodeLchild.add(leafLL); 1617 nodeLchild.add(leafLM); 1618 nodeLchild.add(leafLR); 1619 CMDComponentType nodeL = helper.makeTestComponent("node-L", nodeLchild); 1620 1621 // making children of the node R 1622 CMDComponentType leafRR = helper.makeTestComponent("leaf-RR", null); 1623 CMDComponentType leafRM = helper.makeTestComponent("leaf-RM", null); 1624 CMDComponentType leafRL = helper.makeTestComponent("leaf-RL", null); 1625 1626 // making node R 1627 List<CMDComponentType> nodeRchild = (new ArrayList<CMDComponentType>()); 1628 nodeRchild.add(leafRL); 1629 nodeRchild.add(leafRM); 1630 nodeRchild.add(leafRR); 1631 CMDComponentType nodeR = helper.makeTestComponent("node-R", nodeRchild); 1632 1633 // making the root, which has children NodeL and nodeR 1634 List<CMDComponentType> wortelchild = (new ArrayList<CMDComponentType>()); 1635 wortelchild.add(nodeL); 1636 wortelchild.add(nodeR); 1637 CMDComponentType root = helper.makeTestComponent("wortel", wortelchild); 1638 1639 // checking if the test compnent has the expected structure and the 1640 // expected filenames 1641 // ALSO this checking code below shows the strtucture of the tree 1642 1643 assertEquals(root.getCMDComponent().size(), 2); 1644 assertEquals(root.getCMDComponent().get(0).getCMDComponent().size(), 3); 1645 assertEquals(root.getCMDComponent().get(1).getCMDComponent().size(), 3); 1646 1647 assertEquals(root.getFilename(), "wortel"); 1648 1649 assertEquals(root.getCMDComponent().get(0).getFilename(), "node-L"); 1650 assertEquals(root.getCMDComponent().get(1).getFilename(), "node-R"); 1651 1652 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0) 1653 .getFilename(), "leaf-LL"); 1654 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1) 1655 .getFilename(), "leaf-LM"); 1656 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2) 1657 .getFilename(), "leaf-LR"); 1658 1659 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0) 1660 .getFilename(), "leaf-RL"); 1661 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1) 1662 .getFilename(), "leaf-RM"); 1663 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2) 1664 .getFilename(), "leaf-RR"); 1665 1666 // the actual job 1667 // nulling the filenames will be called as a method of testrestservice 1668 ComponentRegistryRestService restservice = new ComponentRegistryRestService(); 1669 restservice.setFileNamesToNullCurrent(root); 1670 1671 // check if the filenames are nulled 1672 assertEquals(root.getFilename(), null); 1673 1674 assertEquals(root.getCMDComponent().get(0).getFilename(), null); 1675 assertEquals(root.getCMDComponent().get(1).getFilename(), null); 1676 1677 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0) 1678 .getFilename(), null); 1679 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1) 1680 .getFilename(), null); 1681 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2) 1682 .getFilename(), null); 1683 1684 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0) 1685 .getFilename(), null); 1686 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1) 1687 .getFilename(), null); 1688 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2) 1689 .getFilename(), null); 1690 } 1691 1692 @Test 1693 public void testGetDescription() throws Exception{ 1677 System.out.println("testSetfilenamesTonull"); 1678 // helper assists in generating a test component 1679 CMDComponentSetFilenamesToNullTestRunner helper = new CMDComponentSetFilenamesToNullTestRunner(); 1680 1681 // making an (up to ternary) tree of test components 1682 // inductive explaination of the variable names, an example: leaf-LM is 1683 // the middle child of the nodeL 1684 // the filename is this leaf is "leaf-LM" 1685 1686 // making children of the node L 1687 CMDComponentType leafLR = helper.makeTestComponent("leaf-LR", null); 1688 CMDComponentType leafLM = helper.makeTestComponent("leaf-LM", null); 1689 CMDComponentType leafLL = helper.makeTestComponent("leaf-LL", null); 1690 1691 // making node L 1692 List<CMDComponentType> nodeLchild = (new ArrayList<CMDComponentType>()); 1693 nodeLchild.add(leafLL); 1694 nodeLchild.add(leafLM); 1695 nodeLchild.add(leafLR); 1696 CMDComponentType nodeL = helper.makeTestComponent("node-L", nodeLchild); 1697 1698 // making children of the node R 1699 CMDComponentType leafRR = helper.makeTestComponent("leaf-RR", null); 1700 CMDComponentType leafRM = helper.makeTestComponent("leaf-RM", null); 1701 CMDComponentType leafRL = helper.makeTestComponent("leaf-RL", null); 1702 1703 // making node R 1704 List<CMDComponentType> nodeRchild = (new ArrayList<CMDComponentType>()); 1705 nodeRchild.add(leafRL); 1706 nodeRchild.add(leafRM); 1707 nodeRchild.add(leafRR); 1708 CMDComponentType nodeR = helper.makeTestComponent("node-R", nodeRchild); 1709 1710 // making the root, which has children NodeL and nodeR 1711 List<CMDComponentType> wortelchild = (new ArrayList<CMDComponentType>()); 1712 wortelchild.add(nodeL); 1713 wortelchild.add(nodeR); 1714 CMDComponentType root = helper.makeTestComponent("wortel", wortelchild); 1715 1716 // checking if the test compnent has the expected structure and the 1717 // expected filenames 1718 // ALSO this checking code below shows the strtucture of the tree 1719 1720 assertEquals(root.getCMDComponent().size(), 2); 1721 assertEquals(root.getCMDComponent().get(0).getCMDComponent().size(), 3); 1722 assertEquals(root.getCMDComponent().get(1).getCMDComponent().size(), 3); 1723 1724 assertEquals(root.getFilename(), "wortel"); 1725 1726 assertEquals(root.getCMDComponent().get(0).getFilename(), "node-L"); 1727 assertEquals(root.getCMDComponent().get(1).getFilename(), "node-R"); 1728 1729 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0) 1730 .getFilename(), "leaf-LL"); 1731 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1) 1732 .getFilename(), "leaf-LM"); 1733 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2) 1734 .getFilename(), "leaf-LR"); 1735 1736 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0) 1737 .getFilename(), "leaf-RL"); 1738 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1) 1739 .getFilename(), "leaf-RM"); 1740 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2) 1741 .getFilename(), "leaf-RR"); 1742 1743 // the actual job 1744 // nulling the filenames will be called as a method of testrestservice 1745 ComponentRegistryRestService restservice = new ComponentRegistryRestService(); 1746 restservice.setFileNamesToNullCurrent(root); 1747 1748 // check if the filenames are nulled 1749 assertEquals(root.getFilename(), null); 1750 1751 assertEquals(root.getCMDComponent().get(0).getFilename(), null); 1752 assertEquals(root.getCMDComponent().get(1).getFilename(), null); 1753 1754 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0) 1755 .getFilename(), null); 1756 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1) 1757 .getFilename(), null); 1758 assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2) 1759 .getFilename(), null); 1760 1761 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0) 1762 .getFilename(), null); 1763 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1) 1764 .getFilename(), null); 1765 assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2) 1766 .getFilename(), null); 1767 } 1768 1769 @Test 1770 public void testGetDescription() throws Exception { 1771 System.out.println("testGetDescription"); 1694 1772 fillUpPublicItems(); 1695 1773 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java
r5549 r5550 12 12 import clarin.cmdi.componentregistry.model.ComponentDescription; 13 13 import clarin.cmdi.componentregistry.model.ProfileDescription; 14 import clarin.cmdi.componentregistry.model.RegisterResponse;15 14 import com.sun.jersey.api.client.ClientResponse; 16 15 import com.sun.jersey.multipart.FormDataMultiPart; 16 import java.util.List; 17 import javax.ws.rs.WebApplicationException; 17 18 import javax.ws.rs.core.MediaType; 18 19 import org.junit.Before; … … 21 22 import org.springframework.jdbc.core.JdbcTemplate; 22 23 23 import org.springframework.util.Assert;24 24 import static org.junit.Assert.*; 25 25 26 /** 26 27 * 27 28 * @author olhsha 28 29 */ 29 public class SanboxTest extends 30 ComponentRegistryRestServiceTestCase { 30 public class SanboxTest extends ComponentRegistryRestServiceTestCase { 31 31 32 32 @Autowired … … 40 40 @Before 41 41 public void init() { 42 43 44 42 ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate); 43 createUserRecord(); 44 baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS); 45 45 } 46 46 47 47 private String expectedUserId(String principal) { 48 48 return getUserDao().getByPrincipalName(principal).getId().toString(); 49 49 } 50 51 50 private ComponentDescription component1; 52 51 private ComponentDescription component2; 53 52 private ProfileDescription profile1; 54 53 private ProfileDescription profile2; 55 56 54 private ComponentDescription component3; 57 55 private ProfileDescription profile3; 58 59 56 private Comment profile1Comment1; 60 57 private Comment profile1Comment2; 61 58 private Comment component1Comment3; 62 59 private Comment component1Comment4; 63 64 60 private Comment profile3Comment5; 65 61 private Comment component3Comment7; 66 62 67 63 private void fillUpPublicItems() throws Exception { 68 69 profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true);70 profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true);71 component1 = RegistryTestHelper.addComponent(baseRegistry,72 "component2", true);73 component2 = RegistryTestHelper.addComponent(baseRegistry,74 "component1", true);75 profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2",76 ProfileDescription.PROFILE_PREFIX + "profile1",77 "JUnit@test.com");78 profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1",79 ProfileDescription.PROFILE_PREFIX + "profile1",80 "JUnit@test.com");81 component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3",82 ComponentDescription.COMPONENT_PREFIX + "component1",83 "JUnit@test.com");84 component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4",85 ComponentDescription.COMPONENT_PREFIX + "component1",86 "JUnit@test.com");87 }88 89 private void fillUpPrivateItems() throws Exception {90 profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false);91 component3 = RegistryTestHelper.addComponent(baseRegistry,92 "component3", false);93 profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5",94 ProfileDescription.PROFILE_PREFIX + "profile3",95 "JUnit@test.com");96 component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7",97 ComponentDescription.COMPONENT_PREFIX + "component3",98 "JUnit@test.com");99 }100 101 @Test102 public void testCreatePrivateComponentWithRecursion() throws Exception {103 104 fillUpPrivateItems();105 // Create new componet106 FormDataMultiPart form = createFormData(RegistryTestHelper107 .getComponentTestContent());108 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type(109 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);110 assertEquals(ClientResponse.Status.OK.getStatusCode(),111 cResponse.getStatus());112 RegisterResponse response = cResponse.getEntity(RegisterResponse.class);113 assertTrue(response.isRegistered());114 ComponentDescription desc = (ComponentDescription) response115 .getDescription();116 64 117 // Re-define with self-recursion 118 String compContent = ""; 119 compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 120 compContent += "\n"; 121 compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 122 compContent += " xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n"; 123 compContent += " \n"; 124 compContent += " <Header/>\n"; 125 compContent += " \n"; 126 compContent += " <CMD_Component name=\"Nested\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n"; 127 compContent += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 128 compContent += " <CMD_Component ComponentId=\"" 129 + desc.getId() 130 + "\" name=\"Recursive\" CardinalityMin=\"1\" CardinalityMax=\"1\" />\n"; 131 compContent += " </CMD_Component>\n"; 132 compContent += "\n"; 133 compContent += "</CMD_ComponentSpec>\n"; 134 135 // Update component 136 form = createFormData( 137 RegistryTestHelper.getComponentContentAsStream(compContent), 138 "UPDATE DESCRIPTION!"); 139 cResponse = getAuthenticatedResource(getResource().path( 140 "/registry/components/" + desc.getId() + "/update")).type( 141 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 142 assertEquals(ClientResponse.Status.OK.getStatusCode(), 143 cResponse.getStatus()); 144 response = cResponse.getEntity(RegisterResponse.class); 145 assertFalse("Recursive definition should fail", response.isRegistered()); 146 assertEquals("There should be an error message for the recursion", 1, 147 response.getErrors().size()); 148 assertTrue( 149 "There error message should specify the point of recursion", 150 response.getErrors().get(0) 151 .contains("already contains " + desc.getId())); 152 65 profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true); 66 profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true); 67 component1 = RegistryTestHelper.addComponent(baseRegistry, 68 "component2", true); 69 component2 = RegistryTestHelper.addComponent(baseRegistry, 70 "component1", true); 71 profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2", 72 ProfileDescription.PROFILE_PREFIX + "profile1", 73 "JUnit@test.com"); 74 profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1", 75 ProfileDescription.PROFILE_PREFIX + "profile1", 76 "JUnit@test.com"); 77 component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3", 78 ComponentDescription.COMPONENT_PREFIX + "component1", 79 "JUnit@test.com"); 80 component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4", 81 ComponentDescription.COMPONENT_PREFIX + "component1", 82 "JUnit@test.com"); 153 83 } 154 84 155 private FormDataMultiPart createFormData(Object content) { 156 return createFormData(content, "My Test"); 85 private void fillUpPrivateItems() throws Exception { 86 profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false); 87 component3 = RegistryTestHelper.addComponent(baseRegistry, 88 "component3", false); 89 profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5", 90 ProfileDescription.PROFILE_PREFIX + "profile3", 91 "JUnit@test.com"); 92 component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7", 93 ComponentDescription.COMPONENT_PREFIX + "component3", 94 "JUnit@test.com"); 95 } 96 97 @Test 98 public void testDeleteCommentFromPublicProfile() throws Exception { 99 100 System.out.println("testDeleteCommentFromPublicProfile"); 101 102 fillUpPublicItems(); 103 104 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 105 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 106 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 107 assertEquals(2, comments.size()); 108 Comment aComment = this.getAuthenticatedResource(getResource().path( 109 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 110 + "profile1/comments/" + profile1Comment1.getId())).get(Comment.class); 111 assertNotNull(aComment); 112 113 // Try to delete from other profile 114 ClientResponse response = getAuthenticatedResource( 115 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 116 + "profile2/comments/9999").delete(ClientResponse.class); 117 assertEquals(500, response.getStatus()); 118 // Delete from correct profile 119 response = getAuthenticatedResource( 120 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 121 + "profile1/comments/" + profile1Comment1.getId()).delete(ClientResponse.class); 122 assertEquals(200, response.getStatus()); 123 124 comments = this.getAuthenticatedResource(getResource().path( 125 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 126 + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE); 127 assertEquals(1, comments.size()); 128 129 response = getAuthenticatedResource( 130 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 131 + "profile1/comments/" + profile1Comment2.getId()).delete(ClientResponse.class); 132 assertEquals(200, response.getStatus()); 133 134 comments = this.getAuthenticatedResource(getResource().path( 135 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 136 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 137 assertEquals(0, comments.size()); 138 } 139 140 private FormDataMultiPart createFormData(Object content) { 141 return createFormData(content, "My Test"); 157 142 } 158 143 159 144 private FormDataMultiPart createFormData(Object content, String description) { 160 161 162 163 164 165 166 167 168 145 FormDataMultiPart form = new FormDataMultiPart(); 146 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content, 147 MediaType.APPLICATION_OCTET_STREAM_TYPE); 148 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1"); 149 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 150 description); 151 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain"); 152 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); 153 return form; 169 154 } 170 155 }
Note: See TracChangeset
for help on using the changeset viewer.