Search in sources :

Example 1 with FileOutputStream

use of de.schlichtherle.io.FileOutputStream in project opencast by opencast.

the class XACMLSecurityTest method setUp.

@Before
public void setUp() throws Exception {
    authzService = new XACMLAuthorizationService();
    // Mock security service
    securityService = EasyMock.createMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andAnswer(() -> new JaxbUser(currentUser, "test", organization, currentRoles)).anyTimes();
    // Mock workspace
    Workspace workspace = EasyMock.createMock(Workspace.class);
    final Capture<InputStream> in = EasyMock.newCapture();
    final Capture<URI> uri = EasyMock.newCapture();
    EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.capture(in))).andAnswer(() -> {
        final File file = testFolder.newFile();
        FileOutputStream out = new FileOutputStream(file);
        IOUtils.copyLarge(in.getValue(), out);
        IOUtils.closeQuietly(out);
        IOUtils.closeQuietly(in.getValue());
        return file.toURI();
    }).anyTimes();
    EasyMock.expect(workspace.get(EasyMock.capture(uri))).andAnswer(() -> new File(uri.getValue())).anyTimes();
    EasyMock.expect(workspace.read(EasyMock.capture(uri))).andAnswer(() -> new FileInputStream(uri.getValue().getPath())).anyTimes();
    workspace.delete(EasyMock.anyObject(URI.class));
    EasyMock.expectLastCall().anyTimes();
    EasyMock.replay(securityService, workspace);
    authzService.setWorkspace(workspace);
    authzService.setSecurityService(securityService);
}
Also used : SecurityService(org.opencastproject.security.api.SecurityService) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(de.schlichtherle.io.FileOutputStream) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) File(java.io.File) FileInputStream(java.io.FileInputStream) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 2 with FileOutputStream

use of de.schlichtherle.io.FileOutputStream in project opencast by opencast.

the class Mpeg7Test method testNewInstance.

/**
 * Test method for {@link org.opencastproject.mediapackage.mpeg7.Mpeg7CatalogImpl#save()}.
 */
@Test
public void testNewInstance() throws Exception {
    // Read the sample catalog
    Mpeg7Catalog mpeg7Sample = new Mpeg7CatalogImpl(catalogFile.toURI().toURL().openStream());
    // Create a new catalog and fill it with a few fields
    mpeg7TempFile = testFolder.newFile();
    // TODO: Add sample tracks to new catalog
    // TODO: Add sample video segments to new catalog
    // TODO: Add sample annotations to new catalog
    // Store the mpeg7 catalog contents in the temp file
    Mpeg7CatalogService mpeg7Service = new Mpeg7CatalogService();
    InputStream in = mpeg7Service.serialize(mpeg7Sample);
    FileOutputStream out = new FileOutputStream(mpeg7TempFile);
    IOUtils.copy(in, out);
    // Re-read the saved catalog and test for its content
    Mpeg7Catalog mpeg7NewFromDisk = new Mpeg7CatalogImpl(mpeg7TempFile.toURI().toURL().openStream());
    // TODO: Test content
    testContent(mpeg7NewFromDisk);
}
Also used : InputStream(java.io.InputStream) FileOutputStream(de.schlichtherle.io.FileOutputStream) Test(org.junit.Test)

Aggregations

FileOutputStream (de.schlichtherle.io.FileOutputStream)2 InputStream (java.io.InputStream)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 URI (java.net.URI)1 Before (org.junit.Before)1 Test (org.junit.Test)1 JaxbUser (org.opencastproject.security.api.JaxbUser)1 SecurityService (org.opencastproject.security.api.SecurityService)1 Workspace (org.opencastproject.workspace.api.Workspace)1