use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class ExecuteServiceImplTest method prepareTest.
@BeforeClass
public static void prepareTest() throws URISyntaxException, NotFoundException, IOException {
// Get the base directory
baseDirURI = ExecuteServiceImplTest.class.getResource("/").toURI();
baseDir = new File(baseDirURI);
// Set up mock context
configKey1 = "edu.harvard.dce.param1";
String configValue1 = baseDir.getAbsolutePath() + "/test.txt";
bundleContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bundleContext.getProperty(configKey1)).andReturn(configValue1).anyTimes();
EasyMock.replay(bundleContext);
cc = EasyMock.createNiceMock(ComponentContext.class);
EasyMock.expect(cc.getBundleContext()).andReturn(bundleContext).anyTimes();
configKey2 = "edu.harvard.dce.param2";
String configValue2 = baseDir.getAbsolutePath() + "/test.txt";
Hashtable<String, Object> props = new Hashtable<>();
props.put(configKey2, configValue2);
EasyMock.expect(cc.getProperties()).andReturn(props);
EasyMock.replay(cc);
// Create the executor service
executor = new ExecuteServiceImpl();
executor.activate(cc);
// Create a mock workspace
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get(baseDirURI)).andReturn(baseDir).anyTimes();
EasyMock.replay(workspace);
executor.setWorkspace(workspace);
// Set up the text pattern to test
pattern = String.format("The specified track (%s) is in the following location: %s", ExecuteService.INPUT_FILE_PATTERN, ExecuteService.INPUT_FILE_PATTERN);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class OaiPmhPersistenceTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Mock up a security service
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
User user = SecurityUtil.createSystemUser("admin", new DefaultOrganization());
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
mp1 = MediaPackageSupport.loadFromClassPath("/mp1.xml");
mp2 = MediaPackageSupport.loadFromClassPath("/mp2.xml");
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.read(uri("series-dublincore.xml"))).andAnswer(() -> getClass().getResourceAsStream("/series-dublincore.xml")).anyTimes();
EasyMock.expect(workspace.read(uri("episode-dublincore.xml"))).andAnswer(() -> getClass().getResourceAsStream("/episode-dublincore.xml")).anyTimes();
EasyMock.expect(workspace.read(uri("mpeg7.xml"))).andAnswer(() -> getClass().getResourceAsStream("/mpeg7.xml")).anyTimes();
EasyMock.expect(workspace.read(uri("series-xacml.xml"))).andAnswer(() -> getClass().getResourceAsStream("/series-xacml.xml")).anyTimes();
EasyMock.replay(workspace);
oaiPmhDatabase = new OaiPmhDatabaseImpl();
oaiPmhDatabase.setEntityManagerFactory(newTestEntityManagerFactory(OaiPmhDatabaseImpl.PERSISTENCE_UNIT_NAME));
oaiPmhDatabase.setSecurityService(securityService);
oaiPmhDatabase.setWorkspace(workspace);
oaiPmhDatabase.activate(null);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class SchedulerMigrationServiceTest method setUp.
@Before
public void setUp() throws Exception {
OrganizationDirectoryService orgDirService = createNiceMock(OrganizationDirectoryService.class);
expect(orgDirService.getOrganization(anyString())).andReturn(new DefaultOrganization()).anyTimes();
replay(orgDirService);
SecurityService securityService = createNiceMock(SecurityService.class);
expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
expect(securityService.getUser()).andReturn(new JaxbUser()).anyTimes();
replay(securityService);
SchedulerTransaction schedulerTransaction = createNiceMock(SchedulerTransaction.class);
replay(schedulerTransaction);
SchedulerService schedulerService = createNiceMock(SchedulerService.class);
expect(schedulerService.createTransaction(anyString())).andReturn(schedulerTransaction).anyTimes();
expect(schedulerService.search(anyObject(Opt.class), anyObject(Opt.class), anyObject(Opt.class), anyObject(Opt.class), anyObject(Opt.class))).andReturn(new ArrayList<>());
replay(schedulerService);
Workspace workspace = createNiceMock(Workspace.class);
expect(workspace.put(anyString(), anyString(), anyString(), anyObject(InputStream.class))).andReturn(new URI("test")).anyTimes();
replay(workspace);
AuthorizationService authorizationService = createNiceMock(AuthorizationService.class);
replay(authorizationService);
schedulerMigrationService.setAuthorizationService(authorizationService);
schedulerMigrationService.setOrganizationDirectoryService(orgDirService);
schedulerMigrationService.setSchedulerService(schedulerService);
schedulerMigrationService.setSecurityService(securityService);
schedulerMigrationService.setWorkspace(workspace);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class ToolsEndpointTest method testAddSmilToArchive.
/**
* Test method for {@link ToolsEndpoint#addSmilToArchive(org.opencastproject.mediapackage.MediaPackage, Smil)}
*/
@Test
public void testAddSmilToArchive() throws Exception {
final String mpId = UUID.randomUUID().toString();
final URI archiveElementURI = new URI("http://host.tld/archive/cut.smil");
final String smilId = "s-afe311c6-9161-41f4-98d0-e951fe66d89e";
Workspace workspace = createNiceMock(Workspace.class);
expect(workspace.put(same(mpId), same(smilId), same("cut.smil"), anyObject(InputStream.class))).andReturn(archiveElementURI);
replay(workspace);
endpoint.setWorkspace(workspace);
AssetManager assetManager = createNiceMock(AssetManager.class);
replay(assetManager);
endpoint.setAssetManager(assetManager);
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew(new IdImpl(mpId));
endpoint.addSmilToArchive(mp, smil);
assertEquals(1, mp.getCatalogs().length);
assertEquals(smil.getId(), mp.getCatalogs()[0].getIdentifier());
assertEquals("smil/cutting", mp.getCatalogs()[0].getFlavor().toString());
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class DownloadDistributionServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
final File mediaPackageRoot = new File(getClass().getResource("/mediapackage.xml").toURI()).getParentFile();
mp = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/mediapackage.xml"), "UTF-8"));
distributionRoot = new File(mediaPackageRoot, "static");
service = new DownloadDistributionServiceImpl();
StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class);
EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK).anyTimes();
EasyMock.replay(statusLine);
HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes();
EasyMock.replay(response);
final TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response).anyTimes();
EasyMock.expect(httpClient.run((HttpUriRequest) EasyMock.anyObject())).andAnswer(new IAnswer<Function<Function<HttpResponse, Object>, Either<Exception, Object>>>() {
@Override
public Function<Function<HttpResponse, Object>, Either<Exception, Object>> answer() throws Throwable {
HttpUriRequest req = (HttpUriRequest) EasyMock.getCurrentArguments()[0];
return StandAloneTrustedHttpClientImpl.run(httpClient, req);
}
}).anyTimes();
EasyMock.replay(httpClient);
defaultOrganization = new DefaultOrganization();
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);
service.setUserDirectoryService(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
service.setSecurityService(securityService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
service.setServiceRegistry(serviceRegistry);
service.setTrustedHttpClient(httpClient);
final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
service.setWorkspace(workspace);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {
@Override
public File answer() throws Throwable {
final URI uri = (URI) EasyMock.getCurrentArguments()[0];
final String[] pathElems = uri.getPath().split("/");
final String file = pathElems[pathElems.length - 1];
return new File(mediaPackageRoot, file);
}
}).anyTimes();
EasyMock.replay(workspace);
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getProperty("org.opencastproject.download.directory")).andReturn(distributionRoot.toString()).anyTimes();
EasyMock.expect(bc.getProperty("org.opencastproject.download.url")).andReturn(UrlSupport.DEFAULT_BASE_URL).anyTimes();
ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
Dictionary<String, Object> p = new Hashtable<String, Object>();
p.put(DistributionService.CONFIG_KEY_STORE_TYPE, "download");
EasyMock.expect(cc.getProperties()).andReturn(p).anyTimes();
EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
EasyMock.replay(bc, cc);
service.activate(cc);
}
Aggregations