Changeset 5564


Ignore:
Timestamp:
08/18/14 16:33:09 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Unit test for publishing profiles and components from groups.

Location:
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RestGroupServiceTest.java

    r5563 r5564  
    88import clarin.cmdi.componentregistry.ComponentRegistryFactory;
    99import clarin.cmdi.componentregistry.ItemNotFoundException;
     10import clarin.cmdi.componentregistry.RegistrySpace;
    1011import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    1112import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase;
     
    834835    }
    835836   
     837   
    836838    @Test
    837839    public void testUpdateGroupComponentAndProfile() throws Exception {
     
    932934    }
    933935
     936     @Test
     937    public void testPublishGroupProfileAndComponent() throws Exception {
     938
     939        System.out.println("testPublishProfile");
     940
     941        fillUpGroupA();
     942        fillUpGroupB();       
     943        fillUpGroupC();
     944       
     945        baseRegistry.setRegistrySpace(RegistrySpace.PUBLISHED);
     946       
     947        FormDataMultiPart  form = createFormData(
     948                RegistryTestHelper.getTestProfileContent("publishedName"),
     949                "Published");
     950        RegisterResponse response = getAuthenticatedResource(getResource().path(
     951                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1" + "/publish"))
     952                .type(MediaType.MULTIPART_FORM_DATA).post(
     953                RegisterResponse.class, form);
     954        assertFalse(response.isInUserSpace());
     955        assertTrue(response.isProfile());
     956        assertEquals(ProfileDescription.PROFILE_PREFIX+"profile-1", response.getDescription().getId());
     957       
     958       
     959        List<ProfileDescription> profiles = baseRegistry.getProfileDescriptions();
     960        assertEquals(1, profiles.size());       
     961        ProfileDescription profileDescription = profiles.get(0);
     962        assertEquals(ProfileDescription.PROFILE_PREFIX+"profile-1", profileDescription.getId());
     963        assertEquals("link:" + ProfileDescription.PROFILE_PREFIX+"profile-1",
     964                profileDescription.getHref());
     965        assertEquals("Published", profileDescription.getDescription());
     966       
     967       
     968         
     969       
     970        // not my profile from "my" group
     971       
     972        form = createFormData(
     973                RegistryTestHelper.getTestProfileContent("publishedName"),
     974                "Published");
     975        response = getAuthenticatedResource(getResource().path(
     976                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1" + "/publish"))
     977                .type(MediaType.MULTIPART_FORM_DATA).post(
     978                RegisterResponse.class, form);
     979        assertFalse(response.isInUserSpace());
     980        assertTrue(response.isProfile());
     981        assertEquals(ProfileDescription.PROFILE_PREFIX+"Bprofile-1", response.getDescription().getId());
     982     
     983        profiles = baseRegistry.getProfileDescriptions();
     984        assertEquals(2, profiles.size());       
     985        profileDescription = profiles.get(0);
     986        assertEquals(ProfileDescription.PROFILE_PREFIX+"Bprofile-1", profileDescription.getId());
     987        assertEquals("link:" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1",
     988                profileDescription.getHref());
     989        assertEquals("Published", profileDescription.getDescription());
     990       
     991        // not my profile, not my group
     992       
     993       form = createFormData(
     994                RegistryTestHelper.getTestProfileContent("publishedName"),
     995                "Published");
     996        ClientResponse cr = getAuthenticatedResource(getResource().path(
     997                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1" + "/publish"))
     998                .type(MediaType.MULTIPART_FORM_DATA).post(
     999                ClientResponse.class, form);
     1000        assertEquals(403, cr.getStatus());
     1001        profiles = baseRegistry.getProfileDescriptions();
     1002        assertEquals(2, profiles.size());
     1003       
     1004        /// components
     1005       
     1006       
     1007        form = createFormData(
     1008                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
     1009                "Published");
     1010        response = getAuthenticatedResource(getResource().path(
     1011                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1" + "/publish"))
     1012                .type(MediaType.MULTIPART_FORM_DATA).post(
     1013                RegisterResponse.class, form);
     1014        assertFalse(response.isInUserSpace());
     1015        assertFalse(response.isProfile());
     1016        assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-1", response.getDescription().getId());
     1017       
     1018       
     1019        List<ComponentDescription> components = baseRegistry.getComponentDescriptions();
     1020        assertEquals(1, components.size());       
     1021        ComponentDescription componentDescription = components.get(0);
     1022        assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-1", componentDescription.getId());
     1023        assertEquals("link:" + ComponentDescription.COMPONENT_PREFIX+"component-1",
     1024                componentDescription.getHref());
     1025        assertEquals("Published", componentDescription.getDescription());
     1026       
     1027       
     1028         
     1029       
     1030        // not my profile from "my" group
     1031       
     1032       
     1033         form = createFormData(
     1034                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
     1035                "Published");
     1036        response = getAuthenticatedResource(getResource().path(
     1037                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1" + "/publish"))
     1038                .type(MediaType.MULTIPART_FORM_DATA).post(
     1039                RegisterResponse.class, form);
     1040        assertFalse(response.isInUserSpace());
     1041        assertFalse(response.isProfile());
     1042        assertEquals(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1", response.getDescription().getId());
     1043       
     1044       
     1045        components = baseRegistry.getComponentDescriptions();
     1046        assertEquals(2, components.size());       
     1047        componentDescription = components.get(0);
     1048        assertEquals(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1", componentDescription.getId());
     1049        assertEquals("link:" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1",
     1050                componentDescription.getHref());
     1051        assertEquals("Published", componentDescription.getDescription());
     1052       
     1053       
     1054        // not my profile, not my group
     1055       
     1056        form = createFormData(
     1057                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
     1058                "Published");
     1059        cr = getAuthenticatedResource(getResource().path(
     1060                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1" + "/publish"))
     1061                .type(MediaType.MULTIPART_FORM_DATA).post(
     1062                ClientResponse.class, form);
     1063        assertEquals(403, cr.getStatus());
     1064        components = baseRegistry.getComponentDescriptions();
     1065        assertEquals(2, components.size()); 
     1066    }
     1067   
    9341068}
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java

    r5563 r5564  
    88import clarin.cmdi.componentregistry.ComponentRegistryFactory;
    99import clarin.cmdi.componentregistry.ItemNotFoundException;
     10import clarin.cmdi.componentregistry.RegistrySpace;
     11import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    1012import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase;
    1113import clarin.cmdi.componentregistry.impl.database.GroupService;
     14import clarin.cmdi.componentregistry.model.BaseDescription;
    1215import clarin.cmdi.componentregistry.model.Comment;
    1316import clarin.cmdi.componentregistry.model.ComponentDescription;
     
    2225import java.text.ParseException;
    2326import java.util.Date;
     27import java.util.List;
    2428import javax.ws.rs.core.MediaType;
    2529import javax.xml.bind.JAXBException;
     
    224228    }
    225229   
    226     @Test
    227     public void testUpdateGroupComponentAndProfile() throws Exception {
    228 
    229         System.out.println("test updateGorupComponent");
     230 
     231   
     232     @Test
     233    public void testPublishGroupProfileAndComponent() throws Exception {
     234
     235        System.out.println("testPublishProfile");
    230236
    231237        fillUpGroupA();
    232238        fillUpGroupB();       
    233239        fillUpGroupC();
    234 
     240       
     241        baseRegistry.setRegistrySpace(RegistrySpace.PUBLISHED);
     242       
     243        FormDataMultiPart  form = createFormData(
     244                RegistryTestHelper.getTestProfileContent("publishedName"),
     245                "Published");
     246        RegisterResponse response = getAuthenticatedResource(getResource().path(
     247                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1" + "/publish"))
     248                .type(MediaType.MULTIPART_FORM_DATA).post(
     249                RegisterResponse.class, form);
     250        assertFalse(response.isInUserSpace());
     251        assertTrue(response.isProfile());
     252        assertEquals(ProfileDescription.PROFILE_PREFIX+"profile-1", response.getDescription().getId());
     253       
     254       
     255        List<ProfileDescription> profiles = baseRegistry.getProfileDescriptions();
     256        assertEquals(1, profiles.size());       
     257        ProfileDescription profileDescription = profiles.get(0);
     258        assertEquals(ProfileDescription.PROFILE_PREFIX+"profile-1", profileDescription.getId());
     259        assertEquals("link:" + ProfileDescription.PROFILE_PREFIX+"profile-1",
     260                profileDescription.getHref());
     261        assertEquals("Published", profileDescription.getDescription());
     262       
     263       
     264         
     265       
     266        // not my profile from "my" group
     267       
     268        form = createFormData(
     269                RegistryTestHelper.getTestProfileContent("publishedName"),
     270                "Published");
     271        response = getAuthenticatedResource(getResource().path(
     272                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1" + "/publish"))
     273                .type(MediaType.MULTIPART_FORM_DATA).post(
     274                RegisterResponse.class, form);
     275        assertFalse(response.isInUserSpace());
     276        assertTrue(response.isProfile());
     277        assertEquals(ProfileDescription.PROFILE_PREFIX+"Bprofile-1", response.getDescription().getId());
    235278     
    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());
     279        profiles = baseRegistry.getProfileDescriptions();
     280        assertEquals(2, profiles.size());       
     281        profileDescription = profiles.get(0);
     282        assertEquals(ProfileDescription.PROFILE_PREFIX+"Bprofile-1", profileDescription.getId());
     283        assertEquals("link:" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1",
     284                profileDescription.getHref());
     285        assertEquals("Published", profileDescription.getDescription());
     286       
     287        // not my profile, not my group
     288       
     289       form = createFormData(
     290                RegistryTestHelper.getTestProfileContent("publishedName"),
     291                "Published");
     292        ClientResponse cr = getAuthenticatedResource(getResource().path(
     293                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1" + "/publish"))
     294                .type(MediaType.MULTIPART_FORM_DATA).post(
     295                ClientResponse.class, form);
     296        assertEquals(403, cr.getStatus());
     297        profiles = baseRegistry.getProfileDescriptions();
     298        assertEquals(2, profiles.size());
     299       
     300        /// components
     301       
     302       
     303        form = createFormData(
     304                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
     305                "Published");
     306        response = getAuthenticatedResource(getResource().path(
     307                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1" + "/publish"))
     308                .type(MediaType.MULTIPART_FORM_DATA).post(
     309                RegisterResponse.class, form);
     310        assertFalse(response.isInUserSpace());
    247311        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());
     312        assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-1", response.getDescription().getId());
     313       
     314       
     315        List<ComponentDescription> components = baseRegistry.getComponentDescriptions();
     316        assertEquals(1, components.size());       
     317        ComponentDescription componentDescription = components.get(0);
     318        assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-1", componentDescription.getId());
     319        assertEquals("link:" + ComponentDescription.COMPONENT_PREFIX+"component-1",
     320                componentDescription.getHref());
     321        assertEquals("Published", componentDescription.getDescription());
     322       
     323       
     324         
     325       
     326        // not my profile from "my" group
     327       
     328       
     329         form = createFormData(
     330                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
     331                "Published");
     332        response = getAuthenticatedResource(getResource().path(
     333                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1" + "/publish"))
     334                .type(MediaType.MULTIPART_FORM_DATA).post(
     335                RegisterResponse.class, form);
     336        assertFalse(response.isInUserSpace());
     337        assertFalse(response.isProfile());
     338        assertEquals(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1", response.getDescription().getId());
     339       
     340       
     341        components = baseRegistry.getComponentDescriptions();
     342        assertEquals(2, components.size());       
     343        componentDescription = components.get(0);
     344        assertEquals(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1", componentDescription.getId());
     345        assertEquals("link:" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1",
     346                componentDescription.getHref());
     347        assertEquals("Published", componentDescription.getDescription());
     348       
     349       
     350        // not my profile, not my group
    253351       
    254352        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());
    270        
    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        
    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());
    321        
     353                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
     354                "Published");
     355        cr = getAuthenticatedResource(getResource().path(
     356                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1" + "/publish"))
     357                .type(MediaType.MULTIPART_FORM_DATA).post(
     358                ClientResponse.class, form);
     359        assertEquals(403, cr.getStatus());
     360        components = baseRegistry.getComponentDescriptions();
     361        assertEquals(2, components.size()); 
    322362    }
    323363
Note: See TracChangeset for help on using the changeset viewer.