Search in sources :

Example 6 with MediaPackage

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

Example 7 with MediaPackage

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()));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AssetManagerItem(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) File(java.io.File) Date(java.util.Date) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 8 with MediaPackage

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) IAnswer(org.easymock.IAnswer) AuthorizationService(org.opencastproject.security.api.AuthorizationService) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AclScope(org.opencastproject.security.api.AclScope)

Example 9 with MediaPackage

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

Example 10 with MediaPackage

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));
}
Also used : FnX(com.entwinemedia.fn.FnX) P2(com.entwinemedia.fn.P2) MediaPackage(org.opencastproject.mediapackage.MediaPackage) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Ignore(org.junit.Ignore) 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