Search in sources :

Example 76 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project java-sdk by optimizely.

the class HttpProjectConfigManagerTest method testGetDatafileHttpResponse2XX.

@Test
@Ignore
public void testGetDatafileHttpResponse2XX() throws Exception {
    String modifiedStamp = "Wed, 24 Apr 2019 07:07:07 GMT";
    CloseableHttpResponse getResponse = new MyResponse(new ProtocolVersion("TEST", 0, 0), 200, "TEST");
    getResponse.setEntity(new StringEntity(datafileString));
    getResponse.setHeader(HttpHeaders.LAST_MODIFIED, modifiedStamp);
    String datafile = projectConfigManager.getDatafileFromResponse(getResponse);
    assertNotNull(datafile);
    assertEquals("4", parseProjectConfig(datafile).getVersion());
    // Confirm last modified time is set
    assertEquals(modifiedStamp, projectConfigManager.getLastModified());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 77 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project java-sdk by optimizely.

the class HttpProjectConfigManagerTest method testGetDatafileHttpResponse5XX.

@Test(expected = ClientProtocolException.class)
public void testGetDatafileHttpResponse5XX() throws Exception {
    CloseableHttpResponse getResponse = new MyResponse(new ProtocolVersion("TEST", 0, 0), 500, "TEST");
    getResponse.setEntity(new StringEntity(datafileString));
    projectConfigManager.getDatafileFromResponse(getResponse);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) Test(org.junit.Test)

Example 78 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project java-sdk by optimizely.

the class HttpProjectConfigManagerTest method testGetDatafileHttpResponse304.

@Test
public void testGetDatafileHttpResponse304() throws Exception {
    CloseableHttpResponse getResponse = new MyResponse(new ProtocolVersion("TEST", 0, 0), 304, "TEST");
    getResponse.setEntity(new StringEntity(datafileString));
    String datafile = projectConfigManager.getDatafileFromResponse(getResponse);
    assertNull(datafile);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) Test(org.junit.Test)

Example 79 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project elasticsearch by elastic.

the class FailureTrackingResponseListenerTests method mockResponse.

private static Response mockResponse() {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    RequestLine requestLine = new BasicRequestLine("GET", "/", protocolVersion);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);
    return new Response(requestLine, new HttpHost("localhost", 9200), httpResponse);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicRequestLine(org.apache.http.message.BasicRequestLine) RequestLine(org.apache.http.RequestLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicRequestLine(org.apache.http.message.BasicRequestLine) HttpHost(org.apache.http.HttpHost) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 80 with ProtocolVersion

use of org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion in project elasticsearch by elastic.

the class HeapBufferedAsyncResponseConsumerTests method testResponseProcessing.

public void testResponseProcessing() throws Exception {
    ContentDecoder contentDecoder = mock(ContentDecoder.class);
    IOControl ioControl = mock(IOControl.class);
    HttpContext httpContext = mock(HttpContext.class);
    HeapBufferedAsyncResponseConsumer consumer = spy(new HeapBufferedAsyncResponseConsumer(TEST_BUFFER_LIMIT));
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);
    httpResponse.setEntity(new StringEntity("test", ContentType.TEXT_PLAIN));
    //everything goes well
    consumer.responseReceived(httpResponse);
    consumer.consumeContent(contentDecoder, ioControl);
    consumer.responseCompleted(httpContext);
    verify(consumer).releaseResources();
    verify(consumer).buildResult(httpContext);
    assertTrue(consumer.isDone());
    assertSame(httpResponse, consumer.getResult());
    consumer.responseCompleted(httpContext);
    verify(consumer, times(1)).releaseResources();
    verify(consumer, times(1)).buildResult(httpContext);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) IOControl(org.apache.http.nio.IOControl) ContentDecoder(org.apache.http.nio.ContentDecoder) HttpContext(org.apache.http.protocol.HttpContext) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Aggregations

ProtocolVersion (org.apache.http.ProtocolVersion)143 BasicStatusLine (org.apache.http.message.BasicStatusLine)67 Test (org.junit.Test)53 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)50 StatusLine (org.apache.http.StatusLine)44 HttpResponse (org.apache.http.HttpResponse)32 HttpEntity (org.apache.http.HttpEntity)31 Header (org.apache.http.Header)25 StringEntity (org.apache.http.entity.StringEntity)25 IOException (java.io.IOException)18 BasicHeader (org.apache.http.message.BasicHeader)15 URL (java.net.URL)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 HttpURLConnection (java.net.HttpURLConnection)13 HashMap (java.util.HashMap)13 List (java.util.List)13 ParseException (org.apache.http.ParseException)13 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)13 HttpHost (org.apache.http.HttpHost)12 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)11