HostLifeGatherer { public static JSONObject getHostLifePacket(FileWrapper fileWrapper) { long upTime; int statusCode = 0; String statusMessage = "OK"; try { upTime = fileWrapper.getFileAgeInSeconds(UPTIME_PATH); } catch (IOException e) { upTime = 0; statusCode = 1; statusMessage = "Unable to read proc folder"; } JSONObject jsonObject = new JSONObject(); try { jsonObject.put("status_code", statusCode); jsonObject.put("status_msg", statusMessage); jsonObject.put("timestamp", Instant.now().getEpochSecond()); jsonObject.put("application", "host_life"); JSONObject metrics = new JSONObject(); metrics.put("uptime", upTime); metrics.put("alive", 1); jsonObject.put("metrics", metrics); } catch (JSONException e) {} return jsonObject; }  static JSONObject getHostLifePacket(FileWrapper fileWrapper);  }
@Test public void host_is_alive() throws JSONException { JSONObject packet = HostLifeGatherer.getHostLifePacket(new MockFileWrapper()); JSONObject metrics = packet.getJSONObject("metrics"); assertEquals("host_life", packet.getString("application")); assertEquals(0, packet.getInt("status_code")); assertEquals("OK", packet.getString("status_msg")); assertEquals(123l, metrics.getLong("uptime")); assertEquals(1, metrics.getInt("alive")); }