StandardFlowRetrievalService implements FlowRetrievalService { @Override public VersionedFlowSnapshot getFlow(final FlowUri flowUri, final int version) throws IOException, FlowRetrievalException { if (flowUri == null) { throw new IllegalArgumentException("FlowUri cannot be null"); } if (version < 1) { throw new IllegalArgumentException("Version must be greater than or equal to 1"); } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Getting flow for {} with version {}", new Object[] {flowUri, Integer.valueOf(version)}); } final NiFiRegistryClient client = clientFactory.getClient(); try { return client.getFlowSnapshotClient().get(flowUri.getBucketId(), flowUri.getFlowId(), version); } catch (IOException ioe) { throw ioe; } catch (NiFiRegistryException nre) { throw new FlowRetrievalException("Error retrieving 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 testRetrieveSpecificWhenVersionsExist() throws IOException, FlowRetrievalException, NiFiRegistryException { final FlowUri flowUri = new FlowUri("http: final int version = 2; final VersionedFlowSnapshot flowSnapshot = FlowTestUtils.createSnapshot(flowUri.getBucketId(), flowUri.getFlowId(), version); when(flowSnapshotClient.get(flowUri.getBucketId(), flowUri.getFlowId(), version)).thenReturn(flowSnapshot); final VersionedFlowSnapshot returnedFlowSnapshot = flowRetrievalService.getFlow(flowUri, version); 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 testRetrieveSpecificWhenNoVersions() throws IOException, FlowRetrievalException, NiFiRegistryException { final FlowUri flowUri = new FlowUri("http: final int version = 2; when(flowSnapshotClient.get(flowUri.getBucketId(), flowUri.getFlowId(), version)).thenThrow(new NiFiRegistryException("No versions")); flowRetrievalService.getFlow(flowUri, version); }