@Test public void testGetResourcesWithUserInputBeginning() throws Exception { ResourceLookupContext resourceLookupContext = Mockito.mock(ResourceLookupContext.class); when(resourceLookupContext.getUserInput()).thenReturn("/p"); final List<String> expectedResources = new ArrayList<>(); expectedResources.add("/policies"); expectedResources.add("/proxy"); List<String> resources = registryClient.getResources(resourceLookupContext); Assert.assertNotNull(resources); Assert.assertEquals(expectedResources.size(), resources.size()); Assert.assertTrue(resources.containsAll(expectedResources)); }
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 Registry due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi Registry"); } List<String> identifiers = rootNode.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; } }
NiFiRegistryClient { 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 Registry due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi Registry"); } List<String> identifiers = rootNode.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; } } }
NiFiRegistryClient { 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 Registry due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi Registry"); } List<String> identifiers = rootNode.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; } } NiFiRegistryClient(final String url, final SSLContext sslContext); }
NiFiRegistryClient { 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 Registry due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi Registry"); } List<String> identifiers = rootNode.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; } } NiFiRegistryClient(final String url, final SSLContext sslContext); HashMap<String, Object> connectionTest(); List<String> getResources(ResourceLookupContext context); String getUrl(); SSLContext getSslContext(); HostnameVerifier getHostnameVerifier(); }
NiFiRegistryClient { 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 Registry due to: " + errorMsg); } JsonNode rootNode = mapper.readTree(response.getEntityInputStream()); if (rootNode == null) { throw new Exception("Unable to retrieve resources from NiFi Registry"); } List<String> identifiers = rootNode.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; } } NiFiRegistryClient(final String url, final SSLContext sslContext); HashMap<String, Object> connectionTest(); List<String> getResources(ResourceLookupContext context); String getUrl(); SSLContext getSslContext(); HostnameVerifier getHostnameVerifier();  }