Search in sources :

Example 1 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class AssetManagerItemTest method testSerializeUpdate.

@Test
public void testSerializeUpdate() throws Exception {
    final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(new File(getClass().getResource("/dublincore-a.xml").toURI())).once();
    EasyMock.expect(workspace.read(EasyMock.anyObject(URI.class))).andAnswer(() -> getClass().getResourceAsStream("/dublincore-a.xml")).once();
    EasyMock.replay(workspace);
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mp.add(DublinCores.mkOpencastEpisode().getCatalog());
    final AccessControlList acl = new AccessControlList(new AccessControlEntry("admin", "read", true));
    final Date now = new Date();
    final AssetManagerItem item = AssetManagerItem.add(workspace, mp, acl, 10L, now);
    final AssetManagerItem deserialized = IoSupport.serializeDeserialize(item);
    assertEquals(item.getDate(), deserialized.getDate());
    assertEquals(item.getType(), deserialized.getType());
    assertEquals(item.decompose(TakeSnapshot.getMediaPackage, null, null).getIdentifier(), deserialized.decompose(TakeSnapshot.getMediaPackage, null, null).getIdentifier());
    assertEquals(item.decompose(TakeSnapshot.getAcl, null, null).getEntries(), deserialized.decompose(TakeSnapshot.getAcl, null, null).getEntries());
    assertTrue(DublinCoreUtil.equals(item.decompose(TakeSnapshot.getEpisodeDublincore, null, null).get(), deserialized.decompose(TakeSnapshot.getEpisodeDublincore, null, null).get()));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AssetManagerItem(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) File(java.io.File) Date(java.util.Date) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 2 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class AbstractFileSystemAssetStoreTest method setUp.

@Before
public void setUp() throws Exception {
    final File asset = IoSupport.classPathResourceAsFile("/" + FILE_NAME).get();
    final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject())).andReturn(asset);
    EasyMock.expect(workspace.get(EasyMock.anyObject(), EasyMock.anyBoolean())).andAnswer(() -> {
        File tmp = tmpFolder.newFile();
        FileUtils.copyFile(asset, tmp);
        return tmp;
    }).anyTimes();
    EasyMock.replay(workspace);
    tmpRoot = tmpFolder.newFolder();
    repo = new AbstractFileSystemAssetStore() {

        @Override
        protected Workspace getWorkspace() {
            return workspace;
        }

        @Override
        protected String getRootDirectory() {
            return tmpRoot.getAbsolutePath();
        }
    };
    sampleElemDir = new File(PathSupport.concat(new String[] { tmpRoot.toString(), ORG_ID, MP_ID, VERSION_2.toString() }));
    FileUtils.forceMkdir(sampleElemDir);
    FileUtils.copyFile(asset, new File(sampleElemDir, MP_ELEM_ID + XML_EXTENSTION));
}
Also used : File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 3 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class IndexServiceImplTest method testCreateEventInputNormalExpectsCreatedEvent.

