use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.
the class TestRegistryService method testCreateFlowInvalid.
// ---------------------- Test VersionedFlow methods ---------------------------------------------
@Test(expected = ConstraintViolationException.class)
public void testCreateFlowInvalid() {
final VersionedFlow versionedFlow = new VersionedFlow();
registryService.createFlow("b1", versionedFlow);
}
use of org.apache.nifi.registry.flow.VersionedFlow 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());
}
use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.
the class TestRegistryService method testUpdateFlow.
@Test
public void testUpdateFlow() throws InterruptedException {
final BucketEntity existingBucket = new BucketEntity();
existingBucket.setId("b1");
existingBucket.setName("My Bucket");
existingBucket.setDescription("This is my bucket");
existingBucket.setCreated(new Date());
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.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
when(metadataService.getFlowByIdWithSnapshotCounts(flowToUpdate.getId())).thenReturn(flowToUpdate);
when(metadataService.getFlowsByName(flowToUpdate.getName())).thenReturn(Collections.singletonList(flowToUpdate));
doAnswer(updateFlowAnswer()).when(metadataService).updateFlow(any(FlowEntity.class));
final VersionedFlow versionedFlow = new VersionedFlow();
versionedFlow.setBucketIdentifier(flowToUpdate.getBucketId());
versionedFlow.setIdentifier(flowToUpdate.getId());
versionedFlow.setName("New Flow Name");
versionedFlow.setDescription("This is a new description");
Thread.sleep(10);
final VersionedFlow updatedFlow = registryService.updateFlow(versionedFlow);
assertNotNull(updatedFlow);
assertEquals(versionedFlow.getIdentifier(), updatedFlow.getIdentifier());
// name and description should be updated
assertEquals(versionedFlow.getName(), updatedFlow.getName());
assertEquals(versionedFlow.getDescription(), updatedFlow.getDescription());
// other fields should not be updated
assertEquals(flowToUpdate.getBucketId(), updatedFlow.getBucketIdentifier());
assertEquals(flowToUpdate.getCreated().getTime(), updatedFlow.getCreatedTimestamp());
}
use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.
the class FlowsIT method testFlowNameUniquePerBucket.
@Test
public void testFlowNameUniquePerBucket() throws Exception {
final String flowName = "Flow 1";
// verify we have an existing flow with the name "Flow 1" in bucket 1
final VersionedFlow existingFlow = client.target(createURL("buckets/1/flows/1")).request().get(VersionedFlow.class);
assertNotNull(existingFlow);
assertEquals(flowName, existingFlow.getName());
// create a new flow with the same name
final String bucketId = "3";
final VersionedFlow flow = new VersionedFlow();
flow.setBucketIdentifier(bucketId);
flow.setName(flowName);
flow.setDescription("This is a flow created by an integration test.");
// saving this flow to bucket 3 should work because bucket 3 is empty
final VersionedFlow createdFlow = client.target(createURL("buckets/3/flows")).resolveTemplate("bucketId", bucketId).request().post(Entity.entity(flow, MediaType.APPLICATION_JSON), VersionedFlow.class);
assertNotNull(createdFlow);
// saving the flow to bucket 1 should not work because there is a flow with the same name
flow.setBucketIdentifier("1");
try {
client.target(createURL("buckets/1/flows")).resolveTemplate("bucketId", bucketId).request().post(Entity.entity(flow, MediaType.APPLICATION_JSON), VersionedFlow.class);
Assert.fail("Should have thrown exception");
} catch (WebApplicationException e) {
final String errorMessage = e.getResponse().readEntity(String.class);
Assert.assertEquals("A versioned flow with the same name already exists in the selected bucket", errorMessage);
}
}
use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.
the class FlowsIT method testCreateFlowGetFlow.
@Test
public void testCreateFlowGetFlow() throws Exception {
// Given: an empty bucket with id "3" (see FlowsIT.sql)
long testStartTime = System.currentTimeMillis();
final String bucketId = "3";
// When: a flow is created
final VersionedFlow flow = new VersionedFlow();
flow.setBucketIdentifier(bucketId);
flow.setName("Test Flow");
flow.setDescription("This is a flow created by an integration test.");
final VersionedFlow createdFlow = client.target(createURL("buckets/{bucketId}/flows")).resolveTemplate("bucketId", bucketId).request().post(Entity.entity(flow, MediaType.APPLICATION_JSON), VersionedFlow.class);
// Then: the server returns the created flow, with server-set fields populated correctly
assertFlowsEqual(flow, createdFlow, false);
assertNotNull(createdFlow.getIdentifier());
assertNotNull(createdFlow.getBucketName());
assertEquals(0, createdFlow.getVersionCount());
assertEquals(createdFlow.getType(), BucketItemType.Flow);
// both server and client in same JVM, so there shouldn't be skew
assertTrue(createdFlow.getCreatedTimestamp() - testStartTime > 0L);
assertEquals(createdFlow.getCreatedTimestamp(), createdFlow.getModifiedTimestamp());
assertNotNull(createdFlow.getLink());
assertNotNull(createdFlow.getLink().getUri());
// And when .../flows is queried, then the newly created flow is returned in the list
final VersionedFlow[] flows = client.target(createURL("buckets/{bucketId}/flows")).resolveTemplate("bucketId", bucketId).request().get(VersionedFlow[].class);
assertNotNull(flows);
assertEquals(1, flows.length);
assertFlowsEqual(createdFlow, flows[0], true);
// And when the link URI is queried, then the newly created flow is returned
final VersionedFlow flowByLink = client.target(createURL(flows[0].getLink().getUri().toString())).request().get(VersionedFlow.class);
assertFlowsEqual(createdFlow, flowByLink, true);
// And when the bucket is queried by .../flows/ID, then the newly created flow is returned
final VersionedFlow flowById = client.target(createURL("buckets/{bucketId}/flows/{flowId}")).resolveTemplate("bucketId", bucketId).resolveTemplate("flowId", createdFlow.getIdentifier()).request().get(VersionedFlow.class);
assertFlowsEqual(createdFlow, flowById, true);
}
Aggregations