Search in sources :

Example 1 with BucketEntity

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

the class TestRegistryService method createBucketEntity.

private BucketEntity createBucketEntity(final String bucketId) {
    final BucketEntity existingBucket = new BucketEntity();
    existingBucket.setId(bucketId);
    existingBucket.setName("My Bucket");
    existingBucket.setDescription("This is my bucket");
    existingBucket.setCreated(new Date());
    return existingBucket;
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) Date(java.util.Date)

Example 2 with BucketEntity

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

the class TestRegistryService method testUpdateBucketPartial.

@Test
public void testUpdateBucketPartial() {
    final BucketEntity bucketToUpdate = new BucketEntity();
    bucketToUpdate.setId("b1");
    bucketToUpdate.setName("My Bucket");
    bucketToUpdate.setDescription("This is my bucket");
    bucketToUpdate.setCreated(new Date());
    when(metadataService.getBucketById(bucketToUpdate.getId())).thenReturn(bucketToUpdate);
    doAnswer(updateBucketAnswer()).when(metadataService).updateBucket(any(BucketEntity.class));
    final Bucket updatedBucket = new Bucket();
    updatedBucket.setIdentifier(bucketToUpdate.getId());
    updatedBucket.setName("Updated Name");
    updatedBucket.setDescription(null);
    // name should be updated but description should not be changed
    final Bucket result = registryService.updateBucket(updatedBucket);
    assertNotNull(result);
    assertEquals(updatedBucket.getName(), result.getName());
    assertEquals(bucketToUpdate.getDescription(), result.getDescription());
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) Bucket(org.apache.nifi.registry.bucket.Bucket) Date(java.util.Date) Test(org.junit.Test)

Example 3 with BucketEntity

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

the class TestRegistryService method testGetSnapshotDoesNotExistInPersistenceProvider.

@Test(expected = IllegalStateException.class)
public void testGetSnapshotDoesNotExistInPersistenceProvider() {
    final BucketEntity existingBucket = createBucketEntity("b1");
    final FlowEntity existingFlow = createFlowEntity(existingBucket.getId());
    final FlowSnapshotEntity existingSnapshot = createFlowSnapshotEntity(existingFlow.getId());
    existingFlow.setSnapshotCount(10);
    when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
    when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow);
    when(metadataService.getFlowSnapshot(existingFlow.getId(), existingSnapshot.getVersion())).thenReturn(existingSnapshot);
    when(flowPersistenceProvider.getFlowContent(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion())).thenReturn(null);
    registryService.getFlowSnapshot(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion());
}
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) Test(org.junit.Test)

Example 4 with BucketEntity

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

the class TestRegistryService method testCreateBucketWithSameName.

@Test(expected = IllegalStateException.class)
public void testCreateBucketWithSameName() {
    final Bucket bucket = new Bucket();
    bucket.setName("My Bucket");
    bucket.setDescription("This is my bucket.");
    final BucketEntity existingBucket = new BucketEntity();
    existingBucket.setId("b1");
    existingBucket.setName("My Bucket");
    existingBucket.setCreated(new Date());
    when(metadataService.getBucketsByName(bucket.getName())).thenReturn(Collections.singletonList(existingBucket));
    // should throw exception since a bucket with the same name exists
    registryService.createBucket(bucket);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) Bucket(org.apache.nifi.registry.bucket.Bucket) Date(java.util.Date) Test(org.junit.Test)

Example 5 with BucketEntity

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

the class TestRegistryService method testCreateFirstSnapshotWithBadVersion.

@Test(expected = IllegalStateException.class)
public void testCreateFirstSnapshotWithBadVersion() {
    final VersionedFlowSnapshot snapshot = createSnapshot();
    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);
    // set the first version to something other than 1
    snapshot.getSnapshotMetadata().setVersion(100);
    registryService.createFlowSnapshot(snapshot);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) 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