use of org.opencastproject.index.service.resources.list.api.ResourceListProvider in project opencast by opencast.
the class ListProvidersScannerTest method testInstall.
@Test
public void testInstall() throws Exception {
String listName = "BLACKLISTS.USERS.REASONS";
File file = new File(ListProvidersScannerTest.class.getResource("/ListProvidersScannerTest-GoodProperties.properties").toURI());
Capture<ResourceListProvider> resourceListProvider = new Capture<>();
Capture<String> captureListName = new Capture<>();
ListProvidersService listProvidersService = EasyMock.createNiceMock(ListProvidersService.class);
listProvidersService.addProvider(EasyMock.capture(captureListName), EasyMock.capture(resourceListProvider));
EasyMock.expectLastCall();
EasyMock.replay(listProvidersService);
ListProvidersScanner listProvidersScanner = new ListProvidersScanner();
listProvidersScanner.setListProvidersService(listProvidersService);
listProvidersScanner.install(file);
assertEquals(1, resourceListProvider.getValues().size());
assertEquals(listName, resourceListProvider.getValue().getListNames()[0]);
assertEquals("Sick Leave", resourceListProvider.getValue().getList(listName, null, null).get("PM.BLACKLIST.REASONS.SICK_LEAVE"));
assertEquals("Leave", resourceListProvider.getValue().getList(listName, null, null).get("PM.BLACKLIST.REASONS.LEAVE"));
assertEquals("Family Emergency", resourceListProvider.getValue().getList(listName, null, null).get("PM.BLACKLIST.REASONS.FAMILY_EMERGENCY"));
assertNull(resourceListProvider.getValue().getList("Wrong List Name", null, null));
}
use of org.opencastproject.index.service.resources.list.api.ResourceListProvider in project opencast by opencast.
the class ListProvidersScannerTest method testUpdate.
@Test
public void testUpdate() throws Exception {
String listName = "BLACKLISTS.USERS.REASONS";
File file = new File(ListProvidersScannerTest.class.getResource("/ListProvidersScannerTest-GoodProperties.properties").toURI());
Capture<ResourceListProvider> resourceListProvider = new Capture<>();
Capture<String> captureListName = new Capture<>();
ListProvidersService listProvidersService = EasyMock.createNiceMock(ListProvidersService.class);
listProvidersService.addProvider(EasyMock.capture(captureListName), EasyMock.capture(resourceListProvider));
EasyMock.expectLastCall();
EasyMock.replay(listProvidersService);
ListProvidersScanner listProvidersScanner = new ListProvidersScanner();
listProvidersScanner.setListProvidersService(listProvidersService);
listProvidersScanner.update(file);
assertEquals(1, resourceListProvider.getValues().size());
assertEquals(listName, resourceListProvider.getValue().getListNames()[0]);
assertEquals("Sick Leave", resourceListProvider.getValue().getList(listName, null, null).get("PM.BLACKLIST.REASONS.SICK_LEAVE"));
assertEquals("Leave", resourceListProvider.getValue().getList(listName, null, null).get("PM.BLACKLIST.REASONS.LEAVE"));
assertEquals("Family Emergency", resourceListProvider.getValue().getList(listName, null, null).get("PM.BLACKLIST.REASONS.FAMILY_EMERGENCY"));
}
use of org.opencastproject.index.service.resources.list.api.ResourceListProvider 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);
}
}
use of org.opencastproject.index.service.resources.list.api.ResourceListProvider 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;
}
use of org.opencastproject.index.service.resources.list.api.ResourceListProvider in project opencast by opencast.
the class ListProvidersScannerTest method testInstallInputOrgInPropertiesFileExpectsAddedToService.
@Test
public void testInstallInputOrgInPropertiesFileExpectsAddedToService() throws Exception {
Organization org1 = EasyMock.createMock(Organization.class);
EasyMock.expect(org1.getId()).andReturn("org1").anyTimes();
EasyMock.replay(org1);
Organization org2 = EasyMock.createMock(Organization.class);
EasyMock.expect(org2.getId()).andReturn("org2").anyTimes();
EasyMock.replay(org2);
String listName = "BLACKLISTS.USERS.REASONS";
File file = new File(ListProvidersScannerTest.class.getResource("/ListProvidersScannerTest-WithOrg.properties").toURI());
Capture<ResourceListProvider> resourceListProvider = new Capture<>();
Capture<String> captureListName = new Capture<>();
ListProvidersService listProvidersService = EasyMock.createNiceMock(ListProvidersService.class);
listProvidersService.addProvider(EasyMock.capture(captureListName), EasyMock.capture(resourceListProvider));
EasyMock.expectLastCall();
EasyMock.replay(listProvidersService);
ListProvidersScanner listProvidersScanner = new ListProvidersScanner();
listProvidersScanner.setListProvidersService(listProvidersService);
listProvidersScanner.install(file);
ResourceListQuery query = new ResourceListQueryImpl();
assertEquals(1, resourceListProvider.getValues().size());
assertEquals(listName, resourceListProvider.getValue().getListNames()[0]);
Map<String, String> stuff = resourceListProvider.getValue().getList(listName, query, org1);
for (String key : stuff.keySet()) {
logger.info("Key: {}, Value {}.", key, stuff.get(key));
}
assertEquals(3, resourceListProvider.getValue().getList(listName, query, org1).size());
assertNull(resourceListProvider.getValue().getList(listName, query, org2));
assertNull(resourceListProvider.getValue().getList(listName, query, null));
assertEquals("Sick Leave", resourceListProvider.getValue().getList(listName, null, org1).get("PM.BLACKLIST.REASONS.SICK_LEAVE"));
assertEquals("Leave", resourceListProvider.getValue().getList(listName, null, org1).get("PM.BLACKLIST.REASONS.LEAVE"));
assertEquals("Family Emergency", resourceListProvider.getValue().getList(listName, null, org1).get("PM.BLACKLIST.REASONS.FAMILY_EMERGENCY"));
}
Aggregations