Search in sources :

Example 1 with WorkingFileRepository

use of org.opencastproject.workingfilerepository.api.WorkingFileRepository in project opencast by opencast.

the class WorkspaceImplTest method testGetWorkspaceFileWithPort.

@Test
public void testGetWorkspaceFileWithPort() throws Exception {
    WorkingFileRepository repo = EasyMock.createNiceMock(WorkingFileRepository.class);
    EasyMock.expect(repo.getBaseUri()).andReturn(new URI("http://localhost:8080/files")).anyTimes();
    EasyMock.replay(repo);
    workspace.setRepository(repo);
    File workspaceFile = workspace.toWorkspaceFile(new URI("http://foo.com/myaccount/videos/bar.mov"));
    File expected = new File(PathSupport.concat(new String[] { workspaceRoot, "http_foo.com", "myaccount", "videos", "bar.mov" }));
    Assert.assertEquals(expected.getAbsolutePath(), workspaceFile.getAbsolutePath());
    workspaceFile = workspace.toWorkspaceFile(new URI("http://foo.com:8080/myaccount/videos/bar.mov"));
    expected = new File(PathSupport.concat(new String[] { workspaceRoot, "http_foo.com_8080", "myaccount", "videos", "bar.mov" }));
    Assert.assertEquals(expected.getAbsolutePath(), workspaceFile.getAbsolutePath());
    workspaceFile = workspace.toWorkspaceFile(new URI("http://localhost:8080/files/collection/c1/bar.mov"));
    expected = new File(PathSupport.concat(new String[] { workspaceRoot, "collection", "c1", "bar.mov" }));
    Assert.assertEquals(expected.getAbsolutePath(), workspaceFile.getAbsolutePath());
}
Also used : URI(java.net.URI) File(java.io.File) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) Test(org.junit.Test)

Example 2 with WorkingFileRepository

use of org.opencastproject.workingfilerepository.api.WorkingFileRepository in project opencast by opencast.

the class WorkspaceImplTest method testGetWorkspaceFileWithOutPort.

@Test
public void testGetWorkspaceFileWithOutPort() throws Exception {
    WorkingFileRepository repo = EasyMock.createNiceMock(WorkingFileRepository.class);
    EasyMock.expect(repo.getBaseUri()).andReturn(new URI("http://localhost/files")).anyTimes();
    EasyMock.replay(repo);
    workspace.setRepository(repo);
    File workspaceFile = workspace.toWorkspaceFile(new URI("http://foo.com/myaccount/videos/bar.mov"));
    File expected = new File(PathSupport.concat(new String[] { workspaceRoot, "http_foo.com", "myaccount", "videos", "bar.mov" }));
    Assert.assertEquals(expected.getAbsolutePath(), workspaceFile.getAbsolutePath());
    workspaceFile = workspace.toWorkspaceFile(new URI("http://foo.com:8080/myaccount/videos/bar.mov"));
    expected = new File(PathSupport.concat(new String[] { workspaceRoot, "http_foo.com_8080", "myaccount", "videos", "bar.mov" }));
    Assert.assertEquals(expected.getAbsolutePath(), workspaceFile.getAbsolutePath());
    workspaceFile = workspace.toWorkspaceFile(new URI("http://localhost/files/collection/c1/bar.mov"));
    expected = new File(PathSupport.concat(new String[] { workspaceRoot, "collection", "c1", "bar.mov" }));
    Assert.assertEquals(expected.getAbsolutePath(), workspaceFile.getAbsolutePath());
}
Also used : URI(java.net.URI) File(java.io.File) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) Test(org.junit.Test)

Example 3 with WorkingFileRepository

use of org.opencastproject.workingfilerepository.api.WorkingFileRepository in project opencast by opencast.

the class WorkspaceImplTest method testPutCachingWithFilesystemMapping.

