Changeset 5567 for ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java
- Timestamp:
- 08/18/14 18:58:25 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java
r5566 r5567 14 14 import clarin.cmdi.componentregistry.model.BaseDescription; 15 15 import clarin.cmdi.componentregistry.model.Comment; 16 import clarin.cmdi.componentregistry.model.CommentResponse; 16 17 import clarin.cmdi.componentregistry.model.ComponentDescription; 17 18 import clarin.cmdi.componentregistry.model.Ownership; … … 34 35 import static org.junit.Assert.*; 35 36 import org.junit.Test; 37 import org.springframework.util.Assert; 36 38 37 39 /** … … 232 234 233 235 234 @Test 235 public void testDeleteCommentFromGroupComponentAndProfile() throws Exception { 236 237 System.out.println("test deleteCommentFromGroupComponent"); 238 239 240 fillUpGroupA(); 236 @Test 237 public void testRegisterCommentInGroup() throws Exception { 238 239 System.out.println("testRegisterCommmentInGroup"); 240 241 241 242 fillUpGroupB(); 242 243 fillUpGroupC(); 243 244 RegistryTestHelper.addComment(baseRegistry, "COMMENTc1", ComponentDescription.COMPONENT_PREFIX + "component-1", 245 "JUnit@test.com"); 246 RegistryTestHelper.addComment(baseRegistry, "COMMENTp1", ProfileDescription.PROFILE_PREFIX + "profile-1", 247 "JUnit@test.com"); 248 RegistryTestHelper.addComment(baseRegistry, "COMMENTBc1", ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1", 249 "anotherPrincipal"); 250 RegistryTestHelper.addComment(baseRegistry, "COMMENTBp1", ProfileDescription.PROFILE_PREFIX + "Bprofile-1", 251 "anotherPrincipal"); 252 (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCc1", ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1", 253 "anotherPrincipal"); 254 (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1", ProfileDescription.PROFILE_PREFIX + "Cprofile-1","anotherPrincipal"); 255 256 ClientResponse response = getAuthenticatedResource( 257 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1/comments/1").delete( 258 ClientResponse.class); 259 assertEquals(200, response.getStatus()); 244 245 FormDataMultiPart form = new FormDataMultiPart(); 246 String id = ProfileDescription.PROFILE_PREFIX + "Bprofile-1"; 247 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 248 RegistryTestHelper.getCommentTestContentStringForProfile("comment1", id), 249 MediaType.APPLICATION_OCTET_STREAM_TYPE); 250 CommentResponse response = getAuthenticatedResource( 251 "/registry/profiles/" + id + "/comments").type( 252 MediaType.MULTIPART_FORM_DATA) 253 .post(CommentResponse.class, form); 254 assertTrue(response.isRegistered()); 255 assertTrue(response.isInUserSpace()); 256 Comment comment = response.getComment(); 257 assertNotNull(comment); 258 assertEquals("comment1", comment.getComment()); 259 assertEquals("Database test user", comment.getUserName()); 260 Assert.notNull(comment.getCommentDate()); 261 assertEquals(1, Long.parseLong(comment.getId())); 262 263 // User id should not be serialized! 264 assertEquals(0, comment.getUserId()); 265 266 267 form = new FormDataMultiPart(); 268 id = ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1"; 269 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 270 RegistryTestHelper.getCommentTestContentStringForComponent("comment2", id), 271 MediaType.APPLICATION_OCTET_STREAM_TYPE); 260 272 response = getAuthenticatedResource( 261 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1/comments/1").get( 262 ClientResponse.class); 263 assertEquals(404, response.getStatus()); 264 265 response = getAuthenticatedResource( 266 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1/comments/3").delete( 267 ClientResponse.class); 268 assertEquals(403, response.getStatus()); 269 270 271 response = getAuthenticatedResource( 272 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1/comments/5").delete( 273 ClientResponse.class); 274 assertEquals(403, response.getStatus()); 275 276 277 response = getAuthenticatedResource( 278 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1/comments/2").delete( 279 ClientResponse.class); 280 assertEquals(200, response.getStatus()); 281 response = getAuthenticatedResource( 282 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1/comments/2").get( 283 ClientResponse.class); 284 assertEquals(404, response.getStatus()); 285 286 response = getAuthenticatedResource( 287 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1/comments/4").delete( 288 ClientResponse.class); 289 assertEquals(403, response.getStatus()); 290 291 292 response = getAuthenticatedResource( 293 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Cprofile-1/comments/6").delete( 294 ClientResponse.class); 295 assertEquals(403, response.getStatus()); 296 273 "/registry/components/" + id + "/comments").type( 274 MediaType.MULTIPART_FORM_DATA) 275 .post(CommentResponse.class, form); 276 assertTrue(response.isRegistered()); 277 assertTrue(response.isInUserSpace()); 278 comment = response.getComment(); 279 assertNotNull(comment); 280 assertEquals("comment2", comment.getComment()); 281 assertEquals("Database test user", comment.getUserName()); 282 Assert.notNull(comment.getCommentDate()); 283 assertEquals(2, Long.parseLong(comment.getId())); 284 285 // User id should not be serialized! 286 assertEquals(0, comment.getUserId()); 287 288 // not my group 289 290 form = new FormDataMultiPart(); 291 id = ProfileDescription.PROFILE_PREFIX + "Cprofile-1"; 292 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 293 RegistryTestHelper.getCommentTestContentStringForProfile("comment3", id), 294 MediaType.APPLICATION_OCTET_STREAM_TYPE); 295 ClientResponse cresponse = getAuthenticatedResource( 296 "/registry/profiles/" + id + "/comments").type( 297 MediaType.MULTIPART_FORM_DATA) 298 .post(ClientResponse.class, form); 299 assertEquals(403, cresponse.getStatus()); 300 301 302 303 form = new FormDataMultiPart(); 304 id = ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1"; 305 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 306 RegistryTestHelper.getCommentTestContentStringForComponent("comment4", id), 307 MediaType.APPLICATION_OCTET_STREAM_TYPE); 308 cresponse = getAuthenticatedResource( 309 "/registry/components/" + id + "/comments").type( 310 MediaType.MULTIPART_FORM_DATA) 311 .post(ClientResponse.class, form); 312 assertEquals(403, cresponse.getStatus()); 297 313 } 298 314
Note: See TracChangeset
for help on using the changeset viewer.