use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractAssetManagerBasicTest method testSerializeVersion.
@Test
public void testSerializeVersion() throws Exception {
final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
final Version v1 = am.takeSnapshot(OWNER, mp).getVersion();
assertTrue("Version should be ", am.toVersion(v1.toString()).isSome());
assertEquals(v1, am.toVersion(v1.toString()).get());
}
use of org.opencastproject.mediapackage.MediaPackage 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.mediapackage.MediaPackage in project opencast by opencast.
the class AssetManagerWithSecurityTest method mkTestEnvironment.
/**
* Setup the test environment.
*/
public AssetManagerWithSecurity mkTestEnvironment() throws Exception {
final AuthorizationService authSvc = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authSvc.getActiveAcl(EasyMock.<MediaPackage>anyObject())).andAnswer(new IAnswer<Tuple<AccessControlList, AclScope>>() {
@Override
public Tuple<AccessControlList, AclScope> answer() throws Throwable {
return tuple(currentMediaPackageAcl, AclScope.Episode);
}
}).anyTimes();
EasyMock.replay(authSvc);
//
secSvc = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(secSvc.getUser()).andAnswer(new IAnswer<User>() {
@Override
public User answer() throws Throwable {
return currentUser;
}
}).anyTimes();
EasyMock.expect(secSvc.getOrganization()).andAnswer(new IAnswer<Organization>() {
@Override
public Organization answer() throws Throwable {
return currentUser.getOrganization();
}
}).anyTimes();
EasyMock.replay(secSvc);
//
return new AssetManagerWithSecurity(mkAbstractAssetManager(), authSvc, secSvc);
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectParticularProperties.
@Test
public void testSelectParticularProperties() throws Exception {
final MediaPackage mp1 = mkMediaPackage(mkCatalog());
am.takeSnapshot(OWNER, mp1);
// set some properties
am.setProperty(p.count.mk(mp1.getIdentifier().toString(), 10L));
am.setProperty(p.approved.mk(mp1.getIdentifier().toString(), true));
{
final AResult r = q.select(p.count.target()).run();
assertEquals("One record should be selected", 1, r.getSize());
assertEquals("No snapshot should be selected", 0, r.getRecords().bind(getSnapshot).toList().size());
assertEquals("One property should be selected", 1, r.getRecords().bind(getProperties).toList().size());
}
{
final AResult r = q.select(q.properties(PropertyName.mk(p.namespace(), p.count.name().getName()), PropertyName.mk(p.namespace(), "unkown-property"))).run();
assertEquals("One record should be selected", 1, r.getSize());
assertEquals("No snapshot should be selected", 0, r.getRecords().bind(getSnapshot).toList().size());
assertEquals("One property should be selected", 1, r.getRecords().bind(getProperties).toList().size());
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testManyMediaPackages.
@Ignore
@Test
public void testManyMediaPackages() throws Exception {
final long tStart = System.nanoTime();
final int mpCount = 1000;
final Stream<P2<String, Integer>> inserts = Stream.cont(inc()).take(mpCount).map(new FnX<Integer, P2<String, Integer>>() {
@Override
public P2<String, Integer> applyX(Integer ignore) throws Exception {
final MediaPackage mp = mkMediaPackage(mkCatalog());
final String mpId = mp.getIdentifier().toString();
final int versions = (int) (Math.random() * 10.0 + 1.0);
for (int i = 0; i < Math.random() * 10 + 1; i++) {
am.takeSnapshot(OWNER, mp);
}
// set the legacy ID property
am.setProperty(p.legacyId.mk(mpId, "legacyId=" + mpId));
return Products.E.p2(mp.getIdentifier().toString(), versions);
}
}).eval();
final long tInserted = System.nanoTime();
{
RichAResult r = enrich(q.select(q.snapshot()).where(q.version().isLatest()).run());
assertEquals(mpCount, r.getSize());
assertEquals(mpCount, r.countSnapshots());
}
for (final P2<String, Integer> insert : inserts) {
final RichAResult r = enrich(q.select(p.legacyId.target()).where(q.mediaPackageId(insert.get1()).and(q.version().isLatest())).run());
assertEquals(1, r.getSize());
assertEquals(0, r.countSnapshots());
assertEquals(1, r.countProperties());
assertEquals("legacyId=" + r.getRecords().head().get().getMediaPackageId(), r.getProperties().head().get().getValue().get(Value.STRING));
}
final long tQueried = System.nanoTime();
logger.info("Insertion ms " + ((tInserted - tStart) / 1000000));
logger.info("Queries ms " + ((tQueried - tInserted) / 1000000));
}
Aggregations