// Calls to put() should put the file into the working file repository, but not in the local cache if there's a valid
// filesystem mapping present
@Test
public void testPutCachingWithFilesystemMapping() throws Exception {
    WorkingFileRepository repo = EasyMock.createNiceMock(WorkingFileRepository.class);
    EasyMock.expect(repo.getURI((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(new URI("http://localhost:8080/files" + WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX + "foo/bar/header.gif"));
    EasyMock.expect(repo.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(new URI("http://localhost:8080/files" + WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX + "foo/bar/header.gif"));
    EasyMock.expect(repo.getBaseUri()).andReturn(new URI("http://localhost:8080/files")).anyTimes();
    EasyMock.replay(repo);
    workspace.setRepository(repo);
    // Put a stream into the workspace (and hence, the repository)
    InputStream in = null;
    try {
        in = getClass().getResourceAsStream("/opencast_header.gif");
        Assert.assertNotNull(in);
        workspace.put("foo", "bar", "header.gif", in);
    } finally {
        IOUtils.closeQuietly(in);
    }
    // Ensure that the file was put into the working file repository
    EasyMock.verify(repo);
    // Ensure that the file was not cached in the workspace (since there is a configured filesystem mapping)
    File file = new File(workspaceRoot, "http___localhost_8080_files_foo_bar_header.gif");
    Assert.assertFalse(file.exists());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URI(java.net.URI) File(java.io.File) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) Test(org.junit.Test)

Example 4 with WorkingFileRepository

use of org.opencastproject.workingfilerepository.api.WorkingFileRepository in project opencast by opencast.

the class WorkspaceImplTest method testPutCachingWithoutFilesystemMapping.

// Calls to put() should put the file into the working file repository and the local cache if there is no valid
// filesystem mapping present
@Test
public void testPutCachingWithoutFilesystemMapping() throws Exception {
    // First, mock up the collaborating working file repository
    WorkingFileRepository repo = EasyMock.createMock(WorkingFileRepository.class);
    EasyMock.expect(repo.getURI((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(new URI(UrlSupport.concat(new String[] { "http://localhost:8080", WorkingFileRepository.URI_PREFIX, WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX, "foo", "bar", "header.gif" })));
    EasyMock.expect(repo.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(new URI("http://localhost:8080/files" + WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX + "foo/bar/header.gif"));
    EasyMock.expect(repo.getBaseUri()).andReturn(new URI("http://localhost:8080/files")).anyTimes();
    EasyMock.replay(repo);
    workspace.setRepository(repo);
    // Put a stream into the workspace (and hence, the repository)
    InputStream in = null;
    try {
        in = getClass().getResourceAsStream("/opencast_header.gif");
        Assert.assertNotNull(in);
        workspace.put("foo", "bar", "header.gif", in);
    } finally {
        IOUtils.closeQuietly(in);
    }
    // Ensure that the file was put into the working file repository
    EasyMock.verify(repo);
    // Ensure that the file was cached in the workspace (since there is no configured filesystem mapping)
    File file = new File(PathSupport.concat(new String[] { workspaceRoot, WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX, "foo", "bar", "header.gif" }));
    Assert.assertTrue(file.exists());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URI(java.net.URI) File(java.io.File) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) Test(org.junit.Test)

Example 5 with WorkingFileRepository

use of org.opencastproject.workingfilerepository.api.WorkingFileRepository in project opencast by opencast.

the class WorkspaceImplTest method testLongFilenames.

@Test
public void testLongFilenames() throws Exception {
    WorkingFileRepository repo = EasyMock.createNiceMock(WorkingFileRepository.class);
    EasyMock.expect(repo.getBaseUri()).andReturn(new URI("http://localhost:8080/files")).anyTimes();
    EasyMock.replay(repo);
    workspace.setRepository(repo);
    File source = new File("target/test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/opencast_header.gif");
    URL urlToSource = source.toURI().toURL();
    final TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    HttpEntity entity = EasyMock.createNiceMock(HttpEntity.class);
    EasyMock.expect(entity.getContent()).andReturn(new FileInputStream(source));
    StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class);
    EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK);
    HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
    EasyMock.expect(response.getEntity()).andReturn(entity);
    EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes();
    EasyMock.replay(response, entity, statusLine);
    EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response);
    EasyMock.expect(httpClient.runner((HttpUriRequest) EasyMock.anyObject())).andAnswer(new IAnswer<TrustedHttpClient.RequestRunner<Object>>() {

        @Override
        public RequestRunner<Object> answer() throws Throwable {
            HttpUriRequest req = (HttpUriRequest) EasyMock.getCurrentArguments()[0];
            return StandAloneTrustedHttpClientImpl.runner(httpClient, req);
        }
    });
    EasyMock.replay(httpClient);
    workspace.setTrustedHttpClient(httpClient);
    Assert.assertTrue(urlToSource.toString().length() > 255);
    try {
        Assert.assertNotNull(workspace.get(urlToSource.toURI()));
    } catch (NotFoundException e) {
    // This happens on some machines, so we catch and handle it.
    }
}
Also used : TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) RequestRunner(org.opencastproject.security.api.TrustedHttpClient.RequestRunner) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) URI(java.net.URI) URL(java.net.URL) FileInputStream(java.io.FileInputStream) StatusLine(org.apache.http.StatusLine) File(java.io.File) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) Test(org.junit.Test)

Aggregations

File (java.io.File)6 URI (java.net.URI)6 Test (org.junit.Test)6 WorkingFileRepository (org.opencastproject.workingfilerepository.api.WorkingFileRepository)6 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)2 TrustedHttpClient (org.opencastproject.security.api.TrustedHttpClient)2 RequestRunner (org.opencastproject.security.api.TrustedHttpClient.RequestRunner)2 NotFoundException (org.opencastproject.util.NotFoundException)2 URL (java.net.URL)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 Either (org.opencastproject.util.data.Either)1 Function (org.opencastproject.util.data.Function)1 Option (org.opencastproject.util.data.Option)1