use of org.apache.http.message.BasicStatusLine in project gocd by gocd.
the class HttpServiceTest method shouldDownloadArtifact.
@Test
public void shouldDownloadArtifact() throws IOException {
String url = "http://blah";
FetchHandler fetchHandler = mock(FetchHandler.class);
HttpGet mockGetMethod = mock(HttpGet.class);
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
when(httpClient.execute(mockGetMethod)).thenReturn(response);
when(httpClientFactory.createGet(url)).thenReturn(mockGetMethod);
service.download(url, fetchHandler);
verify(httpClient).execute(mockGetMethod);
verify(fetchHandler).handle(null);
}
use of org.apache.http.message.BasicStatusLine in project gocd by gocd.
the class HttpServiceTest method shouldPostArtifactsAlongWithMD5.
@Test
public void shouldPostArtifactsAlongWithMD5() throws IOException {
File uploadingFile = mock(File.class);
java.util.Properties checksums = new java.util.Properties();
String uploadUrl = "url";
HttpPost mockPostMethod = mock(HttpPost.class);
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
when(httpClient.execute(mockPostMethod)).thenReturn(response);
when(uploadingFile.exists()).thenReturn(true);
when(httpClientFactory.createPost(uploadUrl)).thenReturn(mockPostMethod);
service.upload(uploadUrl, 100L, uploadingFile, checksums);
verify(mockPostMethod).setHeader(GO_ARTIFACT_PAYLOAD_SIZE, "100");
verify(mockPostMethod).setHeader("Confirm", "true");
verify(httpClientFactory).createMultipartRequestEntity(uploadingFile, checksums);
verify(httpClient).execute(mockPostMethod);
}
use of org.apache.http.message.BasicStatusLine in project gocd by gocd.
the class RemoteRegistrationRequesterTest method shouldPassAllParametersToPostForRegistrationOfElasticAgent.
@Test
public void shouldPassAllParametersToPostForRegistrationOfElasticAgent() throws IOException, ClassNotFoundException {
String url = "http://cruise.com/go";
GoAgentServerHttpClient httpClient = mock(GoAgentServerHttpClient.class);
final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
final ProtocolVersion protocolVersion = new ProtocolVersion("https", 1, 2);
when(response.getStatusLine()).thenReturn(new BasicStatusLine(protocolVersion, HttpStatus.OK.value(), null));
when(response.getEntity()).thenReturn(new StringEntity(RegistrationJSONizer.toJson(createRegistration())));
when(httpClient.execute(argThat(isA(HttpUriRequest.class)))).thenReturn(response);
final DefaultAgentRegistry defaultAgentRegistry = new DefaultAgentRegistry();
Properties properties = new Properties();
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_KEY, "t0ps3cret");
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_RESOURCES, "linux, java");
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_ENVIRONMENTS, "uat, staging");
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_HOSTNAME, "agent01.example.com");
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_ELASTIC_AGENT_ID, "42");
properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_ELASTIC_PLUGIN_ID, "tw.go.elastic-agent.docker");
remoteRegistryRequester(url, httpClient, defaultAgentRegistry, 200).requestRegistration("cruise.com", new AgentAutoRegistrationPropertiesImpl(null, properties));
verify(httpClient).execute(argThat(hasAllParams(defaultAgentRegistry.uuid(), "42", "tw.go.elastic-agent.docker")));
}
use of org.apache.http.message.BasicStatusLine in project gocd by gocd.
the class SslInfrastructureServiceTest method shouldDeleteTokenFromDiskWhenServerRejectsTheRegistrationRequestWithForbiddenErrorCode.
@Test
public void shouldDeleteTokenFromDiskWhenServerRejectsTheRegistrationRequestWithForbiddenErrorCode() throws Exception {
final CloseableHttpResponse httpResponseForbidden = mock(CloseableHttpResponse.class);
final ProtocolVersion protocolVersion = new ProtocolVersion("https", 1, 2);
when(agentRegistry.uuid()).thenReturn("some-uuid");
when(agentRegistry.tokenPresent()).thenReturn(true);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(protocolVersion, HttpStatus.OK.value(), null));
when(httpResponseForbidden.getStatusLine()).thenReturn(new BasicStatusLine(protocolVersion, HttpStatus.FORBIDDEN.value(), null));
when(httpResponse.getEntity()).thenReturn(new StringEntity(RegistrationJSONizer.toJson(createRegistration())));
when(httpResponseForbidden.getEntity()).thenReturn(new StringEntity("Not a valid token."));
when(httpClient.execute(any(HttpUriRequest.class))).thenReturn(httpResponseForbidden).thenReturn(httpResponse);
sslInfrastructureService.createSslInfrastructure();
sslInfrastructureService.registerIfNecessary(new AgentAutoRegistrationPropertiesImpl(new File("foo", "bar")));
assertThat(GoAgentServerClientBuilder.AGENT_CERTIFICATE_FILE, exists());
verify(agentRegistry, times(1)).deleteToken();
verify(httpClient, times(2)).execute(any(HttpUriRequest.class));
}
use of org.apache.http.message.BasicStatusLine in project gocd by gocd.
the class TokenRequesterTest method shouldErrorOutIfServerRejectTheRequest.
@Test
public void shouldErrorOutIfServerRejectTheRequest() 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("A token has already been issued for this agent."));
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), SC_UNPROCESSABLE_ENTITY, null));
thrown.expect(RuntimeException.class);
thrown.expectMessage("A token has already been issued for this agent.");
tokenRequester.getToken();
}
Aggregations