Search in sources :

Example 1 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class ShouldAssignWorkRequestTest method shouldDeserializeFromJSON.

@Test
void shouldDeserializeFromJSON() {
    String json = "{\n" + "  \"environment\": \"prod\",\n" + "  \"agent\": {\n" + "    \"agent_id\": \"42\",\n" + "    \"agent_state\": \"Idle\",\n" + "    \"build_state\": \"Idle\",\n" + "    \"config_state\": \"Enabled\"\n" + "  },\n" + "  \"elastic_agent_profile_properties\": {\n" + "    \"Image\": \"go-agent\"\n" + "  },\n" + "  \"cluster_profile_properties\": {\n" + "    \"GoServerUrl\": \"https://cd.server.com/go\", \n" + "    \"ClusterName\": \"deployment-cluster\"\n" + "  }\n" + "}";
    ShouldAssignWorkRequest request = ShouldAssignWorkRequest.fromJSON(json);
    assertThat(request.environment()).isEqualTo("prod");
    assertThat(request.agent()).isEqualTo(new Agent("42", Agent.AgentState.Idle, Agent.BuildState.Idle, Agent.ConfigState.Enabled));
    assertThat(request.elasticProfile().getImage()).isEqualTo("go-agent");
    Map<String, String> clusterProfileConfigurations = new HashMap<>();
    clusterProfileConfigurations.put("GoServerUrl", "https://cd.server.com/go");
    clusterProfileConfigurations.put("ClusterName", "deployment-cluster");
    ClusterProfileProperties expectedClusterProfileProperties = ClusterProfileProperties.fromConfiguration(clusterProfileConfigurations);
    assertThat(request.clusterProfileProperties()).isEqualTo(expectedClusterProfileProperties);
}
Also used : ClusterProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties) Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 2 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class AgentTest method agentsWithSameAttributesShouldBeEqual.

@Test
void agentsWithSameAttributesShouldBeEqual() throws Exception {
    Agent agent1 = new Agent("eeb9e0eb-1f12-4366-a5a5-59011810273b", Agent.AgentState.Building, Agent.BuildState.Cancelled, Agent.ConfigState.Disabled);
    Agent agent2 = new Agent("eeb9e0eb-1f12-4366-a5a5-59011810273b", Agent.AgentState.Building, Agent.BuildState.Cancelled, Agent.ConfigState.Disabled);
    assertThat(agent1).isEqualTo((agent2));
}
Also used : Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) Test(org.junit.jupiter.api.Test)

Example 3 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class AgentTest method agentsWithSameAttributesShareSameHashCode.

@Test
void agentsWithSameAttributesShareSameHashCode() throws Exception {
    Agent agent1 = new Agent("eeb9e0eb-1f12-4366-a5a5-59011810273b", Agent.AgentState.Building, Agent.BuildState.Cancelled, Agent.ConfigState.Disabled);
    Agent agent2 = new Agent("eeb9e0eb-1f12-4366-a5a5-59011810273b", Agent.AgentState.Building, Agent.BuildState.Cancelled, Agent.ConfigState.Disabled);
    assertThat(agent1.hashCode()).isEqualTo(agent2.hashCode());
}
Also used : Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) Test(org.junit.jupiter.api.Test)

Example 4 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class AgentTest method shouldDeserializeFromJSON.

@Test
void shouldDeserializeFromJSON() {
    List<Agent> agents = Agent.fromJSONArray("[{\"agent_id\":\"eeb9e0eb-1f12-4366-a5a5-59011810273b\",\"agent_state\":\"Building\",\"build_state\":\"Cancelled\",\"config_state\":\"Disabled\"}]");
    assertThat(agents).hasSize(1);
    Agent agent = agents.get(0);
    assertThat(agent.elasticAgentId()).isEqualTo("eeb9e0eb-1f12-4366-a5a5-59011810273b");
    assertThat(agent.agentState()).isEqualTo(Agent.AgentState.Building);
    assertThat(agent.buildState()).isEqualTo(Agent.BuildState.Cancelled);
    assertThat(agent.configState()).isEqualTo(Agent.ConfigState.Disabled);
}
Also used : Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) Test(org.junit.jupiter.api.Test)

Example 5 with Agent

use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.

the class AgentTest method shouldSerializeToJSON.

@Test
void shouldSerializeToJSON() throws Exception {
    Agent agent = new Agent("eeb9e0eb-1f12-4366-a5a5-59011810273b", Agent.AgentState.Building, Agent.BuildState.Cancelled, Agent.ConfigState.Disabled);
    String agentsJSON = Agent.toJSONArray(Arrays.asList(agent));
    JSONAssert.assertEquals("[{\"agent_id\":\"eeb9e0eb-1f12-4366-a5a5-59011810273b\",\"agent_state\":\"Building\",\"build_state\":\"Cancelled\",\"config_state\":\"Disabled\"}]", agentsJSON, true);
}
Also used : Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) Test(org.junit.jupiter.api.Test)

Aggregations

Agent (com.thoughtworks.gocd.elasticagent.ecs.domain.Agent)12 Test (org.junit.jupiter.api.Test)11 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)3 Agents (com.thoughtworks.gocd.elasticagent.ecs.Agents)2 ClusterProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties)2 ShouldAssignWorkRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.ShouldAssignWorkRequest)2 ElasticAgentProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)1 JobIdentifier (com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier)1 PluginSettings (com.thoughtworks.gocd.elasticagent.ecs.domain.PluginSettings)1 JobCompletionRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest)1 HashMap (java.util.HashMap)1 InOrder (org.mockito.InOrder)1