Changeset 1993 for ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImplTest.java
- Timestamp:
- 06/18/12 15:24:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImplTest.java
r1992 r1993 5 5 import clarin.cmdi.componentregistry.model.RegistryUser; 6 6 import clarin.cmdi.componentregistry.ComponentRegistry; 7 import clarin.cmdi.componentregistry.ComponentStatus; 8 import clarin.cmdi.componentregistry.OwnerUser; 7 9 import clarin.cmdi.componentregistry.UserCredentials; 10 import clarin.cmdi.componentregistry.UserUnauthorizedException; 8 11 import clarin.cmdi.componentregistry.rest.DummyPrincipal; 9 12 import org.springframework.beans.factory.annotation.Autowired; … … 50 53 51 54 @Test 52 public void getComponentRegistry() {55 public void getComponentRegistry() throws UserUnauthorizedException { 53 56 // Get public 54 assertNotNull(componentRegistryFactory.getComponentRegistry( false, null));57 assertNotNull(componentRegistryFactory.getComponentRegistry(ComponentStatus.PUBLIC, null, null)); 55 58 56 59 // Get for non-existing user 57 60 final RegistryUser testUser = UserDaoTest.createTestUser(); 58 UserCredentials credentials = new DummyPrincipal(testUser. 59 getPrincipalName()).getCredentials(); 61 UserCredentials credentials = new DummyPrincipal(testUser.getPrincipalName()).getCredentials(); 60 62 61 ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory. 62 getComponentRegistry(true, credentials); 63 ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials); 63 64 assertNotNull(cr1); 64 65 // Get for existing user 65 ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory. 66 getComponentRegistry(true, credentials); 66 ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials);; 67 67 assertNotNull(cr2); 68 68 assertEquals(cr1.getOwner(), cr2.getOwner()); 69 69 70 70 // 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); 75 73 assertNotNull(cr3); 76 74 assertNotSame(cr1.getOwner(), cr3.getOwner()); … … 78 76 79 77 @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(); 83 80 84 81 // Create registry for new user 85 ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory. 86 getComponentRegistry(true, userCredentials); 82 ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, userCredentials); 87 83 88 String id = cr1.getOwner().getId().toString();84 Number id = cr1.getOwner().getId(); 89 85 90 86 // 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)); 93 88 assertNotNull(cr2); 94 89 // Should be this user's registry … … 97 92 // Try get it as non-admin 98 93 try { 99 componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_PRINCIPAL, id);94 componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_PRINCIPAL, ComponentStatus.DEVELOPMENT, new OwnerUser(id)); 100 95 fail("Non-admin can get other user's component registry"); 101 96 } catch (Exception ex) {
Note: See TracChangeset
for help on using the changeset viewer.