Search in sources :

Example 1 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.

the class ServersListProviderTest method testHostnameList.

@Test
public void testHostnameList() throws ListProviderException {
    ResourceListQuery query = new ServersListQuery();
    Map<String, String> list = serverListProvider.getList(ServersListProvider.LIST_HOSTNAME, query, null);
    assertEquals(HOST1, list.get(HOST1));
    assertEquals(HOST2, list.get(HOST2));
    assertEquals(HOST3, list.get(HOST3));
    assertEquals(HOST4, list.get(HOST4));
}
Also used : ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) ServersListQuery(org.opencastproject.index.service.resources.list.query.ServersListQuery) Test(org.junit.Test)

Example 2 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.

the class ServersListProviderTest method testListNames.

@Test
public void testListNames() throws ListProviderException {
    ResourceListQuery query = new ServersListQuery();
    assertEquals(4, serverListProvider.getList("non-existing-name", query, null).size());
    assertEquals(4, serverListProvider.getList(ServersListProvider.LIST_HOSTNAME, query, null).size());
    assertEquals(3, serverListProvider.getList(ServersListProvider.LIST_STATUS, query, null).size());
}
Also used : ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) ServersListQuery(org.opencastproject.index.service.resources.list.query.ServersListQuery) Test(org.junit.Test)

Example 3 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.

the class JSONUtilsTest method testFiltersToJSON.

/**
 * Test method for
 * {@link JSONUtils#filtersToJSON(org.opencastproject.index.service.resources.list.api.ResourceListQuery, org.opencastproject.index.service.resources.list.api.ListProvidersService, org.opencastproject.security.api.Organization)}
 * (filters, listProviderService, query, org)}
 */
@Test
public void testFiltersToJSON() throws Exception {
    String expectedJSON = IOUtils.toString(getClass().getResource("/filters.json"));
    JaxbOrganization defaultOrganization = new DefaultOrganization();
    ListProvidersServiceImpl listProvidersService = new ListProvidersServiceImpl();
    SimpleSerializer serializer = new SimpleSerializer();
    final Map<String, String> license = new HashMap<String, String>();
    license.put("contributor1", "My first contributor");
    license.put("contributor2", "My second contributor");
    license.put("contributor3", "My third contributor");
    // Create test list provider
    listProvidersService.addProvider(new ResourceListProvider() {

        @Override
        public String[] getListNames() {
            return new String[] { ContributorsListProvider.DEFAULT };
        }

        @Override
        public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
            return ListProviderUtil.filterMap(license, query);
        }

        @Override
        public boolean isTranslatable(String listName) {
            return false;
        }

        @Override
        public String getDefault() {
            return null;
        }
    });
    // Prepare mock query
    List<ResourceListFilter<?>> filters = new ArrayList<ResourceListFilter<?>>();
    filters.add(SeriesListQuery.createContributorsFilter(Option.<String>none()));
    filters.add(new StringListFilter(""));
    ResourceListQueryImpl query = EasyMock.createNiceMock(ResourceListQueryImpl.class);
    EasyMock.expect(query.getAvailableFilters()).andReturn(filters).anyTimes();
    EasyMock.expect(query.getFilters()).andReturn(new ArrayList<ResourceListFilter<?>>()).anyTimes();
    EasyMock.expect(query.getLimit()).andReturn(Option.<Integer>none()).anyTimes();
    EasyMock.expect(query.getOffset()).andReturn(Option.<Integer>none()).anyTimes();
    EasyMock.replay(query);
    JValue result = JSONUtils.filtersToJSON(query, listProvidersService, defaultOrganization);
    StreamingOutput stream = RestUtils.stream(serializer.fn.toJson(result));
    ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
    try {
        stream.write(resultStream);
        assertThat(expectedJSON, SameJSONAs.sameJSONAs(resultStream.toString()));
    } finally {
        IOUtils.closeQuietly(resultStream);
    }
}
Also used : SimpleSerializer(com.entwinemedia.fn.data.json.SimpleSerializer) ResourceListProvider(org.opencastproject.index.service.resources.list.api.ResourceListProvider) Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) ListProvidersServiceImpl(org.opencastproject.index.service.resources.list.impl.ListProvidersServiceImpl) HashMap(java.util.HashMap) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) ArrayList(java.util.ArrayList) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) StreamingOutput(javax.ws.rs.core.StreamingOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) ResourceListFilter(org.opencastproject.index.service.resources.list.api.ResourceListFilter) JValue(com.entwinemedia.fn.data.json.JValue) HashMap(java.util.HashMap) Map(java.util.Map) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) StringListFilter(org.opencastproject.index.service.resources.list.query.StringListFilter) Test(org.junit.Test)

