Search in sources :

Example 61 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project gocd by gocd.

the class AgentUpgradeServiceTest method setUp.

@BeforeEach
void setUp() throws Exception {
    systemEnvironment = mock(SystemEnvironment.class);
    URLService urlService = mock(URLService.class);
    GoAgentServerHttpClient httpClient = mock(GoAgentServerHttpClient.class);
    jvmExitter = mock(AgentUpgradeService.JvmExitter.class);
    agentUpgradeService = spy(new AgentUpgradeService(urlService, httpClient, systemEnvironment, jvmExitter));
    HttpGet httpMethod = mock(HttpGet.class);
    doReturn(httpMethod).when(agentUpgradeService).getAgentLatestStatusGetMethod();
    closeableHttpResponse = mock(CloseableHttpResponse.class);
    when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    when(httpClient.execute(httpMethod)).thenReturn(closeableHttpResponse);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) URLService(com.thoughtworks.go.util.URLService) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) GoAgentServerHttpClient(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient) BasicStatusLine(org.apache.http.message.BasicStatusLine) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 62 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project graylog2-server by Graylog2.

the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorSingleHeader.

@Test
public void testInterceptorSingleHeader() throws IOException, HttpException {
    ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
    response.addHeader("Test", "This header should not trigger the interceptor.");
    interceptor.process(response, null);
    assertThat(response.getAllHeaders()).as("Number of Headers should be unchanged.").hasSize(1);
    assertThat(response.getAllHeaders()[0].getName()).as("Remaining Header should be same as the given.").isEqualTo("Test");
}
Also used : BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) HttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse) ProtocolVersion(org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion) BasicStatusLine(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 63 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project graylog2-server by Graylog2.

the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorMultipleHeaderFilteredWarningAndMultipleTriggers.

@Test
public void testInterceptorMultipleHeaderFilteredWarningAndMultipleTriggers() throws IOException, HttpException {
    ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
    response.addHeader("Test", "This header should not trigger the interceptor.");
    response.addHeader("Warning", "This warning should not trigger the interceptor.");
    response.addHeader("Warning", "This text contains the trigger: but in a future major version, direct access to system indices and their aliases will not be allowed - and should be filtered out");
    response.addHeader("Warning", "This text contains the trigger: setting was deprecated in Elasticsearch - and should be filtered out");
    assertThat(response.getAllHeaders()).as("Number of Headers should be 4 before start.").hasSize(4);
    interceptor.process(response, null);
    assertThat(response.getAllHeaders()).as("Number of Headers should be 2 less after running the interceptor.").hasSize(2);
}
Also used : BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) HttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse) ProtocolVersion(org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion) BasicStatusLine(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 64 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project graylog2-server by Graylog2.

the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorMultipleHeaderIgnoredWarning.

@Test
public void testInterceptorMultipleHeaderIgnoredWarning() throws IOException, HttpException {
    ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
    response.addHeader("Test", "This header should not trigger the interceptor.");
    response.addHeader("Warning", "This warning should not trigger the interceptor.");
    interceptor.process(response, null);
    assertThat(response.getAllHeaders()).as("Number of Headers should be unchanged.").hasSize(2);
}
Also used : BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) HttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse) ProtocolVersion(org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion) BasicStatusLine(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 65 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project graylog2-server by Graylog2.

the class ElasticsearchFilterDeprecationWarningsInterceptorTest method testInterceptorMultipleHeaderFilteredWarning.

@Test
public void testInterceptorMultipleHeaderFilteredWarning() throws IOException, HttpException {
    ElasticsearchFilterDeprecationWarningsInterceptor interceptor = new ElasticsearchFilterDeprecationWarningsInterceptor();
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
    response.addHeader("Test", "This header should not trigger the interceptor.");
    response.addHeader("Warning", "This warning should not trigger the interceptor.");
    response.addHeader("Warning", "This text contains the trigger: setting was deprecated in Elasticsearch - and should be filtered out");
    assertThat(response.getAllHeaders()).as("Number of Headers should be 3 before start.").hasSize(3);
    interceptor.process(response, null);
    assertThat(response.getAllHeaders()).as("Number of Headers should be 1 less after running the interceptor.").hasSize(2);
}
Also used : BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse) HttpResponse(org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse) ProtocolVersion(org.graylog.shaded.elasticsearch7.org.apache.http.ProtocolVersion) BasicStatusLine(org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine) 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