Search in sources :

Example 41 with BucketEntity

use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.

the class TestRegistryService method testGetLatestSnapshotMetadataWhenVersionsExist.

@Test
public void testGetLatestSnapshotMetadataWhenVersionsExist() {
    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");
    when(metadataService.getLatestSnapshot(existingFlow.getId())).thenReturn(existingSnapshot1);
    VersionedFlowSnapshotMetadata latestMetadata = registryService.getLatestFlowSnapshotMetadata(existingBucket.getId(), existingFlow.getId());
    assertNotNull(latestMetadata);
    assertEquals(1, latestMetadata.getVersion());
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) Test(org.junit.Test)

Example 42 with BucketEntity

use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.

the class TestRegistryService method testDeleteBucketWithFlows.

@Test
public void testDeleteBucketWithFlows() {
    final BucketEntity bucketToDelete = new BucketEntity();
    bucketToDelete.setId("b1");
    bucketToDelete.setName("My Bucket");
    bucketToDelete.setDescription("This is my bucket");
    bucketToDelete.setCreated(new Date());
    final FlowEntity flowToDelete = new FlowEntity();
    flowToDelete.setId("flow1");
    flowToDelete.setName("Flow 1");
    flowToDelete.setDescription("This is flow 1");
    flowToDelete.setCreated(new Date());
    final List<FlowEntity> flows = new ArrayList<>();
    flows.add(flowToDelete);
    when(metadataService.getBucketById(bucketToDelete.getId())).thenReturn(bucketToDelete);
    when(metadataService.getFlowsByBucket(bucketToDelete.getId())).thenReturn(flows);
    final Bucket deletedBucket = registryService.deleteBucket(bucketToDelete.getId());
    assertNotNull(deletedBucket);
    assertEquals(bucketToDelete.getId(), deletedBucket.getIdentifier());
    verify(flowPersistenceProvider, times(1)).deleteAllFlowContent(eq(bucketToDelete.getId()), eq(flowToDelete.getId()));
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) Bucket(org.apache.nifi.registry.bucket.Bucket) ArrayList(java.util.ArrayList) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 43 with BucketEntity

use of org.apache.nifi.registry.db.entity.BucketEntity 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);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) Test(org.junit.Test)

Example 44 with BucketEntity

use of org.apache.nifi.registry.db.entity.BucketEntity 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());
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) HashSet(java.util.HashSet) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) Test(org.junit.Test)

Example 45 with BucketEntity

use of org.apache.nifi.registry.db.entity.BucketEntity 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());
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) ArrayList(java.util.ArrayList) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Aggregations

BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)49 Test (org.junit.Test)32 FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)31 Date (java.util.Date)26 FlowSnapshotEntity (org.apache.nifi.registry.db.entity.FlowSnapshotEntity)16 ResourceNotFoundException (org.apache.nifi.registry.exception.ResourceNotFoundException)14 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)11 Bucket (org.apache.nifi.registry.bucket.Bucket)10 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)9 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)8 ArrayList (java.util.ArrayList)5 InputStream (java.io.InputStream)3 TreeSet (java.util.TreeSet)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 BucketItem (org.apache.nifi.registry.bucket.BucketItem)2 BucketItemEntity (org.apache.nifi.registry.db.entity.BucketItemEntity)2 FlowSnapshotContext (org.apache.nifi.registry.flow.FlowSnapshotContext)2 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)2 StandardFlowSnapshotContext (org.apache.nifi.registry.provider.flow.StandardFlowSnapshotContext)2