Search in sources :

Example 1 with GoAgentServerHttpClient

use of com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient in project gocd by gocd.

the class RemoteRegistrationRequesterTest method shouldPassAllParametersToPostForRegistrationOfNonElasticAgent.

@Test
public void shouldPassAllParametersToPostForRegistrationOfNonElasticAgent() throws IOException, ClassNotFoundException {
    String url = "http://cruise.com/go";
    GoAgentServerHttpClient httpClient = mock(GoAgentServerHttpClient.class);
    when(httpClient.execute(argThat(isA(HttpUriRequest.class)))).thenReturn(mock(CloseableHttpResponse.class));
    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");
    remoteRegistryRequester(url, httpClient, defaultAgentRegistry, 200).requestRegistration("cruise.com", new AgentAutoRegistrationPropertiesImpl(null, properties));
    verify(httpClient).execute(argThat(hasAllParams(defaultAgentRegistry.uuid(), "", "")));
}
Also used : AgentAutoRegistrationPropertiesImpl(com.thoughtworks.go.agent.AgentAutoRegistrationPropertiesImpl) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) GoAgentServerHttpClient(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient) DefaultAgentRegistry(com.thoughtworks.go.config.DefaultAgentRegistry) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with GoAgentServerHttpClient

use of com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient in project gocd by gocd.

the class SslInfrastructureServiceTest method requesterStub.

private SslInfrastructureService.RemoteRegistrationRequester requesterStub(final Registration registration) {
    final SslInfrastructureServiceTest me = this;
    final SystemEnvironment systemEnvironment = new SystemEnvironment();
    return new SslInfrastructureService.RemoteRegistrationRequester(null, agentRegistryStub(), new GoAgentServerHttpClient(new GoAgentServerHttpClientBuilder(systemEnvironment))) {

        protected Registration requestRegistration(String agentHostName, AgentAutoRegistrationProperties agentAutoRegisterProperties) throws IOException, ClassNotFoundException {
            LOGGER.debug("Requesting remote registration");
            me.remoteCalled = true;
            return registration;
        }
    };
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) GoAgentServerHttpClientBuilder(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder) GoAgentServerHttpClient(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient) AgentAutoRegistrationProperties(com.thoughtworks.go.config.AgentAutoRegistrationProperties)

Example 3 with GoAgentServerHttpClient

use of com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient in project gocd by gocd.

the class AgentUpgradeServiceTest method setUp.

@Before
public void setUp() throws Exception {
    systemEnvironment = mock(SystemEnvironment.class);
    urlService = mock(URLService.class);
    GoAgentServerHttpClient httpClient = mock(GoAgentServerHttpClient.class);
    jvmExitter = mock(AgentUpgradeService.JvmExitter.class);
    agentUpgradeService = spy(new AgentUpgradeService(urlService, httpClient, systemEnvironment, jvmExitter));
    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) Before(org.junit.Before)

Example 4 with GoAgentServerHttpClient

use of com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient in project gocd by gocd.

the class HttpService method execute.

public CloseableHttpResponse execute(HttpRequestBase httpMethod) throws IOException {
    GoAgentServerHttpClient client = httpClientFactory.httpClient();
    CloseableHttpResponse response = client.execute(httpMethod);
    LOGGER.info("Got back " + response.getStatusLine().getStatusCode() + " from server");
    return response;
}
Also used : CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) GoAgentServerHttpClient(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient)

Example 5 with GoAgentServerHttpClient

use of com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient 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);
    when(httpClient.execute(argThat(isA(HttpUriRequest.class)))).thenReturn(mock(CloseableHttpResponse.class));
    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")));
}
Also used : AgentAutoRegistrationPropertiesImpl(com.thoughtworks.go.agent.AgentAutoRegistrationPropertiesImpl) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) GoAgentServerHttpClient(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient) DefaultAgentRegistry(com.thoughtworks.go.config.DefaultAgentRegistry) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

GoAgentServerHttpClient (com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient)6 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 AgentAutoRegistrationPropertiesImpl (com.thoughtworks.go.agent.AgentAutoRegistrationPropertiesImpl)2 DefaultAgentRegistry (com.thoughtworks.go.config.DefaultAgentRegistry)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 GoAgentServerHttpClientBuilder (com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder)1 AgentAutoRegistrationProperties (com.thoughtworks.go.config.AgentAutoRegistrationProperties)1 URLService (com.thoughtworks.go.util.URLService)1 IOException (java.io.IOException)1 HttpGet (org.apache.http.client.methods.HttpGet)1 BasicStatusLine (org.apache.http.message.BasicStatusLine)1 Expectations (org.jmock.Expectations)1 Before (org.junit.Before)1