Search in sources :

Example 6 with ListProvidersService

use of org.opencastproject.index.service.resources.list.api.ListProvidersService 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"));
}
Also used : Organization(org.opencastproject.security.api.Organization) ResourceListProvider(org.opencastproject.index.service.resources.list.api.ResourceListProvider) ListProvidersService(org.opencastproject.index.service.resources.list.api.ListProvidersService) ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) File(java.io.File) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 7 with ListProvidersService

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

the class ListProvidersScannerTest method testInstallInputEmptyListNameInPropertiesFileExpectsNotAddedToService.

@Test
public void testInstallInputEmptyListNameInPropertiesFileExpectsNotAddedToService() throws Exception {
    File file = new File(ListProvidersScannerTest.class.getResource("/ListProvidersScannerTest-EmptyListName.properties").toURI());
    ListProvidersService listProvidersService = EasyMock.createMock(ListProvidersService.class);
    EasyMock.replay(listProvidersService);
    ListProvidersScanner listProvidersScanner = new ListProvidersScanner();
    listProvidersScanner.setListProvidersService(listProvidersService);
    listProvidersScanner.install(file);
}
Also used : ListProvidersService(org.opencastproject.index.service.resources.list.api.ListProvidersService) File(java.io.File) Test(org.junit.Test)

Example 8 with ListProvidersService

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

the class EventCatalogUIAdapterTest method setUp.

@Before
public void setUp() throws URISyntaxException, NotFoundException, IOException, ListProviderException {
    TreeMap<String, String> collection = new TreeMap<String, String>();
    collection.put("Entry 1", "Value 1");
    collection.put("Entry 2", "Value 2");
    collection.put("Entry 3", "Value 3");
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.replay(bundleContext);
    listProvidersService = EasyMock.createMock(ListProvidersService.class);
    EasyMock.expect(listProvidersService.getList(EasyMock.anyString(), EasyMock.anyObject(ResourceListQueryImpl.class), EasyMock.anyObject(Organization.class), EasyMock.anyBoolean())).andReturn(collection).anyTimes();
    EasyMock.expect(listProvidersService.isTranslatable(EasyMock.anyString())).andThrow(new ListProviderException("not implemented")).anyTimes();
    EasyMock.expect(listProvidersService.getDefault(EasyMock.anyString())).andThrow(new ListProviderException("not implemented")).anyTimes();
    EasyMock.replay(listProvidersService);
    Properties props = new Properties();
    InputStream in = getClass().getResourceAsStream("/catalog-adapter/event.properties");
    props.load(in);
    in.close();
    eventProperties = PropertiesUtil.toDictionary(props);
    mediaPackageElementFlavor = new MediaPackageElementFlavor(FLAVOR_STRING.split("/")[0], FLAVOR_STRING.split("/")[1]);
    URI eventDublincoreURI = getClass().getResource("/catalog-adapter/event-dublincore.xml").toURI();
    workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.read(eventDublincoreURI)).andAnswer(() -> new FileInputStream(new File(eventDublincoreURI)));
    EasyMock.replay(workspace);
    Catalog eventCatalog = EasyMock.createMock(Catalog.class);
    EasyMock.expect(eventCatalog.getURI()).andReturn(eventDublincoreURI).anyTimes();
    EasyMock.replay(eventCatalog);
    Catalog[] catalogs = { eventCatalog };
    mediapackage = EasyMock.createMock(MediaPackage.class);
    EasyMock.expect(mediapackage.getCatalogs(mediaPackageElementFlavor)).andReturn(catalogs).anyTimes();
    EasyMock.replay(mediapackage);
    dictionary = new Hashtable<String, String>();
    dictionary.put(CONF_ORGANIZATION_KEY, ORGANIZATION_STRING);
    dictionary.put(CONF_FLAVOR_KEY, FLAVOR_STRING);
    dictionary.put(CONF_TITLE_KEY, TITLE_STRING);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_INPUT_ID_KEY, title);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_LABEL_KEY, label);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_TYPE_KEY, type);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_READ_ONLY_KEY, readOnly);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_REQUIRED_KEY, required);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_LIST_PROVIDER_KEY, listProvider);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_COLLECTION_ID_KEY, collectionID);
}
Also used : ListProvidersService(org.opencastproject.index.service.resources.list.api.ListProvidersService) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) TreeMap(java.util.TreeMap) Properties(java.util.Properties) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) FileInputStream(java.io.FileInputStream) Catalog(org.opencastproject.mediapackage.Catalog) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Aggregations

File (java.io.File)8 ListProvidersService (org.opencastproject.index.service.resources.list.api.ListProvidersService)8 Test (org.junit.Test)6 Capture (org.easymock.Capture)3 ResourceListProvider (org.opencastproject.index.service.resources.list.api.ResourceListProvider)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 TreeMap (java.util.TreeMap)2 Before (org.junit.Before)2 Catalog (org.opencastproject.mediapackage.Catalog)2 MediaPackage (org.opencastproject.mediapackage.MediaPackage)2 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)2 Workspace (org.opencastproject.workspace.api.Workspace)2 BundleContext (org.osgi.framework.BundleContext)2 URI (java.net.URI)1 ListProviderException (org.opencastproject.index.service.exception.ListProviderException)1 ResourceListQuery (org.opencastproject.index.service.resources.list.api.ResourceListQuery)1 ResourceListQueryImpl (org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl)1 Id (org.opencastproject.mediapackage.identifier.Id)1