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