Ignore:
Timestamp:
08/11/14 16:07:55 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Added group service. Tested via the tomcat on loclahots (test URI and postman), old unit tests are adjusted and work well. Todo: retest on localhost tomcat, look at run-time exceptions, add new unit tests, adjust front-end

File:
1 edited

Legend:

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

    r4098 r5549  
    11package clarin.cmdi.componentregistry.rest;
    22
     3import clarin.cmdi.componentregistry.RegistrySpace;
    34import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase;
    45import clarin.cmdi.componentregistry.model.BaseDescription;
     
    2021
    2122import org.junit.Before;
    22 import org.junit.BeforeClass;
    2323import org.junit.Test;
    2424import org.slf4j.Logger;
     
    2727import org.springframework.jdbc.core.JdbcTemplate;
    2828
    29 import static clarin.cmdi.componentregistry.rest.ComponentRegistryRestService.USERSPACE_PARAM;
     29import static clarin.cmdi.componentregistry.rest.ComponentRegistryRestService.REGISTRY_SPACE_PARAM;
    3030import static org.junit.Assert.*;
    3131
     
    5858        List<Thread> ts = new ArrayList<Thread>();
    5959
    60         registerProfiles(ts, NR_OF_PROFILES, errors, false);
    61         registerProfiles(ts, NR_OF_PROFILES, errors, true);
    62 
    63         registerComponents(ts, NR_OF_COMPONENTS, errors, false);
    64         registerComponents(ts, NR_OF_COMPONENTS, errors, true);
     60        registerProfiles(ts, NR_OF_PROFILES, errors, RegistrySpace.PRIVATE);
     61        //a profile can be first registered (created) only in private space, and then moved.
     62        //registerProfiles(ts, NR_OF_PROFILES, errors, RegistrySpace.PUBLISHED);
     63
     64        registerComponents(ts, NR_OF_COMPONENTS, errors, RegistrySpace.PRIVATE);
     65        //a profile can be first registered (created) only in private space, and then moved.
     66        //registerComponents(ts, NR_OF_COMPONENTS, errors, RegistrySpace.PUBLISHED);
    6567        runAllThreads(ts);
    6668        if (errors.size() > 0) {
     
    7072            fail();
    7173        }
    72         assertProfiles(NR_OF_PROFILES, false);
    73         assertProfiles(NR_OF_PROFILES, true);
    74 
    75         assertComponents(NR_OF_COMPONENTS, false);
    76         assertComponents(NR_OF_COMPONENTS, true);
    77     }
    78 
    79     private void assertProfiles(int nrOfProfiles, boolean userSpace) {
     74        assertProfiles(NR_OF_PROFILES, RegistrySpace.PRIVATE);
     75        //assertProfiles(NR_OF_PROFILES, RegistrySpace.PUBLISHED);
     76
     77        assertComponents(NR_OF_COMPONENTS, RegistrySpace.PRIVATE);
     78        //assertComponents(NR_OF_COMPONENTS, RegistrySpace.PUBLISHED);
     79    }
     80
     81    private void assertProfiles(int nrOfProfiles, RegistrySpace registrySpace) {
    8082        List<ProfileDescription> response = getAuthenticatedResource(
    8183                getResource().path("/registry/profiles").queryParam(
    82                         USERSPACE_PARAM, "" + userSpace)).accept(
     84                        REGISTRY_SPACE_PARAM, registrySpace.name())).accept(
    8385                MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
    8486        Collections.sort(response, descriptionComparator);
     
    101103    };
    102104
    103     private void assertComponents(int nrOfComponents, boolean userSpace) {
     105    private void assertComponents(int nrOfComponents, RegistrySpace registrySpace) {
    104106        List<ComponentDescription> cResponse = getAuthenticatedResource(
    105107                getResource().path("/registry/components").queryParam(
    106                         USERSPACE_PARAM, "" + userSpace)).accept(
     108                        REGISTRY_SPACE_PARAM, registrySpace.name())).accept(
    107109                MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
    108110        Collections.sort(cResponse, descriptionComparator);
     
    128130
    129131    private void registerProfiles(List<Thread> ts, int size,
    130             final List<String> errors, boolean userSpace)
     132            final List<String> errors, RegistrySpace registrySpace)
    131133            throws InterruptedException {
    132134        for (int i = 0; i < size; i++) {
     
    134136            LOG.debug("Profile {} should be registered in {} and {}",
    135137                    new Object[] { i + 1000,
    136                             userSpace ? "user space" : "public space",
     138                            registrySpace.name(),
    137139                            shouldDelete ? "ALSO DELETED" : "not deleted" });
    138             Thread thread = createThread("/registry/profiles/", userSpace,
     140            Thread thread = createThread("/registry/profiles/", registrySpace,
    139141                    "Test Profile" + (i + 1000), shouldDelete,
    140142                    RegistryTestHelper.getTestProfileContent(), errors);
     
    144146
    145147    private void registerComponents(List<Thread> ts, int size,
    146             final List<String> errors, boolean userSpace)
     148            final List<String> errors, RegistrySpace registrySpace)
    147149            throws InterruptedException {
    148150        for (int i = 0; i < size; i++) {
     
    150152            LOG.debug("Component {} should be registered in {} and {}",
    151153                    new Object[] { i + 1000,
    152                             userSpace ? "user space" : "public space",
     154                            registrySpace.name(),
    153155                            shouldDelete ? "ALSO DELETED" : "not deleted" });
    154             Thread thread = createThread("/registry/components/", userSpace,
     156            Thread thread = createThread("/registry/components/", registrySpace,
    155157                    "Test Component" + (i + 1000), shouldDelete,
    156158                    RegistryTestHelper.getComponentTestContent(), errors);
     
    159161    }
    160162
    161     private Thread createThread(final String path, final boolean userSpace,
     163    private Thread createThread(final String path, final RegistrySpace registrySpace,
    162164            final String name, final boolean alsoDelete, InputStream content,
    163165            final List<String> errors) throws InterruptedException {
     
    176178                    // System.out.println("THREAD STARTED"+Thread.currentThread().getName());
    177179                    RegisterResponse registerResponse = getAuthenticatedResource(
    178                             getResource().path(path).queryParam(
    179                                     USERSPACE_PARAM, "" + userSpace)).type(
     180                            getResource().path(path)).type(
    180181                            MediaType.MULTIPART_FORM_DATA).post(
    181182                            RegisterResponse.class, form);
     
    188189                            + "] REGISTERING DESCRIPTION " + name + " "
    189190                            + registerResponse.getDescription().getId()
    190                             + (Boolean.valueOf(userSpace) ? " userspace" : "")
     191                            + registrySpace.name()
    191192                            + (alsoDelete ? " alsoDelete" : ""));
    192193                    if (alsoDelete) {
     
    197198                                + " "
    198199                                + registerResponse.getDescription().getId()
    199                                 + (Boolean.valueOf(userSpace) ? " userspace "
    200                                         : "")
     200                                + registrySpace.name()
    201201                                + (alsoDelete ? " alsoDelete" : ""));
    202202                        ClientResponse response = getAuthenticatedResource(
     
    205205                                                + registerResponse
    206206                                                        .getDescription()
    207                                                         .getId()).queryParam(
    208                                         USERSPACE_PARAM, "" + userSpace))
     207                                                        .getId()))
    209208                                .delete(ClientResponse.class);
    210209                        if (response.getStatus() != 200) {
Note: See TracChangeset for help on using the changeset viewer.