@Test
public void testUpdateFlow() throws InterruptedException {

    final BucketEntity existingBucket = new BucketEntity();
    existingBucket.setId("b1");
    existingBucket.setName("My Bucket");
    existingBucket.setDescription("This is my bucket");
    existingBucket.setCreated(new Date());
    final FlowEntity flowToUpdate = new FlowEntity();
    flowToUpdate.setId("flow1");
    flowToUpdate.setName("My Flow");
    flowToUpdate.setDescription("This is my flow.");
    flowToUpdate.setCreated(new Date());
    flowToUpdate.setModified(new Date());
    flowToUpdate.setBucketId(existingBucket.getId());
    when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
    when(metadataService.getFlowByIdWithSnapshotCounts(flowToUpdate.getId())).thenReturn(flowToUpdate);
    when(metadataService.getFlowsByName(flowToUpdate.getName())).thenReturn(Collections.singletonList(flowToUpdate));
    doAnswer(updateFlowAnswer()).when(metadataService).updateFlow(any(FlowEntity.class));
    final VersionedFlow versionedFlow = new VersionedFlow();
    versionedFlow.setBucketIdentifier(flowToUpdate.getBucketId());
    versionedFlow.setIdentifier(flowToUpdate.getId());
    versionedFlow.setName("New Flow Name");
    versionedFlow.setDescription("This is a new description");
    Thread.sleep(10);
    final VersionedFlow updatedFlow = registryService.updateFlow(versionedFlow);
    assertNotNull(updatedFlow);
    assertEquals(versionedFlow.getIdentifier(), updatedFlow.getIdentifier());
    // name and description should be updated
    assertEquals(versionedFlow.getName(), updatedFlow.getName());
    assertEquals(versionedFlow.getDescription(), updatedFlow.getDescription());
    // other fields should not be updated
    assertEquals(flowToUpdate.getBucketId(), updatedFlow.getBucketIdentifier());
    assertEquals(flowToUpdate.getCreated().getTime(), updatedFlow.getCreatedTimestamp());
}