use of org.opencastproject.assetmanager.api.query.AResult in project opencast by opencast.
the class TestRestService method newAssetManager.
private static AssetManager newAssetManager() {
Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
try {
EasyMock.expect(snapshot.getMediaPackage()).andReturn(new MediaPackageBuilderImpl().createNew()).anyTimes();
} catch (MediaPackageException e) {
throw new RuntimeException(e);
}
ARecord record = EasyMock.createNiceMock(ARecord.class);
EasyMock.expect(record.getSnapshot()).andReturn(Opt.some(snapshot)).anyTimes();
AResult result = EasyMock.createNiceMock(AResult.class);
EasyMock.expect(result.getRecords()).andReturn($(record)).anyTimes();
ASelectQuery select = EasyMock.createNiceMock(ASelectQuery.class);
EasyMock.expect(select.where(EasyMock.anyObject(Predicate.class))).andReturn(select).anyTimes();
EasyMock.expect(select.run()).andReturn(result).anyTimes();
Predicate predicate = EasyMock.createNiceMock(Predicate.class);
EasyMock.expect(predicate.and(EasyMock.anyObject(Predicate.class))).andReturn(predicate).anyTimes();
AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
VersionField version = EasyMock.createNiceMock(VersionField.class);
EasyMock.expect(query.version()).andReturn(version).anyTimes();
EasyMock.expect(query.mediaPackageId(EasyMock.anyString())).andReturn(predicate).anyTimes();
EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(select).anyTimes();
AssetManager assetManager = EasyMock.createNiceMock(AssetManager.class);
EasyMock.expect(assetManager.createQuery()).andReturn(query).anyTimes();
EasyMock.replay(assetManager, version, query, predicate, select, result, record, snapshot);
return assetManager;
}
use of org.opencastproject.assetmanager.api.query.AResult 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.assetmanager.api.query.AResult in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectSnapshotAndProperties.
@Test
public void testSelectSnapshotAndProperties() throws Exception {
final MediaPackage mp1 = mkMediaPackage(mkCatalog());
am.takeSnapshot(OWNER, mp1);
// only select snapshots
{
final AResult r = q.select(q.snapshot()).run();
assertEquals("One record should be found", 1, r.getSize());
assertEquals("One snapshot should be found", 1, r.getRecords().bind(getSnapshot).toList().size());
assertEquals("No properties should be found", 0, r.getRecords().bind(getProperties).toList().size());
}
// select snapshots and properties
{
final AResult r = q.select(q.snapshot(), p.allProperties()).run();
assertEquals("One record should be found", 1, r.getSize());
assertEquals("One snapshot should be found", 1, r.getRecords().bind(getSnapshot).toList().size());
assertEquals("No properties should be found", 0, r.getRecords().bind(getProperties).toList().size());
}
}
use of org.opencastproject.assetmanager.api.query.AResult in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectSnapshots.
@Test
public void testSelectSnapshots() throws Exception {
final MediaPackage mp = mkMediaPackage();
final MediaPackageElement mpe = mkCatalog();
mp.add(mpe);
final Snapshot snapshot = am.takeSnapshot(OWNER, mp);
final Version version = snapshot.getVersion();
assertThat("Archival date should not be in the future", snapshot.getArchivalDate(), lessThanOrEqualTo(new Date()));
assertThat("Snapshot should be available", snapshot.getAvailability(), equalTo(Availability.ONLINE));
assertThat("Snapshot should belong to the default organization", snapshot.getOrganizationId(), equalTo(DefaultOrganization.DEFAULT_ORGANIZATION_ID));
final Opt<Asset> asset = am.getAsset(version, mp.getIdentifier().toString(), mpe.getIdentifier());
assertTrue("Asset should be found", asset.isSome());
assertEquals("Media package element part of the asset ID should equal the element's ID", mpe.getIdentifier(), asset.get().getId().getMediaPackageElementId());
assertEquals("Mime types should equal", mpe.getMimeType(), asset.get().getMimeType().get());
assertFalse("Asset should not be found", am.getAsset(version, "id", "id").isSome());
// try to find the catalog of the media package by checksum
final MediaPackage mpCopy = MediaPackageSupport.copy(mp);
am.calcChecksumsForMediaPackageElements(AbstractAssetManager.assetsOnly(mpCopy));
assertEquals("Media package should be set up with a single catalog", 1, mpCopy.getCatalogs().length);
final String checksum = mpCopy.getCatalogs()[0].getChecksum().toString();
assertTrue("Media package element should be retrievable by checksum", am.getDb().findAssetByChecksum(checksum).isSome());
// issue some queries
{
logger.info("Run a failing query");
assertEquals("The result should not contain any records", 0, q.select(q.snapshot()).where(q.mediaPackageId(mp.getIdentifier().toString()).and(q.availability(Availability.ONLINE))).where(q.mediaPackageId("12")).run().getSize());
}
{
logger.info("Run query to find snapshot");
final AResult r = q.select(q.snapshot()).where(q.mediaPackageId(mp.getIdentifier().toString()).and(q.availability(Availability.ONLINE))).run();
assertEquals("The result set should contain exactly one record", 1, r.getSize());
assertEquals("The media package IDs should be equal", mp.getIdentifier().toString(), r.getRecords().head2().getMediaPackageId());
assertTrue("The snapshot should be contained in the record", r.getRecords().head2().getSnapshot().isSome());
assertEquals("The media package IDs should be equal", mp.getIdentifier(), r.getRecords().head2().getSnapshot().get().getMediaPackage().getIdentifier());
}
{
final AResult r = q.select().where(q.mediaPackageId(mp.getIdentifier().toString()).and(q.availability(Availability.ONLINE))).run();
assertEquals("The result should contain one record", 1, r.getSize());
assertTrue("The result should not contain a snapshot", r.getRecords().head2().getSnapshot().isNone());
}
}
use of org.opencastproject.assetmanager.api.query.AResult in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectByVersion.
@Test
public void testSelectByVersion() throws Exception {
final MediaPackage mp1 = mkMediaPackage(mkCatalog());
logger.info("Create 4 versions");
am.takeSnapshot(OWNER, mp1);
am.takeSnapshot(OWNER, mp1);
am.takeSnapshot(OWNER, mp1);
am.takeSnapshot(OWNER, mp1);
assertEquals("4 records should be found", 4, q.select(q.snapshot()).run().getSize());
assertEquals("4 records should be found", 4, q.select().run().getSize());
final Version latest;
{
AResult r = q.select(q.snapshot()).where(q.version().isLatest()).run();
assertEquals("1 latest record should be found", 1, r.getSize());
latest = r.getRecords().head2().getSnapshot().get().getVersion();
}
final Version first;
{
AResult r = q.select(q.snapshot()).where(q.version().isFirst()).run();
assertEquals("1 first record should be found", 1, r.getSize());
first = r.getRecords().head2().getSnapshot().get().getVersion();
}
assertTrue("The first version should be older", first.isOlder(latest));
assertTrue("The last version should be younger", latest.isYounger(first));
assertFalse("The versions should not be equal", latest.equals(first));
//
assertEquals("Three older records should be found", 3, q.select(q.snapshot()).where(q.version().lt(latest)).run().getSize());
assertEquals("4 records should be found", 4, q.select(q.snapshot()).where(q.version().le(latest)).run().getSize());
assertEquals("Three younger records should be found", 3, q.select(q.snapshot()).where(q.version().gt(first)).run().getSize());
assertEquals("4 records should be found", 4, q.select(q.snapshot()).where(q.version().ge(first)).run().getSize());
assertEquals("2 intermediate records should be found", 2, q.select(q.snapshot()).where(q.version().gt(first).and(q.version().lt(latest))).run().getSize());
//
logger.info("Now add another media package");
am.takeSnapshot(OWNER, mkMediaPackage(mkCatalog()));
assertEquals("Three older records should be found", 3, q.select(q.snapshot()).where(q.version().lt(latest).and(q.mediaPackageId(mp1.getIdentifier().toString()))).run().getSize());
assertEquals("Two latest versions should be found", 2, q.select(q.snapshot()).where(q.version().isLatest()).run().getSize());
assertEquals("Two first versions should be found", 2, q.select(q.snapshot()).where(q.version().isFirst()).run().getSize());
}
Aggregations