StandardFlowRetrievalService implements FlowRetrievalService { @Override public VersionedFlowSnapshot getLatestFlow(final FlowUri flowUri) throws IOException, FlowRetrievalException { if (flowUri == null) { throw new IllegalArgumentException("FlowUri cannot be null"); } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Getting latest flow for {}", new Object[] {flowUri}); } final NiFiRegistryClient client = clientFactory.getClient(); try { return client.getFlowSnapshotClient().getLatest(flowUri.getBucketId(), flowUri.getFlowId()); } catch (IOException ioe) { throw ioe; } catch (NiFiRegistryException nre) { throw new FlowRetrievalException("Error retrieving latest flow for " + flowUri + ": " + nre.getMessage(), nre); } } @Autowired  StandardFlowRetrievalService(final C2NiFiRegistryClient clientFactory); @Override List<VersionedFlowSnapshotMetadata> getVersions(final FlowUri flowUri); @Override VersionedFlowSnapshot getFlow(final FlowUri flowUri, final int version); @Override VersionedFlowSnapshot getLatestFlow(final FlowUri flowUri);  }
@Test public void testRetrieveLatestWhenVersionsExist() throws IOException, FlowRetrievalException, NiFiRegistryException { final FlowUri flowUri = new FlowUri("http: final VersionedFlowSnapshot flowSnapshot = FlowTestUtils.createSnapshot(flowUri.getBucketId(), flowUri.getFlowId(), 2); when(flowSnapshotClient.getLatest(flowUri.getBucketId(), flowUri.getFlowId())).thenReturn(flowSnapshot); final VersionedFlowSnapshot returnedFlowSnapshot = flowRetrievalService.getLatestFlow(flowUri); assertNotNull(returnedFlowSnapshot); assertEquals(flowSnapshot.getSnapshotMetadata().getBucketIdentifier(), returnedFlowSnapshot.getSnapshotMetadata().getBucketIdentifier()); assertEquals(flowSnapshot.getSnapshotMetadata().getFlowIdentifier(), returnedFlowSnapshot.getSnapshotMetadata().getFlowIdentifier()); assertEquals(flowSnapshot.getSnapshotMetadata().getVersion(), returnedFlowSnapshot.getSnapshotMetadata().getVersion()); }
@Test(expected = FlowRetrievalException.class) public void testRetrieveLatestWhenNoVersions() throws IOException, FlowRetrievalException, NiFiRegistryException { final FlowUri flowUri = new FlowUri("http: when(flowSnapshotClient.getLatest(flowUri.getBucketId(), flowUri.getFlowId())).thenThrow(new NiFiRegistryException("No Versions")); flowRetrievalService.getLatestFlow(flowUri); }