Search in sources :

Example 16 with Snapshot

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

the class LiveScheduleServiceImplTest method testGetSnapshot.

@Test
public void testGetSnapshot() throws Exception {
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    setUpAssetManager(mp);
    replayServices();
    Snapshot s = service.getSnapshot(MP_ID);
    Assert.assertNotNull(s);
    MediaPackage mp1 = s.getMediaPackage();
    Assert.assertNotNull(mp1);
    Assert.assertEquals(MP_ID, mp1.getIdentifier().compact());
    Assert.assertEquals("Live Test", mp1.getTitle());
    Assert.assertEquals("2017-10-12T18:10:59Z", DateTimeSupport.toUTC(mp1.getDate().getTime()));
    Assert.assertEquals("20170119999", mp1.getSeries());
    Assert.assertEquals("Test Fall 2017", mp1.getSeriesTitle());
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackage(org.opencastproject.mediapackage.MediaPackage) URI(java.net.URI) Test(org.junit.Test)

Example 17 with Snapshot

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

the class LiveScheduleServiceImplTest method testAddAndDistributeElements.

@Test
public void testAddAndDistributeElements() throws Exception {
    URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/series.xml").toURI();
    DublinCoreCatalog seriesDC = DublinCores.read(catalogURI.toURL().openStream());
    EasyMock.expect(seriesService.getSeries(SERIES_ID)).andReturn(seriesDC).anyTimes();
    Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"9ad6ebcb-b414-4b15-ab62-5e5ddede447e\" type=\"dublincore/episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/episode.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"23113662-1a84-457a-85d5-0b3e32d2413a\" type=\"dublincore/series\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/series.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml</url></attachment>");
    EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class), EasyMock.anyBoolean())).andReturn(job).once();
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    replayServices();
    Snapshot s = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(s.getMediaPackage()).andReturn(mp);
    EasyMock.replay(s);
    service.setDownloadDistributionService(downloadDistributionService);
    MediaPackage mp1 = service.addAndDistributeElements(s);
    Catalog[] catalogs = mp1.getCatalogs(MediaPackageElements.EPISODE);
    Assert.assertNotNull(catalogs);
    Assert.assertEquals(1, catalogs.length);
    Catalog catalog = catalogs[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/episode.xml", catalog.getURI().toString());
    Assert.assertEquals("dublincore/episode", catalog.getFlavor().toString());
    catalogs = mp1.getCatalogs(MediaPackageElements.SERIES);
    Assert.assertNotNull(catalogs);
    Assert.assertEquals(1, catalogs.length);
    catalog = catalogs[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/series.xml", catalog.getURI().toString());
    Assert.assertEquals("dublincore/series", catalog.getFlavor().toString());
    Attachment[] atts = mp1.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
    Assert.assertNotNull(atts);
    Assert.assertEquals(1, atts.length);
    Attachment att = atts[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml", att.getURI().toString());
    Assert.assertEquals("security/xacml+episode", att.getFlavor().toString());
    EasyMock.verify(downloadDistributionService, workspace);
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) URI(java.net.URI) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) Test(org.junit.Test)

Example 18 with Snapshot

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

the class LiveScheduleServiceImplTest method testRetractLiveEvent.

@Test
public void testRetractLiveEvent() throws Exception {
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp-with-live.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    setUpAssetManager(mp);
    mpURI = LiveScheduleServiceImplTest.class.getResource("/live-mp.xml").toURI();
    mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    Job job1 = createJob(1L, "anything", "anything");
    Capture<String> capturedMpId = Capture.newInstance();
    EasyMock.expect(searchService.delete(EasyMock.capture(capturedMpId))).andReturn(job1);
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job1).anyTimes();
    Job job2 = createJob(2L, "anything", "anything");
    EasyMock.expect(downloadDistributionService.retract(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class))).andReturn(job2);
    EasyMock.expect(serviceRegistry.getJob(2L)).andReturn(job2).anyTimes();
    Capture<MediaPackage> capturedSnapshotMp = Capture.newInstance();
    Version v = EasyMock.createNiceMock(Version.class);
    Snapshot s = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(s.getVersion()).andReturn(v);
    EasyMock.replay(s, v);
    EasyMock.expect(assetManager.takeSnapshot(EasyMock.capture(capturedSnapshotMp))).andReturn(s);
    replayServices();
    service.setDownloadDistributionService(downloadDistributionService);
    service.retractLiveEvent(mp);
    // Check archived media package
    MediaPackage archivedMp = capturedSnapshotMp.getValue();
    Assert.assertEquals(MP_ID, archivedMp.getIdentifier().compact());
    Assert.assertEquals(0, archivedMp.getPublications().length);
    EasyMock.verify(searchService, downloadDistributionService);
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) Set(java.util.Set) Version(org.opencastproject.assetmanager.api.Version) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Job(org.opencastproject.job.api.Job) URI(java.net.URI) Test(org.junit.Test)

