PriamInstanceResource { @GET @Path("{id}") public String getInstance(@PathParam("id") int id) { PriamInstance node = getByIdIfFound(id); return node.toString(); } @Inject // Note: do not parameterize the generic type variable to an implementation as it confuses // Guice in the binding.  PriamInstanceResource(
            IConfiguration config, IPriamInstanceFactory factory, InstanceInfo instanceInfo); @GET String getInstances(); @GET @Path("{id}") String getInstance(@PathParam("id") int id); @POST Response createInstance(
            @QueryParam("id") int id,
            @QueryParam("instanceID") String instanceID,
            @QueryParam("hostname") String hostname,
            @QueryParam("ip") String ip,
            @QueryParam("rack") String rack,
            @QueryParam("token") String token); @DELETE @Path("{id}") Response deleteInstance(@PathParam("id") int id);  }
@Test public void getInstance_notFound() { new Expectations() { { config.getAppName(); result = APP_NAME; factory.getInstance(APP_NAME, instanceInfo.getRegion(), NODE_ID); result = null; } }; try { resource.getInstance(NODE_ID); fail("Expected WebApplicationException thrown"); } catch (WebApplicationException e) { assertEquals(404, e.getResponse().getStatus()); assertEquals( "No priam instance with id " + NODE_ID + " found", e.getResponse().getEntity()); } }
@Test public void deleteInstance_notFound() { new Expectations() { { config.getAppName(); result = APP_NAME; factory.getInstance(APP_NAME, instanceInfo.getRegion(), NODE_ID); result = null; } }; try { resource.getInstance(NODE_ID); fail("Expected WebApplicationException thrown"); } catch (WebApplicationException e) { assertEquals(404, e.getResponse().getStatus()); assertEquals( "No priam instance with id " + NODE_ID + " found", e.getResponse().getEntity()); } }
@Test public void getInstance(@Mocked final PriamInstance instance) { final String expected = "plain text describing the instance"; new Expectations() { { config.getAppName(); result = APP_NAME; factory.getInstance(APP_NAME, instanceInfo.getRegion(), NODE_ID); result = instance; instance.toString(); result = expected; } }; assertEquals(expected, resource.getInstance(NODE_ID)); }