Search in sources :

Example 1 with ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.

the class ListProviderUtilTest method testFilterMap.

@Test
public void testFilterMap() {
    Map<String, String> testMap = getTestMap();
    ResourceListQueryImpl query = new ResourceListQueryImpl();
    query.setLimit(3);
    query.setOffset(0);
    assertEquals(3, filterMap(testMap, query).size());
    query.setLimit(0);
    query.setOffset(testMap.size());
    assertEquals(0, filterMap(testMap, query).size());
    query.setLimit(6);
    query.setOffset(testMap.size() - 3);
    assertEquals(3, filterMap(testMap, query).size());
}
Also used : ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) Test(org.junit.Test)

Example 2 with ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.

the class UsersListProviderTest method testListQuery.

@Test
public void testListQuery() {
    ResourceListQueryImpl query = new ResourceListQueryImpl();
    query.setLimit(0);
    query.setOffset(0);
    Assert.assertEquals(4, usersListProvider.getList(UsersListProvider.USERNAME, query, null).size());
    query.setOffset(3);
    Assert.assertEquals(1, usersListProvider.getList(UsersListProvider.USERNAME, query, null).size());
    query.setOffset(0);
    query.setLimit(1);
    Assert.assertEquals(1, usersListProvider.getList(UsersListProvider.USERNAME, query, null).size());
}
Also used : ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) Test(org.junit.Test)

Example 3 with ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl 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 ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.

the class ServiceTest method testConcreteFilter.

@Test
public void testConcreteFilter() {
    ResourceListQueryImpl query = makeQuery(new StringListFilter("host", "HOST 1"));
    assertTrue(service.isCompliant(query));
}
Also used : ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) StringListFilter(org.opencastproject.index.service.resources.list.query.StringListFilter) Test(org.junit.Test)

Example 5 with ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.

the class ServiceTest method makeQuery.

private ResourceListQueryImpl makeQuery(StringListFilter filter) {
    ResourceListQueryImpl query = new ResourceListQueryImpl();
    query.addFilter(filter);
    return query;
}
Also used : ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl)

Aggregations

ResourceListQueryImpl (org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl)15 Test (org.junit.Test)12 StringListFilter (org.opencastproject.index.service.resources.list.query.StringListFilter)7 ResourceListQuery (org.opencastproject.index.service.resources.list.api.ResourceListQuery)4 HashMap (java.util.HashMap)3 ListProviderException (org.opencastproject.index.service.exception.ListProviderException)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 JSONObject (org.json.simple.JSONObject)2 EndpointUtil.generateJSONObject (org.opencastproject.adminui.endpoint.EndpointUtil.generateJSONObject)2 JsonCreationException (org.opencastproject.adminui.exception.JsonCreationException)2 ResourceListProvider (org.opencastproject.index.service.resources.list.api.ResourceListProvider)2 Organization (org.opencastproject.security.api.Organization)2 RestQuery (org.opencastproject.util.doc.rest.RestQuery)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