use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class SearchServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
// workspace
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {
@Override
public File answer() throws Throwable {
return new File(new URI(EasyMock.getCurrentArguments()[0].toString()));
}
}).anyTimes();
EasyMock.replay(workspace);
// User, organization and service registry
userResponder = new Responder<User>(defaultUser);
organizationResponder = new Responder<Organization>(defaultOrganization);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andAnswer(userResponder).anyTimes();
EasyMock.expect(securityService.getOrganization()).andAnswer(organizationResponder).anyTimes();
EasyMock.replay(securityService);
User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
// mpeg7 service
Mpeg7CatalogService mpeg7CatalogService = new Mpeg7CatalogService();
// Persistence storage
searchDatabase = new SearchServiceDatabaseImpl();
searchDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SearchServiceDatabaseImpl.PERSISTENCE_UNIT));
searchDatabase.activate(null);
searchDatabase.setSecurityService(securityService);
// search service
service = new SearchServiceImpl();
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
StaticMetadataService mdService = newStaticMetadataService(workspace);
SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
DublinCoreCatalog seriesCatalog = getSeriesDublinCoreCatalog("/series-dublincore.xml");
AccessControlList seriesAcl = new AccessControlList();
EasyMock.expect(seriesService.getSeries((String) EasyMock.anyObject())).andReturn(seriesCatalog).anyTimes();
EasyMock.expect(seriesService.getSeriesAccessControl((String) EasyMock.anyObject())).andReturn(seriesAcl).anyTimes();
EasyMock.replay(seriesService);
service.setStaticMetadataService(mdService);
service.setWorkspace(workspace);
service.setMpeg7CatalogService(mpeg7CatalogService);
service.setSecurityService(securityService);
service.setOrganizationDirectoryService(organizationDirectoryService);
service.setUserDirectoryService(userDirectoryService);
service.setServiceRegistry(serviceRegistry);
service.setPersistence(searchDatabase);
SolrServer solrServer = SearchServiceImpl.setupSolr(new File(solrRoot));
service.testSetup(solrServer, new SolrRequester(solrServer, securityService), new SolrIndexManager(solrServer, workspace, Arrays.asList(mdService), seriesService, mpeg7CatalogService, securityService));
// acl
String anonymousRole = securityService.getOrganization().getAnonymousRole();
acl = new AccessControlList(new AccessControlEntry(anonymousRole, Permissions.Action.READ.toString(), true));
authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.expect(authorizationService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(true).anyTimes();
service.setAuthorizationService(authorizationService);
EasyMock.replay(authorizationService);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class SilenceDetectorTest method init.
/**
* Setup test.
*/
@Ignore
private FFmpegSilenceDetector init(URI resource, Boolean hasAudio, Properties props) throws Exception {
final File f = new File(resource);
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get(resource)).andReturn(f);
EasyMock.replay(workspace);
Track track = EasyMock.createNiceMock(Track.class);
EasyMock.expect(track.getURI()).andReturn(resource);
EasyMock.expect(track.getIdentifier()).andReturn("123");
EasyMock.expect(track.getDuration()).andStubReturn(60000L);
EasyMock.expect(track.hasAudio()).andReturn(hasAudio);
EasyMock.replay(track);
return new FFmpegSilenceDetector(props, track, workspace);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class WorkflowServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
// always start with a fresh solr root directory
sRoot = new File(getStorageRoot());
try {
FileUtils.forceMkdir(sRoot);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
// create operation handlers for our workflows
succeedingOperationHandler = new SucceedingWorkflowOperationHandler();
failingOperationHandler = new FailingWorkflowOperationHandler();
handlerRegistrations = new HashSet<HandlerRegistration>();
handlerRegistrations.add(new HandlerRegistration("op1", succeedingOperationHandler));
handlerRegistrations.add(new HandlerRegistration("op2", succeedingOperationHandler));
handlerRegistrations.add(new HandlerRegistration("op3", failingOperationHandler));
handlerRegistrations.add(new HandlerRegistration(WorkflowServiceImpl.ERROR_RESOLUTION_HANDLER_ID, new ErrorResolutionWorkflowOperationHandler()));
handlerRegistrations.add(new HandlerRegistration("opPause", new ResumableTestWorkflowOperationHandler()));
handlerRegistrations.add(new HandlerRegistration("failOnHost", new FailOnHostWorkflowOperationHandler()));
handlerRegistrations.add(new HandlerRegistration("failOneTime", new FailOnceWorkflowOperationHandler()));
handlerRegistrations.add(new HandlerRegistration("failTwice", new FailTwiceWorkflowOperationHandler()));
scanner = new WorkflowDefinitionScanner();
// instantiate a service implementation and its DAO, overriding the methods that depend on the osgi runtime
service = new WorkflowServiceImpl() {
@Override
public Set<HandlerRegistration> getRegisteredHandlers() {
return handlerRegistrations;
}
};
// Add scanner to activate workflow service and store definitions
service.addWorkflowDefinitionScanner(scanner);
// security service
DefaultOrganization organization = new DefaultOrganization();
securityService = createNiceMock(SecurityService.class);
expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
expect(securityService.getOrganization()).andReturn(organization).anyTimes();
replay(securityService);
service.setSecurityService(securityService);
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
replay(userDirectoryService);
service.setUserDirectoryService(userDirectoryService);
AuthorizationService authzService = createNiceMock(AuthorizationService.class);
expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
replay(authzService);
service.setAuthorizationService(authzService);
List<Organization> organizationList = new ArrayList<Organization>();
organizationList.add(organization);
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(securityService.getOrganization()).anyTimes();
expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
MediaPackageMetadataService mds = createNiceMock(MediaPackageMetadataService.class);
replay(mds);
service.addMetadataService(mds);
workspace = createNiceMock(Workspace.class);
expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
replay(workspace);
IncidentService incidentService = createNiceMock(IncidentService.class);
replay(incidentService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, incidentService);
serviceRegistry.registerHost(REMOTE_HOST, REMOTE_HOST, Runtime.getRuntime().totalMemory(), Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors());
serviceRegistry.registerService(REMOTE_SERVICE, REMOTE_HOST, "/path", true);
service.setWorkspace(workspace);
MessageSender messageSender = createNiceMock(MessageSender.class);
replay(messageSender);
dao = new WorkflowServiceSolrIndex();
dao.setServiceRegistry(serviceRegistry);
dao.setSecurityService(securityService);
dao.setOrgDirectory(organizationDirectoryService);
dao.setAuthorizationService(authzService);
dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
dao.activate("System Admin");
service.setDao(dao);
service.setServiceRegistry(serviceRegistry);
service.setMessageSender(messageSender);
service.activate(null);
InputStream is = null;
try {
is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-1.xml");
workingDefinition = WorkflowParser.parseWorkflowDefinition(is);
IOUtils.closeQuietly(is);
is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-2.xml");
failingDefinitionWithoutErrorHandler = WorkflowParser.parseWorkflowDefinition(is);
IOUtils.closeQuietly(is);
is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-3.xml");
failingDefinitionWithErrorHandler = WorkflowParser.parseWorkflowDefinition(is);
IOUtils.closeQuietly(is);
is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-4.xml");
pausingWorkflowDefinition = WorkflowParser.parseWorkflowDefinition(is);
IOUtils.closeQuietly(is);
service.registerWorkflowDefinition(workingDefinition);
service.registerWorkflowDefinition(failingDefinitionWithoutErrorHandler);
service.registerWorkflowDefinition(failingDefinitionWithErrorHandler);
service.registerWorkflowDefinition(pausingWorkflowDefinition);
MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
is = WorkflowServiceImplTest.class.getResourceAsStream("/mediapackage-1.xml");
mediapackage1 = mediaPackageBuilder.loadFromXml(is);
IOUtils.closeQuietly(is);
is = WorkflowServiceImplTest.class.getResourceAsStream("/mediapackage-2.xml");
mediapackage2 = mediaPackageBuilder.loadFromXml(is);
Assert.assertNotNull(mediapackage1.getIdentifier());
Assert.assertNotNull(mediapackage2.getIdentifier());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class DuplicateEventWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
operationHandler = new DuplicateEventWorkflowOperationHandler();
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
URI uriMP = getClass().getResource("/duplicate-event_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
workspace = createNiceMock(Workspace.class);
assetManager = createNiceMock(AssetManager.class);
distributionService = createNiceMock(DistributionService.class);
serviceRegistry = createNiceMock(ServiceRegistry.class);
operationHandler.setWorkspace(workspace);
operationHandler.setAssetManager(assetManager);
operationHandler.setDistributionService(distributionService);
operationHandler.setServiceRegistry(serviceRegistry);
}
use of org.opencastproject.workspace.api.Workspace 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);
}
Aggregations