SlotResource { @Path("{slotId}") @DELETE public Response terminateSlot(@HeaderParam(AIRSHIP_AGENT_VERSION_HEADER) String agentVersion, @HeaderParam(AIRSHIP_SLOT_VERSION_HEADER) String slotVersion, @PathParam("slotId") UUID slotId) { Preconditions.checkNotNull(slotId, "slotId must not be null"); Slot slot = agent.getSlot(slotId); if (slot == null) { return Response.status(Response.Status.NOT_FOUND).build(); } checkAgentVersion(agent.getAgentStatus(), agentVersion); checkSlotVersion(slot.status(), slotVersion); SlotStatus slotStatus = agent.terminateSlot(slotId); if (slotStatus == null) { return Response.status(Response.Status.NOT_FOUND).build(); } return Response.ok(SlotStatusRepresentation.from(slotStatus)) .header(AIRSHIP_AGENT_VERSION_HEADER, agent.getAgentStatus().getVersion()) .header(AIRSHIP_SLOT_VERSION_HEADER, slotStatus.getVersion()) .build(); } @Inject  SlotResource(Agent agent); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response installSlot(@HeaderParam(AIRSHIP_AGENT_VERSION_HEADER) String agentVersion, InstallationRepresentation installation, @Context UriInfo uriInfo); @Path("{slotId}") @DELETE Response terminateSlot(@HeaderParam(AIRSHIP_AGENT_VERSION_HEADER) String agentVersion,
            @HeaderParam(AIRSHIP_SLOT_VERSION_HEADER) String slotVersion,
            @PathParam("slotId") UUID slotId); @Path("{slotId}") @GET @Produces(MediaType.APPLICATION_JSON) Response getSlotStatus(@PathParam("slotId") UUID slotId, @Context UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) Response getAllSlotsStatus(@Context UriInfo uriInfo);  }
@Test public void testTerminateSlot() { SlotStatus slotStatus = agent.install(APPLE_INSTALLATION); Response response = resource.terminateSlot(null, null, slotStatus.getId()); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); SlotStatus expectedStatus = slotStatus.changeState(TERMINATED); assertEquals(response.getEntity(), SlotStatusRepresentation.from(expectedStatus)); assertEquals(response.getMetadata().get(AIRSHIP_AGENT_VERSION_HEADER).get(0), agent.getAgentStatus().getVersion()); assertEquals(response.getMetadata().get(AIRSHIP_SLOT_VERSION_HEADER).get(0), expectedStatus.getVersion()); assertNull(response.getMetadata().get("Content-Type")); assertNull(agent.getSlot(slotStatus.getId())); }
@Test public void testTerminateUnknownSlot() { Response response = resource.terminateSlot(null, null, UUID.randomUUID()); assertEquals(response.getStatus(), Status.NOT_FOUND.getStatusCode()); }
@Test(expectedExceptions = NullPointerException.class) public void testRemoveSlotNullId() { resource.terminateSlot(null, null, null); }