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));
}
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"));
}
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"));
}
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();
}
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();
}
Aggregations