@Test public void testGetResourcesWithUserInputAnywhere() throws Exception { ResourceLookupContext resourceLookupContext = Mockito.mock(ResourceLookupContext.class); when(resourceLookupContext.getUserInput()).thenReturn("trol"); final List<String> expectedResources = new ArrayList<>(); expectedResources.add("/controller"); List<String> resources = niFiClient.getResources(resourceLookupContext); Assert.assertNotNull(resources); Assert.assertEquals(expectedResources.size(), resources.size()); resources.removeAll(expectedResources); Assert.assertEquals(0, resources.size()); }
public List<String> getResources(ResourceLookupContext context) throws Exception { final WebResource resource = getWebResource(); final ClientResponse response = getResponse(resource, "application/json"); if (Response.Status.OK.getStatusCode() != response.getStatus()) { String errorMsg = IOUtils.toString(response.getEntityInputStream()); throw new Exception("Unable to retrieve resources from NiFi due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi"); } JsonNode resourcesNode = rootNode.findValue("resources"); List<String> identifiers = resourcesNode.findValuesAsText("identifier"); final String userInput = context.getUserInput(); if (StringUtils.isBlank(userInput)) { return identifiers; } else { List<String> filteredIdentifiers = new ArrayList<>(); for (String identifier : identifiers) { if (identifier.contains(userInput)) { filteredIdentifiers.add(identifier); } } return filteredIdentifiers; } }
NiFiClient { public List<String> getResources(ResourceLookupContext context) throws Exception { final WebResource resource = getWebResource(); final ClientResponse response = getResponse(resource, "application/json"); if (Response.Status.OK.getStatusCode() != response.getStatus()) { String errorMsg = IOUtils.toString(response.getEntityInputStream()); throw new Exception("Unable to retrieve resources from NiFi due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi"); } JsonNode resourcesNode = rootNode.findValue("resources"); List<String> identifiers = resourcesNode.findValuesAsText("identifier"); final String userInput = context.getUserInput(); if (StringUtils.isBlank(userInput)) { return identifiers; } else { List<String> filteredIdentifiers = new ArrayList<>(); for (String identifier : identifiers) { if (identifier.contains(userInput)) { filteredIdentifiers.add(identifier); } } return filteredIdentifiers; } } }
NiFiClient { public List<String> getResources(ResourceLookupContext context) throws Exception { final WebResource resource = getWebResource(); final ClientResponse response = getResponse(resource, "application/json"); if (Response.Status.OK.getStatusCode() != response.getStatus()) { String errorMsg = IOUtils.toString(response.getEntityInputStream()); throw new Exception("Unable to retrieve resources from NiFi due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi"); } JsonNode resourcesNode = rootNode.findValue("resources"); List<String> identifiers = resourcesNode.findValuesAsText("identifier"); final String userInput = context.getUserInput(); if (StringUtils.isBlank(userInput)) { return identifiers; } else { List<String> filteredIdentifiers = new ArrayList<>(); for (String identifier : identifiers) { if (identifier.contains(userInput)) { filteredIdentifiers.add(identifier); } } return filteredIdentifiers; } } NiFiClient(final String url, final SSLContext sslContext); }
NiFiClient { public List<String> getResources(ResourceLookupContext context) throws Exception { final WebResource resource = getWebResource(); final ClientResponse response = getResponse(resource, "application/json"); if (Response.Status.OK.getStatusCode() != response.getStatus()) { String errorMsg = IOUtils.toString(response.getEntityInputStream()); throw new Exception("Unable to retrieve resources from NiFi due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi"); } JsonNode resourcesNode = rootNode.findValue("resources"); List<String> identifiers = resourcesNode.findValuesAsText("identifier"); final String userInput = context.getUserInput(); if (StringUtils.isBlank(userInput)) { return identifiers; } else { List<String> filteredIdentifiers = new ArrayList<>(); for (String identifier : identifiers) { if (identifier.contains(userInput)) { filteredIdentifiers.add(identifier); } } return filteredIdentifiers; } } NiFiClient(final String url, final SSLContext sslContext); HashMap<String, Object> connectionTest(); List<String> getResources(ResourceLookupContext context); String getUrl(); SSLContext getSslContext(); HostnameVerifier getHostnameVerifier(); }
NiFiClient { public List<String> getResources(ResourceLookupContext context) throws Exception { final WebResource resource = getWebResource(); final ClientResponse response = getResponse(resource, "application/json"); if (Response.Status.OK.getStatusCode() != response.getStatus()) { String errorMsg = IOUtils.toString(response.getEntityInputStream()); throw new Exception("Unable to retrieve resources from NiFi due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi"); } JsonNode resourcesNode = rootNode.findValue("resources"); List<String> identifiers = resourcesNode.findValuesAsText("identifier"); final String userInput = context.getUserInput(); if (StringUtils.isBlank(userInput)) { return identifiers; } else { List<String> filteredIdentifiers = new ArrayList<>(); for (String identifier : identifiers) { if (identifier.contains(userInput)) { filteredIdentifiers.add(identifier); } } return filteredIdentifiers; } } NiFiClient(final String url, final SSLContext sslContext); HashMap<String, Object> connectionTest(); List<String> getResources(ResourceLookupContext context); String getUrl(); SSLContext getSslContext(); HostnameVerifier getHostnameVerifier();  }