Search in sources :

Example 11 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class TestRegistryService method testUpdateFlowWithoutId.

@Test(expected = IllegalArgumentException.class)
public void testUpdateFlowWithoutId() {
    final VersionedFlow versionedFlow = new VersionedFlow();
    registryService.updateFlow(versionedFlow);
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Test(org.junit.Test)

Example 12 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class TestRegistryService method testUpdateFlowWithSameNameAsExistingFlow.

@Test(expected = IllegalStateException.class)
public void testUpdateFlowWithSameNameAsExistingFlow() {
    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 flowToUpdate = new FlowEntity();
    flowToUpdate.setId("flow1");
    flowToUpdate.setName("My Flow");
    flowToUpdate.setDescription("This is my flow.");
    flowToUpdate.setCreated(new Date());
    flowToUpdate.setModified(new Date());
    flowToUpdate.setBucketId(existingBucket.getId());
    when(metadataService.getFlowByIdWithSnapshotCounts(flowToUpdate.getId())).thenReturn(flowToUpdate);
    final FlowEntity otherFlow = new FlowEntity();
    otherFlow.setId("flow2");
    otherFlow.setName("My Flow 2");
    otherFlow.setDescription("This is my flow 2.");
    otherFlow.setCreated(new Date());
    otherFlow.setModified(new Date());
    otherFlow.setBucketId(existingBucket.getId());
    when(metadataService.getFlowsByName(existingBucket.getId(), otherFlow.getName())).thenReturn(Collections.singletonList(otherFlow));
    final VersionedFlow versionedFlow = new VersionedFlow();
    versionedFlow.setIdentifier(flowToUpdate.getId());
    versionedFlow.setBucketIdentifier(existingBucket.getId());
    versionedFlow.setName(otherFlow.getName());
    registryService.updateFlow(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 13 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class TestRegistryService method testGetSnapshotExists.

@Test
public void testGetSnapshotExists() {
    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);
    // return a non-null, non-zero-length array so something gets passed to the serializer
    when(flowPersistenceProvider.getFlowContent(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion())).thenReturn(new byte[10]);
    final VersionedFlowSnapshot snapshotToDeserialize = createSnapshot();
    when(snapshotSerializer.deserialize(any(InputStream.class))).thenReturn(snapshotToDeserialize.getFlowContents());
    final VersionedFlowSnapshot returnedSnapshot = registryService.getFlowSnapshot(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion());
    assertNotNull(returnedSnapshot);
    assertNotNull(returnedSnapshot.getSnapshotMetadata());
    final VersionedFlowSnapshotMetadata snapshotMetadata = returnedSnapshot.getSnapshotMetadata();
    assertEquals(existingSnapshot.getVersion().intValue(), snapshotMetadata.getVersion());
    assertEquals(existingBucket.getId(), snapshotMetadata.getBucketIdentifier());
    assertEquals(existingSnapshot.getFlowId(), snapshotMetadata.getFlowIdentifier());
    assertEquals(existingSnapshot.getCreated(), new Date(snapshotMetadata.getTimestamp()));
    assertEquals(existingSnapshot.getCreatedBy(), snapshotMetadata.getAuthor());
    assertEquals(existingSnapshot.getComments(), snapshotMetadata.getComments());
    final VersionedFlow versionedFlow = returnedSnapshot.getFlow();
    assertNotNull(versionedFlow);
    assertNotNull(versionedFlow.getVersionCount());
    assertTrue(versionedFlow.getVersionCount() > 0);
    final Bucket bucket = returnedSnapshot.getBucket();
    assertNotNull(bucket);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) Bucket(org.apache.nifi.registry.bucket.Bucket) InputStream(java.io.InputStream) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) Test(org.junit.Test)

Example 14 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow 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 15 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class TestRegistryService method testCreateFlowBucketDoesNotExist.

@Test(expected = ResourceNotFoundException.class)
public void testCreateFlowBucketDoesNotExist() {
    when(metadataService.getBucketById(any(String.class))).thenReturn(null);
    final VersionedFlow versionedFlow = new VersionedFlow();
    versionedFlow.setName("My Flow");
    versionedFlow.setBucketIdentifier("b1");
    registryService.createFlow(versionedFlow.getBucketIdentifier(), versionedFlow);
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)46 Test (org.junit.Test)19 Bucket (org.apache.nifi.registry.bucket.Bucket)12 BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)11 FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)11 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)11 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)10 Date (java.util.Date)9 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 ArrayList (java.util.ArrayList)6 Path (javax.ws.rs.Path)6 IOException (java.io.IOException)5 FlowClient (org.apache.nifi.registry.client.FlowClient)5 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)5 TreeSet (java.util.TreeSet)3 Response (javax.ws.rs.core.Response)3