Changeset 5563
- Timestamp:
- 08/18/14 15:36:30 (10 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r5552 r5563 1302 1302 "UPDATE DESCRIPTION!"); 1303 1303 cResponse = getAuthenticatedResource(getResource().path( 1304 "/registry/components/" + desc.getId() + "/update") 1305 .queryParam(REGISTRY_SPACE_PARAM, "private")).type( 1304 "/registry/components/" + desc.getId() + "/update")).type( 1306 1305 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1307 1306 assertEquals(ClientResponse.Status.OK.getStatusCode(), -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RestGroupServiceTest.java
r5561 r5563 16 16 import clarin.cmdi.componentregistry.model.Ownership; 17 17 import clarin.cmdi.componentregistry.model.ProfileDescription; 18 import clarin.cmdi.componentregistry.model.RegisterResponse; 18 19 import clarin.cmdi.componentregistry.model.RegistryUser; 19 20 import clarin.cmdi.componentregistry.persistence.jpa.CommentsDao; … … 21 22 import clarin.cmdi.componentregistry.rss.Rss; 22 23 import com.sun.jersey.api.client.ClientResponse; 24 import com.sun.jersey.multipart.FormDataMultiPart; 23 25 import java.text.ParseException; 26 import java.util.Date; 24 27 import java.util.List; 25 28 import javax.ws.rs.core.MediaType; … … 813 816 814 817 } 818 819 820 private FormDataMultiPart createFormData(Object content) { 821 return createFormData(content, "My Test"); 822 } 823 824 private FormDataMultiPart createFormData(Object content, String description) { 825 FormDataMultiPart form = new FormDataMultiPart(); 826 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content, 827 MediaType.APPLICATION_OCTET_STREAM_TYPE); 828 form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1"); 829 form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, 830 description); 831 form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain"); 832 form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); 833 return form; 834 } 835 836 @Test 837 public void testUpdateGroupComponentAndProfile() throws Exception { 838 839 System.out.println("test updateGorupComponent"); 840 841 fillUpGroupA(); 842 fillUpGroupB(); 843 fillUpGroupC(); 844 845 846 847 FormDataMultiPart form = createFormData( 848 RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"), 849 "UPDATE DESCRIPTION!"); 850 ClientResponse cResponse = getAuthenticatedResource(getResource().path( 851 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1" + "/update")).type( 852 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 853 assertEquals(ClientResponse.Status.OK.getStatusCode(), 854 cResponse.getStatus()); 855 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 856 assertTrue(response.isRegistered()); 857 assertFalse(response.isProfile()); 858 assertTrue(response.isInUserSpace()); 859 ComponentDescription desc = (ComponentDescription) response.getDescription(); 860 assertNotNull(desc); 861 assertEquals("Test1", desc.getName()); 862 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 863 864 form = createFormData( 865 RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"), 866 "UPDATE DESCRIPTION!"); 867 cResponse = getAuthenticatedResource(getResource().path( 868 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1" + "/update")).type( 869 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 870 assertEquals(ClientResponse.Status.OK.getStatusCode(), 871 cResponse.getStatus()); 872 response = cResponse.getEntity(RegisterResponse.class); 873 assertTrue(response.isRegistered()); 874 assertFalse(response.isProfile()); 875 assertTrue(response.isInUserSpace()); 876 desc = (ComponentDescription) response.getDescription(); 877 assertNotNull(desc); 878 assertEquals("Test1", desc.getName()); 879 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 880 881 form = createFormData( 882 RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"), 883 "UPDATE DESCRIPTION!"); 884 cResponse = getAuthenticatedResource(getResource().path( 885 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1" + "/update")).type( 886 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 887 assertEquals(403, cResponse.getStatus()); 888 889 // profile 890 891 form = createFormData(RegistryTestHelper.getTestProfileContent("TESTNAME"), 892 "UPDATE DESCRIPTION!"); 893 cResponse = getAuthenticatedResource(getResource().path( 894 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1" + "/update")).type( 895 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 896 assertEquals(ClientResponse.Status.OK.getStatusCode(), 897 cResponse.getStatus()); 898 response = cResponse.getEntity(RegisterResponse.class); 899 assertTrue(response.isRegistered()); 900 assertTrue(response.isProfile()); 901 assertTrue(response.isInUserSpace()); 902 ProfileDescription pdesc = (ProfileDescription) response.getDescription(); 903 assertNotNull(pdesc); 904 assertEquals("Test1", pdesc.getName()); 905 assertEquals("UPDATE DESCRIPTION!", pdesc.getDescription()); 906 907 form = createFormData( 908 RegistryTestHelper.getTestProfileContent("TESTNAME"), 909 "UPDATE DESCRIPTION!"); 910 cResponse = getAuthenticatedResource(getResource().path( 911 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1" + "/update")).type( 912 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 913 assertEquals(ClientResponse.Status.OK.getStatusCode(), 914 cResponse.getStatus()); 915 response = cResponse.getEntity(RegisterResponse.class); 916 assertTrue(response.isRegistered()); 917 assertTrue(response.isProfile()); 918 assertTrue(response.isInUserSpace()); 919 pdesc = (ProfileDescription) response.getDescription(); 920 assertNotNull(pdesc); 921 assertEquals("Test1", pdesc.getName()); 922 assertEquals("UPDATE DESCRIPTION!", pdesc.getDescription()); 923 924 form = createFormData( 925 RegistryTestHelper.getTestProfileContent("TESTNAME"), 926 "UPDATE DESCRIPTION!"); 927 cResponse = getAuthenticatedResource(getResource().path( 928 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1" + "/update")).type( 929 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 930 assertEquals(403, cResponse.getStatus()); 931 932 } 815 933 816 934 } -
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.