@Test
public void testGetFlowSnapshots() {

    final BucketEntity existingBucket = new BucketEntity();
    existingBucket.setId("b1");
    existingBucket.setName("My Bucket");
    existingBucket.setDescription("This is my bucket");
    existingBucket.setCreated(new Date());
    when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
    // return a flow with the existing snapshot when getFlowById is called
    final FlowEntity existingFlow = new FlowEntity();
    existingFlow.setId("flow1");
    existingFlow.setName("My Flow");
    existingFlow.setDescription("This is my flow.");
    existingFlow.setCreated(new Date());
    existingFlow.setModified(new Date());
    existingFlow.setBucketId(existingBucket.getId());
    when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);
    final FlowSnapshotEntity existingSnapshot1 = new FlowSnapshotEntity();
    existingSnapshot1.setVersion(1);
    existingSnapshot1.setFlowId(existingFlow.getId());
    existingSnapshot1.setCreatedBy("user1");
    existingSnapshot1.setCreated(new Date());
    existingSnapshot1.setComments("This is snapshot 1");
    final FlowSnapshotEntity existingSnapshot2 = new FlowSnapshotEntity();
    existingSnapshot2.setVersion(2);
    existingSnapshot2.setFlowId(existingFlow.getId());
    existingSnapshot2.setCreatedBy("user2");
    existingSnapshot2.setCreated(new Date());
    existingSnapshot2.setComments("This is snapshot 2");
    final List<FlowSnapshotEntity> snapshots = new ArrayList<>();
    snapshots.add(existingSnapshot1);
    snapshots.add(existingSnapshot2);
    when(metadataService.getSnapshots(existingFlow.getId())).thenReturn(snapshots);
    final SortedSet<VersionedFlowSnapshotMetadata> retrievedSnapshots = registryService.getFlowSnapshots(existingBucket.getId(), existingFlow.getId());
    assertNotNull(retrievedSnapshots);
    assertEquals(2, retrievedSnapshots.size());
    // check that sorted set order is reversed
    assertEquals(2, retrievedSnapshots.first().getVersion());
    assertEquals(1, retrievedSnapshots.last().getVersion());
}