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()));
}
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));
}
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());
}
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);
}
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);
}
Aggregations