NiFiClient { public HashMap<String, Object> connectionTest() { String errMsg = ""; boolean connectivityStatus; HashMap<String, Object> responseData = new HashMap<>(); try { final WebResource resource = getWebResource(); final ClientResponse response = getResponse(resource, "application/json"); if (LOG.isDebugEnabled()) { LOG.debug("Got response from NiFi with status code " + response.getStatus()); } if (Response.Status.OK.getStatusCode() == response.getStatus()) { connectivityStatus = true; } else { connectivityStatus = false; errMsg = "Status Code = " + response.getStatus(); } } catch (Exception e) { LOG.error("Connection to NiFi failed due to " + e.getMessage(), e); connectivityStatus = false; errMsg = e.getMessage(); } if (connectivityStatus) { BaseClient.generateResponseDataMap(connectivityStatus, SUCCESS_MSG, SUCCESS_MSG, null, null, responseData); } else { BaseClient.generateResponseDataMap(connectivityStatus, FAILURE_MSG, FAILURE_MSG + errMsg, null, null, responseData); } if (LOG.isDebugEnabled()) { LOG.debug("Response Data - " + responseData); } return responseData; } NiFiClient(final String url, final SSLContext sslContext); HashMap<String, Object> connectionTest(); List<String> getResources(ResourceLookupContext context); String getUrl(); SSLContext getSslContext(); HostnameVerifier getHostnameVerifier();  }
@Test public void testConnectionTestSuccess() { HashMap<String, Object> ret = niFiClient.connectionTest(); Assert.assertNotNull(ret); Assert.assertEquals(NiFiClient.SUCCESS_MSG, ret.get("message")); }
@Test public void testConnectionTestFailure() { final String errorMsg = "unknown error"; niFiClient = new MockNiFiClient(errorMsg, Response.Status.BAD_REQUEST.getStatusCode()); HashMap<String, Object> ret = niFiClient.connectionTest(); Assert.assertNotNull(ret); Assert.assertEquals(NiFiClient.FAILURE_MSG, ret.get("message")); }