use of org.apache.nifi.registry.db.entity.BucketEntity 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());
}
use of org.apache.nifi.registry.db.entity.BucketEntity 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);
}
use of org.apache.nifi.registry.db.entity.BucketEntity 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.db.entity.BucketEntity in project nifi-registry by apache.
the class TestRegistryService method testGetLatestSnapshotMetadataWhenNoVersionsExist.
@Test
public void testGetLatestSnapshotMetadataWhenNoVersionsExist() {
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);
final FlowSnapshotEntity existingSnapshot1 = new FlowSnapshotEntity();
existingSnapshot1.setVersion(1);
existingSnapshot1.setFlowId(existingFlow.getId());
existingSnapshot1.setCreatedBy("user1");
existingSnapshot1.setCreated(new Date());
existingSnapshot1.setComments("This is snapshot 1");
when(metadataService.getLatestSnapshot(existingFlow.getId())).thenReturn(null);
try {
registryService.getLatestFlowSnapshotMetadata(existingBucket.getId(), existingFlow.getId());
Assert.fail("Should have thrown exception");
} catch (ResourceNotFoundException e) {
assertEquals("The specified flow ID has no versions", e.getMessage());
}
}
use of org.apache.nifi.registry.db.entity.BucketEntity 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());
}
Aggregations