use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project opencast by opencast.
the class TrustedHttpClientImplTest method setUp.
@Before
public void setUp() throws Exception {
// Setup bundle context for TrustedHttpClientImpl
bundleContextMock = createNiceMock(BundleContext.class);
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.DIGEST_AUTH_USER_KEY)).andReturn("matterhorn_system_account");
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.DIGEST_AUTH_PASS_KEY)).andReturn("CHANGE_ME");
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_KEY)).andReturn("3");
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_BASE_TIME_KEY)).andReturn("0");
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_MAXIMUM_VARIABLE_TIME_KEY)).andReturn("0");
replay(bundleContextMock);
componentContextMock = createNiceMock(ComponentContext.class);
expect(componentContextMock.getBundleContext()).andReturn(bundleContextMock).anyTimes();
replay(componentContextMock);
long currentJobId = 20L;
Job currentJob = createNiceMock(Job.class);
expect(currentJob.getId()).andReturn(currentJobId).anyTimes();
replay(currentJob);
securityService = createNiceMock(SecurityService.class);
expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
expect(securityService.getUser()).andReturn(new JaxbUser()).anyTimes();
replay(securityService);
serviceRegistry = createNiceMock(ServiceRegistry.class);
expect(serviceRegistry.getCurrentJob()).andReturn(currentJob).anyTimes();
expect(serviceRegistry.getJob(currentJobId)).andReturn(currentJob).anyTimes();
replay(serviceRegistry);
client = new TrustedHttpClientImpl("matterhorn_system_account", "CHANGE_ME");
client.setServiceRegistry(serviceRegistry);
client.setSecurityService(securityService);
client.activate(componentContextMock);
// Setup responses.
String digestValue = "Digest realm=\"testrealm@host.com\"," + "qop=\"auth,auth-int\"," + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\"," + "opaque=\"5ccc069c403ebaf9f0171e9517f40e41\"";
okResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("Http", 1, 1), 200, "Good to go"));
digestResponse = new BasicHttpResponse(new ProtocolVersion("Http", 1, 1), 401, "Unauthorized");
digestResponse.addHeader("WWW-Authenticate", digestValue);
nonceResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("Http", 1, 1), 401, "Nonce has expired/timed out"));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project opencast by opencast.
the class HttpNotificationWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
URI uriMP = getClass().getResource("/concat_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
// set up mock trusted http client
client = EasyMock.createNiceMock(TrustedHttpClient.class);
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_ACCEPTED, ""));
EasyMock.expect(client.execute((HttpUriRequest) EasyMock.anyObject(), EasyMock.anyInt(), EasyMock.anyInt())).andReturn(response);
EasyMock.replay(client);
// set up service
operationHandler = new HttpNotificationWorkflowOperationHandler();
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project wildfly-camel by wildfly-extras.
the class HipchatConsumerIntegrationTest method sendInOnlyNoResponse.
@Test
public void sendInOnlyNoResponse() throws Exception {
CamelContext camelctx = createCamelContext();
MockEndpoint result = camelctx.getEndpoint("mock:result", MockEndpoint.class);
result.expectedMessageCount(0);
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
HttpEntity mockHttpEntity = mock(HttpEntity.class);
when(mockHttpEntity.getContent()).thenReturn(null);
when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity);
when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
result.assertIsSatisfied();
} finally {
camelctx.stop();
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project wildfly-camel by wildfly-extras.
the class HipchatConsumerIntegrationTest method sendInOnly.
@Test
public void sendInOnly() throws Exception {
CamelContext camelctx = createCamelContext();
MockEndpoint result = camelctx.getEndpoint("mock:result", MockEndpoint.class);
result.expectedMessageCount(1);
camelctx.start();
try {
String expectedResponse = //
"{\n" + " \"items\" : [\n" + " {\n" + //
" \"date\" : \"2015-01-19T22:07:11.030740+00:00\",\n" + //
" \"from\" : {\n" + //
" \"id\" : 1647095,\n" + //
" \"links\" : {\n" + //
" \"self\" : \"https://api.hipchat.com/v2/user/1647095\"\n" + //
" },\n" + //
" \"mention_name\" : \"notifier\",\n" + //
" \"name\" : \"Message Notifier\"\n" + //
" },\n" + //
" \"id\" : \"6567c6f7-7c1b-43cf-bed0-792b1d092919\",\n" + //
" \"mentions\" : [ ],\n" + //
" \"message\" : \"Unit test Alert\",\n" + //
" \"type\" : \"message\"\n" + //
" }\n" + //
" ],\n" + //
" \"links\" : {\n" + //
" \"self\" : \"https://api.hipchat.com/v2/user/%40ShreyasPurohit/history/latest\"\n" + //
" },\n" + //
" \"maxResults\" : 1,\n" + //
" \"startIndex\" : 0\n" + "}";
HttpEntity mockHttpEntity = mock(HttpEntity.class);
when(mockHttpEntity.getContent()).thenReturn(new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8)));
when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity);
when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
result.assertIsSatisfied();
assertCommonResultExchange(result.getExchanges().get(0));
} finally {
camelctx.stop();
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project wikidata-query-rdf by wikimedia.
the class EventHttpSenderUnitTest method testSendMultipleEvents.
@Test
public void testSendMultipleEvents() throws IOException {
String eventGateHost = "https://eventgate.test.local/v1/events";
CloseableHttpClient client = mock(CloseableHttpClient.class);
CloseableHttpResponse resp = mock(CloseableHttpResponse.class);
when(resp.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
when(client.execute(any(HttpUriRequest.class))).thenReturn(resp);
int n = 5;
Collection<Event> events = Stream.generate(EventTestUtils::newQueryEvent).limit(n).collect(Collectors.toList());
String expectedEventsAsJson = Stream.generate(EventTestUtils::queryEventJsonString).limit(n).collect(Collectors.joining(",", "[", "]"));
EventHttpSender sender = new EventHttpSender(client, eventGateHost, JacksonUtil.DEFAULT_OBJECT_WRITER);
assertThat(sender.push(events)).isEqualTo(events.size());
ArgumentCaptor<HttpUriRequest> captor = ArgumentCaptor.forClass(HttpUriRequest.class);
verify(client, times(1)).execute(captor.capture());
verify(resp, times(1)).close();
HttpUriRequest request = captor.getValue();
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getURI().toString()).isEqualTo(eventGateHost);
assertThat(request).isInstanceOf(HttpPost.class);
HttpPost post = (HttpPost) request;
assertThat(post.getEntity().getContentType().getValue()).isEqualTo(ContentType.APPLICATION_JSON.toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
post.getEntity().writeTo(baos);
assertThat(new String(baos.toByteArray(), StandardCharsets.UTF_8)).isEqualTo(expectedEventsAsJson);
}
Aggregations