use of org.apache.nifi.registry.flow.VersionedFlowSnapshot 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));
}
use of org.apache.nifi.registry.flow.VersionedFlowSnapshot in project nifi-registry by apache.
the class TestRegistryService method testCreateSnapshotNullFlowContents.
@Test(expected = ConstraintViolationException.class)
public void testCreateSnapshotNullFlowContents() {
final VersionedFlowSnapshot snapshot = createSnapshot();
snapshot.setFlowContents(null);
registryService.createFlowSnapshot(snapshot);
}
use of org.apache.nifi.registry.flow.VersionedFlowSnapshot in project nifi-registry by apache.
the class TestRegistryService method testCreateSnapshotFlowDoesNotExist.
@Test(expected = ResourceNotFoundException.class)
public void testCreateSnapshotFlowDoesNotExist() {
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);
when(metadataService.getFlowById(snapshot.getSnapshotMetadata().getFlowIdentifier())).thenReturn(null);
registryService.createFlowSnapshot(snapshot);
}
use of org.apache.nifi.registry.flow.VersionedFlowSnapshot in project nifi-registry by apache.
the class TestRegistryService method createSnapshot.
// ---------------------- Test VersionedFlowSnapshot methods ---------------------------------------------
private VersionedFlowSnapshot createSnapshot() {
final VersionedFlowSnapshotMetadata snapshotMetadata = new VersionedFlowSnapshotMetadata();
snapshotMetadata.setFlowIdentifier("flow1");
snapshotMetadata.setVersion(1);
snapshotMetadata.setComments("This is the first snapshot");
snapshotMetadata.setBucketIdentifier("b1");
snapshotMetadata.setAuthor("user1");
final VersionedProcessGroup processGroup = new VersionedProcessGroup();
processGroup.setIdentifier("pg1");
processGroup.setName("My Process Group");
final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot();
snapshot.setSnapshotMetadata(snapshotMetadata);
snapshot.setFlowContents(processGroup);
return snapshot;
}
use of org.apache.nifi.registry.flow.VersionedFlowSnapshot in project nifi-registry by apache.
the class FlowsIT method testCreateFlowVersionGetFlowVersion.
@Test
public void testCreateFlowVersionGetFlowVersion() throws Exception {
// Given: an empty Bucket "3" (see FlowsIT.sql) with a newly created flow
long testStartTime = System.currentTimeMillis();
final String bucketId = "2";
final VersionedFlow flow = new VersionedFlow();
flow.setBucketIdentifier(bucketId);
flow.setName("Test Flow for creating snapshots");
flow.setDescription("This is a randomly named flow created by an integration test for the purpose of holding snapshots.");
final VersionedFlow createdFlow = client.target(createURL("buckets/{bucketId}/flows")).resolveTemplate("bucketId", bucketId).request().post(Entity.entity(flow, MediaType.APPLICATION_JSON), VersionedFlow.class);
final String flowId = createdFlow.getIdentifier();
// When: an initial flow snapshot is created *without* a version
final VersionedFlowSnapshotMetadata flowSnapshotMetadata = new VersionedFlowSnapshotMetadata();
flowSnapshotMetadata.setBucketIdentifier("2");
flowSnapshotMetadata.setFlowIdentifier(flowId);
flowSnapshotMetadata.setComments("This is snapshot 1, created by an integration test.");
final VersionedFlowSnapshot flowSnapshot = new VersionedFlowSnapshot();
flowSnapshot.setSnapshotMetadata(flowSnapshotMetadata);
// an empty root process group
flowSnapshot.setFlowContents(new VersionedProcessGroup());
WebTarget clientRequestTarget = client.target(createURL("buckets/{bucketId}/flows/{flowId}/versions")).resolveTemplate("bucketId", bucketId).resolveTemplate("flowId", flowId);
final Response response = clientRequestTarget.request().post(Entity.entity(flowSnapshot, MediaType.APPLICATION_JSON), Response.class);
// Then: an error is returned because version != 1
assertEquals(400, response.getStatus());
// But When: an initial flow snapshot is created with version == 1
flowSnapshot.getSnapshotMetadata().setVersion(1);
final VersionedFlowSnapshot createdFlowSnapshot = clientRequestTarget.request().post(Entity.entity(flowSnapshot, MediaType.APPLICATION_JSON), VersionedFlowSnapshot.class);
// Then: the server returns the created flow snapshot, with server-set fields populated correctly :)
assertFlowSnapshotsEqual(flowSnapshot, createdFlowSnapshot, false);
// both server and client in same JVM, so there shouldn't be skew
assertTrue(createdFlowSnapshot.getSnapshotMetadata().getTimestamp() - testStartTime > 0L);
assertEquals("anonymous", createdFlowSnapshot.getSnapshotMetadata().getAuthor());
assertNotNull(createdFlowSnapshot.getSnapshotMetadata().getLink());
assertNotNull(createdFlowSnapshot.getSnapshotMetadata().getLink().getUri());
assertNotNull(createdFlowSnapshot.getFlow());
assertEquals(1, createdFlowSnapshot.getFlow().getVersionCount());
assertNotNull(createdFlowSnapshot.getBucket());
// And when .../flows/{id}/versions is queried, then the newly created flow snapshot is returned in the list
final VersionedFlowSnapshotMetadata[] versionedFlowSnapshots = clientRequestTarget.request().get(VersionedFlowSnapshotMetadata[].class);
assertNotNull(versionedFlowSnapshots);
assertEquals(1, versionedFlowSnapshots.length);
assertFlowSnapshotMetadataEqual(createdFlowSnapshot.getSnapshotMetadata(), versionedFlowSnapshots[0], true);
// And when the link URI is queried, then the newly created flow snapshot is returned
final VersionedFlowSnapshot flowSnapshotByLink = client.target(createURL(versionedFlowSnapshots[0].getLink().getUri().toString())).request().get(VersionedFlowSnapshot.class);
assertFlowSnapshotsEqual(createdFlowSnapshot, flowSnapshotByLink, true);
assertNotNull(flowSnapshotByLink.getFlow());
assertNotNull(flowSnapshotByLink.getBucket());
// And when the bucket is queried by .../versions/{v}, then the newly created flow snapshot is returned
final VersionedFlowSnapshot flowSnapshotByVersionNumber = clientRequestTarget.path("/1").request().get(VersionedFlowSnapshot.class);
assertFlowSnapshotsEqual(createdFlowSnapshot, flowSnapshotByVersionNumber, true);
assertNotNull(flowSnapshotByVersionNumber.getFlow());
assertNotNull(flowSnapshotByVersionNumber.getBucket());
// And when the latest URI is queried, then the newly created flow snapshot is returned
final VersionedFlowSnapshot flowSnapshotByLatest = clientRequestTarget.path("/latest").request().get(VersionedFlowSnapshot.class);
assertFlowSnapshotsEqual(createdFlowSnapshot, flowSnapshotByLatest, true);
assertNotNull(flowSnapshotByLatest.getFlow());
assertNotNull(flowSnapshotByLatest.getBucket());
}
Aggregations