Search in sources :

Example 6 with TrustedHttpClient

use of org.opencastproject.security.api.TrustedHttpClient in project opencast by opencast.

the class WorkspaceImplTest method testGetNoFilename.

@Test
public void testGetNoFilename() throws Exception {
    final File expectedFile = testFolder.newFile("test.txt");
    FileUtils.write(expectedFile, "asdf");
    expectedFile.deleteOnExit();
    WorkingFileRepository repo = EasyMock.createNiceMock(WorkingFileRepository.class);
    EasyMock.expect(repo.getBaseUri()).andReturn(new URI("http://localhost:8080/files")).anyTimes();
    EasyMock.replay(repo);
    workspace.setRepository(repo);
    RequestRunner<Either<String, Option<File>>> requestRunner = new TrustedHttpClient.RequestRunner<Either<String, Option<File>>>() {

        @Override
        public Either<Exception, Either<String, Option<File>>> run(Function<HttpResponse, Either<String, Option<File>>> f) {
            Either<String, Option<File>> right = Either.right(Option.some(expectedFile));
            return Either.right(right);
        }
    };
    TrustedHttpClient trustedHttpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    EasyMock.expect(trustedHttpClient.<Either<String, Option<File>>>runner(EasyMock.anyObject(HttpUriRequest.class))).andReturn(requestRunner).anyTimes();
    EasyMock.replay(trustedHttpClient);
    workspace.setTrustedHttpClient(trustedHttpClient);
    File resultingFile = workspace.get(URI.create("http://foo.com/myaccount/videos/"));
    Assert.assertEquals(expectedFile, resultingFile);
}
Also used : TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) Function(org.opencastproject.util.data.Function) RequestRunner(org.opencastproject.security.api.TrustedHttpClient.RequestRunner) Either(org.opencastproject.util.data.Either) Option(org.opencastproject.util.data.Option) File(java.io.File) URI(java.net.URI) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) NotFoundException(org.opencastproject.util.NotFoundException) Test(org.junit.Test)

Aggregations

TrustedHttpClient (org.opencastproject.security.api.TrustedHttpClient)6 HttpResponse (org.apache.http.HttpResponse)4 StatusLine (org.apache.http.StatusLine)4 File (java.io.File)3 URI (java.net.URI)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 IAnswer (org.easymock.IAnswer)3 Before (org.junit.Before)3 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)3 JaxbRole (org.opencastproject.security.api.JaxbRole)3 JaxbUser (org.opencastproject.security.api.JaxbUser)3 Organization (org.opencastproject.security.api.Organization)3 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)3 SecurityService (org.opencastproject.security.api.SecurityService)3 User (org.opencastproject.security.api.User)3 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)3 FileInputStream (java.io.FileInputStream)2 HttpEntity (org.apache.http.HttpEntity)2 Test (org.junit.Test)2 RequestRunner (org.opencastproject.security.api.TrustedHttpClient.RequestRunner)2