use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class TestRegistryService method testDeleteSnapshotExists.
@Test
public void testDeleteSnapshotExists() {
final BucketEntity existingBucket = createBucketEntity("b1");
final FlowEntity existingFlow = createFlowEntity(existingBucket.getId());
final FlowSnapshotEntity existingSnapshot = createFlowSnapshotEntity(existingFlow.getId());
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);
when(metadataService.getFlowSnapshot(existingSnapshot.getFlowId(), existingSnapshot.getVersion())).thenReturn(existingSnapshot);
final VersionedFlowSnapshotMetadata deletedSnapshot = registryService.deleteFlowSnapshot(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion());
assertNotNull(deletedSnapshot);
assertEquals(existingSnapshot.getFlowId(), deletedSnapshot.getFlowIdentifier());
verify(flowPersistenceProvider, times(1)).deleteFlowContent(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion());
verify(metadataService, times(1)).deleteFlowSnapshot(existingSnapshot);
}
use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class TestRegistryService method testGetFlowSnapshotsWhenNoSnapshots.
@Test
public void testGetFlowSnapshotsWhenNoSnapshots() {
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());
final Set<FlowSnapshotEntity> snapshots = new HashSet<>();
when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);
final SortedSet<VersionedFlowSnapshotMetadata> retrievedSnapshots = registryService.getFlowSnapshots(existingBucket.getId(), existingFlow.getId());
assertNotNull(retrievedSnapshots);
assertEquals(0, retrievedSnapshots.size());
}
use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class TestRegistryService method testGetFlowsByBucketExists.
@Test
public void testGetFlowsByBucketExists() {
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);
final FlowEntity flowEntity1 = new FlowEntity();
flowEntity1.setId("flow1");
flowEntity1.setName("My Flow");
flowEntity1.setDescription("This is my flow.");
flowEntity1.setCreated(new Date());
flowEntity1.setModified(new Date());
flowEntity1.setBucketId(existingBucket.getId());
final FlowEntity flowEntity2 = new FlowEntity();
flowEntity2.setId("flow2");
flowEntity2.setName("My Flow 2");
flowEntity2.setDescription("This is my flow 2.");
flowEntity2.setCreated(new Date());
flowEntity2.setModified(new Date());
flowEntity2.setBucketId(existingBucket.getId());
final List<FlowEntity> flows = new ArrayList<>();
flows.add(flowEntity1);
flows.add(flowEntity2);
when(metadataService.getFlowsByBucket(eq(existingBucket.getId()))).thenReturn(flows);
final List<VersionedFlow> allFlows = registryService.getFlows(existingBucket.getId());
assertNotNull(allFlows);
assertEquals(2, allFlows.size());
}
use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class TestRegistryService method testCreateFlowWithSameName.
@Test(expected = IllegalStateException.class)
public void testCreateFlowWithSameName() {
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);
// setup a flow with the same name that already exists
final FlowEntity flowWithSameName = new FlowEntity();
flowWithSameName.setId("flow1");
flowWithSameName.setName("Flow 1");
flowWithSameName.setDescription("This is flow 1");
flowWithSameName.setCreated(new Date());
flowWithSameName.setModified(new Date());
when(metadataService.getFlowsByName(existingBucket.getId(), flowWithSameName.getName())).thenReturn(Collections.singletonList(flowWithSameName));
final VersionedFlow versionedFlow = new VersionedFlow();
versionedFlow.setName(flowWithSameName.getName());
versionedFlow.setBucketIdentifier("b1");
registryService.createFlow(versionedFlow.getBucketIdentifier(), versionedFlow);
}
use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class TestRegistryService method testDeleteFlowWithSnapshots.
@Test
public void testDeleteFlowWithSnapshots() {
final BucketEntity existingBucket = new BucketEntity();
existingBucket.setId("b1");
existingBucket.setName("My Bucket");
existingBucket.setDescription("This is my bucket");
existingBucket.setCreated(new Date());
final FlowEntity flowToDelete = new FlowEntity();
flowToDelete.setId("flow1");
flowToDelete.setName("My Flow");
flowToDelete.setDescription("This is my flow.");
flowToDelete.setCreated(new Date());
flowToDelete.setModified(new Date());
flowToDelete.setBucketId(existingBucket.getId());
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
when(metadataService.getFlowById(flowToDelete.getId())).thenReturn(flowToDelete);
when(metadataService.getFlowsByName(flowToDelete.getName())).thenReturn(Collections.singletonList(flowToDelete));
final VersionedFlow deletedFlow = registryService.deleteFlow(existingBucket.getId(), flowToDelete.getId());
assertNotNull(deletedFlow);
assertEquals(flowToDelete.getId(), deletedFlow.getIdentifier());
verify(flowPersistenceProvider, times(1)).deleteAllFlowContent(flowToDelete.getBucketId(), flowToDelete.getId());
verify(metadataService, times(1)).deleteFlow(flowToDelete);
}
Aggregations