use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project opencast by opencast.
the class HttpNotificationWorkflowOperationHandlerTest method testNotificationFailedAfterOneTry.
@Test
public void testNotificationFailedAfterOneTry() throws Exception {
client = EasyMock.createNiceMock(TrustedHttpClient.class);
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_NOT_FOUND, ""));
EasyMock.expect(client.execute((HttpPut) EasyMock.anyObject(), EasyMock.anyInt(), EasyMock.anyInt())).andReturn(response);
EasyMock.replay(client);
// set up service
operationHandler = new HttpNotificationWorkflowOperationHandler();
// operation configuration
Map<String, String> configurations = new HashMap<String, String>();
configurations.put(HttpNotificationWorkflowOperationHandler.OPT_URL_PATH, "http://127.0.0.1:9");
configurations.put(HttpNotificationWorkflowOperationHandler.OPT_NOTIFICATION_SUBJECT, "test");
configurations.put(HttpNotificationWorkflowOperationHandler.OPT_MAX_RETRY, "0");
configurations.put(HttpNotificationWorkflowOperationHandler.OPT_TIMEOUT, Integer.toString(10));
// run the operation handler
try {
getWorkflowOperationResult(mp, configurations);
Assert.fail("Operation handler should have thrown an exception!");
} catch (WorkflowOperationException e) {
Assert.assertTrue("Exception thrown as expected by the operation handler", true);
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project opencast by opencast.
the class ServiceRegistryJpaImplTest method setUpServiceRegistryJpaImpl.
public void setUpServiceRegistryJpaImpl() throws PropertyVetoException, NotFoundException, TrustedHttpClientException {
serviceRegistryJpaImpl = new ServiceRegistryJpaImpl();
serviceRegistryJpaImpl.setEntityManagerFactory(emf);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
serviceRegistryJpaImpl.setOrganizationDirectoryService(organizationDirectoryService);
JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
User anonymous = new JaxbUser("anonymous", "test", jaxbOrganization, new JaxbRole(jaxbOrganization.getAnonymousRole(), jaxbOrganization));
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
serviceRegistryJpaImpl.setSecurityService(securityService);
UserDirectoryService userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser(EasyMock.anyString())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
serviceRegistryJpaImpl.setUserDirectoryService(userDirectoryService);
final Capture<HttpUriRequest> request = EasyMock.newCapture();
final BasicHttpResponse successRespone = new BasicHttpResponse(new BasicStatusLine(new HttpVersion(1, 1), HttpStatus.SC_NO_CONTENT, "No message"));
final BasicHttpResponse unavailableResponse = new BasicHttpResponse(new BasicStatusLine(new HttpVersion(1, 1), HttpStatus.SC_SERVICE_UNAVAILABLE, "No message"));
TrustedHttpClient trustedHttpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
EasyMock.expect(trustedHttpClient.execute(EasyMock.capture(request))).andAnswer(new IAnswer<HttpResponse>() {
@Override
public HttpResponse answer() throws Throwable {
if (!request.hasCaptured())
return unavailableResponse;
if (request.getValue().getURI().toString().contains(TEST_PATH))
return unavailableResponse;
if (request.getValue().getURI().toString().contains(TEST_PATH_3))
return unavailableResponse;
return successRespone;
}
}).anyTimes();
EasyMock.replay(trustedHttpClient);
serviceRegistryJpaImpl.setTrustedHttpClient(trustedHttpClient);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project opencast by opencast.
the class TrustedHttpClientImplTest method testAlreadySignedUrlIgnoredByUrlSigningService.
@Test
public void testAlreadySignedUrlIgnoredByUrlSigningService() throws IOException, UrlSigningException {
String acceptsUrl = "http://alreadysigned.com?signature=thesig&policy=thepolicy&keyId=thekey";
HttpHead headRequest = new HttpHead(acceptsUrl);
// Setup signing service
UrlSigningService urlSigningService = EasyMock.createMock(UrlSigningService.class);
EasyMock.expect(urlSigningService.accepts(acceptsUrl)).andReturn(true);
EasyMock.replay(urlSigningService);
CredentialsProvider cp = EasyMock.createNiceMock(CredentialsProvider.class);
Capture<HttpUriRequest> request = EasyMock.newCapture();
// Setup Http Client
HttpClient httpClient = createMock("Request", HttpClient.class);
HttpParams httpParams = createNiceMock(HttpParams.class);
expect(httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000)).andReturn(httpParams);
expect(httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)).andReturn(httpParams);
replay(httpParams);
expect(httpClient.getParams()).andReturn(httpParams).anyTimes();
expect(httpClient.getCredentialsProvider()).andReturn(cp);
expect(httpClient.execute(EasyMock.capture(request))).andReturn(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "ok")));
EasyMock.replay(httpClient);
// Setup DefaultHttpClientFactory
HttpClientFactory httpClientFactory = createMock(HttpClientFactory.class);
expect(httpClientFactory.makeHttpClient()).andReturn(httpClient).atLeastOnce();
replay(httpClientFactory);
client = new TrustedHttpClientImpl("user", "pass");
client.setHttpClientFactory(httpClientFactory);
client.setSecurityService(securityService);
client.setUrlSigningService(urlSigningService);
client.execute(headRequest);
assertTrue(request.hasCaptured());
assertEquals(acceptsUrl, request.getValue().getURI().toString());
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project opencast by opencast.
the class TrustedHttpClientImplTest method testAcceptsUrlSigningService.
@Test
public void testAcceptsUrlSigningService() throws IOException, UrlSigningException {
String acceptsUrl = "http://accepts.com";
String signedUrl = "http://accepts.com?policy=testPolicy&signature=testSignature&keyId=testKeyId";
HttpGet get = new HttpGet(acceptsUrl);
// Setup signing service
UrlSigningService urlSigningService = EasyMock.createMock(UrlSigningService.class);
EasyMock.expect(urlSigningService.accepts(acceptsUrl)).andReturn(true);
EasyMock.expect(urlSigningService.sign(EasyMock.anyString(), EasyMock.anyLong(), EasyMock.anyLong(), EasyMock.anyString())).andReturn(signedUrl);
EasyMock.replay(urlSigningService);
CredentialsProvider cp = EasyMock.createNiceMock(CredentialsProvider.class);
Capture<HttpUriRequest> request = EasyMock.newCapture();
// Setup Http Client
HttpClient httpClient = createMock("Request", HttpClient.class);
HttpParams httpParams = createNiceMock(HttpParams.class);
expect(httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000)).andReturn(httpParams);
expect(httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)).andReturn(httpParams);
replay(httpParams);
expect(httpClient.getParams()).andReturn(httpParams).anyTimes();
expect(httpClient.getCredentialsProvider()).andReturn(cp);
expect(httpClient.execute(EasyMock.capture(request))).andReturn(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "ok")));
EasyMock.replay(httpClient);
// Setup DefaultHttpClientFactory
HttpClientFactory httpClientFactory = createMock(HttpClientFactory.class);
expect(httpClientFactory.makeHttpClient()).andReturn(httpClient).atLeastOnce();
replay(httpClientFactory);
client = new TrustedHttpClientImpl("user", "pass");
client.setHttpClientFactory(httpClientFactory);
client.setSecurityService(securityService);
client.setUrlSigningService(urlSigningService);
client.execute(get);
assertTrue(request.hasCaptured());
assertEquals(signedUrl, request.getValue().getURI().toString());
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project spring-cloud-netflix by spring-cloud.
the class HttpClientStatusCodeExceptionTest method getResponse.
@Test
public void getResponse() throws Exception {
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
doReturn(new Locale("en")).when(response).getLocale();
Header foo = new BasicHeader("foo", "bar");
Header[] headers = new Header[] { foo };
doReturn(headers).when(response).getAllHeaders();
StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("http", 1, 1), 200, "Success");
doReturn(statusLine).when(response).getStatusLine();
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream("foo".getBytes()));
entity.setContentLength(3);
doReturn(entity).when(response).getEntity();
HttpEntity copiedEntity = HttpClientUtils.createEntity(response);
HttpClientStatusCodeException ex = new HttpClientStatusCodeException("service", response, copiedEntity, new URI("http://service.com"));
assertEquals("en", ex.getResponse().getLocale().toString());
assertArrayEquals(headers, ex.getResponse().getAllHeaders());
assertEquals("Success", ex.getResponse().getStatusLine().getReasonPhrase());
assertEquals(200, ex.getResponse().getStatusLine().getStatusCode());
assertEquals("http", ex.getResponse().getStatusLine().getProtocolVersion().getProtocol());
assertEquals(1, ex.getResponse().getStatusLine().getProtocolVersion().getMajor());
assertEquals(1, ex.getResponse().getStatusLine().getProtocolVersion().getMinor());
assertEquals("foo", EntityUtils.toString(ex.getResponse().getEntity()));
verify(response, times(1)).close();
}
Aggregations