@Test
public void testCreateEventInputNormalExpectsCreatedEvent() throws Exception {
    String expectedTitle = "Test Event Creation";
    String username = "akm220";
    String org = "mh_default_org";
    String[] creators = new String[] {};
    Id mpId = new IdImpl("mp-id");
    String testResourceLocation = "/events/create-event.json";
    JSONObject metadataJson = (JSONObject) parser.parse(IOUtils.toString(IndexServiceImplTest.class.getResourceAsStream(testResourceLocation)));
    Capture<Catalog> result = EasyMock.newCapture();
    Capture<String> mediapackageIdResult = EasyMock.newCapture();
    Capture<String> catalogIdResult = EasyMock.newCapture();
    Capture<String> filenameResult = EasyMock.newCapture();
    Capture<InputStream> catalogResult = EasyMock.newCapture();
    Capture<String> mediapackageTitleResult = EasyMock.newCapture();
    SecurityService securityService = setupSecurityService(username, org);
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.capture(mediapackageIdResult), EasyMock.capture(catalogIdResult), EasyMock.capture(filenameResult), EasyMock.capture(catalogResult))).andReturn(new URI("catalog.xml"));
    EasyMock.replay(workspace);
    // Create Common Event Catalog UI Adapter
    CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
    // Setup mediapackage.
    MediaPackage mediapackage = EasyMock.createMock(MediaPackage.class);
    mediapackage.add(EasyMock.capture(result));
    EasyMock.expectLastCall();
    EasyMock.expect(mediapackage.getCatalogs(EasyMock.anyObject(MediaPackageElementFlavor.class))).andReturn(new Catalog[] {});
    EasyMock.expect(mediapackage.getIdentifier()).andReturn(mpId).anyTimes();
    EasyMock.expect(mediapackage.getCreators()).andReturn(creators);
    mediapackage.addCreator("");
    EasyMock.expectLastCall();
    mediapackage.setTitle(EasyMock.capture(mediapackageTitleResult));
    EasyMock.expectLastCall();
    EasyMock.expect(mediapackage.getElements()).andReturn(new MediaPackageElement[] {}).anyTimes();
    EasyMock.expect(mediapackage.getCatalogs(EasyMock.anyObject(MediaPackageElementFlavor.class))).andReturn(new Catalog[] {}).anyTimes();
    EasyMock.expect(mediapackage.getSeries()).andReturn(null).anyTimes();
    mediapackage.setSeries(EasyMock.anyString());
    mediapackage.setSeriesTitle(EasyMock.anyString());
    EasyMock.expectLastCall();
    EasyMock.replay(mediapackage);
    IngestService ingestService = setupIngestService(mediapackage, Capture.<InputStream>newInstance());
    // Setup Authorization Service
    Tuple<MediaPackage, Attachment> returnValue = new Tuple<MediaPackage, Attachment>(mediapackage, null);
    AuthorizationService authorizationService = EasyMock.createMock(AuthorizationService.class);
    EasyMock.expect(authorizationService.setAcl(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(AclScope.class), EasyMock.anyObject(AccessControlList.class))).andReturn(returnValue);
    EasyMock.replay(authorizationService);
    // Run Test
    IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
    indexServiceImpl.setAuthorizationService(setupAuthorizationService(mediapackage));
    indexServiceImpl.setIngestService(ingestService);
    indexServiceImpl.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexServiceImpl.addCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexServiceImpl.setUserDirectoryService(noUsersUserDirectoryService);
    indexServiceImpl.setSecurityService(securityService);
    indexServiceImpl.setWorkspace(workspace);
    indexServiceImpl.createEvent(metadataJson, mediapackage);
    assertTrue("The catalog must be added to the mediapackage", result.hasCaptured());
    assertEquals("The catalog should have been added to the correct mediapackage", mpId.toString(), mediapackageIdResult.getValue());
    assertTrue("The catalog should have a new id", catalogIdResult.hasCaptured());
    assertTrue("The catalog should have a new filename", filenameResult.hasCaptured());
    assertTrue("The catalog should have been added to the input stream", catalogResult.hasCaptured());
    assertTrue("The mediapackage should have had its title updated", catalogResult.hasCaptured());
    assertEquals("The mediapackage title should have been updated.", expectedTitle, mediapackageTitleResult.getValue());
    assertTrue("The catalog should have been created", catalogResult.hasCaptured());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Attachment(org.opencastproject.mediapackage.Attachment) AclScope(org.opencastproject.security.api.AclScope) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) IngestService(org.opencastproject.ingest.api.IngestService) InputStream(java.io.InputStream) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) JSONObject(org.json.simple.JSONObject) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) Tuple(org.opencastproject.util.data.Tuple) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 4 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class AssetManagerMessageReceiverImplTest method setUp.

@Before
public void setUp() throws Exception {
    workspace = createNiceMock(Workspace.class);
    expect(workspace.read(EasyMock.anyObject(URI.class))).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml")).anyTimes();
    replay(workspace);
    AclService aclService = createNiceMock(AclService.class);
    expect(aclService.getAcls()).andReturn(new ArrayList<>()).anyTimes();
    replay(aclService);
    DefaultOrganization organization = new DefaultOrganization();
    AclServiceFactory aclServiceFactory = createNiceMock(AclServiceFactory.class);
    expect(aclServiceFactory.serviceFor(organization)).andReturn(aclService).anyTimes();
    replay(aclServiceFactory);
    SecurityService securityService = TestSearchIndex.createSecurityService(organization);
    assetManager = new AssetManagerMessageReceiverImpl();
    assetManager.setAclServiceFactory(aclServiceFactory);
    assetManager.setSecurityService(securityService);
    assetManager.setSearchIndex(index);
}
Also used : AclServiceFactory(org.opencastproject.authorization.xacml.manager.api.AclServiceFactory) SecurityService(org.opencastproject.security.api.SecurityService) ArrayList(java.util.ArrayList) AclService(org.opencastproject.authorization.xacml.manager.api.AclService) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 5 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class DublinCoreCatalogUIAdapterTest method setUp.

