@Test public void testValidVersion() { UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/lifecycle?binary=*:apple:*"); String slotsVersion = VersionsUtil.createSlotsVersion( coordinator.getAllSlotsStatus( SlotFilterBuilder.build(uriInfo, false, ImmutableList.<UUID>of()))); assertOkResponse( resource.setState("running", uriInfo, slotsVersion), RUNNING, apple1SlotId, apple2SlotId); }
@GET @Produces(MediaType.APPLICATION_JSON) public Response getAllSlots(@Context UriInfo uriInfo) { Predicate<RemoteSlot> slotFilter = SlotFilterBuilder.build(uriInfo); List<SlotStatusRepresentation> representations = Lists.newArrayList(); for (RemoteSlot remoteSlot : coordinator.getAllSlots()) { if (slotFilter.apply(remoteSlot)) { representations.add(SlotStatusRepresentation.from(remoteSlot.status())); } } return Response.ok(representations).build(); }
@Test public void testInvalidVersion() { UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/lifecycle?binary=*:apple:*"); try { resource.setState("running", uriInfo, "invalid-version"); fail("Expected VersionConflictException"); } catch (VersionConflictException e) { assertEquals(e.getName(), AIRSHIP_SLOTS_VERSION_HEADER); assertEquals( e.getVersion(), VersionsUtil.createSlotsVersion( coordinator.getAllSlotsStatus( SlotFilterBuilder.build(uriInfo, false, ImmutableList.<UUID>of())))); } }