Search in sources :

Example 1 with OrganizationDatabase

use of org.opencastproject.kernel.security.persistence.OrganizationDatabase in project opencast by opencast.

the class OrganizationDirectoryServiceTest method setUp.

@Before
public void setUp() {
    OrganizationDatabase organizationDatabase = new OrganizationDatabase() {

        private int i = 0;

        private Organization organization;

        @Override
        public void storeOrganization(Organization organization) throws OrganizationDatabaseException {
            this.organization = organization;
            if (i == 0) {
                assertNotNull(organization);
                assertEquals("mh_default", organization.getId());
                assertEquals("Opencast Test", organization.getName());
                assertEquals("ROLE_TEST_ADMIN", organization.getAdminRole());
                assertEquals("ROLE_TEST_ANONYMOUS", organization.getAnonymousRole());
                Map<String, Integer> servers = organization.getServers();
                assertEquals(1, servers.size());
                assertTrue(servers.containsKey("localhost"));
                assertTrue(servers.containsValue(8080));
                assertEquals("true", organization.getProperties().get("org.test"));
            } else if (i == 1) {
                assertNotNull(organization);
                assertEquals("mh_default", organization.getId());
                assertEquals("Opencast Test 2", organization.getName());
                assertEquals("ROLE_TEST2_ADMIN", organization.getAdminRole());
                assertEquals("ROLE_TEST2_ANONYMOUS", organization.getAnonymousRole());
                Map<String, Integer> servers = organization.getServers();
                assertEquals(3, servers.size());
                assertTrue(servers.containsKey("localhost"));
                assertTrue(servers.containsValue(8080));
                assertTrue(servers.containsKey("localhost2"));
                assertTrue(servers.containsValue(8081));
                assertTrue(servers.containsKey("another"));
                assertEquals("false", organization.getProperties().get("org.test"));
            } else {
                fail("Too many storeOrganization calls: " + i);
            }
            i++;
        }

        @Override
        public List<Organization> getOrganizations() throws OrganizationDatabaseException {
            return null;
        }

        @Override
        public Organization getOrganizationByHost(String host, int port) throws OrganizationDatabaseException, NotFoundException {
            return null;
        }

        @Override
        public Organization getOrganization(String orgId) throws OrganizationDatabaseException, NotFoundException {
            if (organization == null)
                throw new NotFoundException();
            return organization;
        }

        @Override
        public void deleteOrganization(String orgId) throws OrganizationDatabaseException, NotFoundException {
        }

        @Override
        public int countOrganizations() throws OrganizationDatabaseException {
            return 0;
        }

        @Override
        public boolean containsOrganization(String orgId) throws OrganizationDatabaseException {
            return false;
        }
    };
    orgDirectoryService = new OrganizationDirectoryServiceImpl();
    orgDirectoryService.setOrgPersistence(organizationDatabase);
}
Also used : Organization(org.opencastproject.security.api.Organization) NotFoundException(org.opencastproject.util.NotFoundException) OrganizationDatabase(org.opencastproject.kernel.security.persistence.OrganizationDatabase) Map(java.util.Map) Before(org.junit.Before)

Aggregations

Map (java.util.Map)1 Before (org.junit.Before)1 OrganizationDatabase (org.opencastproject.kernel.security.persistence.OrganizationDatabase)1 Organization (org.opencastproject.security.api.Organization)1 NotFoundException (org.opencastproject.util.NotFoundException)1