AdminResource { @GET @Path("status") @Produces(Servlets.JSON_MEDIA_TYPE) public Response getStatus() { if (LOG.isDebugEnabled()) { LOG.debug("==> AdminResource.getStatus()"); } Response response; try { JSONObject responseData = new JSONObject(); responseData.put(AtlasClient.STATUS, serviceState.getState().toString()); response = Response.ok(responseData).build(); } catch (JSONException e) { throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); } if (LOG.isDebugEnabled()) { LOG.debug("<== AdminResource.getStatus()"); } return response; } @Inject  AdminResource(ServiceState serviceState, MetricsService metricsService,
                         ExportService exportService, ImportService importService, SearchTracker activeSearches); @GET @Path("stack") @Produces(MediaType.TEXT_PLAIN) String getThreadDump(); @GET @Path("version") @Produces(Servlets.JSON_MEDIA_TYPE) Response getVersion(); @GET @Path("status") @Produces(Servlets.JSON_MEDIA_TYPE) Response getStatus(); @GET @Path("session") @Produces(Servlets.JSON_MEDIA_TYPE) Response getUserProfile(); @GET @Path("metrics") @Produces(Servlets.JSON_MEDIA_TYPE) AtlasMetrics getMetrics(@QueryParam("ignoreCache") boolean ignoreCache); @POST @Path("/export") @Consumes(Servlets.JSON_MEDIA_TYPE) Response export(AtlasExportRequest request); @POST @Path("/import") @Produces(Servlets.JSON_MEDIA_TYPE) @Consumes(MediaType.MULTIPART_FORM_DATA) AtlasImportResult importData(@FormDataParam("request") String jsonData,
                                        @FormDataParam("data") InputStream inputStream); @POST @Path("/importfile") @Produces(Servlets.JSON_MEDIA_TYPE) AtlasImportResult importFile(String jsonData); @GET @Path("activeSearches") @Produces(Servlets.JSON_MEDIA_TYPE) Set<String> getActiveSearches(); @DELETE @Path("activeSearches/{id}") @Produces(Servlets.JSON_MEDIA_TYPE) boolean terminateActiveSearch(@PathParam("id") String searchId);  }
@Test public void testStatusOfActiveServerIsReturned() throws JSONException { when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.ACTIVE); AdminResource adminResource = new AdminResource(serviceState, null, null, null, null); Response response = adminResource.getStatus(); assertEquals(response.getStatus(), HttpServletResponse.SC_OK); JSONObject entity = (JSONObject) response.getEntity(); assertEquals(entity.get("Status"), "ACTIVE"); }
@Test public void testResourceGetsValueFromServiceState() throws JSONException { when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE); AdminResource adminResource = new AdminResource(serviceState, null, null, null, null); Response response = adminResource.getStatus(); verify(serviceState).getState(); JSONObject entity = (JSONObject) response.getEntity(); assertEquals(entity.get("Status"), "PASSIVE"); }