@Test
  public void testGetAllAgentsSingle() throws Exception {
    String agentId = UUID.randomUUID().toString();
    URI internalUri = URI.create("fake://agent/" + agentId + "/internal");
    URI externalUri = URI.create("fake://agent/" + agentId + "/external");
    String instanceId = "instance-id";
    String location = "/unknown/location";
    String instanceType = "instance.type";
    Map<String, Integer> resources = ImmutableMap.of("cpu", 8, "memory", 1024);

    AgentStatus status =
        new AgentStatus(
            agentId,
            AgentLifecycleState.ONLINE,
            instanceId,
            internalUri,
            externalUri,
            location,
            instanceType,
            ImmutableList.<SlotStatus>of(),
            resources);

    // add the agent
    provisioner.addAgents(status);
    coordinator.updateAllAgentsAndWait();

    Request request =
        Request.Builder.prepareGet()
            .setUri(coordinatorUriBuilder().appendPath("/v1/admin/agent").build())
            .build();

    List<AgentStatusRepresentation> agents =
        httpClient.execute(
            request, createJsonResponseHandler(agentStatusesCodec, Status.OK.getStatusCode()));
    assertEquals(agents.size(), 1);

    AgentStatusRepresentation actual = agents.get(0);
    assertEquals(actual.getAgentId(), agentId);
    assertEquals(actual.getState(), AgentLifecycleState.ONLINE);
    assertEquals(actual.getInstanceId(), instanceId);
    assertEquals(actual.getLocation(), location);
    assertEquals(actual.getInstanceType(), instanceType);
    assertEquals(actual.getSelf(), internalUri);
    assertEquals(actual.getExternalUri(), externalUri);
    assertEquals(actual.getResources(), resources);
  }
  @Test
  public void testAgentProvision() throws Exception {
    // provision the agent and verify
    String instanceType = "instance-type";
    AgentProvisioningRepresentation agentProvisioningRepresentation =
        new AgentProvisioningRepresentation(
            "agent:config:1", 1, instanceType, null, null, null, null, null);
    Request request =
        Request.Builder.preparePost()
            .setUri(coordinatorUriBuilder().appendPath("/v1/admin/agent").build())
            .setHeader(CONTENT_TYPE, APPLICATION_JSON)
            .setBodyGenerator(
                jsonBodyGenerator(agentProvisioningCodec, agentProvisioningRepresentation))
            .build();
    List<AgentStatusRepresentation> agents =
        httpClient.execute(
            request, createJsonResponseHandler(agentStatusesCodec, Status.OK.getStatusCode()));

    assertEquals(agents.size(), 1);
    String instanceId = agents.get(0).getInstanceId();
    assertNotNull(instanceId);
    String location = agents.get(0).getLocation();
    assertNotNull(location);
    assertEquals(agents.get(0).getInstanceType(), instanceType);
    assertNull(agents.get(0).getAgentId());
    assertNull(agents.get(0).getSelf());
    assertNull(agents.get(0).getExternalUri());
    assertEquals(agents.get(0).getState(), AgentLifecycleState.PROVISIONING);

    // start the agent and verify
    AgentStatus expectedAgentStatus = provisioner.startAgent(instanceId);
    coordinator.updateAllAgentsAndWait();
    assertEquals(coordinator.getAgents().size(), 1);
    assertEquals(coordinator.getAgent(instanceId).getInstanceId(), instanceId);
    assertEquals(coordinator.getAgent(instanceId).getInstanceType(), instanceType);
    assertEquals(coordinator.getAgent(instanceId).getLocation(), location);
    assertEquals(coordinator.getAgent(instanceId).getAgentId(), expectedAgentStatus.getAgentId());
    assertEquals(
        coordinator.getAgent(instanceId).getInternalUri(), expectedAgentStatus.getInternalUri());
    assertEquals(
        coordinator.getAgent(instanceId).getExternalUri(), expectedAgentStatus.getExternalUri());
    assertEquals(coordinator.getAgent(instanceId).getState(), AgentLifecycleState.ONLINE);

    request =
        Request.Builder.prepareGet()
            .setUri(coordinatorUriBuilder().appendPath("/v1/admin/agent").build())
            .build();

    agents =
        httpClient.execute(
            request, createJsonResponseHandler(agentStatusesCodec, Status.OK.getStatusCode()));
    assertEquals(agents.size(), 1);

    AgentStatusRepresentation actual = agents.get(0);
    assertEquals(actual.getInstanceId(), instanceId);
    assertEquals(actual.getInstanceType(), instanceType);
    assertEquals(actual.getLocation(), location);
    assertEquals(actual.getAgentId(), expectedAgentStatus.getAgentId());
    assertEquals(actual.getSelf(), expectedAgentStatus.getInternalUri());
    assertEquals(actual.getExternalUri(), expectedAgentStatus.getExternalUri());
    assertEquals(actual.getState(), AgentLifecycleState.ONLINE);
  }