Search in sources :

Example 56 with ProtocolVersion

use of org.apache.http.ProtocolVersion in project gocd by gocd.

the class SslInfrastructureServiceTest method shouldInvalidateKeystore.

@Test
public void shouldInvalidateKeystore() throws Exception {
    temporaryFolder.create();
    File configFile = temporaryFolder.newFile();
    when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), 200, null));
    when(httpResponse.getEntity()).thenReturn(new StringEntity(RegistrationJSONizer.toJson(createRegistration())));
    when(agentRegistry.guidPresent()).thenReturn(true);
    when(httpClient.execute(any(HttpRequestBase.class))).thenReturn(httpResponse);
    when(agentRegistry.tokenPresent()).thenReturn(true);
    shouldCreateSslInfrastructure();
    sslInfrastructureService.registerIfNecessary(new AgentAutoRegistrationPropertiesImpl(configFile));
    assertThat(GoAgentServerClientBuilder.AGENT_CERTIFICATE_FILE, exists());
    verify(httpClient, times(1)).execute(any(HttpRequestBase.class));
    sslInfrastructureService.registerIfNecessary(new AgentAutoRegistrationPropertiesImpl(configFile));
    verify(httpClient, times(1)).execute(any(HttpRequestBase.class));
    sslInfrastructureService.invalidateAgentCertificate();
    sslInfrastructureService.registerIfNecessary(new AgentAutoRegistrationPropertiesImpl(configFile));
    verify(httpClient, times(2)).execute(any(HttpRequestBase.class));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) AgentAutoRegistrationPropertiesImpl(com.thoughtworks.go.agent.AgentAutoRegistrationPropertiesImpl) ProtocolVersion(org.apache.http.ProtocolVersion) File(java.io.File) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 57 with ProtocolVersion

use of org.apache.http.ProtocolVersion in project gocd by gocd.

the class SslInfrastructureServiceTest method shouldPassUUIDAndTokenDuringAgentRegistration.

@Test
public void shouldPassUUIDAndTokenDuringAgentRegistration() throws Exception {
    final ArgumentCaptor<HttpEntityEnclosingRequestBase> httpRequestBaseArgumentCaptor = ArgumentCaptor.forClass(HttpEntityEnclosingRequestBase.class);
    when(agentRegistry.uuid()).thenReturn("some-uuid");
    when(agentRegistry.token()).thenReturn("some-token");
    when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), 200, null));
    when(httpResponse.getEntity()).thenReturn(new StringEntity(RegistrationJSONizer.toJson(createRegistration())));
    when(httpClient.execute(httpRequestBaseArgumentCaptor.capture())).thenReturn(httpResponse);
    sslInfrastructureService.createSslInfrastructure();
    sslInfrastructureService.registerIfNecessary(new AgentAutoRegistrationPropertiesImpl(new File("foo", "bar")));
    assertThat(GoAgentServerClientBuilder.AGENT_CERTIFICATE_FILE, exists());
    final HttpEntityEnclosingRequestBase httpRequestBase = httpRequestBaseArgumentCaptor.getValue();
    final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(httpRequestBase.getEntity());
    assertThat(findParam(nameValuePairs, "uuid").getValue(), is("some-uuid"));
    assertThat(findParam(nameValuePairs, "token").getValue(), is("some-token"));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) NameValuePair(org.apache.http.NameValuePair) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) AgentAutoRegistrationPropertiesImpl(com.thoughtworks.go.agent.AgentAutoRegistrationPropertiesImpl) ProtocolVersion(org.apache.http.ProtocolVersion) File(java.io.File) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 58 with ProtocolVersion

use of org.apache.http.ProtocolVersion in project gocd by gocd.

the class TokenRequesterTest method shouldGetTokenFromServer.

@Test
public void shouldGetTokenFromServer() throws Exception {
    final ArgumentCaptor<HttpRequestBase> argumentCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
    final CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class);
    when(agentRegistry.uuid()).thenReturn("agent-uuid");
    when(httpClient.execute(any(HttpRequestBase.class))).thenReturn(httpResponse);
    when(httpResponse.getEntity()).thenReturn(new StringEntity("token-from-server"));
    when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), SC_OK, null));
    final String token = tokenRequester.getToken();
    verify(httpClient).execute(argumentCaptor.capture());
    final HttpRequestBase requestBase = argumentCaptor.getValue();
    final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(requestBase.getURI(), StandardCharsets.UTF_8.name());
    assertThat(token, is("token-from-server"));
    assertThat(findParam(nameValuePairs, "uuid").getValue(), is("agent-uuid"));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) NameValuePair(org.apache.http.NameValuePair) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 59 with ProtocolVersion

use of org.apache.http.ProtocolVersion in project cdap-ingest by caskdata.

the class RestClientTest method testConflictResponseCodeAnalysis.

@Test
public void testConflictResponseCodeAnalysis() {
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_CONFLICT, "Conflict");
    when(response.getStatusLine()).thenReturn(statusLine);
    TestUtils.verifyResponse(HttpStatus.SC_CONFLICT, response);
    verify(response).getStatusLine();
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 60 with ProtocolVersion

use of org.apache.http.ProtocolVersion in project cdap-ingest by caskdata.

the class RestClientTest method testInternalServerErrorResponseCodeAnalysis.

@Test
public void testInternalServerErrorResponseCodeAnalysis() {
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
    when(response.getStatusLine()).thenReturn(statusLine);
    TestUtils.verifyResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, response);
    verify(response).getStatusLine();
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Aggregations

ProtocolVersion (org.apache.http.ProtocolVersion)113 BasicStatusLine (org.apache.http.message.BasicStatusLine)54 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)43 StatusLine (org.apache.http.StatusLine)42 Test (org.junit.Test)33 Header (org.apache.http.Header)26 HttpEntity (org.apache.http.HttpEntity)26 HttpResponse (org.apache.http.HttpResponse)22 StringEntity (org.apache.http.entity.StringEntity)20 URL (java.net.URL)16 BasicHeader (org.apache.http.message.BasicHeader)16 IOException (java.io.IOException)15 HttpURLConnection (java.net.HttpURLConnection)15 List (java.util.List)15 HashMap (java.util.HashMap)14 HttpHost (org.apache.http.HttpHost)12 ParseException (org.apache.http.ParseException)12 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)11 MockHttpStack (com.android.volley.mock.MockHttpStack)10 HttpRequest (org.apache.http.HttpRequest)10