Ignore:
Timestamp:
06/18/12 15:24:30 (12 years ago)
Author:
twagoo
Message:

ComponentRegistryFactory? now using ComponentStatus? and Owner instead of userId and userspace parameter.

Refs #142 and #143

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImplTest.java

    r1992 r1993  
    55import clarin.cmdi.componentregistry.model.RegistryUser;
    66import clarin.cmdi.componentregistry.ComponentRegistry;
     7import clarin.cmdi.componentregistry.ComponentStatus;
     8import clarin.cmdi.componentregistry.OwnerUser;
    79import clarin.cmdi.componentregistry.UserCredentials;
     10import clarin.cmdi.componentregistry.UserUnauthorizedException;
    811import clarin.cmdi.componentregistry.rest.DummyPrincipal;
    912import org.springframework.beans.factory.annotation.Autowired;
     
    5053
    5154    @Test
    52     public void getComponentRegistry() {
     55    public void getComponentRegistry() throws UserUnauthorizedException {
    5356        // Get public
    54         assertNotNull(componentRegistryFactory.getComponentRegistry(false, null));
     57        assertNotNull(componentRegistryFactory.getComponentRegistry(ComponentStatus.PUBLIC, null, null));
    5558
    5659        // Get for non-existing user
    5760        final RegistryUser testUser = UserDaoTest.createTestUser();
    58         UserCredentials credentials = new DummyPrincipal(testUser.
    59                 getPrincipalName()).getCredentials();
     61        UserCredentials credentials = new DummyPrincipal(testUser.getPrincipalName()).getCredentials();
    6062
    61         ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.
    62                 getComponentRegistry(true, credentials);
     63        ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials);
    6364        assertNotNull(cr1);
    6465        // Get for existing user
    65         ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.
    66                 getComponentRegistry(true, credentials);
     66        ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials);;
    6767        assertNotNull(cr2);
    6868        assertEquals(cr1.getOwner(), cr2.getOwner());
    6969
    7070        // Get for another new user
    71         UserCredentials credentials2 = new DummyPrincipal(testUser.
    72                 getPrincipalName() + "2").getCredentials();
    73         ComponentRegistryDbImpl cr3 = (ComponentRegistryDbImpl) componentRegistryFactory.
    74                 getComponentRegistry(true, credentials2);
     71        UserCredentials credentials2 = new DummyPrincipal(testUser.getPrincipalName() + "2").getCredentials();
     72        ComponentRegistryDbImpl cr3 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials2);
    7573        assertNotNull(cr3);
    7674        assertNotSame(cr1.getOwner(), cr3.getOwner());
     
    7876
    7977    @Test
    80     public void testGetOtherUserComponentRegistry() {
    81         UserCredentials userCredentials = DummyPrincipal.DUMMY_PRINCIPAL.
    82                 getCredentials();
     78    public void testGetOtherUserComponentRegistry() throws UserUnauthorizedException {
     79        UserCredentials userCredentials = DummyPrincipal.DUMMY_PRINCIPAL.getCredentials();
    8380
    8481        // Create registry for new user
    85         ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.
    86                 getComponentRegistry(true, userCredentials);
     82        ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, userCredentials);
    8783
    88         String id = cr1.getOwner().getId().toString();
     84        Number id = cr1.getOwner().getId();
    8985
    9086        // Get it as admin
    91         ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.
    92                 getOtherUserComponentRegistry(DummyPrincipal.DUMMY_ADMIN_PRINCIPAL, id);
     87        ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_ADMIN_PRINCIPAL, ComponentStatus.DEVELOPMENT, new OwnerUser(id));
    9388        assertNotNull(cr2);
    9489        // Should be this user's registry
     
    9792        // Try get it as non-admin
    9893        try {
    99             componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_PRINCIPAL, id);
     94            componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_PRINCIPAL, ComponentStatus.DEVELOPMENT, new OwnerUser(id));
    10095            fail("Non-admin can get other user's component registry");
    10196        } catch (Exception ex) {
Note: See TracChangeset for help on using the changeset viewer.