Search in sources :

Example 16 with VersionedFlow

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);
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Test(org.junit.Test)

Example 17 with 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());
}
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 18 with VersionedFlow

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());
}
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 19 with VersionedFlow

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Test(org.junit.Test)

Example 20 with VersionedFlow

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);
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) 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