AdminResource { @GET @Path("/agent") @Produces(MediaType.APPLICATION_JSON) public Response getAllAgents(@Context UriInfo uriInfo) { List<SlotStatus> allSlotStatus = coordinator.getAllSlotStatus(); Predicate<AgentStatus> agentPredicate = AgentFilterBuilder.build(uriInfo, transform(coordinator.getAgents(), idGetter()), transform(allSlotStatus, SlotStatus.uuidGetter()), false, repository); List<AgentStatus> agents = coordinator.getAgents(agentPredicate); return Response.ok(transform(agents, fromAgentStatus(coordinator.getAgents(), repository))) .header(AIRSHIP_AGENTS_VERSION_HEADER, createAgentsVersion(agents)) .build(); } @Inject  AdminResource(Coordinator coordinator, Repository repository); @GET @Path("/coordinator") @Produces(MediaType.APPLICATION_JSON) Response getAllCoordinators(@Context UriInfo uriInfo); @POST @Path("/coordinator") @Produces(MediaType.APPLICATION_JSON) Response provisionCoordinator(
            CoordinatorProvisioningRepresentation provisioning,
            @Context UriInfo uriInfo); @GET @Path("/agent") @Produces(MediaType.APPLICATION_JSON) Response getAllAgents(@Context UriInfo uriInfo); @POST @Path("/agent") @Produces(MediaType.APPLICATION_JSON) Response provisionAgent(
            AgentProvisioningRepresentation provisioning,
            @Context UriInfo uriInfo); @DELETE @Path("/agent/{agentId: [a-z0-9-]+}") Response terminateAgent(String agentId, @Context UriInfo uriInfo);  }
@Test public void testGetAllAgentsEmpty() { URI requestUri = URI.create("http: Response response = resource.getAllAgents(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of()); assertNull(response.getMetadata().get("Content-Type")); }
@Test public void testGetAllAgentsSingle() throws Exception { String agentId = UUID.randomUUID().toString(); URI internalUri = URI.create("fake: URI externalUri = URI.create("fake: 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); provisioner.addAgents(status); coordinator.updateAllAgentsAndWait(); URI requestUri = URI.create("http: Response response = resource.getAllAgents(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertNull(response.getMetadata().get("Content-Type")); Iterable<AgentStatusRepresentation> agents = (Iterable<AgentStatusRepresentation>) response.getEntity(); assertEquals(Iterables.size(agents), 1); AgentStatusRepresentation actual = agents.iterator().next(); 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); }