AssignmentResource { @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response assign(@HeaderParam(AIRSHIP_AGENT_VERSION_HEADER) String agentVersion, @HeaderParam(AIRSHIP_SLOT_VERSION_HEADER) String slotVersion, @PathParam("slotId") UUID slotId, InstallationRepresentation installation) { Preconditions.checkNotNull(slotId, "slotId must not be null"); Preconditions.checkNotNull(installation, "installation 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 status = slot.assign(installation.toInstallation()); return Response.ok(SlotStatusRepresentation.from(status)) .header(AIRSHIP_AGENT_VERSION_HEADER, agent.getAgentStatus().getVersion()) .header(AIRSHIP_SLOT_VERSION_HEADER, status.getVersion()) .build(); } @Inject  AssignmentResource(Agent agent); @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response assign(@HeaderParam(AIRSHIP_AGENT_VERSION_HEADER) String agentVersion,
            @HeaderParam(AIRSHIP_SLOT_VERSION_HEADER) String slotVersion,
            @PathParam("slotId") UUID slotId,
            InstallationRepresentation installation);  }
@Test public void testAssignUnknown() { Response response = resource.assign(null, null, UUID.randomUUID(), UPGRADE); assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); }
@Test(expectedExceptions = NullPointerException.class) public void testAssignNullId() { resource.assign(null, null, null, UPGRADE); }
@Test(expectedExceptions = NullPointerException.class) public void testAssignNullAssignment() { SlotStatus slotStatus = agent.install(APPLE_INSTALLATION); resource.assign(null, null, slotStatus.getId(), null); }
@Test public void testAssignInvalidVersion() { SlotStatus slotStatus = agent.install(APPLE_INSTALLATION); try { resource.assign("bad-version", "bad-version", slotStatus.getId(), UPGRADE); fail("Expected VersionConflictException"); } catch (VersionConflictException e) { } try { resource.assign("bad-version", null, slotStatus.getId(), UPGRADE); fail("Expected VersionConflictException"); } catch (VersionConflictException e) { assertEquals(e.getName(), AIRSHIP_AGENT_VERSION_HEADER); assertEquals(e.getVersion(), agent.getAgentStatus().getVersion()); } try { resource.assign(null, "bad-version", slotStatus.getId(), UPGRADE); fail("Expected VersionConflictException"); } catch (VersionConflictException e) { assertEquals(e.getName(), AIRSHIP_SLOT_VERSION_HEADER); assertEquals(e.getVersion(), slotStatus.getVersion()); } }
@Test public void testAssign() { SlotStatus slotStatus = agent.install(APPLE_INSTALLATION); assertUpgrade(slotStatus, agent.getAgentStatus().getVersion(), slotStatus.getVersion()); }