@Test public void testSaveAllResults() throws Exception { Icinga2Result result = new Icinga2Result(); Map<String, String> map = new HashMap<>(); map.put("code", "200.00"); map.put("status", "Successfully processed"); result.setResults(Collections.singletonList(map)); mockAndReturn(result); when(icinga2CheckResultBuilder.build()).thenReturn(getRequestExample()); testling.teardownTestSuite(new TestSuite()); verify(exceptionHandler, never()).handleException(any(Exception.class)); verify(icinga2CheckResultBuilder).build(); }
@Override public void teardownTestSuite(@NonNull TestSuite testSuite) throws RuntimeException { LOGGER.info("======= SEND RESULTS TO ICINGA SERVER ======"); LOGGER.info("POST Sakuli results to '{}'", icinga2RestCient.getTargetCheckResult().getUri().toString()); Entity<Icinga2Request> payload = Entity.json(icinga2CheckResultBuilder.build()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("ICINGA Payload: {}", convertToJSON(payload)); } Response response = icinga2RestCient.getTargetCheckResult() .request(MediaType.APPLICATION_JSON_TYPE) .post(payload); Icinga2Result result = response.readEntity(Icinga2Result.class); if (result.isSuccess()) { LOGGER.info("ICINGA Response: {}", result.getFirstElementAsString()); LOGGER.info("======= FINISHED: SEND RESULTS TO ICINGA SERVER ======"); } else { throw new SakuliForwarderRuntimeException(String.format( "Unexpected result of REST-POST to Incinga monitoring server (%s): %s", icinga2RestCient.getTargetCheckResult().getUri(), result.getFirstElementAsString())); } }
Icinga2ResultServiceImpl extends AbstractTeardownService implements ResultService { @Override public void teardownTestSuite(@NonNull TestSuite testSuite) throws RuntimeException { LOGGER.info("======= SEND RESULTS TO ICINGA SERVER ======"); LOGGER.info("POST Sakuli results to '{}'", icinga2RestCient.getTargetCheckResult().getUri().toString()); Entity<Icinga2Request> payload = Entity.json(icinga2CheckResultBuilder.build()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("ICINGA Payload: {}", convertToJSON(payload)); } Response response = icinga2RestCient.getTargetCheckResult() .request(MediaType.APPLICATION_JSON_TYPE) .post(payload); Icinga2Result result = response.readEntity(Icinga2Result.class); if (result.isSuccess()) { LOGGER.info("ICINGA Response: {}", result.getFirstElementAsString()); LOGGER.info("======= FINISHED: SEND RESULTS TO ICINGA SERVER ======"); } else { throw new SakuliForwarderRuntimeException(String.format( "Unexpected result of REST-POST to Incinga monitoring server (%s): %s", icinga2RestCient.getTargetCheckResult().getUri(), result.getFirstElementAsString())); } } }
Icinga2ResultServiceImpl extends AbstractTeardownService implements ResultService { @Override public void teardownTestSuite(@NonNull TestSuite testSuite) throws RuntimeException { LOGGER.info("======= SEND RESULTS TO ICINGA SERVER ======"); LOGGER.info("POST Sakuli results to '{}'", icinga2RestCient.getTargetCheckResult().getUri().toString()); Entity<Icinga2Request> payload = Entity.json(icinga2CheckResultBuilder.build()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("ICINGA Payload: {}", convertToJSON(payload)); } Response response = icinga2RestCient.getTargetCheckResult() .request(MediaType.APPLICATION_JSON_TYPE) .post(payload); Icinga2Result result = response.readEntity(Icinga2Result.class); if (result.isSuccess()) { LOGGER.info("ICINGA Response: {}", result.getFirstElementAsString()); LOGGER.info("======= FINISHED: SEND RESULTS TO ICINGA SERVER ======"); } else { throw new SakuliForwarderRuntimeException(String.format( "Unexpected result of REST-POST to Incinga monitoring server (%s): %s", icinga2RestCient.getTargetCheckResult().getUri(), result.getFirstElementAsString())); } }  }
Icinga2ResultServiceImpl extends AbstractTeardownService implements ResultService { @Override public void teardownTestSuite(@NonNull TestSuite testSuite) throws RuntimeException { LOGGER.info("======= SEND RESULTS TO ICINGA SERVER ======"); LOGGER.info("POST Sakuli results to '{}'", icinga2RestCient.getTargetCheckResult().getUri().toString()); Entity<Icinga2Request> payload = Entity.json(icinga2CheckResultBuilder.build()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("ICINGA Payload: {}", convertToJSON(payload)); } Response response = icinga2RestCient.getTargetCheckResult() .request(MediaType.APPLICATION_JSON_TYPE) .post(payload); Icinga2Result result = response.readEntity(Icinga2Result.class); if (result.isSuccess()) { LOGGER.info("ICINGA Response: {}", result.getFirstElementAsString()); LOGGER.info("======= FINISHED: SEND RESULTS TO ICINGA SERVER ======"); } else { throw new SakuliForwarderRuntimeException(String.format( "Unexpected result of REST-POST to Incinga monitoring server (%s): %s", icinga2RestCient.getTargetCheckResult().getUri(), result.getFirstElementAsString())); } }  static String convertToJSON(Entity<?> entity); @Override int getServicePriority(); @Override void teardownTestSuite(@NonNull TestSuite testSuite); }
Icinga2ResultServiceImpl extends AbstractTeardownService implements ResultService { @Override public void teardownTestSuite(@NonNull TestSuite testSuite) throws RuntimeException { LOGGER.info("======= SEND RESULTS TO ICINGA SERVER ======"); LOGGER.info("POST Sakuli results to '{}'", icinga2RestCient.getTargetCheckResult().getUri().toString()); Entity<Icinga2Request> payload = Entity.json(icinga2CheckResultBuilder.build()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("ICINGA Payload: {}", convertToJSON(payload)); } Response response = icinga2RestCient.getTargetCheckResult() .request(MediaType.APPLICATION_JSON_TYPE) .post(payload); Icinga2Result result = response.readEntity(Icinga2Result.class); if (result.isSuccess()) { LOGGER.info("ICINGA Response: {}", result.getFirstElementAsString()); LOGGER.info("======= FINISHED: SEND RESULTS TO ICINGA SERVER ======"); } else { throw new SakuliForwarderRuntimeException(String.format( "Unexpected result of REST-POST to Incinga monitoring server (%s): %s", icinga2RestCient.getTargetCheckResult().getUri(), result.getFirstElementAsString())); } }  static String convertToJSON(Entity<?> entity); @Override int getServicePriority(); @Override void teardownTestSuite(@NonNull TestSuite testSuite);  }