Changeset 5563 for ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java
- Timestamp:
- 08/18/14 15:36:30 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java
r5561 r5563 14 14 import clarin.cmdi.componentregistry.model.Ownership; 15 15 import clarin.cmdi.componentregistry.model.ProfileDescription; 16 import clarin.cmdi.componentregistry.model.RegisterResponse; 16 17 import clarin.cmdi.componentregistry.model.RegistryUser; 17 18 import clarin.cmdi.componentregistry.persistence.jpa.CommentsDao; 18 19 import clarin.cmdi.componentregistry.persistence.jpa.UserDao; 19 import clarin.cmdi.componentregistry.rss.Rss;20 20 import com.sun.jersey.api.client.ClientResponse; 21 import com.sun.jersey.multipart.FormDataMultiPart; 21 22 import java.text.ParseException; 22 import java.util. List;23 import java.util.Date; 23 24 import javax.ws.rs.core.MediaType; 24 25 import javax.xml.bind.JAXBException; … … 207 208 208 209 210 private FormDataMultiPart createFormData(Object content) { 211 return createFormData(content, "My Test"); 212 } 213 214 private FormDataMultiPart createFormData(Object content, String description) { 215 FormDataMultiPart form = new FormDataMultiPart(); 216 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content, 217 MediaType.APPLICATION_OCTET_STREAM_TYPE); 218 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1"); 219 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 220 description); 221 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain"); 222 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); 223 return form; 224 } 225 209 226 @Test 210 public void test GetGroupRss() throws Exception {211 212 System.out.println("test getGroupRss");227 public void testUpdateGroupComponentAndProfile() throws Exception { 228 229 System.out.println("test updateGorupComponent"); 213 230 214 231 fillUpGroupA(); … … 216 233 fillUpGroupC(); 217 234 218 219 // lists of profiles and components 220 221 Rss response = this.getAuthenticatedResource(getResource() 222 .path("/registry/profiles/rss").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML) 223 .get(Rss.class); 224 assertEquals(1, response.getChannel().getItem().size()); 225 226 response = this.getAuthenticatedResource(getResource() 227 .path("/registry/components/rss").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML) 228 .get(Rss.class); 229 assertEquals(2, response.getChannel().getItem().size()); 230 231 response = this.getAuthenticatedResource(getResource() 232 .path("/registry/profiles/rss").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML) 233 .get(Rss.class); 234 assertEquals(1, response.getChannel().getItem().size()); 235 236 response = this.getAuthenticatedResource(getResource() 237 .path("/registry/components/rss").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML) 238 .get(Rss.class); 239 assertEquals(2, response.getChannel().getItem().size()); 240 241 ClientResponse clientResponse = this.getAuthenticatedResource(getResource() 242 .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "3")).accept(MediaType.APPLICATION_XML) 243 .get(ClientResponse.class); 244 245 assertEquals(403, clientResponse.getStatus()); 235 236 237 FormDataMultiPart form = createFormData( 238 RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"), 239 "UPDATE DESCRIPTION!"); 240 ClientResponse cResponse = getAuthenticatedResource(getResource().path( 241 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1" + "/update")).type( 242 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 243 assertEquals(ClientResponse.Status.OK.getStatusCode(), 244 cResponse.getStatus()); 245 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 246 assertTrue(response.isRegistered()); 247 assertFalse(response.isProfile()); 248 assertTrue(response.isInUserSpace()); 249 ComponentDescription desc = (ComponentDescription) response.getDescription(); 250 assertNotNull(desc); 251 assertEquals("Test1", desc.getName()); 252 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 253 254 form = createFormData( 255 RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"), 256 "UPDATE DESCRIPTION!"); 257 cResponse = getAuthenticatedResource(getResource().path( 258 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1" + "/update")).type( 259 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 260 assertEquals(ClientResponse.Status.OK.getStatusCode(), 261 cResponse.getStatus()); 262 response = cResponse.getEntity(RegisterResponse.class); 263 assertTrue(response.isRegistered()); 264 assertFalse(response.isProfile()); 265 assertTrue(response.isInUserSpace()); 266 desc = (ComponentDescription) response.getDescription(); 267 assertNotNull(desc); 268 assertEquals("Test1", desc.getName()); 269 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 246 270 247 RegistryTestHelper.addComment(baseRegistry, "COMMENTc1", ComponentDescription.COMPONENT_PREFIX + "component-1", 248 "JUnit@test.com"); 249 RegistryTestHelper.addComment(baseRegistry, "COMMENTp1", ProfileDescription.PROFILE_PREFIX + "profile-1", 250 "JUnit@test.com"); 251 RegistryTestHelper.addComment(baseRegistry, "COMMENTBc1", ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1", 252 "anotherPrincipal"); 253 RegistryTestHelper.addComment(baseRegistry, "COMMENTBp1", ProfileDescription.PROFILE_PREFIX + "Bprofile-1", 254 "anotherPrincipal"); 255 (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCc1", ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1", 256 "anotherPrincipal"); 257 (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1", ProfileDescription.PROFILE_PREFIX + "Cprofile-1","anotherPrincipal"); 258 259 260 // lists 261 262 response = this.getAuthenticatedResource(getResource() 263 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/rss")) 264 .accept(MediaType.APPLICATION_XML) 265 .get(Rss.class); 266 assertEquals(1, response.getChannel().getItem().size()); 267 268 response = this.getAuthenticatedResource(getResource() 269 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/rss")) 270 .accept(MediaType.APPLICATION_XML) 271 .get(Rss.class); 272 assertEquals(1, response.getChannel().getItem().size()); 273 274 response = this.getAuthenticatedResource(getResource() 275 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/rss")) 276 .accept(MediaType.APPLICATION_XML) 277 .get(Rss.class); 278 assertEquals(1, response.getChannel().getItem().size()); 279 280 response = this.getAuthenticatedResource(getResource() 281 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/rss")) 282 .accept(MediaType.APPLICATION_XML) 283 .get(Rss.class); 284 assertEquals(1, response.getChannel().getItem().size()); 285 286 287 288 clientResponse = this.getAuthenticatedResource(getResource() 289 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/rss")) 290 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); 291 assertEquals(403, clientResponse.getStatus()); 292 293 clientResponse = this.getAuthenticatedResource(getResource() 294 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/rss")) 295 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); 296 assertEquals(403, clientResponse.getStatus()); 297 298 // particular comments 299 300 Comment responseComment = this.getAuthenticatedResource(getResource() 301 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/1")) 302 .accept(MediaType.APPLICATION_XML) 303 .get(Comment.class); 304 assertNotNull(responseComment); 305 306 assertEquals(1, Long.parseLong(responseComment.getId())); 307 308 responseComment = this.getAuthenticatedResource(getResource() 309 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/2")) 310 .accept(MediaType.APPLICATION_XML) 311 .get(Comment.class); 312 assertNotNull(responseComment); 271 form = createFormData( 272 RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"), 273 "UPDATE DESCRIPTION!"); 274 cResponse = getAuthenticatedResource(getResource().path( 275 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1" + "/update")).type( 276 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 277 assertEquals(403, cResponse.getStatus()); 278 279 // profile 280 281 form = createFormData(RegistryTestHelper.getTestProfileContent("TESTNAME"), 282 "UPDATE DESCRIPTION!"); 283 cResponse = getAuthenticatedResource(getResource().path( 284 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1" + "/update")).type( 285 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 286 assertEquals(ClientResponse.Status.OK.getStatusCode(), 287 cResponse.getStatus()); 288 response = cResponse.getEntity(RegisterResponse.class); 289 assertTrue(response.isRegistered()); 290 assertTrue(response.isProfile()); 291 assertTrue(response.isInUserSpace()); 292 ProfileDescription pdesc = (ProfileDescription) response.getDescription(); 293 assertNotNull(pdesc); 294 assertEquals("Test1", pdesc.getName()); 295 assertEquals("UPDATE DESCRIPTION!", pdesc.getDescription()); 296 297 form = createFormData( 298 RegistryTestHelper.getTestProfileContent("TESTNAME"), 299 "UPDATE DESCRIPTION!"); 300 cResponse = getAuthenticatedResource(getResource().path( 301 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1" + "/update")).type( 302 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 303 assertEquals(ClientResponse.Status.OK.getStatusCode(), 304 cResponse.getStatus()); 305 response = cResponse.getEntity(RegisterResponse.class); 306 assertTrue(response.isRegistered()); 307 assertTrue(response.isProfile()); 308 assertTrue(response.isInUserSpace()); 309 pdesc = (ProfileDescription) response.getDescription(); 310 assertNotNull(pdesc); 311 assertEquals("Test1", pdesc.getName()); 312 assertEquals("UPDATE DESCRIPTION!", pdesc.getDescription()); 313 313 314 assertEquals(2, Long.parseLong(responseComment.getId())); 315 316 responseComment = this.getAuthenticatedResource(getResource() 317 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/3")) 318 .accept(MediaType.APPLICATION_XML) 319 .get(Comment.class); 320 assertNotNull(responseComment); 321 assertEquals(3, Long.parseLong(responseComment.getId())); 322 323 responseComment = this.getAuthenticatedResource(getResource() 324 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/4")) 325 .accept(MediaType.APPLICATION_XML) 326 .get(Comment.class); 327 assertNotNull(responseComment); 328 assertEquals(4, Long.parseLong(responseComment.getId())); 329 330 clientResponse = this.getAuthenticatedResource(getResource() 331 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/6")) 332 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); 333 assertEquals(403, clientResponse.getStatus()); 334 335 clientResponse = this.getAuthenticatedResource(getResource() 336 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/5")) 337 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); 338 assertEquals(403, clientResponse.getStatus()); 314 form = createFormData( 315 RegistryTestHelper.getTestProfileContent("TESTNAME"), 316 "UPDATE DESCRIPTION!"); 317 cResponse = getAuthenticatedResource(getResource().path( 318 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1" + "/update")).type( 319 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 320 assertEquals(403, cResponse.getStatus()); 339 321 340 322 }
Note: See TracChangeset
for help on using the changeset viewer.