AdminResource { @GET @Path("/coordinator") @Produces(MediaType.APPLICATION_JSON) public Response getAllCoordinators(@Context UriInfo uriInfo) { Predicate<CoordinatorStatus> coordinatorPredicate = CoordinatorFilterBuilder.build(uriInfo); List<CoordinatorStatus> coordinators = coordinator.getCoordinators(coordinatorPredicate); return Response.ok(transform(coordinators, fromCoordinatorStatus(coordinator.getCoordinators()))).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 testGetCoordinatorsDefault() { URI requestUri = URI.create("http: Response response = resource.getAllCoordinators(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertNull(response.getMetadata().get("Content-Type")); Iterable<CoordinatorStatusRepresentation> coordinators = (Iterable<CoordinatorStatusRepresentation>) response.getEntity(); assertEquals(Iterables.size(coordinators), 1); CoordinatorStatusRepresentation actual = coordinators.iterator().next(); assertEquals(actual.getCoordinatorId(), coordinatorStatus.getCoordinatorId()); assertEquals(actual.getState(), CoordinatorLifecycleState.ONLINE); assertEquals(actual.getInstanceId(), coordinatorStatus.getInstanceId()); assertEquals(actual.getLocation(), coordinatorStatus.getLocation()); assertEquals(actual.getInstanceType(), coordinatorStatus.getInstanceType()); assertEquals(actual.getSelf(), coordinatorStatus.getInternalUri()); assertEquals(actual.getExternalUri(), coordinatorStatus.getExternalUri()); }
@Test public void testGetAllCoordinatorsSingle() throws Exception { String coordinatorId = UUID.randomUUID().toString(); String instanceId = "instance-id"; URI internalUri = URI.create("fake: URI externalUri = URI.create("fake: String location = "/unknown/location"; String instanceType = "instance.type"; CoordinatorStatus status = new CoordinatorStatus(coordinatorId, CoordinatorLifecycleState.ONLINE, instanceId, internalUri, externalUri, location, instanceType); provisioner.addCoordinators(status); coordinator.updateAllCoordinatorsAndWait(); URI requestUri = URI.create("http: Response response = resource.getAllCoordinators(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertNull(response.getMetadata().get("Content-Type")); List<CoordinatorStatusRepresentation> coordinators = ImmutableList.copyOf((Iterable<CoordinatorStatusRepresentation>) response.getEntity()); CoordinatorStatusRepresentation actual = getNonMainCoordinator(coordinators); assertEquals(actual.getCoordinatorId(), coordinatorId); assertEquals(actual.getState(), CoordinatorLifecycleState.ONLINE); assertEquals(actual.getInstanceId(), instanceId); assertEquals(actual.getLocation(), location); assertEquals(actual.getInstanceType(), instanceType); assertEquals(actual.getSelf(), internalUri); assertEquals(actual.getExternalUri(), externalUri); }