Example 19 with Snapshot

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

the class AssetManagerWithSecurityTest method testSetAvailabilityAndSetProperty.

/* ------------------------------------------------------------------------------------------------------------------ */
/**
 * Media package is created under the admin of the default organization.
 */
@Test
@Parameters
public void testSetAvailabilityAndSetProperty(final AccessControlList acl, User user, boolean assertGrant) throws Exception {
    // create a snapshot
    final Snapshot snapshot = createSnapshot(acl);
    runWith(user, assertGrant, new P1Lazy<Unit>() {

        @Override
        public Unit get1() {
            // set availability
            am.setAvailability(snapshot.getVersion(), snapshot.getMediaPackage().getIdentifier().toString(), Availability.OFFLINE);
            // set a property
            assertTrue(am.setProperty(Property.mk(PropertyId.mk(snapshot.getMediaPackage().getIdentifier().toString(), "namespace", "property-name"), Value.mk("value"))));
            return Unit.unit;
        }
    });
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) Unit(com.entwinemedia.fn.Unit) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 20 with Snapshot

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

the class AssetManagerWithSecurityTest method testQuery.

/* ------------------------------------------------------------------------------------------------------------------ */
@Test
@Parameters
public void testQuery(AccessControlList acl, User writeUser, User queryUser, final boolean assertReadAccess, final boolean assertWriteAccess) throws Exception {
    // create a snapshot -> should always work (set assertAccess to true)
    final Snapshot snapshot = createSnapshot(acl, writeUser, true);
    // Set assertAccess to true since querying does not yield a security exception.
    // Restricted records are simply filtered out.
    runWith(queryUser, true, new P1Lazy<Unit>() {

        @Override
        public Unit get1() {
            // if read access is granted the result contains one record
            assertEquals("Snapshot should be retrieved: " + assertReadAccess, assertReadAccess, q.select(q.snapshot()).run().getSize() == 1);
            return Unit.unit;
        }
    });
    runWith(queryUser, true, new P1Lazy<Unit>() {

        @Override
        public Unit get1() {
            // if write access is granted one snapshot should be deleted
            assertEquals("Snapshots should be deleted: " + assertWriteAccess, assertWriteAccess, q.delete(OWNER, q.snapshot()).run() == 1);
            return Unit.unit;
        }
    });
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) Unit(com.entwinemedia.fn.Unit) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

Snapshot (org.opencastproject.assetmanager.api.Snapshot)26 Test (org.junit.Test)11 MediaPackage (org.opencastproject.mediapackage.MediaPackage)10 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)9 AResult (org.opencastproject.assetmanager.api.query.AResult)7 URI (java.net.URI)6 Set (java.util.Set)5 ARecord (org.opencastproject.assetmanager.api.query.ARecord)5 ASelectQuery (org.opencastproject.assetmanager.api.query.ASelectQuery)5 Parameters (junitparams.Parameters)4 Version (org.opencastproject.assetmanager.api.Version)4 Predicate (org.opencastproject.assetmanager.api.query.Predicate)4 Unit (com.entwinemedia.fn.Unit)3 Target (org.opencastproject.assetmanager.api.query.Target)3 VersionField (org.opencastproject.assetmanager.api.query.VersionField)3 Database (org.opencastproject.assetmanager.impl.persistence.Database)3 Job (org.opencastproject.job.api.Job)3 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2