use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class DublinCoreTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
catalogFile = new File(this.getClass().getResource(catalogName).toURI());
File tmpCatalogFile = testFolder.newFile();
FileUtils.copyFile(catalogFile, tmpCatalogFile);
File tmpCatalogFile2 = testFolder.newFile();
FileUtils.copyFile(catalogFile, tmpCatalogFile2);
catalogFile2 = new File(this.getClass().getResource(catalogName2).toURI());
if (!catalogFile.exists() || !catalogFile.canRead())
throw new Exception("Unable to access test catalog");
if (!catalogFile2.exists() || !catalogFile2.canRead())
throw new Exception("Unable to access test catalog 2");
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get(EasyMock.anyObject())).andReturn(catalogFile).anyTimes();
EasyMock.expect(workspace.get(EasyMock.anyObject(), EasyMock.anyBoolean())).andReturn(tmpCatalogFile).andReturn(tmpCatalogFile2);
EasyMock.expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> new FileInputStream(catalogFile)).anyTimes();
EasyMock.replay(workspace);
service = new DublinCoreCatalogService();
service.setWorkspace(workspace);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class EmailTemplateServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
uriMP = EmailTemplateServiceImplTest.class.getResource("/email_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
service = new EmailTemplateServiceImpl();
URI episodeURI = EmailTemplateServiceImplTest.class.getResource("/episode_dublincore.xml").toURI();
URI seriesURI = EmailTemplateServiceImplTest.class.getResource("/series_dublincore.xml").toURI();
Workspace workspace = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspace.get(new URI("episode_dublincore.xml"))).andReturn(new File(episodeURI));
EasyMock.expect(workspace.get(new URI("series_dublincore.xml"))).andReturn(new File(seriesURI));
EasyMock.replay(workspace);
service.setWorkspace(workspace);
EmailTemplateScanner templateScanner = EasyMock.createMock(EmailTemplateScanner.class);
EasyMock.expect(templateScanner.getTemplate("templateBasic")).andReturn("Media package id: ${mediaPackage.identifier}, workflow id: ${workflow.id}, " + "title: ${mediaPackage.title}, series title: ${mediaPackage.seriesTitle}, " + "date: ${mediaPackage.date?datetime?iso_utc}");
EasyMock.expect(templateScanner.getTemplate("templateCatalog")).andReturn("EPISODE creator: ${catalogs[\"episode\"][\"creator\"]}, isPartOf: ${catalogs[\"episode\"][\"isPartOf\"]}, " + "title: ${catalogs[\"episode\"][\"title\"]}, created: ${catalogs[\"episode\"][\"created\"]}, " + "SERIES creator: ${catalogs[\"series\"][\"creator\"]}, description: ${catalogs[\"series\"][\"description\"]}, " + "subject: ${catalogs[\"series\"][\"subject\"]}");
EasyMock.expect(templateScanner.getTemplate("templateFailed")).andReturn("<#if failedOperation?has_content>Workflow failed in operation: ${failedOperation.template}</#if>, " + "Workflow errors: <#list incident as inc><#list inc.details as de>${de.b} </#list></#list>");
EasyMock.expect(templateScanner.getTemplate("templateSyntaxError")).andReturn("${mediaPackage");
EasyMock.replay(templateScanner);
service.setEmailTemplateScanner(templateScanner);
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("wfdef");
Map<String, String> props = new HashMap<String, String>();
props.put("emailAddress", "user@domain.com");
IncidentService is = EasyMock.createMock(IncidentService.class);
/*
* This is what we're building. EasyMock makes it ugly, of course /-------job1Tree / | / incident2 subtree |
* incident1
*/
// Create the tree and subtree
IncidentTree subtree = EasyMock.createNiceMock(IncidentTree.class);
IncidentTree job1Tree = EasyMock.createNiceMock(IncidentTree.class);
// Create the incidents
Incident incident1 = EasyMock.createNiceMock(Incident.class);
List<Tuple<String, String>> details = new LinkedList<Tuple<String, String>>();
Tuple<String, String> detail = new Tuple<String, String>("detail-type", "error in operation1");
details.add(detail);
EasyMock.expect(incident1.getDetails()).andReturn(details);
Incident incident2 = EasyMock.createNiceMock(Incident.class);
details = new LinkedList<Tuple<String, String>>();
detail = new Tuple<String, String>("detail-type", "error in operation2");
details.add(detail);
EasyMock.expect(incident2.getDetails()).andReturn(details);
// Link the incident and the subtree
LinkedList<Incident> incidents = new LinkedList<Incident>();
incidents.add(incident1);
EasyMock.expect(subtree.getIncidents()).andReturn(incidents).anyTimes();
// This is what Entwine wrote in the IncidentTree class, so rather than null we're using Immutables.nil()
List<IncidentTree> subtreeDecendants = Immutables.nil();
EasyMock.expect(subtree.getDescendants()).andReturn(subtreeDecendants).anyTimes();
// Link the incident and the parent tree
incidents = new LinkedList<Incident>();
incidents.add(incident2);
EasyMock.expect(job1Tree.getIncidents()).andReturn(incidents).anyTimes();
// Link the subtree and parent tree
LinkedList<IncidentTree> subtreeList = new LinkedList<IncidentTree>();
subtreeList.add(subtree);
EasyMock.expect(job1Tree.getDescendants()).andReturn(subtreeList).anyTimes();
service.setIncidentService(is);
workflowInstance = new WorkflowInstanceImpl(def, null, null, null, null, props);
workflowInstance.setId(1);
workflowInstance.setState(WorkflowState.RUNNING);
workflowInstance.setMediaPackage(mp);
WorkflowOperationInstanceImpl failedOperation1 = new WorkflowOperationInstanceImpl("operation1", OperationState.FAILED);
failedOperation1.setFailWorkflowOnException(true);
failedOperation1.setId(1L);
EasyMock.expect(is.getIncidentsOfJob(1L, true)).andReturn(subtree).anyTimes();
WorkflowOperationInstanceImpl failedOperation2 = new WorkflowOperationInstanceImpl("operation2", OperationState.FAILED);
failedOperation2.setFailWorkflowOnException(false);
failedOperation1.setId(2L);
EasyMock.expect(is.getIncidentsOfJob(2L, true)).andReturn(job1Tree).anyTimes();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("email", OperationState.RUNNING);
List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
operationList.add(failedOperation1);
operationList.add(failedOperation2);
operationList.add(operation);
workflowInstance.setOperations(operationList);
EasyMock.replay(is, subtree, job1Tree, incident1, incident2);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class ConcatWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
URI uriMP = InspectWorkflowOperationHandler.class.getResource("/concat_mediapackage.xml").toURI();
URI uriMPEncode = InspectWorkflowOperationHandler.class.getResource("/concatenated_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
mpEncode = builder.loadFromXml(uriMPEncode.toURL().openStream());
encodedTracks = mpEncode.getTracks();
// set up mock workspace
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(uriMP);
EasyMock.replay(workspace);
// set up mock receipt
job = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(encodedTracks[0])).anyTimes();
EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job.getDateCreated()).andReturn(new Date());
EasyMock.expect(job.getDateStarted()).andReturn(new Date());
EasyMock.expect(job.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job);
// set up mock service registry
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
EasyMock.replay(serviceRegistry);
// set up service
operationHandler = new ConcatWorkflowOperationHandler();
operationHandler.setJobBarrierPollingInterval(0);
operationHandler.setWorkspace(workspace);
operationHandler.setServiceRegistry(serviceRegistry);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class ComposerServiceTest method testImageToVideo.
/**
* Test method for
* {@link org.opencastproject.composer.impl.ComposerServiceImpl#imageToVideo(org.opencastproject.mediapackage.Attachment, String, Long)}
*/
@Test
public void testImageToVideo() throws Exception {
if (!ffmpegInstalled)
return;
assertTrue(sourceImage.isFile());
// Need different media files
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get(EasyMock.anyObject())).andReturn(sourceImage).anyTimes();
EasyMock.expect(workspace.putInCollection(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject())).andReturn(sourceImage.toURI()).anyTimes();
composerService.setWorkspace(workspace);
EasyMock.replay(workspace);
EncodingProfile imageToVideoProfile = profileScanner.getProfile("image-movie.work");
Attachment attachment = AttachmentImpl.fromURI(sourceImage.toURI());
attachment.setIdentifier("test image");
Job imageToVideo = composerService.imageToVideo(attachment, imageToVideoProfile.getIdentifier(), 1L);
Track imageToVideoTrack = (Track) MediaPackageElementParser.getFromXml(imageToVideo.getPayload());
Assert.assertNotNull(imageToVideoTrack);
inspectedTrack.setIdentifier(imageToVideoTrack.getIdentifier());
inspectedTrack.setMimeType(MimeType.mimeType("video", "mp4"));
Assert.assertEquals(inspectedTrack, imageToVideoTrack);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class ComposerServiceTest method testParallelEncode.
@Test
public void testParallelEncode() throws Exception {
assertTrue(sourceVideoOnly.isFile());
// Need different media files
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get(EasyMock.anyObject())).andReturn(sourceVideoOnly).anyTimes();
EasyMock.expect(workspace.putInCollection(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject())).andReturn(sourceVideoOnly.toURI()).anyTimes();
composerService.setWorkspace(workspace);
EasyMock.replay(workspace);
// Prepare job
Job job = composerService.parallelEncode(sourceVideoTrack, "parallel.http");
assertEquals(3, MediaPackageElementParser.getArrayFromXml(job.getPayload()).size());
}
Aggregations