CoordinatorSlotResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getAllSlots(@Context UriInfo uriInfo) { List<UUID> uuids = transform(coordinator.getAllSlotStatus(), uuidGetter()); Predicate<SlotStatus> slotFilter = SlotFilterBuilder.build(uriInfo, false, uuids); List<SlotStatus> slots = coordinator.getAllSlotsStatus(slotFilter); return Response.ok(Iterables.transform(slots, fromSlotStatus(coordinator.getAllSlotStatus(), repository))) .header(AIRSHIP_SLOTS_VERSION_HEADER, createSlotsVersion(slots)) .build(); } @Inject  CoordinatorSlotResource(Coordinator coordinator, Repository repository); @GET @Produces(MediaType.APPLICATION_JSON) Response getAllSlots(@Context UriInfo uriInfo); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response install(
            AssignmentRepresentation assignmentRepresentation,
            @DefaultValue("1") @QueryParam("limit") int limit,
            @Context UriInfo uriInfo,
            @HeaderParam(AIRSHIP_AGENTS_VERSION_HEADER) String expectedAgentsVersion); @DELETE @Produces(MediaType.APPLICATION_JSON) Response terminateSlots(@Context UriInfo uriInfo,
            @HeaderParam(AIRSHIP_SLOTS_VERSION_HEADER) String expectedSlotsVersion); static final int MIN_PREFIX_SIZE; }
@Test public void testGetAllSlots() { SlotStatus slot1 = createSlotStatus(UUID.randomUUID(), URI.create("fake: URI.create("fake: "instance-id", "/location", STOPPED, APPLE_ASSIGNMENT, "/slot1", ImmutableMap.<String, Integer>of()); SlotStatus slot2 = createSlotStatus(UUID.randomUUID(), URI.create("fake: URI.create("fake: "instance-id", "/location", STOPPED, APPLE_ASSIGNMENT, "/slot2", ImmutableMap.<String, Integer>of()); AgentStatus agentStatus = new AgentStatus(UUID.randomUUID().toString(), ONLINE, "instance-id", URI.create("fake: URI.create("fake: "/unknown/location", "instance.type", ImmutableList.of(slot1, slot2), ImmutableMap.<String, Integer>of()); provisioner.addAgents(agentStatus); coordinator.updateAllAgentsAndWait(); int prefixSize = shortestUniquePrefix(asList(slot1.getId().toString(), slot2.getId().toString()), MIN_PREFIX_SIZE); URI requestUri = URI.create("http: Response response = resource.getAllSlots(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of(SlotStatusRepresentation.from(slot1, prefixSize, repository), SlotStatusRepresentation.from(slot2, prefixSize, repository))); assertNull(response.getMetadata().get("Content-Type")); }
@Test public void testGetAllSlotsWithFilter() { SlotStatus slot1 = createSlotStatus(UUID.randomUUID(), URI.create("fake: URI.create("fake: "instance-id", "/location", STOPPED, APPLE_ASSIGNMENT, "/slot1", ImmutableMap.<String, Integer>of()); SlotStatus slot2 = createSlotStatus(UUID.randomUUID(), URI.create("fake: URI.create("fake: "instance-id", "/location", STOPPED, APPLE_ASSIGNMENT, "/slot2", ImmutableMap.<String, Integer>of()); AgentStatus agentStatus = new AgentStatus(UUID.randomUUID().toString(), ONLINE, "instance-id", URI.create("fake: URI.create("fake: "/unknown/location", "instance.type", ImmutableList.of(slot1, slot2), ImmutableMap.<String, Integer>of()); provisioner.addAgents(agentStatus); coordinator.updateAllAgentsAndWait(); int prefixSize = shortestUniquePrefix(asList(slot1.getId().toString(), slot2.getId().toString()), MIN_PREFIX_SIZE); URI requestUri = URI.create("http: Response response = resource.getAllSlots(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of(SlotStatusRepresentation.from(slot1, prefixSize, repository))); assertNull(response.getMetadata().get("Content-Type")); }
@Test public void testGetAllSlotEmpty() { URI requestUri = URI.create("http: Response response = resource.getAllSlots(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of()); assertNull(response.getMetadata().get("Content-Type")); }