use of org.opencastproject.index.service.resources.list.api.ResourceListQuery 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"));
}
use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.
the class ServersListProviderTest method testStatusList.
@Test
public void testStatusList() throws ListProviderException {
ResourceListQuery query = new ServersListQuery();
Map<String, String> list = serverListProvider.getList(ServersListProvider.LIST_STATUS, query, null);
assertEquals(ServersListProvider.SERVER_STATUS_LABEL_ONLINE, list.get(ServersListProvider.SERVER_STATUS_ONLINE));
assertEquals(ServersListProvider.SERVER_STATUS_LABEL_OFFLINE, list.get(ServersListProvider.SERVER_STATUS_OFFLINE));
assertEquals(ServersListProvider.SERVER_STATUS_LABEL_MAINTENANCE, list.get(ServersListProvider.SERVER_STATUS_MAINTENANCE));
}
use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.
the class ListProvidersServiceTest method testAddandRemove.
@Test
public void testAddandRemove() throws ListProviderException {
final String providerName1 = "test1";
final Map<String, String> list1 = new HashMap<String, String>();
list1.put("1", "test");
list1.put("2", "test");
list1.put("3", "test");
list1.put("4", "test");
final String providerName2 = "test2";
final Map<String, String> list2 = new HashMap<String, String>();
list2.put("1", "test");
list2.put("2", "test");
list2.put("3", "test");
list2.put("4", "test");
int baseNumber = listProviderService.getAvailableProviders().size();
ResourceListQuery query = new ResourceListQueryImpl();
listProviderService.addProvider(getResourceListProvider(providerName1, list1));
listProviderService.addProvider(getResourceListProvider(providerName2, list2));
Assert.assertEquals(baseNumber + 2, listProviderService.getAvailableProviders().size());
Assert.assertTrue(listProviderService.hasProvider(providerName1));
Assert.assertTrue(listProviderService.hasProvider(providerName2));
Assert.assertEquals(list1, listProviderService.getList(providerName1, query, null, false));
Assert.assertEquals(list2, listProviderService.getList(providerName2, query, null, false));
listProviderService.removeProvider(providerName2);
Assert.assertEquals(baseNumber + 1, listProviderService.getAvailableProviders().size());
Assert.assertFalse(listProviderService.hasProvider(providerName2));
}
use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.
the class JobsListProviderTest method testStatusListName.
@Test
public void testStatusListName() throws ListProviderException, WorkflowDatabaseException {
ResourceListQuery query = new JobsListQuery();
assertEquals(4, jobsListProvider.getList(JobsListProvider.LIST_STATUS, query, null).size());
for (Entry<String, String> entry : jobsListProvider.getList(JobsListProvider.LIST_STATUS, query, null).entrySet()) {
try {
Job.Status.valueOf(entry.getKey());
} catch (IllegalArgumentException ex) {
fail("Can not parse job state");
}
assertTrue(StringUtils.startsWith(entry.getValue(), JobsListProvider.JOB_STATUS_FILTER_PREFIX));
}
}
use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.
the class ListProvidersEndpoint method getComponents.
@GET
@Path("components.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "components", description = "Provides a set of constants lists (right now only eventCommentReasons) for use in the admin UI", reponses = { @RestResponse(description = "Returns a set of constants lists (right now only eventCommentReasons) for use in the admin UI", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "")
public Response getComponents(@Context HttpHeaders headers) {
String[] sources = { "eventCommentReasons" };
ResourceListQuery query = new ResourceListQueryImpl();
JSONObject list = new JSONObject();
for (String source : sources) {
if (listProvidersService.hasProvider(source)) {
JSONObject subList;
try {
subList = generateJSONObject(listProvidersService.getList(source, query, securityService.getOrganization(), true));
list.put(source, subList);
} catch (JsonCreationException e) {
logger.error("Not able to generate resources list JSON from source {}: {}", source, e);
return SERVER_ERROR;
} catch (ListProviderException e) {
logger.error("Not able to get list from provider {}: {}", source, e);
return SERVER_ERROR;
}
} else {
return NOT_FOUND;
}
}
return Response.ok(list.toString()).build();
}
Aggregations