Search in sources :

Example 1 with Version

use of org.opencastproject.assetmanager.api.Version in project opencast by opencast.

the class AbstractAssetManagerBasicTest method testSetAvailability.

@Test
public void testSetAvailability() throws Exception {
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    final Version v1 = am.takeSnapshot(OWNER, mp).getVersion();
    am.setAvailability(v1, mp.getIdentifier().toString(), Availability.OFFLINE);
    assertEquals("One offline snapshot should be found", 1, q.select(q.snapshot()).where(q.availability(Availability.OFFLINE)).run().getSize());
    assertEquals("No online snapshot should be found", 0, q.select(q.snapshot()).where(q.availability(Availability.ONLINE)).run().getSize());
}
Also used : Version(org.opencastproject.assetmanager.api.Version) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Test(org.junit.Test)

Example 2 with Version

use of org.opencastproject.assetmanager.api.Version in project opencast by opencast.

the class AbstractAssetManagerBasicTest method testVersioning.

@Test
public void testVersioning() throws Exception {
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    final Version v1 = am.takeSnapshot(OWNER, mp).getVersion();
    final Version v2 = am.takeSnapshot(OWNER, mp).getVersion();
    assertTrue("First version must be older", v1.isOlder(v2));
    assertTrue("Second version must be younger", v2.isYounger(v1));
    assertTrue(v1.equals(v1));
    assertFalse(v1.equals(v2));
}
Also used : Version(org.opencastproject.assetmanager.api.Version) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Test(org.junit.Test)

Example 3 with Version

use of org.opencastproject.assetmanager.api.Version 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());
}
Also used : Version(org.opencastproject.assetmanager.api.Version) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Test(org.junit.Test)

Example 4 with Version

use of org.opencastproject.assetmanager.api.Version 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());
    }
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecords.getSnapshot(org.opencastproject.assetmanager.api.fn.ARecords.getSnapshot) Version(org.opencastproject.assetmanager.api.Version) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Asset(org.opencastproject.assetmanager.api.Asset) AResult(org.opencastproject.assetmanager.api.query.AResult) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Date(java.util.Date) Test(org.junit.Test)

Example 5 with Version

use of org.opencastproject.assetmanager.api.Version 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());
}
Also used : Version(org.opencastproject.assetmanager.api.Version) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AResult(org.opencastproject.assetmanager.api.query.AResult) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Test(org.junit.Test)

Aggregations

Version (org.opencastproject.assetmanager.api.Version)10 Test (org.junit.Test)9 MediaPackage (org.opencastproject.mediapackage.MediaPackage)8 Snapshot (org.opencastproject.assetmanager.api.Snapshot)4 AResult (org.opencastproject.assetmanager.api.query.AResult)3 URI (java.net.URI)2 Set (java.util.Set)2 RichAResult (org.opencastproject.assetmanager.api.query.RichAResult)2 Job (org.opencastproject.job.api.Job)2 Date (java.util.Date)1 Asset (org.opencastproject.assetmanager.api.Asset)1 ARecords.getSnapshot (org.opencastproject.assetmanager.api.fn.ARecords.getSnapshot)1 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)1 ARecord (org.opencastproject.assetmanager.api.query.ARecord)1 ASelectQuery (org.opencastproject.assetmanager.api.query.ASelectQuery)1 Predicate (org.opencastproject.assetmanager.api.query.Predicate)1 Target (org.opencastproject.assetmanager.api.query.Target)1 VersionField (org.opencastproject.assetmanager.api.query.VersionField)1 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)1 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)1