use of org.opencastproject.mediapackage.attachment.AttachmentImpl in project opencast by opencast.
the class TestRestService method newAuthorizationService.
private static AuthorizationService newAuthorizationService() {
AccessControlList acl = new AccessControlList();
Attachment attachment = new AttachmentImpl();
MediaPackage mediapackage;
try {
mediapackage = new MediaPackageBuilderImpl().createNew();
} catch (MediaPackageException e) {
throw new RuntimeException(e);
}
AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.expect(authorizationService.setAcl((MediaPackage) EasyMock.anyObject(), (AclScope) EasyMock.anyObject(), (AccessControlList) EasyMock.anyObject())).andReturn(Tuple.tuple(mediapackage, attachment));
EasyMock.replay(authorizationService);
return authorizationService;
}
use of org.opencastproject.mediapackage.attachment.AttachmentImpl in project opencast by opencast.
the class IndexServiceImplTest method testAddAssetsToMp.
@Test
public void testAddAssetsToMp() throws org.json.simple.parser.ParseException, IOException, ConfigurationException, MediaPackageException, HandleException, IngestException, NotFoundException {
MediaPackage mediapackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
JSONArray assetMetadata = (JSONArray) new JSONParser().parse("[{\"id\":\"attachment_attachment_notes\", " + "\"title\": \"class handout notes\"," + "\"flavorType\": \"attachment\"," + "\"flavorSubType\": \"notes\"," + "\"type\": \"attachment\"}]");
// a test asset input stream
List<String> assetList = new LinkedList<String>();
assetList.add("attachment_attachment_notes");
MediaPackageElementFlavor elemflavor = new MediaPackageElementFlavor("attachment_attachment_notes", "*");
MediaPackageElementFlavor newElemflavor = new MediaPackageElementFlavor("attachment", "notes");
// Set up the mock Ingest Service's attachment
Attachment attachment = new AttachmentImpl();
attachment.setFlavor(elemflavor);
mediapackage.add(attachment);
// Run Test
IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
indexServiceImpl.setIngestService(setupIngestService(mediapackage, Capture.<InputStream>newInstance()));
mediapackage = indexServiceImpl.updateMpAssetFlavor(assetList, mediapackage, assetMetadata, true);
assertTrue("The mediapackage attachment has the updated flavor", mediapackage.getAttachments(newElemflavor).length == 1);
}
use of org.opencastproject.mediapackage.attachment.AttachmentImpl in project opencast by opencast.
the class ImportWorkflowPropertiesWOHTest method testStartOp.
@Test
public void testStartOp() throws Exception {
final WorkflowOperationInstance woi = createMock(WorkflowOperationInstance.class);
expect(woi.getConfiguration("source-flavor")).andStubReturn(FLAVOR);
expect(woi.getConfiguration("keys")).andStubReturn("chapter, presenter_position, cover_marker_in_s");
replay(woi);
final Attachment att = new AttachmentImpl();
att.setURI(new URI(WF_PROPS_ATT_URI));
att.setFlavor(MediaPackageElementFlavor.parseFlavor(FLAVOR));
final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mp.add(att);
WorkflowInstance wi = createMock(WorkflowInstance.class);
expect(wi.getCurrentOperation()).andStubReturn(woi);
expect(wi.getMediaPackage()).andStubReturn(mp);
replay(wi);
try (InputStream is = ImportWorkflowPropertiesWOHTest.class.getResourceAsStream("/workflow-properties.xml")) {
Files.copy(is, tmpPropsFile, StandardCopyOption.REPLACE_EXISTING);
}
final Workspace workspace = createNiceMock(Workspace.class);
expect(workspace.get(new URI(WF_PROPS_ATT_URI))).andStubReturn(tmpPropsFile.toFile());
replay(workspace);
final ImportWorkflowPropertiesWOH woh = new ImportWorkflowPropertiesWOH();
woh.setWorkspace(workspace);
WorkflowOperationResult result = woh.start(wi, null);
Map<String, String> properties = result.getProperties();
Assert.assertTrue(properties.containsKey("chapter"));
Assert.assertEquals("true", properties.get("chapter"));
Assert.assertTrue(properties.containsKey("presenter_position"));
Assert.assertEquals("left", properties.get("presenter_position"));
Assert.assertTrue(properties.containsKey("cover_marker_in_s"));
Assert.assertEquals("30.674", properties.get("cover_marker_in_s"));
verify(wi);
}
use of org.opencastproject.mediapackage.attachment.AttachmentImpl in project opencast by opencast.
the class ExportWorkflowPropertiesWOHTest method testExport.
@Test
public void testExport() throws Exception {
final WorkflowOperationInstance woi = createMock(WorkflowOperationInstance.class);
expect(woi.getConfiguration("target-flavor")).andStubReturn(FLAVOR);
expect(woi.getConfiguration("target-tags")).andStubReturn("archive");
expect(woi.getConfiguration("keys")).andStubReturn("chapter,presenter_position");
replay(woi);
final Attachment att = new AttachmentImpl();
att.setURI(uri);
att.setFlavor(MediaPackageElementFlavor.parseFlavor(FLAVOR));
final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mp.add(att);
WorkflowInstance wi = createMock(WorkflowInstance.class);
expect(wi.getCurrentOperation()).andStubReturn(woi);
expect(wi.getMediaPackage()).andStubReturn(mp);
Set<String> keys = new HashSet<>();
keys.add("presenter_position");
keys.add("cover_marker_in_s");
expect(wi.getConfigurationKeys()).andStubReturn(keys);
expect(wi.getConfiguration("presenter_position")).andStubReturn("right");
expect(wi.getConfiguration("cover_marker_in_s")).andStubReturn("30.674");
replay(wi);
final ExportWorkflowPropertiesWOH woh = new ExportWorkflowPropertiesWOH();
woh.setWorkspace(workspace);
WorkflowOperationResult result = woh.start(wi, null);
Attachment[] attachments = result.getMediaPackage().getAttachments();
Assert.assertTrue(attachments.length == 1);
Attachment attachment = attachments[0];
assertEquals("processing/defaults", attachment.getFlavor().toString());
assertEquals("archive", attachment.getTags()[0]);
Assert.assertNotNull(attachment.getURI());
File file = workspace.get(attachment.getURI());
Properties props = new Properties();
try (InputStream is = new FileInputStream(file)) {
props.loadFromXML(is);
}
assertEquals("30.674", props.get("cover_marker_in_s"));
assertEquals("right", props.get("presenter_position"));
Assert.assertFalse(props.contains("chapter"));
verify(wi);
}
Aggregations