Example 4 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.

the class JobsListProviderTest method testWorkflowListName.

@Test
public void testWorkflowListName() throws ListProviderException, WorkflowDatabaseException {
    ResourceListQuery query = new JobsListQuery();
    assertEquals(workflowDefinitions.size(), jobsListProvider.getList(JobsListProvider.LIST_WORKFLOW, query, null).size());
    for (Entry<String, String> entry : jobsListProvider.getList(JobsListProvider.LIST_WORKFLOW, query, null).entrySet()) {
        boolean match = false;
        for (WorkflowDefinition wfD : workflowDefinitions) {
            if (StringUtils.equals(wfD.getId(), entry.getKey()) && StringUtils.equals(wfD.getTitle(), entry.getValue())) {
                match = true;
                break;
            }
        }
        assertTrue(match);
    }
}
Also used : WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) JobsListQuery(org.opencastproject.index.service.resources.list.query.JobsListQuery) Test(org.junit.Test)

Example 5 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.

the class TestSeriesEndpoint method createListProviderService.

private ListProvidersService createListProviderService(List<User> users) {
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.findUsers("%", 0, 0)).andReturn(users.iterator()).anyTimes();
    EasyMock.replay(userDirectoryService);
    UsersListProvider userListProvider = new UsersListProvider();
    userListProvider.setUserDirectoryService(userDirectoryService);
    ListProvidersServiceImpl listProvidersServiceImpl = new ListProvidersServiceImpl();
    listProvidersServiceImpl.addProvider(userListProvider);
    listProvidersServiceImpl.addProvider(new ResourceListProvider() {

        @Override
        public String[] getListNames() {
            return new String[] { "LANGUAGES" };
        }

        @Override
        public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) {
            return new HashMap<>();
        }

        @Override
        public boolean isTranslatable(String listName) {
            return false;
        }

        @Override
        public String getDefault() {
            return null;
        }
    });
    return listProvidersServiceImpl;
}
Also used : UsersListProvider(org.opencastproject.index.service.resources.list.provider.UsersListProvider) ResourceListProvider(org.opencastproject.index.service.resources.list.api.ResourceListProvider) Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) ListProvidersServiceImpl(org.opencastproject.index.service.resources.list.impl.ListProvidersServiceImpl) ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) Map(java.util.Map) HashMap(java.util.HashMap) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService)

Aggregations

ResourceListQuery (org.opencastproject.index.service.resources.list.api.ResourceListQuery)10 Test (org.junit.Test)8 ResourceListQueryImpl (org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl)4 HashMap (java.util.HashMap)3 ResourceListProvider (org.opencastproject.index.service.resources.list.api.ResourceListProvider)3 ServersListQuery (org.opencastproject.index.service.resources.list.query.ServersListQuery)3 Organization (org.opencastproject.security.api.Organization)3 Map (java.util.Map)2 ListProviderException (org.opencastproject.index.service.exception.ListProviderException)2 ListProvidersServiceImpl (org.opencastproject.index.service.resources.list.impl.ListProvidersServiceImpl)2 JobsListQuery (org.opencastproject.index.service.resources.list.query.JobsListQuery)2 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)2 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)2 JValue (com.entwinemedia.fn.data.json.JValue)1 SimpleSerializer (com.entwinemedia.fn.data.json.SimpleSerializer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1