@Before
public void setUp() throws URISyntaxException, NotFoundException, IOException, ListProviderException {
    startDateTimeDurationCatalog = new FileInputStream(new File(getClass().getResource("/catalog-adapter/start-date-time-duration.xml").toURI()));
    dc = DublinCores.read(startDateTimeDurationCatalog);
    metadata = new DublinCoreMetadataCollection();
    startDateMetadataField = MetadataField.createTemporalStartDateMetadata(TEMPORAL_DUBLIN_CORE_KEY, Opt.some("startDate"), "START_DATE_LABEL", false, false, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Opt.<Integer>none(), Opt.<String>none());
    durationMetadataField = MetadataField.createDurationMetadataField(TEMPORAL_DUBLIN_CORE_KEY, Opt.some("duration"), "DURATION_LABEL", false, false, Opt.<Integer>none(), Opt.<String>none());
    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.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]);
    eventDublincoreURI = getClass().getResource("/catalog-adapter/dublincore.xml").toURI();
    outputCatalog = testFolder.newFile("out.xml");
    Capture<String> mediapackageIDCapture = EasyMock.newCapture();
    Capture<String> catalogIDCapture = EasyMock.newCapture();
    Capture<String> filenameCapture = EasyMock.newCapture();
    writtenCatalog = EasyMock.newCapture();
    workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.read(eventDublincoreURI)).andAnswer(() -> new FileInputStream(new File(eventDublincoreURI)));
    EasyMock.expect(workspace.put(EasyMock.capture(mediapackageIDCapture), EasyMock.capture(catalogIDCapture), EasyMock.capture(filenameCapture), EasyMock.capture(writtenCatalog))).andReturn(outputCatalog.toURI());
    EasyMock.replay(workspace);
    Catalog eventCatalog = EasyMock.createMock(Catalog.class);
    EasyMock.expect(eventCatalog.getIdentifier()).andReturn("CatalogID").anyTimes();
    EasyMock.expect(eventCatalog.getURI()).andReturn(eventDublincoreURI).anyTimes();
    eventCatalog.setURI(outputCatalog.toURI());
    EasyMock.expectLastCall();
    eventCatalog.setChecksum(null);
    EasyMock.expectLastCall();
    EasyMock.replay(eventCatalog);
    Catalog[] catalogs = { eventCatalog };
    Id id = EasyMock.createMock(Id.class);
    EasyMock.replay(id);
    mediapackage = EasyMock.createMock(MediaPackage.class);
    EasyMock.expect(mediapackage.getCatalogs(mediaPackageElementFlavor)).andReturn(catalogs).anyTimes();
    EasyMock.expect(mediapackage.getIdentifier()).andReturn(id).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) TreeMap(java.util.TreeMap) Properties(java.util.Properties) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) FileInputStream(java.io.FileInputStream) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Aggregations

Workspace (org.opencastproject.workspace.api.Workspace)71 Before (org.junit.Before)47 File (java.io.File)41 URI (java.net.URI)38 SecurityService (org.opencastproject.security.api.SecurityService)30 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)25 Job (org.opencastproject.job.api.Job)23 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)23 InputStream (java.io.InputStream)20 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)19 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)18 Test (org.junit.Test)17 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)17 ArrayList (java.util.ArrayList)15 JaxbUser (org.opencastproject.security.api.JaxbUser)15 Organization (org.opencastproject.security.api.Organization)14 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)14 AuthorizationService (org.opencastproject.security.api.AuthorizationService)13 JaxbRole (org.opencastproject.security.api.JaxbRole)13