Search in sources :

Example 11 with VersionedFlowSnapshot

use of org.apache.nifi.registry.flow.VersionedFlowSnapshot 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)

Example 12 with VersionedFlowSnapshot

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

the class TestRegistryService method testCreateSnapshotInvalidFlowContents.

@Test(expected = ConstraintViolationException.class)
public void testCreateSnapshotInvalidFlowContents() {
    final VersionedFlowSnapshot snapshot = createSnapshot();
    snapshot.setFlowContents(null);
    registryService.createFlowSnapshot(snapshot);
}
Also used : VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Test(org.junit.Test)

Example 13 with VersionedFlowSnapshot

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

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

the class TestRegistryService method testCreateSnapshotInvalidMetadata.

@Test(expected = ConstraintViolationException.class)
public void testCreateSnapshotInvalidMetadata() {
    final VersionedFlowSnapshot snapshot = createSnapshot();
    snapshot.getSnapshotMetadata().setFlowIdentifier(null);
    registryService.createFlowSnapshot(snapshot);
}
Also used : VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Test(org.junit.Test)

Example 15 with VersionedFlowSnapshot

use of org.apache.nifi.registry.flow.VersionedFlowSnapshot 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)

Aggregations

VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)38 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)18 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)16 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)15 Bucket (org.apache.nifi.registry.bucket.Bucket)12 IOException (java.io.IOException)11 Date (java.util.Date)11 Test (org.junit.Test)11 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Consumes (javax.ws.rs.Consumes)8 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 Authorizable (org.apache.nifi.authorization.resource.Authorizable)8 VersionedFlowState (org.apache.nifi.registry.flow.VersionedFlowState)8 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)8 VersionControlInformationDTO (org.apache.nifi.web.api.dto.VersionControlInformationDTO)8 HashMap (java.util.HashMap)7 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)7 Collections (java.util.Collections)6