Search in sources :

Example 46 with BucketEntity

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

Example 47 with BucketEntity

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

Example 48 with BucketEntity

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

the class TestRegistryService method testGetExistingBucket.

@Test
public void testGetExistingBucket() {
    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 Bucket bucket = registryService.getBucket(existingBucket.getId());
    assertNotNull(bucket);
    assertEquals(existingBucket.getId(), bucket.getIdentifier());
    assertEquals(existingBucket.getName(), bucket.getName());
    assertEquals(existingBucket.getDescription(), bucket.getDescription());
    assertEquals(existingBucket.getCreated().getTime(), bucket.getCreatedTimestamp());
}
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 49 with BucketEntity

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

the class TestRegistryService method testCreateSnapshotVersionNotNextVersion.

@Test(expected = IllegalStateException.class)
public void testCreateSnapshotVersionNotNextVersion() {
    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());
    // make a snapshot that has the same version as the one being created
    final FlowSnapshotEntity existingSnapshot = new FlowSnapshotEntity();
    existingSnapshot.setFlowId(snapshot.getSnapshotMetadata().getFlowIdentifier());
    existingSnapshot.setVersion(snapshot.getSnapshotMetadata().getVersion());
    existingSnapshot.setComments("This is an existing snapshot");
    existingSnapshot.setCreated(new Date());
    existingSnapshot.setCreatedBy("test-user");
    when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);
    // set the version to something that is not the next one-up version
    snapshot.getSnapshotMetadata().setVersion(100);
    registryService.createFlowSnapshot(snapshot);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) 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