Ignore:
Timestamp:
06/18/12 14:03:46 (12 years ago)
Author:
twagoo
Message:

Created 'ComponentStatus?' enum and 'Owner' classes, and replaced userId in ComponentRegistry by Status and Owner properties.

Refs #142 and #143

File:
1 edited

Legend:

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

    r1892 r1992  
    33import clarin.cmdi.componentregistry.ComponentRegistry;
    44import clarin.cmdi.componentregistry.ComponentRegistryException;
     5import clarin.cmdi.componentregistry.ComponentStatus;
    56import clarin.cmdi.componentregistry.DeleteFailedException;
     7import clarin.cmdi.componentregistry.OwnerGroup;
     8import clarin.cmdi.componentregistry.OwnerUser;
    69import clarin.cmdi.componentregistry.UserCredentials;
    710import clarin.cmdi.componentregistry.UserUnauthorizedException;
     
    374377    private ComponentRegistry getComponentRegistryForUser(Number userId) {
    375378        ComponentRegistryDbImpl componentRegistry = componentRegistryBeanFactory.getNewComponentRegistry();
    376         componentRegistry.setUserId(userId);
     379        if (userId != null) {
     380            componentRegistry.setStatus(ComponentStatus.DEVELOPMENT, new OwnerUser(userId));
     381        }
    377382        return componentRegistry;
    378383    }
     
    669674        assertEquals("0", comment.getUserId());
    670675        assertEquals(USER_CREDS.getDisplayName(), comment.getUserName());
    671        
     676
    672677        // Should not be allowed to delete, not authenticated
    673678        assertFalse(comment.isCanDelete());
     
    774779        assertEquals("Registry of J.Unit", register.getName());
    775780    }
     781
     782    @Test
     783    public void testGetStatus() {
     784        ComponentRegistry register = new ComponentRegistryDbImpl();
     785        assertEquals(ComponentStatus.PUBLIC, register.getStatus());
     786        register = new ComponentRegistryDbImpl(ComponentStatus.DEVELOPMENT, null);
     787        assertEquals(ComponentStatus.DEVELOPMENT, register.getStatus());
     788    }
     789
     790    @Test
     791    public void testGetOwner() {
     792        ComponentRegistry register = new ComponentRegistryDbImpl();
     793        assertNull(register.getOwner());
     794        register = new ComponentRegistryDbImpl(ComponentStatus.DEVELOPMENT, new OwnerUser(101));
     795        assertEquals(new OwnerUser(101), register.getOwner());
     796
     797        register = new ComponentRegistryDbImpl(ComponentStatus.DEVELOPMENT, new OwnerGroup(101));
     798        assertEquals(new OwnerGroup(101), register.getOwner());
     799    }
     800
     801    @Test
     802    public void testSetStatus() throws Exception {
     803        // Construct with an owner
     804        ComponentRegistryDbImpl register = new ComponentRegistryDbImpl(ComponentStatus.PUBLIC, new OwnerUser(101));
     805        register.setStatus(ComponentStatus.DEVELOPMENT);
     806        assertEquals(ComponentStatus.DEVELOPMENT, register.getStatus());
     807        // Owner should remain unchanged
     808        assertEquals(new OwnerUser(101), register.getOwner());
     809
     810        // Construct with no owner
     811        register = new ComponentRegistryDbImpl(ComponentStatus.PUBLIC, null);
     812        register.setStatus(ComponentStatus.DEVELOPMENT);
     813        assertEquals(ComponentStatus.DEVELOPMENT, register.getStatus());
     814        // Owner should remain unchanged
     815        assertNull(register.getOwner());
     816    }
     817
     818    @Test
     819    public void testSetStatusAndOwner() throws Exception {
     820        ComponentRegistryDbImpl register = new ComponentRegistryDbImpl(ComponentStatus.PUBLIC, new OwnerUser(101));
     821
     822        register.setStatus(ComponentStatus.DEVELOPMENT, new OwnerGroup(102));
     823        assertEquals(ComponentStatus.DEVELOPMENT, register.getStatus());
     824        assertEquals(new OwnerGroup(102), register.getOwner());
     825    }
    776826}
Note: See TracChangeset for help on using the changeset viewer.