StandardFlowRetrievalService implements FlowRetrievalService { @Override public List<VersionedFlowSnapshotMetadata> getVersions(final FlowUri flowUri) throws IOException, FlowRetrievalException { if (flowUri == null) { throw new IllegalArgumentException("FlowUri cannot be null"); } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Getting flow versions for {}", new Object[] {flowUri}); } final NiFiRegistryClient client = clientFactory.getClient(); try { return client.getFlowSnapshotClient().getSnapshotMetadata(flowUri.getBucketId(), flowUri.getFlowId()); } catch (IOException ioe) { throw ioe; } catch (NiFiRegistryException nre) { throw new FlowRetrievalException("Error retrieving flow versions 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 testRetrieveVersionsListWhenVersionsExist() throws IOException, FlowRetrievalException, NiFiRegistryException { final FlowUri flowUri = new FlowUri("http: final VersionedFlowSnapshot flowSnapshot1 = FlowTestUtils.createSnapshot(flowUri.getBucketId(), flowUri.getFlowId(), 1); final VersionedFlowSnapshot flowSnapshot2 = FlowTestUtils.createSnapshot(flowUri.getBucketId(), flowUri.getFlowId(), 2); when(flowSnapshotClient.getSnapshotMetadata(flowUri.getBucketId(), flowUri.getFlowId())) .thenReturn(Arrays.asList( flowSnapshot1.getSnapshotMetadata(), flowSnapshot2.getSnapshotMetadata())); final List<VersionedFlowSnapshotMetadata> returnedVersions = flowRetrievalService.getVersions(flowUri); assertNotNull(returnedVersions); assertEquals(2, returnedVersions.size()); }
@Test public void testRetrieveVersionsListWhenNoVersions() throws IOException, FlowRetrievalException, NiFiRegistryException { final FlowUri flowUri = new FlowUri("http: when(flowSnapshotClient.getSnapshotMetadata(flowUri.getBucketId(), flowUri.getFlowId())).thenReturn(Collections.emptyList()); final List<VersionedFlowSnapshotMetadata> returnedVersions = flowRetrievalService.getVersions(flowUri); assertNotNull(returnedVersions); assertEquals(0, returnedVersions.size()); }