Search in sources :

Example 91 with BasicStatusLine

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"));
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) JaxbUser(org.opencastproject.security.api.JaxbUser) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) BundleContext(org.osgi.framework.BundleContext) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 92 with BasicStatusLine

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();
}
Also used : TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) URI(java.net.URI) BasicStatusLine(org.apache.http.message.BasicStatusLine) Before(org.junit.Before)

Example 93 with BasicStatusLine

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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) HttpEntity(org.apache.http.HttpEntity) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 94 with BasicStatusLine

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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) HttpEntity(org.apache.http.HttpEntity) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 95 with BasicStatusLine

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);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicStatusLine(org.apache.http.message.BasicStatusLine) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Test(org.junit.Test)

Aggregations

BasicStatusLine (org.apache.http.message.BasicStatusLine)118 ProtocolVersion (org.apache.http.ProtocolVersion)67 Test (org.junit.Test)56 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)54 StatusLine (org.apache.http.StatusLine)45 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)33 StringEntity (org.apache.http.entity.StringEntity)32 ByteArrayInputStream (java.io.ByteArrayInputStream)29 HttpResponse (org.apache.http.HttpResponse)27 IOException (java.io.IOException)19 HttpEntity (org.apache.http.HttpEntity)19 BasicHeader (org.apache.http.message.BasicHeader)19 URL (java.net.URL)17 HttpURLConnection (java.net.HttpURLConnection)16 List (java.util.List)16 Header (org.apache.http.Header)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 HashMap (java.util.HashMap)14 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)13 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)12