use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class TestRegistryService method testGetFlowSnapshots.
@Test
public void testGetFlowSnapshots() {
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");
final FlowSnapshotEntity existingSnapshot2 = new FlowSnapshotEntity();
existingSnapshot2.setVersion(2);
existingSnapshot2.setFlowId(existingFlow.getId());
existingSnapshot2.setCreatedBy("user2");
existingSnapshot2.setCreated(new Date());
existingSnapshot2.setComments("This is snapshot 2");
final List<FlowSnapshotEntity> snapshots = new ArrayList<>();
snapshots.add(existingSnapshot1);
snapshots.add(existingSnapshot2);
when(metadataService.getSnapshots(existingFlow.getId())).thenReturn(snapshots);
final SortedSet<VersionedFlowSnapshotMetadata> retrievedSnapshots = registryService.getFlowSnapshots(existingBucket.getId(), existingFlow.getId());
assertNotNull(retrievedSnapshots);
assertEquals(2, retrievedSnapshots.size());
// check that sorted set order is reversed
assertEquals(2, retrievedSnapshots.first().getVersion());
assertEquals(1, retrievedSnapshots.last().getVersion());
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class TestRegistryService method testUpdateBucket.
@Test
public void testUpdateBucket() {
final BucketEntity bucketToUpdate = new BucketEntity();
bucketToUpdate.setId("b1");
bucketToUpdate.setName("My Bucket");
bucketToUpdate.setDescription("This is my bucket");
bucketToUpdate.setCreated(new Date());
when(metadataService.getBucketById(bucketToUpdate.getId())).thenReturn(bucketToUpdate);
doAnswer(updateBucketAnswer()).when(metadataService).updateBucket(any(BucketEntity.class));
final Bucket updatedBucket = new Bucket();
updatedBucket.setIdentifier(bucketToUpdate.getId());
updatedBucket.setName("Updated Name");
updatedBucket.setDescription("Updated Description");
final Bucket result = registryService.updateBucket(updatedBucket);
assertNotNull(result);
assertEquals(updatedBucket.getName(), result.getName());
assertEquals(updatedBucket.getDescription(), result.getDescription());
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class TestRegistryService method testUpdateFlowWithSameNameAsExistingFlow.
@Test(expected = IllegalStateException.class)
public void testUpdateFlowWithSameNameAsExistingFlow() {
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 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.getFlowByIdWithSnapshotCounts(flowToUpdate.getId())).thenReturn(flowToUpdate);
final FlowEntity otherFlow = new FlowEntity();
otherFlow.setId("flow2");
otherFlow.setName("My Flow 2");
otherFlow.setDescription("This is my flow 2.");
otherFlow.setCreated(new Date());
otherFlow.setModified(new Date());
otherFlow.setBucketId(existingBucket.getId());
when(metadataService.getFlowsByName(existingBucket.getId(), otherFlow.getName())).thenReturn(Collections.singletonList(otherFlow));
final VersionedFlow versionedFlow = new VersionedFlow();
versionedFlow.setIdentifier(flowToUpdate.getId());
versionedFlow.setBucketIdentifier(existingBucket.getId());
versionedFlow.setName(otherFlow.getName());
registryService.updateFlow(versionedFlow);
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class TestRegistryService method testUpdateBucketWithSameNameAsExistingBucket.
@Test(expected = IllegalStateException.class)
public void testUpdateBucketWithSameNameAsExistingBucket() {
final BucketEntity bucketToUpdate = new BucketEntity();
bucketToUpdate.setId("b1");
bucketToUpdate.setName("My Bucket");
bucketToUpdate.setDescription("This is my bucket");
bucketToUpdate.setCreated(new Date());
when(metadataService.getBucketById(bucketToUpdate.getId())).thenReturn(bucketToUpdate);
final BucketEntity otherBucket = new BucketEntity();
otherBucket.setId("b2");
otherBucket.setName("My Bucket #2");
otherBucket.setDescription("This is my bucket");
otherBucket.setCreated(new Date());
when(metadataService.getBucketsByName(otherBucket.getName())).thenReturn(Collections.singletonList(otherBucket));
// should fail because other bucket has the same name
final Bucket updatedBucket = new Bucket();
updatedBucket.setIdentifier(bucketToUpdate.getId());
updatedBucket.setName("My Bucket #2");
updatedBucket.setDescription(bucketToUpdate.getDescription());
registryService.updateBucket(updatedBucket);
}
use of org.apache.nifi.registry.db.entity.BucketEntity 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);
}
Aggregations