Search in sources :

Example 11 with BucketEntity

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

the class TestRegistryService method testCreateFlowValid.

@Test
public void testCreateFlowValid() {
    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 VersionedFlow versionedFlow = new VersionedFlow();
    versionedFlow.setName("My Flow");
    versionedFlow.setBucketIdentifier("b1");
    doAnswer(createFlowAnswer()).when(metadataService).createFlow(any(FlowEntity.class));
    final VersionedFlow createdFlow = registryService.createFlow(versionedFlow.getBucketIdentifier(), versionedFlow);
    assertNotNull(createdFlow);
    assertNotNull(createdFlow.getIdentifier());
    assertTrue(createdFlow.getCreatedTimestamp() > 0);
    assertTrue(createdFlow.getModifiedTimestamp() > 0);
    assertEquals(versionedFlow.getName(), createdFlow.getName());
    assertEquals(versionedFlow.getBucketIdentifier(), createdFlow.getBucketIdentifier());
    assertEquals(versionedFlow.getDescription(), createdFlow.getDescription());
}
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 12 with BucketEntity

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

the class TestRegistryService method testCreateSnapshotVersionAlreadyExists.

@Test(expected = IllegalStateException.class)
public void testCreateSnapshotVersionAlreadyExists() {
    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);
    // 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");
    final List<FlowSnapshotEntity> existingSnapshots = Arrays.asList(existingSnapshot);
    when(metadataService.getSnapshots(existingFlow.getId())).thenReturn(existingSnapshots);
    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)

Example 13 with BucketEntity

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

the class TestRegistryService method testCreateFirstSnapshot.

@Test
public void testCreateFirstSnapshot() {
    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);
    when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow);
    final VersionedFlowSnapshot createdSnapshot = registryService.createFlowSnapshot(snapshot);
    assertNotNull(createdSnapshot);
    assertNotNull(createdSnapshot.getSnapshotMetadata());
    assertNotNull(createdSnapshot.getFlow());
    assertNotNull(createdSnapshot.getBucket());
    verify(snapshotSerializer, times(1)).serialize(eq(snapshot.getFlowContents()), any(OutputStream.class));
    verify(flowPersistenceProvider, times(1)).saveFlowContent(any(), any());
    verify(metadataService, times(1)).createFlowSnapshot(any(FlowSnapshotEntity.class));
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) OutputStream(java.io.OutputStream) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 14 with BucketEntity

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

the class TestRegistryService method testGetLatestSnapshotMetadataWhenNoVersionsExist.

@Test
public void testGetLatestSnapshotMetadataWhenNoVersionsExist() {
    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(null);
    try {
        registryService.getLatestFlowSnapshotMetadata(existingBucket.getId(), existingFlow.getId());
        Assert.fail("Should have thrown exception");
    } catch (ResourceNotFoundException e) {
        assertEquals("The specified flow ID has no versions", e.getMessage());
    }
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 15 with BucketEntity

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

the class TestRegistryService method testGetFlowExists.

@Test
public void testGetFlowExists() {
    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 flowEntity = new FlowEntity();
    flowEntity.setId("flow1");
    flowEntity.setName("My Flow");
    flowEntity.setDescription("This is my flow.");
    flowEntity.setCreated(new Date());
    flowEntity.setModified(new Date());
    flowEntity.setBucketId(existingBucket.getId());
    when(metadataService.getFlowByIdWithSnapshotCounts(flowEntity.getId())).thenReturn(flowEntity);
    final VersionedFlow versionedFlow = registryService.getFlow(existingBucket.getId(), flowEntity.getId());
    assertNotNull(versionedFlow);
    assertEquals(flowEntity.getId(), versionedFlow.getIdentifier());
    assertEquals(flowEntity.getName(), versionedFlow.getName());
    assertEquals(flowEntity.getDescription(), versionedFlow.getDescription());
    assertEquals(flowEntity.getBucketId(), versionedFlow.getBucketIdentifier());
    assertEquals(existingBucket.getName(), versionedFlow.getBucketName());
    assertEquals(flowEntity.getCreated().getTime(), versionedFlow.getCreatedTimestamp());
    assertEquals(flowEntity.getModified().getTime(), versionedFlow.getModifiedTimestamp());
}
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)

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