Search in sources :

Example 11 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AbstractAssetManagerSelectTest method testSelectByArchivedDate.

@Test
public void testSelectByArchivedDate() throws Exception {
    final Date backThen = DateTime.now().minusSeconds(5).withMillisOfSecond(0).toDate();
    final MediaPackage mp1 = mkMediaPackage(mkCatalog());
    am.takeSnapshot(OWNER, mp1);
    final MediaPackage mp2 = mkMediaPackage(mkCatalog());
    am.takeSnapshot(OWNER, mp2);
    final Date now = DateTime.now().plusSeconds(1).withMillisOfSecond(0).toDate();
    assertEquals("Two records should be found", 2, q.select(q.snapshot()).where(q.archived().le(now)).run().getSize());
    assertEquals("No record should be found", 0, q.select(q.snapshot()).where(q.archived().gt(now)).run().getSize());
    assertEquals("Two records should be found", 2, q.select(q.snapshot()).where(q.archived().ge(backThen)).run().getSize());
    assertEquals("No record should be found", 0, q.select(q.snapshot()).where(q.archived().lt(backThen)).run().getSize());
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Date(java.util.Date) Test(org.junit.Test)

Example 12 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AbstractAssetManagerSelectTest method testSelectMultiplePropertyNamespaces.

@Test
public void testSelectMultiplePropertyNamespaces() throws Exception {
    final MediaPackage mp1 = mkMediaPackage(mkCatalog());
    final String mp1Id = mp1.getIdentifier().toString();
    am.takeSnapshot(OWNER, mp1);
    am.setProperty(p.approved.mk(mp1Id, true));
    am.setProperty(p.count.mk(mp1Id, 10L));
    am.setProperty(p.start.mk(mp1Id, new Date()));
    // 
    am.setProperty(Property.mk(PropertyId.mk(mp1Id, "org.opencastproject.scheduler", "start"), Value.mk(new Date())));
    am.setProperty(Property.mk(PropertyId.mk(mp1Id, "org.opencastproject.scheduler", "end"), Value.mk(new Date())));
    // 
    {
        final RichAResult r = enrich(q.select(p.allProperties(), q.propertiesOf("org.opencastproject.scheduler")).run());
        assertEquals("One record should be found", 1, r.getSize());
        assertEquals("All five properties should be found", 5, r.countProperties());
    }
    {
        final RichAResult r = enrich(q.select(q.propertiesOf(p.namespace())).run());
        assertEquals("One record should be found", 1, r.getSize());
        assertEquals("No snapshot has been selected", 0, r.countSnapshots());
        assertEquals("Three properties should be found", 3, r.countProperties());
    }
    {
        final RichAResult r = enrich(q.select(q.propertiesOf("org.opencastproject.scheduler")).where(q.mediaPackageId(mp1Id)).run());
        assertEquals(2, r.countProperties());
    }
    {
        final RichAResult r = enrich(q.select(q.snapshot()).where(p.hasPropertiesOfNamespace()).run());
        assertEquals(1, r.getSize());
    }
    {
        final RichAResult r = enrich(q.select(p.allProperties(), q.propertiesOf("org.opencastproject.scheduler")).run());
        assertEquals(1, r.getSize());
        assertEquals(5, r.countProperties());
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Date(java.util.Date) Test(org.junit.Test)

Example 13 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AbstractAssetManagerSelectTest method testSelectMultipleProperties.

@Test
public void testSelectMultipleProperties() throws Exception {
    final MediaPackage mp1 = mkMediaPackage(mkCatalog());
    am.takeSnapshot(OWNER, mp1);
    am.setProperty(p.approved.mk(mp1.getIdentifier().toString(), true));
    am.setProperty(p.count.mk(mp1.getIdentifier().toString(), 10L));
    am.setProperty(p.start.mk(mp1.getIdentifier().toString(), new Date()));
    assertEquals("Querying all properties, three should be found", 3, sizeOf(q.select(q.properties()).run().getRecords().bind(getProperties)));
    assertEquals("Querying 'approved' and 'count', both should be found", 2, sizeOf(q.select(p.approved.target(), p.count.target()).where(q.mediaPackageId(mp1.getIdentifier().toString())).run().getRecords().bind(getProperties)));
    assertEquals("Querying 'approved' and 'count' in a different style, both should be found again", 2, sizeOf(q.select(q.properties(p.approved.name(), p.count.name())).where(q.mediaPackageId(mp1.getIdentifier().toString())).run().getRecords().bind(getProperties)));
    logger.info("Add another media package with some properties");
    final MediaPackage mp2 = mkMediaPackage(mkCatalog());
    am.takeSnapshot(OWNER, mp2);
    am.setProperty(p.approved.mk(mp2.getIdentifier().toString(), true));
    am.setProperty(p.start.mk(mp2.getIdentifier().toString(), new Date()));
    assertEquals("Querying all properties, five should be found", 5, sizeOf(q.select(q.properties()).run().getRecords().bind(getProperties)));
    assertEquals("Querying target and count of the first media package, both should be found", 2, sizeOf(q.select(p.approved.target(), p.count.target()).where(q.mediaPackageId(mp1.getIdentifier().toString())).run().getRecords().bind(getProperties)));
    assertEquals("Querying target and count of all media packages, 3 properties should be found", 3, sizeOf(q.select(q.properties(p.approved.name(), p.count.name())).run().getRecords().bind(getProperties)));
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Date(java.util.Date) Test(org.junit.Test)

Example 14 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AbstractAssetManagerSelectTest method testSelectBySeries.

@Test
public void testSelectBySeries() throws Exception {
    final MediaPackage mp = mkMediaPackage();
    logger.info("The series ID field of the media package links it to a series. Attached DublinCore catalogs are not relevant.");
    mp.setSeries("series-1");
    am.takeSnapshot(OWNER, mp);
    assertEquals(1, q.select(q.snapshot()).where(q.seriesId().eq("series-1")).run().getSize());
    assertEquals(0, q.select(q.snapshot()).where(q.seriesId().eq("series-2")).run().getSize());
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Test(org.junit.Test)

Example 15 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AbstractAssetManagerSelectTest method testComparisons.

@Test
public void testComparisons() throws Exception {
    final MediaPackage mp = mkMediaPackage(mkCatalog());
    final String mpId = mp.getIdentifier().toString();
    am.takeSnapshot(OWNER, mp);
    // set the milliseconds to 0 since MySQL (or the driver) rounds milliseconds to the next or previous
    // second which may cause subsequent tests (.le(now)) to fail.
    final Date now = DateTime.now().withMillisOfSecond(0).toDate();
    logger.info("now=" + now);
    // set up a property for each property type
    am.setProperty(p.start.mk(mpId, now));
    am.setProperty(p.agent.mk(mpId, "agent"));
    am.setProperty(p.approved.mk(mpId, true));
    am.setProperty(p.count.mk(mpId, 10L));
    {
        assertEquals(1, q.select(q.snapshot()).where(p.count.le(10L)).run().getSize());
        assertEquals(1, q.select(q.snapshot()).where(p.count.ge(10L)).run().getSize());
        assertEquals(1, q.select(q.snapshot()).where(p.count.eq(10L)).run().getSize());
        assertEquals(0, q.select(q.snapshot()).where(p.count.lt(10L)).run().getSize());
        assertEquals(0, q.select(q.snapshot()).where(p.count.gt(10L)).run().getSize());
        assertEquals(1, q.select(q.snapshot()).where(p.count.lt(11L)).run().getSize());
        assertEquals(1, q.select(q.snapshot()).where(p.count.gt(9L)).run().getSize());
    }
    {
        assertEquals(1, q.select(q.snapshot()).where(p.start.le(now)).run().getSize());
        assertEquals(1, q.select(q.snapshot()).where(p.start.ge(now)).run().getSize());
        assertEquals(1, q.select(q.snapshot()).where(p.start.eq(now)).run().getSize());
        assertEquals(0, q.select(q.snapshot()).where(p.start.lt(now)).run().getSize());
        assertEquals(0, q.select(q.snapshot()).where(p.start.gt(now)).run().getSize());
        assertEquals(1, q.select(q.snapshot()).where(p.start.lt(new Date(now.getTime() + 120000L))).run().getSize());
        assertEquals(1, q.select(q.snapshot()).where(p.start.gt(new Date(now.getTime() - 120000L))).run().getSize());
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Date(java.util.Date) Test(org.junit.Test)

Aggregations

MediaPackage (org.opencastproject.mediapackage.MediaPackage)407 Test (org.junit.Test)180 NotFoundException (org.opencastproject.util.NotFoundException)108 Job (org.opencastproject.job.api.Job)89 Date (java.util.Date)82 IOException (java.io.IOException)77 URI (java.net.URI)74 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)72 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)70 ArrayList (java.util.ArrayList)69 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)60 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)59 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)55 Path (javax.ws.rs.Path)53 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)52 Track (org.opencastproject.mediapackage.Track)48 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)48 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)45 HashSet (java.util.HashSet)43