Search in sources :

Example 1 with Unit

use of com.entwinemedia.fn.Unit in project opencast by opencast.

the class AssetManagerWithSecurityTest method testGetAsset.

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

        @Override
        public Unit get1() {
            assertTrue(am.getAsset(snapshot.getVersion(), snapshot.getMediaPackage().getIdentifier().toString(), snapshot.getMediaPackage().getElements()[0].getIdentifier()).isSome());
            return Unit.unit;
        }
    });
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) Unit(com.entwinemedia.fn.Unit) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 2 with Unit

use of com.entwinemedia.fn.Unit 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 3 with Unit

use of com.entwinemedia.fn.Unit 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)

Example 4 with Unit

use of com.entwinemedia.fn.Unit in project opencast by opencast.

the class DublinCoreCatalogTest method testLoadAndSave.

@Test
public void testLoadAndSave() throws Exception {
    final DublinCoreCatalog dc = read("/dublincore-extended.xml");
    final File out = testFolder.newFile("dublincore.xml");
    IoSupport.withResource(new FileOutputStream(out), new FnX<FileOutputStream, Unit>() {

        @Override
        public Unit applyX(FileOutputStream out) throws Exception {
            dc.toXml(out, false);
            return Unit.unit;
        }
    });
    final DublinCoreCatalog reloaded = DublinCoreXmlFormat.read(out);
    assertEquals("The reloaded catalog should have the same amount of properties than the original one.", dc.getValues().size(), reloaded.getValues().size());
}
Also used : FileOutputStream(java.io.FileOutputStream) Unit(com.entwinemedia.fn.Unit) File(java.io.File) Test(org.junit.Test)

Aggregations

Unit (com.entwinemedia.fn.Unit)4 Test (org.junit.Test)4 Parameters (junitparams.Parameters)3 Snapshot (org.opencastproject.assetmanager.api.Snapshot)3 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1