CassandraConfig { @GET @Path("/get_token") public Response getToken() { try { String token = priamServer.getInstanceIdentity().getInstance().getToken(); if (StringUtils.isNotBlank(token)) { logger.info("Returning token value \"{}\" for this instance to caller.", token); metrics.incGetToken(); return Response.ok(priamServer.getInstanceIdentity().getInstance().getToken()) .build(); } logger.error("Cannot find token for this instance."); } catch (Exception e) { logger.error("Error while executing get_token", e); return Response.serverError().build(); } return Response.status(500).build(); } @Inject  CassandraConfig(PriamServer server, DoubleRing doubleRing, CassMonitorMetrics metrics); @GET @Path("/get_seeds") Response getSeeds(); @GET @Path("/get_token") Response getToken(); @GET @Path("/is_replace_token") Response isReplaceToken(); @GET @Path("/get_replaced_ip") Response getReplacedIp(); @POST @Path("/set_replaced_ip") Response setReplacedIp(@QueryParam("ip") String ip); @GET @Path("/get_extra_env_params") Response getExtraEnvParams(); @GET @Path("/double_ring") Response doubleRing();  }
@Test public void getToken( @Mocked final InstanceIdentity identity, @Mocked final PriamInstance instance) { final String token = "myToken"; new Expectations() { { priamServer.getInstanceIdentity(); result = identity; times = 2; identity.getInstance(); result = instance; times = 2; instance.getToken(); result = token; times = 2; } }; Response response = resource.getToken(); assertEquals(200, response.getStatus()); assertEquals(token, response.getEntity()); }
@Test public void getToken_notFound( @Mocked final InstanceIdentity identity, @Mocked final PriamInstance instance) { final String token = ""; new Expectations() { { priamServer.getInstanceIdentity(); result = identity; identity.getInstance(); result = instance; instance.getToken(); result = token; } }; Response response = resource.getToken(); assertEquals(500, response.getStatus()); }
@Test public void getToken_handlesException( @Mocked final InstanceIdentity identity, @Mocked final PriamInstance instance) { new Expectations() { { priamServer.getInstanceIdentity(); result = identity; identity.getInstance(); result = instance; instance.getToken(); result = new RuntimeException(); } }; Response response = resource.getToken(); assertEquals(500, response.getStatus()); }