You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2017/12/14 17:43:58 UTC
[2/3] nifi-registry git commit: NIFIREG-69 Switching from Hibernate
to JDBC since Hibernate is LGPL
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java
index a8ff424..80c8582 100644
--- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java
+++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java
@@ -21,7 +21,6 @@ import org.apache.nifi.registry.db.entity.BucketEntity;
import org.apache.nifi.registry.db.entity.BucketItemEntityType;
import org.apache.nifi.registry.db.entity.FlowEntity;
import org.apache.nifi.registry.db.entity.FlowSnapshotEntity;
-import org.apache.nifi.registry.db.entity.FlowSnapshotEntityKey;
import org.apache.nifi.registry.db.entity.KeyEntity;
import org.apache.nifi.registry.flow.VersionedFlow;
import org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata;
@@ -67,42 +66,47 @@ public class DataModelMapper {
return flowEntity;
}
- public static VersionedFlow map(final FlowEntity flowEntity) {
+ public static VersionedFlow map(final BucketEntity bucketEntity, final FlowEntity flowEntity) {
final VersionedFlow versionedFlow = new VersionedFlow();
versionedFlow.setIdentifier(flowEntity.getId());
- versionedFlow.setBucketIdentifier(flowEntity.getBucket().getId());
- versionedFlow.setBucketName(flowEntity.getBucket().getName());
+ versionedFlow.setBucketIdentifier(flowEntity.getBucketId());
versionedFlow.setName(flowEntity.getName());
versionedFlow.setDescription(flowEntity.getDescription());
versionedFlow.setCreatedTimestamp(flowEntity.getCreated().getTime());
versionedFlow.setModifiedTimestamp(flowEntity.getModified().getTime());
versionedFlow.setVersionCount(flowEntity.getSnapshotCount());
+
+ if (bucketEntity != null) {
+ versionedFlow.setBucketName(bucketEntity.getName());
+ }
+
return versionedFlow;
}
// --- Map snapshots
public static FlowSnapshotEntity map(final VersionedFlowSnapshotMetadata versionedFlowSnapshot) {
- final FlowSnapshotEntityKey key = new FlowSnapshotEntityKey();
- key.setFlowId(versionedFlowSnapshot.getFlowIdentifier());
- key.setVersion(versionedFlowSnapshot.getVersion());
-
final FlowSnapshotEntity flowSnapshotEntity = new FlowSnapshotEntity();
- flowSnapshotEntity.setId(key);
+ flowSnapshotEntity.setFlowId(versionedFlowSnapshot.getFlowIdentifier());
+ flowSnapshotEntity.setVersion(versionedFlowSnapshot.getVersion());
flowSnapshotEntity.setComments(versionedFlowSnapshot.getComments());
flowSnapshotEntity.setCreated(new Date(versionedFlowSnapshot.getTimestamp()));
flowSnapshotEntity.setCreatedBy(versionedFlowSnapshot.getAuthor());
return flowSnapshotEntity;
}
- public static VersionedFlowSnapshotMetadata map(final FlowSnapshotEntity flowSnapshotEntity) {
+ public static VersionedFlowSnapshotMetadata map(final BucketEntity bucketEntity, final FlowSnapshotEntity flowSnapshotEntity) {
final VersionedFlowSnapshotMetadata metadata = new VersionedFlowSnapshotMetadata();
- metadata.setFlowIdentifier(flowSnapshotEntity.getId().getFlowId());
- metadata.setVersion(flowSnapshotEntity.getId().getVersion());
- metadata.setBucketIdentifier(flowSnapshotEntity.getFlow().getBucket().getId());
+ metadata.setFlowIdentifier(flowSnapshotEntity.getFlowId());
+ metadata.setVersion(flowSnapshotEntity.getVersion());
metadata.setComments(flowSnapshotEntity.getComments());
metadata.setTimestamp(flowSnapshotEntity.getCreated().getTime());
metadata.setAuthor(flowSnapshotEntity.getCreatedBy());
+
+ if (bucketEntity != null) {
+ metadata.setBucketIdentifier(bucketEntity.getId());
+ }
+
return metadata;
}
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/MetadataService.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/MetadataService.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/MetadataService.java
index 0613aa5..453271a 100644
--- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/MetadataService.java
+++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/MetadataService.java
@@ -72,11 +72,10 @@ public interface MetadataService {
/**
* Retrieves all buckets with the given ids.
*
- * @param params the paging and sorting params, or null
* @param bucketIds the ids of the buckets to retrieve
* @return the set of all buckets
*/
- List<BucketEntity> getBuckets(QueryParameters params, Set<String> bucketIds);
+ List<BucketEntity> getBuckets(Set<String> bucketIds);
/**
* Retrieves all buckets.
@@ -90,20 +89,18 @@ public interface MetadataService {
/**
* Retrieves items for the given bucket.
*
- * @param bucket the bucket to retrieve items for
- * @param queryParameters the parameters for retrieving the items, or null
+ * @param bucketId the id of bucket to retrieve items for
* @return the set of items for the bucket
*/
- List<BucketItemEntity> getBucketItems(QueryParameters queryParameters, BucketEntity bucket);
+ List<BucketItemEntity> getBucketItems(String bucketId);
/**
* Retrieves items for the given buckets.
*
* @param bucketIds the ids of buckets to retrieve items for
- * @param queryParameters the parameters for retrieving the items, or null
* @return the set of items for the bucket
*/
- List<BucketItemEntity> getBucketItems(QueryParameters queryParameters, Set<String> bucketIds);
+ List<BucketItemEntity> getBucketItems(Set<String> bucketIds);
// --------------------------------------------------------------------------------------------
@@ -119,20 +116,18 @@ public interface MetadataService {
/**
* Retrieves the versioned flow with the given id and DOES NOT populate the versionCount.
*
- * @param bucketIdentifier the identifier of the bucket storing the flow
* @param flowIdentifier the identifier of the flow to retrieve
* @return the versioned flow with the given id, or null if no flow with the given id exists
*/
- FlowEntity getFlowById(String bucketIdentifier, String flowIdentifier);
+ FlowEntity getFlowById(String flowIdentifier);
/**
* Retrieves the versioned flow with the given id and DOES populate the versionCount.
*
- * @param bucketIdentifier the identifier of the bucket storing the flow
* @param flowIdentifier the identifier of the flow to retrieve
* @return the versioned flow with the given id, or null if no flow with the given id exists
*/
- FlowEntity getFlowByIdWithSnapshotCounts(final String bucketIdentifier, final String flowIdentifier);
+ FlowEntity getFlowByIdWithSnapshotCounts(String flowIdentifier);
/**
* Retrieves the versioned flows with the given name. The name comparison must be case-insensitive.
@@ -145,10 +140,10 @@ public interface MetadataService {
/**
* Retrieves the versioned flows for the given bucket.
*
- * @param bucketEntity the bucket entity
+ * @param bucketIdentifier the bucket id to retrieve flows for
* @return the flows in the given bucket
*/
- List<FlowEntity> getFlowsByBucket(BucketEntity bucketEntity);
+ List<FlowEntity> getFlowsByBucket(String bucketIdentifier);
/**
* Updates the given versioned flow, only the name and description should be allowed to be updated.
@@ -179,20 +174,27 @@ public interface MetadataService {
/**
* Retrieves the snapshot for the given flow identifier and snapshot version.
*
- * @param bucketIdentifier the identifier of the bucket storing the flow
* @param flowIdentifier the identifier of the flow the snapshot belongs to
* @param version the version of the snapshot
* @return the versioned flow snapshot for the given flow identifier and version, or null if none exists
*/
- FlowSnapshotEntity getFlowSnapshot(String bucketIdentifier, String flowIdentifier, Integer version);
+ FlowSnapshotEntity getFlowSnapshot(String flowIdentifier, Integer version);
/**
* Retrieves the snapshot with the latest version number for the given flow in the given bucket.
*
- * @param flowEntity the flow to retrieve the latest snapshot for
+ * @param flowIdentifier the id of flow to retrieve the latest snapshot for
* @return the latest snapshot for the flow, or null if one doesn't exist
*/
- FlowSnapshotEntity getLatestSnapshot(FlowEntity flowEntity);
+ FlowSnapshotEntity getLatestSnapshot(String flowIdentifier);
+
+ /**
+ * Retrieves the snapshots for the given flow in the given bucket.
+ *
+ * @param flowIdentifier the id of the flow
+ * @return the snapshots
+ */
+ List<FlowSnapshotEntity> getSnapshots(String flowIdentifier);
/**
* Deletes the flow snapshot.
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
index 7021f38..1717776 100644
--- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
+++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
@@ -47,7 +47,6 @@ import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
@@ -156,10 +155,10 @@ public class RegistryService {
}
}
- public List<Bucket> getBuckets(final QueryParameters queryParameters, final Set<String> bucketIds) {
+ public List<Bucket> getBuckets(final Set<String> bucketIds) {
readLock.lock();
try {
- final List<BucketEntity> buckets = metadataService.getBuckets(queryParameters, bucketIds);
+ final List<BucketEntity> buckets = metadataService.getBuckets(bucketIds);
return buckets.stream().map(b -> DataModelMapper.map(b)).collect(Collectors.toList());
} finally {
readLock.unlock();
@@ -227,7 +226,7 @@ public class RegistryService {
}
// for each flow in the bucket, delete all snapshots from the flow persistence provider
- for (final FlowEntity flowEntity : existingBucket.getFlows()) {
+ for (final FlowEntity flowEntity : metadataService.getFlowsByBucket(existingBucket.getId())) {
flowPersistenceProvider.deleteAllFlowContent(bucketIdentifier, flowEntity.getId());
}
@@ -242,7 +241,7 @@ public class RegistryService {
// ---------------------- BucketItem methods ---------------------------------------------
- public List<BucketItem> getBucketItems(final QueryParameters queryParameters, final String bucketIdentifier) {
+ public List<BucketItem> getBucketItems(final String bucketIdentifier) {
if (bucketIdentifier == null) {
throw new IllegalArgumentException("Bucket identifier cannot be null");
}
@@ -255,14 +254,14 @@ public class RegistryService {
}
final List<BucketItem> bucketItems = new ArrayList<>();
- metadataService.getBucketItems(queryParameters, bucket).stream().forEach(b -> addBucketItem(bucketItems, b));
+ metadataService.getBucketItems(bucket.getId()).stream().forEach(b -> addBucketItem(bucketItems, b));
return bucketItems;
} finally {
readLock.unlock();
}
}
- public List<BucketItem> getBucketItems(final QueryParameters queryParameters, final Set<String> bucketIdentifiers) {
+ public List<BucketItem> getBucketItems(final Set<String> bucketIdentifiers) {
if (bucketIdentifiers == null || bucketIdentifiers.isEmpty()) {
throw new IllegalArgumentException("Bucket identifiers cannot be null or empty");
}
@@ -270,7 +269,7 @@ public class RegistryService {
readLock.lock();
try {
final List<BucketItem> bucketItems = new ArrayList<>();
- metadataService.getBucketItems(queryParameters, bucketIdentifiers).stream().forEach(b -> addBucketItem(bucketItems, b));
+ metadataService.getBucketItems(bucketIdentifiers).stream().forEach(b -> addBucketItem(bucketItems, b));
return bucketItems;
} finally {
readLock.unlock();
@@ -280,7 +279,9 @@ public class RegistryService {
private void addBucketItem(final List<BucketItem> bucketItems, final BucketItemEntity itemEntity) {
if (itemEntity instanceof FlowEntity) {
final FlowEntity flowEntity = (FlowEntity) itemEntity;
- bucketItems.add(DataModelMapper.map(flowEntity));
+
+ // Currently we don't populate the bucket name for items
+ bucketItems.add(DataModelMapper.map(null, flowEntity));
} else {
LOGGER.error("Unknown type of BucketItemEntity: " + itemEntity.getClass().getCanonicalName());
}
@@ -294,7 +295,7 @@ public class RegistryService {
}
if (versionedFlow == null) {
- throw new IllegalArgumentException("VersionedFlow cannot be null");
+ throw new IllegalArgumentException("Versioned flow cannot be null");
}
if (versionedFlow.getBucketIdentifier() != null && !bucketIdentifier.equals(versionedFlow.getBucketIdentifier())) {
@@ -311,7 +312,7 @@ public class RegistryService {
versionedFlow.setCreatedTimestamp(timestamp);
versionedFlow.setModifiedTimestamp(timestamp);
- validate(versionedFlow, "VersionedFlow is not valid");
+ validate(versionedFlow, "Versioned flow is not valid");
writeLock.lock();
try {
@@ -324,16 +325,16 @@ public class RegistryService {
// ensure another flow with the same name doesn't exist
final List<FlowEntity> flowsWithSameName = metadataService.getFlowsByName(versionedFlow.getName());
if (flowsWithSameName != null && flowsWithSameName.size() > 0) {
- throw new IllegalStateException("A VersionedFlow with the same name already exists");
+ throw new IllegalStateException("A versioned flow with the same name already exists");
}
// convert from dto to entity and set the bucket relationship
final FlowEntity flowEntity = DataModelMapper.map(versionedFlow);
- flowEntity.setBucket(existingBucket);
+ flowEntity.setBucketId(existingBucket.getId());
// persist the flow and return the created entity
final FlowEntity createdFlow = metadataService.createFlow(flowEntity);
- return DataModelMapper.map(createdFlow);
+ return DataModelMapper.map(existingBucket, createdFlow);
} finally {
writeLock.unlock();
}
@@ -345,17 +346,27 @@ public class RegistryService {
}
if (StringUtils.isBlank(flowIdentifier)) {
- throw new IllegalArgumentException("Flow identifier cannot be null or blank");
+ throw new IllegalArgumentException("Versioned flow identifier cannot be null or blank");
}
readLock.lock();
try {
- final FlowEntity flowEntity = metadataService.getFlowByIdWithSnapshotCounts(bucketIdentifier, flowIdentifier);
- if (flowEntity == null) {
- throw new ResourceNotFoundException("VersionedFlow does not exist for identifier " + flowIdentifier);
+ // ensure the bucket exists
+ final BucketEntity existingBucket = metadataService.getBucketById(bucketIdentifier);
+ if (existingBucket == null) {
+ throw new ResourceNotFoundException("Bucket does not exist for identifier " + bucketIdentifier);
}
- return DataModelMapper.map(flowEntity);
+ final FlowEntity existingFlow = metadataService.getFlowByIdWithSnapshotCounts(flowIdentifier);
+ if (existingFlow == null) {
+ throw new ResourceNotFoundException("Versioned flow does not exist for identifier " + flowIdentifier);
+ }
+
+ if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
+ throw new IllegalStateException("The requested flow is not located in the given bucket");
+ }
+
+ return DataModelMapper.map(existingBucket, existingFlow);
} finally {
readLock.unlock();
}
@@ -374,8 +385,8 @@ public class RegistryService {
}
// return non-verbose set of flows for the given bucket
- final List<FlowEntity> flows = metadataService.getFlowsByBucket(existingBucket);
- return flows.stream().map(f -> DataModelMapper.map(f)).collect(Collectors.toList());
+ final List<FlowEntity> flows = metadataService.getFlowsByBucket(existingBucket.getId());
+ return flows.stream().map(f -> DataModelMapper.map(existingBucket, f)).collect(Collectors.toList());
} finally {
readLock.unlock();
}
@@ -383,23 +394,32 @@ public class RegistryService {
public VersionedFlow updateFlow(final VersionedFlow versionedFlow) {
if (versionedFlow == null) {
- throw new IllegalArgumentException("VersionedFlow cannot be null");
+ throw new IllegalArgumentException("Versioned flow cannot be null");
}
if (StringUtils.isBlank(versionedFlow.getIdentifier())) {
- throw new IllegalArgumentException("VersionedFlow identifier cannot be null or blank");
+ throw new IllegalArgumentException("Versioned flow identifier cannot be null or blank");
}
if (StringUtils.isBlank(versionedFlow.getBucketIdentifier())) {
- throw new IllegalArgumentException("VersionedFlow bucket identifier cannot be null or blank");
+ throw new IllegalArgumentException("Versioned flow bucket identifier cannot be null or blank");
}
writeLock.lock();
try {
- // ensure a flow with the given id exists
- final FlowEntity existingFlow = metadataService.getFlowById(versionedFlow.getBucketIdentifier(), versionedFlow.getIdentifier());
+ // ensure the bucket exists
+ final BucketEntity existingBucket = metadataService.getBucketById(versionedFlow.getBucketIdentifier());
+ if (existingBucket == null) {
+ throw new ResourceNotFoundException("Bucket does not exist for identifier " + versionedFlow.getBucketIdentifier());
+ }
+
+ final FlowEntity existingFlow = metadataService.getFlowByIdWithSnapshotCounts(versionedFlow.getIdentifier());
if (existingFlow == null) {
- throw new ResourceNotFoundException("VersionedFlow does not exist for identifier " + versionedFlow.getIdentifier());
+ throw new ResourceNotFoundException("Versioned flow does not exist for identifier " + versionedFlow.getIdentifier());
+ }
+
+ if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
+ throw new IllegalStateException("The requested flow is not located in the given bucket");
}
// ensure a different flow with the same name does not exist
@@ -409,7 +429,7 @@ public class RegistryService {
if (flowsWithSameName != null) {
for (final FlowEntity flowWithSameName : flowsWithSameName) {
if(!flowWithSameName.getId().equals(existingFlow.getId())) {
- throw new IllegalStateException("A VersionedFlow with the same name already exists - " + versionedFlow.getName());
+ throw new IllegalStateException("A versioned flow with the same name already exists - " + versionedFlow.getName());
}
}
}
@@ -426,7 +446,7 @@ public class RegistryService {
// perform the actual update
final FlowEntity updatedFlow = metadataService.updateFlow(existingFlow);
- return DataModelMapper.map(updatedFlow);
+ return DataModelMapper.map(existingBucket, updatedFlow);
} finally {
writeLock.unlock();
}
@@ -442,19 +462,29 @@ public class RegistryService {
writeLock.lock();
try {
+ // ensure the bucket exists
+ final BucketEntity existingBucket = metadataService.getBucketById(bucketIdentifier);
+ if (existingBucket == null) {
+ throw new ResourceNotFoundException("Bucket does not exist for identifier " + bucketIdentifier);
+ }
+
// ensure the flow exists
- final FlowEntity existingFlow = metadataService.getFlowById(bucketIdentifier, flowIdentifier);
+ final FlowEntity existingFlow = metadataService.getFlowById(flowIdentifier);
if (existingFlow == null) {
- throw new ResourceNotFoundException("VersionedFlow does not exist for identifier " + flowIdentifier);
+ throw new ResourceNotFoundException("Versioned flow does not exist for identifier " + flowIdentifier);
+ }
+
+ if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
+ throw new IllegalStateException("The requested flow is not located in the given bucket");
}
// delete all snapshots from the flow persistence provider
- flowPersistenceProvider.deleteAllFlowContent(existingFlow.getBucket().getId(), existingFlow.getId());
+ flowPersistenceProvider.deleteAllFlowContent(existingFlow.getBucketId(), existingFlow.getId());
// now delete the flow from the metadata provider
metadataService.deleteFlow(existingFlow);
- return DataModelMapper.map(existingFlow);
+ return DataModelMapper.map(existingBucket, existingFlow);
} finally {
writeLock.unlock();
}
@@ -464,7 +494,7 @@ public class RegistryService {
public VersionedFlowSnapshot createFlowSnapshot(final VersionedFlowSnapshot flowSnapshot) {
if (flowSnapshot == null) {
- throw new IllegalArgumentException("VersionedFlowSnapshot cannot be null");
+ throw new IllegalArgumentException("Versioned flow snapshot cannot be null");
}
// validation will ensure that the metadata and contents are not null
@@ -476,7 +506,7 @@ public class RegistryService {
flowSnapshot.setFlow(null);
flowSnapshot.setBucket(null);
- validate(flowSnapshot, "VersionedFlowSnapshot is not valid");
+ validate(flowSnapshot, "Versioned flow snapshot is not valid");
writeLock.lock();
try {
@@ -489,23 +519,28 @@ public class RegistryService {
}
// ensure the flow exists, we need to use "with counts" here so we can return this is a part of the response
- final FlowEntity existingFlow = metadataService.getFlowByIdWithSnapshotCounts(snapshotMetadata.getBucketIdentifier(), snapshotMetadata.getFlowIdentifier());
+ final FlowEntity existingFlow = metadataService.getFlowByIdWithSnapshotCounts(snapshotMetadata.getFlowIdentifier());
if (existingFlow == null) {
- throw new ResourceNotFoundException("VersionedFlow does not exist for identifier " + snapshotMetadata.getFlowIdentifier());
+ throw new ResourceNotFoundException("Versioned flow does not exist for identifier " + snapshotMetadata.getFlowIdentifier());
+ }
+
+ if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
+ throw new IllegalStateException("The requested flow is not located in the given bucket");
}
// convert the set of FlowSnapshotEntity to set of VersionedFlowSnapshotMetadata
- final SortedSet<VersionedFlowSnapshotMetadata> existingSnapshots = new TreeSet<>();
- if (existingFlow.getSnapshots() != null) {
- existingFlow.getSnapshots().stream().forEach(s -> existingSnapshots.add(DataModelMapper.map(s)));
+ final SortedSet<VersionedFlowSnapshotMetadata> sortedSnapshots = new TreeSet<>();
+ final List<FlowSnapshotEntity> existingFlowSnapshots = metadataService.getSnapshots(existingFlow.getId());
+ if (existingFlowSnapshots != null) {
+ existingFlowSnapshots.stream().forEach(s -> sortedSnapshots.add(DataModelMapper.map(existingBucket, s)));
}
// if we already have snapshots we need to verify the new one has the correct version
- if (existingSnapshots != null && existingSnapshots.size() > 0) {
- final VersionedFlowSnapshotMetadata lastSnapshot = existingSnapshots.last();
+ if (sortedSnapshots != null && sortedSnapshots.size() > 0) {
+ final VersionedFlowSnapshotMetadata lastSnapshot = sortedSnapshots.last();
if (snapshotMetadata.getVersion() <= lastSnapshot.getVersion()) {
- throw new IllegalStateException("A VersionedFlowSnapshot with the same version already exists: " + snapshotMetadata.getVersion());
+ throw new IllegalStateException("A Versioned flow snapshot with the same version already exists: " + snapshotMetadata.getVersion());
}
if (snapshotMetadata.getVersion() > (lastSnapshot.getVersion() + 1)) {
@@ -523,7 +558,7 @@ public class RegistryService {
// save the serialized snapshot to the persistence provider
final Bucket bucket = DataModelMapper.map(existingBucket);
- final VersionedFlow versionedFlow = DataModelMapper.map(existingFlow);
+ final VersionedFlow versionedFlow = DataModelMapper.map(existingBucket, existingFlow);
final FlowSnapshotContext context = new StandardFlowSnapshotContext.Builder(bucket, versionedFlow, snapshotMetadata).build();
flowPersistenceProvider.saveFlowContent(context, out.toByteArray());
@@ -531,7 +566,6 @@ public class RegistryService {
metadataService.createFlowSnapshot(DataModelMapper.map(snapshotMetadata));
// update the modified date on the flow
- existingFlow.setModified(new Date());
metadataService.updateFlow(existingFlow);
flowSnapshot.setBucket(bucket);
@@ -557,16 +591,25 @@ public class RegistryService {
readLock.lock();
try {
+ final BucketEntity existingBucket = metadataService.getBucketById(bucketIdentifier);
+ if (existingBucket == null) {
+ throw new ResourceNotFoundException("Bucket does not exist for identifier " + bucketIdentifier);
+ }
+
// we need to populate the version count here so we have to do this retrieval instead of snapshotEntity.getFlow()
- final FlowEntity flowEntityWithCount = metadataService.getFlowByIdWithSnapshotCounts(bucketIdentifier, flowIdentifier);
+ final FlowEntity flowEntityWithCount = metadataService.getFlowByIdWithSnapshotCounts(flowIdentifier);
if (flowEntityWithCount == null) {
- throw new ResourceNotFoundException("VersionedFlow does not exist with identifier " + flowIdentifier);
+ throw new ResourceNotFoundException("Versioned flow does not exist with identifier " + flowIdentifier);
+ }
+
+ if (!existingBucket.getId().equals(flowEntityWithCount.getBucketId())) {
+ throw new IllegalStateException("The requested flow is not located in the given bucket");
}
// ensure the snapshot exists
- final FlowSnapshotEntity snapshotEntity = metadataService.getFlowSnapshot(bucketIdentifier, flowIdentifier, version);
+ final FlowSnapshotEntity snapshotEntity = metadataService.getFlowSnapshot(flowIdentifier, version);
if (snapshotEntity == null) {
- throw new ResourceNotFoundException("VersionedFlowSnapshot does not exist for flow " + flowIdentifier + " and version " + version);
+ throw new ResourceNotFoundException("Versioned flow snapshot does not exist for flow " + flowIdentifier + " and version " + version);
}
// get the serialized bytes of the snapshot
@@ -582,9 +625,9 @@ public class RegistryService {
final VersionedProcessGroup flowContents = processGroupSerializer.deserialize(input);
// map entities to data model
- final Bucket bucket = DataModelMapper.map(flowEntityWithCount.getBucket());
- final VersionedFlow versionedFlow = DataModelMapper.map(flowEntityWithCount);
- final VersionedFlowSnapshotMetadata snapshotMetadata = DataModelMapper.map(snapshotEntity);
+ final Bucket bucket = DataModelMapper.map(existingBucket);
+ final VersionedFlow versionedFlow = DataModelMapper.map(existingBucket, flowEntityWithCount);
+ final VersionedFlowSnapshotMetadata snapshotMetadata = DataModelMapper.map(existingBucket, snapshotEntity);
// create the snapshot to return
final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot();
@@ -623,18 +666,23 @@ public class RegistryService {
}
// ensure the flow exists
- final FlowEntity existingFlow = metadataService.getFlowById(bucketIdentifier, flowIdentifier);
+ final FlowEntity existingFlow = metadataService.getFlowById(flowIdentifier);
if (existingFlow == null) {
- throw new ResourceNotFoundException("VersionedFlow does not exist for identifier " + flowIdentifier);
+ throw new ResourceNotFoundException("Versioned flow does not exist for identifier " + flowIdentifier);
+ }
+
+ if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
+ throw new IllegalStateException("The requested flow is not located in the given bucket");
}
// convert the set of FlowSnapshotEntity to set of VersionedFlowSnapshotMetadata, ordered by version descending
- final SortedSet<VersionedFlowSnapshotMetadata> existingSnapshots = new TreeSet<>(Collections.reverseOrder());
- if (existingFlow.getSnapshots() != null) {
- existingFlow.getSnapshots().stream().forEach(s -> existingSnapshots.add(DataModelMapper.map(s)));
+ final SortedSet<VersionedFlowSnapshotMetadata> sortedSnapshots = new TreeSet<>(Collections.reverseOrder());
+ final List<FlowSnapshotEntity> existingFlowSnapshots = metadataService.getSnapshots(existingFlow.getId());
+ if (existingFlowSnapshots != null) {
+ existingFlowSnapshots.stream().forEach(s -> sortedSnapshots.add(DataModelMapper.map(existingBucket, s)));
}
- return existingSnapshots;
+ return sortedSnapshots;
} finally {
readLock.unlock();
@@ -659,14 +707,18 @@ public class RegistryService {
}
// ensure the flow exists
- final FlowEntity existingFlow = metadataService.getFlowById(bucketIdentifier, flowIdentifier);
+ final FlowEntity existingFlow = metadataService.getFlowById(flowIdentifier);
if (existingFlow == null) {
- throw new ResourceNotFoundException("VersionedFlow does not exist for identifier " + flowIdentifier);
+ throw new ResourceNotFoundException("Versioned flow does not exist for identifier " + flowIdentifier);
+ }
+
+ if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
+ throw new IllegalStateException("The requested flow is not located in the given bucket");
}
// get latest snapshot for the flow
- final FlowSnapshotEntity latestSnapshot = metadataService.getLatestSnapshot(existingFlow);
- return DataModelMapper.map(latestSnapshot);
+ final FlowSnapshotEntity latestSnapshot = metadataService.getLatestSnapshot(existingFlow.getId());
+ return DataModelMapper.map(existingBucket, latestSnapshot);
} finally {
readLock.unlock();
}
@@ -687,10 +739,26 @@ public class RegistryService {
writeLock.lock();
try {
+ // ensure the bucket exists
+ final BucketEntity existingBucket = metadataService.getBucketById(bucketIdentifier);
+ if (existingBucket == null) {
+ throw new ResourceNotFoundException("Bucket does not exist for identifier " + bucketIdentifier);
+ }
+
+ // ensure the flow exists
+ final FlowEntity existingFlow = metadataService.getFlowById(flowIdentifier);
+ if (existingFlow == null) {
+ throw new ResourceNotFoundException("Versioned flow does not exist for identifier " + flowIdentifier);
+ }
+
+ if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
+ throw new IllegalStateException("The requested flow is not located in the given bucket");
+ }
+
// ensure the snapshot exists
- final FlowSnapshotEntity snapshotEntity = metadataService.getFlowSnapshot(bucketIdentifier, flowIdentifier, version);
+ final FlowSnapshotEntity snapshotEntity = metadataService.getFlowSnapshot(flowIdentifier, version);
if (snapshotEntity == null) {
- throw new ResourceNotFoundException("VersionedFlowSnapshot does not exist for flow "
+ throw new ResourceNotFoundException("Versioned flow snapshot does not exist for flow "
+ flowIdentifier + " and version " + version);
}
@@ -699,7 +767,7 @@ public class RegistryService {
// delete the snapshot itself
metadataService.deleteFlowSnapshot(snapshotEntity);
- return DataModelMapper.map(snapshotEntity);
+ return DataModelMapper.map(existingBucket, snapshotEntity);
} finally {
writeLock.unlock();
}
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/test/groovy/org/apache/nifi/registry/db/DatabaseKeyServiceSpec.groovy
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/groovy/org/apache/nifi/registry/db/DatabaseKeyServiceSpec.groovy b/nifi-registry-framework/src/test/groovy/org/apache/nifi/registry/db/DatabaseKeyServiceSpec.groovy
deleted file mode 100644
index 3695ead..0000000
--- a/nifi-registry-framework/src/test/groovy/org/apache/nifi/registry/db/DatabaseKeyServiceSpec.groovy
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.registry.db
-
-import org.apache.nifi.registry.db.entity.KeyEntity
-import org.apache.nifi.registry.db.repository.KeyRepository
-import org.apache.nifi.registry.security.key.Key
-import spock.lang.Specification
-
-class DatabaseKeyServiceSpec extends Specification {
-
- def keyRepository = Mock(KeyRepository)
-
- DatabaseKeyService keyService
-
- def setup() {
- keyService = new DatabaseKeyService(keyRepository)
- }
-
- def "get key"() {
-
- given: "a record exists for id=key1"
- keyRepository.findById("key1") >> Optional.of(new KeyEntity([id: "key1", tenantIdentity: "user1", keyValue: "keyValue1"]))
- keyRepository.findById("key2") >> Optional.empty()
-
- when: "getKey is called with an existing id"
- Key existingKey = keyService.getKey("key1")
-
- then: "the existing key is returned as model object"
- with(existingKey) {
- id == "key1"
- identity == "user1"
- key == "keyValue1"
- }
-
- when: "getKey is called for a nonexistent id"
- Key nonexistentKey = keyService.getKey("key2")
-
- then: "null is returned"
- nonexistentKey == null
-
- }
-
- def "get or create key"() {
-
- given: "a record exists for identity=user1"
- keyRepository.findOneByTenantIdentity("user1") >> new KeyEntity([id: "key1", tenantIdentity: "user1", keyValue: "keyValue1"])
- keyRepository.findOneByTenantIdentity("user2") >> null
- keyRepository.save(_ as KeyEntity) >> { KeyEntity ke -> new KeyEntity([id: ke.id, tenantIdentity: ke.tenantIdentity, keyValue: ke.keyValue])}
-
- when: "getOrCreateKey is called with an existing identity"
- Key existingKey = keyService.getOrCreateKey("user1")
-
- then: "the existing key is returned as model object"
- with(existingKey) {
- id == "key1"
- identity == "user1"
- key == "keyValue1"
- }
-
- when: "getOrCreateKey is called for a nonexistent identity"
- Key newKey = keyService.getOrCreateKey("user2")
-
- then: "a new key is returned"
- with(newKey) {
- id != null
- identity == "user2"
- key != null
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/DatabaseBaseTest.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/DatabaseBaseTest.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/DatabaseBaseTest.java
index 6376918..02b04c0 100644
--- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/DatabaseBaseTest.java
+++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/DatabaseBaseTest.java
@@ -16,7 +16,6 @@
*/
package org.apache.nifi.registry.db;
-import org.apache.nifi.registry.db.DatabaseTestApplication;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestExecutionListeners;
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/TestDatabaseKeyService.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/TestDatabaseKeyService.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/TestDatabaseKeyService.java
new file mode 100644
index 0000000..d0ab56a
--- /dev/null
+++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/TestDatabaseKeyService.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.registry.db;
+
+import org.apache.nifi.registry.security.key.Key;
+import org.apache.nifi.registry.security.key.KeyService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class TestDatabaseKeyService extends DatabaseBaseTest {
+
+ @Autowired
+ private KeyService keyService;
+
+ @Test
+ public void testGetKeyByIdWhenExists() {
+ final Key existingKey = keyService.getKey("1");
+ assertNotNull(existingKey);
+ assertEquals("1", existingKey.getId());
+ assertEquals("unit_test_tenant_identity", existingKey.getIdentity());
+ assertEquals("0123456789abcdef", existingKey.getKey());
+ }
+
+ @Test
+ public void testGetKeyByIdWhenDoesNotExist() {
+ final Key existingKey = keyService.getKey("2");
+ assertNull(existingKey);
+ }
+
+ @Test
+ public void testGetOrCreateKeyWhenExists() {
+ final Key existingKey = keyService.getOrCreateKey("unit_test_tenant_identity");
+ assertNotNull(existingKey);
+ assertEquals("1", existingKey.getId());
+ assertEquals("unit_test_tenant_identity", existingKey.getIdentity());
+ assertEquals("0123456789abcdef", existingKey.getKey());
+ }
+
+ @Test
+ public void testGetOrCreateKeyWhenDoesNotExist() {
+ final Key createdKey = keyService.getOrCreateKey("does-not-exist");
+ assertNotNull(createdKey);
+ assertNotNull(createdKey.getId());
+ assertEquals("does-not-exist", createdKey.getIdentity());
+ assertNotNull(createdKey.getKey());
+ }
+
+ @Test
+ public void testDeleteKeyWhenExists() {
+ final Key existingKey = keyService.getKey("1");
+ assertNotNull(existingKey);
+
+ keyService.deleteKey(existingKey.getIdentity());
+
+ final Key deletedKey = keyService.getKey("1");
+ assertNull(deletedKey);
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/TestDatabaseMetadataService.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/TestDatabaseMetadataService.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/TestDatabaseMetadataService.java
index b07e4ed..dfdeef4 100644
--- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/TestDatabaseMetadataService.java
+++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/TestDatabaseMetadataService.java
@@ -21,22 +21,117 @@ import org.apache.nifi.registry.db.entity.BucketItemEntity;
import org.apache.nifi.registry.db.entity.BucketItemEntityType;
import org.apache.nifi.registry.db.entity.FlowEntity;
import org.apache.nifi.registry.db.entity.FlowSnapshotEntity;
-import org.apache.nifi.registry.service.QueryParameters;
+import org.apache.nifi.registry.service.MetadataService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Date;
import java.util.HashSet;
import java.util.List;
+import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class TestDatabaseMetadataService extends DatabaseBaseTest {
@Autowired
- private DatabaseMetadataService metadataService;
+ private MetadataService metadataService;
+
+ //----------------- Buckets ---------------------------------
+
+ @Test
+ public void testCreateAndGetBucket() {
+ final BucketEntity b = new BucketEntity();
+ b.setId("testBucketId");
+ b.setName("testBucketName");
+ b.setDescription("testBucketDesc");
+ b.setCreated(new Date());
+
+ metadataService.createBucket(b);
+
+ final BucketEntity createdBucket = metadataService.getBucketById(b.getId());
+ assertNotNull(createdBucket);
+ assertEquals(b.getId(), createdBucket.getId());
+ assertEquals(b.getName(), createdBucket.getName());
+ assertEquals(b.getDescription(), createdBucket.getDescription());
+ assertEquals(b.getCreated(), createdBucket.getCreated());
+ }
+
+ @Test
+ public void testGetBucketDoesNotExist() {
+ final BucketEntity bucket = metadataService.getBucketById("does-not-exist");
+ assertNull(bucket);
+ }
+
+ @Test
+ public void testGetBucketsByName() {
+ final List<BucketEntity> buckets = metadataService.getBucketsByName("Bucket 1");
+ assertNotNull(buckets);
+ assertEquals(1, buckets.size());
+ assertEquals("Bucket 1", buckets.get(0).getName());
+ }
+
+ @Test
+ public void testGetBucketsByNameNoneFound() {
+ final List<BucketEntity> buckets = metadataService.getBucketsByName("Bucket XYZ");
+ assertNotNull(buckets);
+ assertEquals(0, buckets.size());
+ }
+
+ @Test
+ public void testUpdateBucket() {
+ final BucketEntity bucket = metadataService.getBucketById("1");
+ assertNotNull(bucket);
+
+ final String updatedName = bucket.getName() + " UPDATED";
+ final String updatedDesc = bucket.getDescription() + "DESC";
+
+ bucket.setName(updatedName);
+ bucket.setDescription(updatedDesc);
+
+ metadataService.updateBucket(bucket);
+
+ final BucketEntity updatedBucket = metadataService.getBucketById(bucket.getId());
+ assertNotNull(updatedName);
+ assertEquals(updatedName, updatedBucket.getName());
+ assertEquals(updatedDesc, updatedBucket.getDescription());
+ }
+
+ @Test
+ public void testDeleteBucketNoChildren() {
+ final BucketEntity bucket = metadataService.getBucketById("6");
+ assertNotNull(bucket);
+
+ metadataService.deleteBucket(bucket);
+
+ final BucketEntity deletedBucket = metadataService.getBucketById("6");
+ assertNull(deletedBucket);
+ }
+
+ @Test
+ public void testDeleteBucketWithChildren() {
+ final BucketEntity bucket = metadataService.getBucketById("1");
+ assertNotNull(bucket);
+
+ metadataService.deleteBucket(bucket);
+
+ final BucketEntity deletedBucket = metadataService.getBucketById("1");
+ assertNull(deletedBucket);
+ }
+
+ @Test
+ public void testGetBucketsForIds() {
+ final List<BucketEntity> buckets = metadataService.getBuckets(new HashSet<>(Arrays.asList("1", "2")));
+ assertNotNull(buckets);
+ assertEquals(2, buckets.size());
+ assertEquals("1", buckets.get(0).getId());
+ assertEquals("2", buckets.get(1).getId());
+ }
@Test
public void testGetAllBuckets() {
@@ -45,16 +140,28 @@ public class TestDatabaseMetadataService extends DatabaseBaseTest {
assertEquals(6, buckets.size());
}
+ //----------------- BucketItems ---------------------------------
+
@Test
- public void testGetBuckets() {
- final List<BucketEntity> buckets = metadataService.getBuckets(QueryParameters.EMPTY_PARAMETERS, new HashSet<>(Arrays.asList("1", "2")));
- assertNotNull(buckets);
- assertEquals(2, buckets.size());
+ public void testGetBucketItemsForBucket() {
+ final BucketEntity bucket = metadataService.getBucketById("1");
+ assertNotNull(bucket);
+
+ final List<BucketItemEntity> items = metadataService.getBucketItems(bucket.getId());
+ assertNotNull(items);
+ assertEquals(2, items.size());
+ }
+
+ @Test
+ public void testGetBucketItemsForBuckets() {
+ final List<BucketItemEntity> items = metadataService.getBucketItems(new HashSet<>(Arrays.asList("1", "2")));
+ assertNotNull(items);
+ assertEquals(3, items.size());
}
@Test
public void testGetItemsWithCounts() {
- final List<BucketItemEntity> items = metadataService.getBucketItems(null, new HashSet<>(Arrays.asList("1", "2")));
+ final List<BucketItemEntity> items = metadataService.getBucketItems(new HashSet<>(Arrays.asList("1", "2")));
assertNotNull(items);
// 3 items across all buckets
@@ -70,7 +177,7 @@ public class TestDatabaseMetadataService extends DatabaseBaseTest {
@Test
public void testGetItemsWithCountsFilteredByBuckets() {
- final List<BucketItemEntity> items = metadataService.getBucketItems(null, Collections.singleton("1"));
+ final List<BucketItemEntity> items = metadataService.getBucketItems(Collections.singleton("1"));
assertNotNull(items);
// only 2 items in bucket 1
@@ -84,10 +191,59 @@ public class TestDatabaseMetadataService extends DatabaseBaseTest {
assertEquals(3, flowEntity.getSnapshotCount());
}
+ //----------------- Flows ---------------------------------
+
+ @Test
+ public void testGetFlowByIdWhenExists() {
+ final FlowEntity flow = metadataService.getFlowById("1");
+ assertNotNull(flow);
+ assertEquals("1", flow.getId());
+ assertEquals("1", flow.getBucketId());
+ }
+
+ @Test
+ public void testGetFlowByIdWhenDoesNotExist() {
+ final FlowEntity flow = metadataService.getFlowById("does-not-exist");
+ assertNull(flow);
+ }
+
+ @Test
+ public void testCreateFlow() {
+ final String bucketId = "1";
+
+ final FlowEntity flow = new FlowEntity();
+ flow.setId(UUID.randomUUID().toString());
+ flow.setBucketId(bucketId);
+ flow.setName("Test Flow 1");
+ flow.setDescription("Description for Test Flow 1");
+ flow.setCreated(new Date());
+ flow.setModified(new Date());
+ flow.setType(BucketItemEntityType.FLOW);
+
+ metadataService.createFlow(flow);
+
+ final FlowEntity createdFlow = metadataService.getFlowById(flow.getId());
+ assertNotNull(flow);
+ assertEquals(flow.getId(), createdFlow.getId());
+ assertEquals(flow.getBucketId(), createdFlow.getBucketId());
+ assertEquals(flow.getName(), createdFlow.getName());
+ assertEquals(flow.getDescription(), createdFlow.getDescription());
+ assertEquals(flow.getCreated(), createdFlow.getCreated());
+ assertEquals(flow.getModified(), createdFlow.getModified());
+ assertEquals(flow.getType(), createdFlow.getType());
+ }
+
+ @Test
+ public void testGetFlowByIdWithSnapshotCount() {
+ final FlowEntity flowEntity = metadataService.getFlowByIdWithSnapshotCounts("1");
+ assertNotNull(flowEntity);
+ assertEquals(3, flowEntity.getSnapshotCount());
+ }
+
@Test
- public void testGetFlowsByBucketWithCounts() {
+ public void testGetFlowsByBucket() {
final BucketEntity bucketEntity = metadataService.getBucketById("1");
- final List<FlowEntity> flows = metadataService.getFlowsByBucket(bucketEntity);
+ final List<FlowEntity> flows = metadataService.getFlowsByBucket(bucketEntity.getId());
assertEquals(2, flows.size());
final FlowEntity flowEntity = flows.stream().filter(f -> f.getId().equals("1")).findFirst().orElse(null);
@@ -96,20 +252,117 @@ public class TestDatabaseMetadataService extends DatabaseBaseTest {
}
@Test
- public void testGetFlowByIdWithVersionCount() {
- final FlowEntity flowEntity = metadataService.getFlowByIdWithSnapshotCounts("1", "1");
- assertNotNull(flowEntity);
- assertEquals(3, flowEntity.getSnapshotCount());
+ public void testGetFlowsByName() {
+ final List<FlowEntity> flows = metadataService.getFlowsByName("Flow 1");
+ assertNotNull(flows);
+ assertEquals(1, flows.size());
+ assertEquals("Flow 1", flows.get(0).getName());
+ }
+
+ @Test
+ public void testUpdateFlow() {
+ final FlowEntity flow = metadataService.getFlowById("1");
+ assertNotNull(flow);
+
+ final Date originalModified = flow.getModified();
+
+ flow.setName(flow.getName() + " UPDATED");
+ flow.setDescription(flow.getDescription() + " UPDATED");
+
+ metadataService.updateFlow(flow);
+
+ final FlowEntity updatedFlow = metadataService.getFlowById( "1");
+ assertNotNull(flow);
+ assertEquals(flow.getName(), updatedFlow.getName());
+ assertEquals(flow.getDescription(), updatedFlow.getDescription());
+ assertEquals(flow.getModified().getTime(), updatedFlow.getModified().getTime());
+ assertTrue(updatedFlow.getModified().getTime() > originalModified.getTime());
+ }
+
+ @Test
+ public void testDeleteFlowWithSnapshots() {
+ final FlowEntity flow = metadataService.getFlowById( "1");
+ assertNotNull(flow);
+
+ metadataService.deleteFlow(flow);
+
+ final FlowEntity deletedFlow = metadataService.getFlowById("1");
+ assertNull(deletedFlow);
+ }
+
+ //----------------- FlowSnapshots ---------------------------------
+
+ @Test
+ public void testGetFlowSnapshot() {
+ final FlowSnapshotEntity entity = metadataService.getFlowSnapshot( "1", 1);
+ assertNotNull(entity);
+ assertEquals("1", entity.getFlowId());
+ assertEquals(1, entity.getVersion().intValue());
+ }
+
+ @Test
+ public void testGetFlowSnapshotDoesNotExist() {
+ final FlowSnapshotEntity entity = metadataService.getFlowSnapshot( "DOES-NOT-EXIST", 1);
+ assertNull(entity);
+ }
+
+ @Test
+ public void testCreateFlowSnapshot() {
+ final FlowSnapshotEntity flowSnapshot = new FlowSnapshotEntity();
+ flowSnapshot.setFlowId("1");
+ flowSnapshot.setVersion(4);
+ flowSnapshot.setCreated(new Date());
+ flowSnapshot.setCreatedBy("test-user");
+ flowSnapshot.setComments("Comments");
+
+ metadataService.createFlowSnapshot(flowSnapshot);
+
+ final FlowSnapshotEntity createdFlowSnapshot = metadataService.getFlowSnapshot(flowSnapshot.getFlowId(), flowSnapshot.getVersion());
+ assertNotNull(createdFlowSnapshot);
+ assertEquals(flowSnapshot.getFlowId(), createdFlowSnapshot.getFlowId());
+ assertEquals(flowSnapshot.getVersion(), createdFlowSnapshot.getVersion());
+ assertEquals(flowSnapshot.getComments(), createdFlowSnapshot.getComments());
+ assertEquals(flowSnapshot.getCreated(), createdFlowSnapshot.getCreated());
+ assertEquals(flowSnapshot.getCreatedBy(), createdFlowSnapshot.getCreatedBy());
}
@Test
public void testGetLatestSnapshot() {
- final FlowEntity flowEntity = metadataService.getFlowById("1", "1");
- assertNotNull(flowEntity);
+ final FlowSnapshotEntity latest = metadataService.getLatestSnapshot("1");
+ assertNotNull(latest);
+ assertEquals("1", latest.getFlowId());
+ assertEquals(3, latest.getVersion().intValue());
+ }
+
+ @Test
+ public void testGetLatestSnapshotDoesNotExist() {
+ final FlowSnapshotEntity latest = metadataService.getLatestSnapshot("DOES-NOT-EXIST");
+ assertNull(latest);
+ }
+
+ @Test
+ public void testGetFlowSnapshots() {
+ final List<FlowSnapshotEntity> flowSnapshots = metadataService.getSnapshots( "1");
+ assertNotNull(flowSnapshots);
+ assertEquals(3, flowSnapshots.size());
+ }
+
+ @Test
+ public void testGetFlowSnapshotsNoneFound() {
+ final List<FlowSnapshotEntity> flowSnapshots = metadataService.getSnapshots( "2");
+ assertNotNull(flowSnapshots);
+ assertEquals(0, flowSnapshots.size());
+ }
+
+ @Test
+ public void testDeleteFlowSnapshot() {
+ final FlowSnapshotEntity entity = metadataService.getFlowSnapshot( "1", 1);
+ assertNotNull(entity);
+
+ metadataService.deleteFlowSnapshot(entity);
- final FlowSnapshotEntity flowSnapshotEntity = metadataService.getLatestSnapshot(flowEntity);
- assertNotNull(flowSnapshotEntity);
- assertEquals(3, flowSnapshotEntity.getId().getVersion().intValue());
+ final FlowSnapshotEntity deletedEntity = metadataService.getFlowSnapshot( "1", 1);
+ assertNull(deletedEntity);
}
}
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketItemRepository.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketItemRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketItemRepository.java
deleted file mode 100644
index c024d76..0000000
--- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketItemRepository.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.registry.db.repository;
-
-import org.apache.nifi.registry.db.DatabaseBaseTest;
-import org.apache.nifi.registry.db.entity.BucketEntity;
-import org.apache.nifi.registry.db.entity.BucketItemEntity;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-public class TestBucketItemRepository extends DatabaseBaseTest {
-
- @Autowired
- private BucketRepository bucketRepository;
-
- @Autowired
- private BucketItemRepository bucketItemRepository;
-
- @Test
- public void testFindByBucket() {
- final BucketEntity bucket = bucketRepository.findById("1").orElse(null);
- assertNotNull(bucket);
-
- final List<BucketItemEntity> entities = bucketItemRepository.findByBucket(bucket);
- assertNotNull(entities);
- assertEquals(2, entities.size());
- }
-
- @Test
- public void testFindByBucketPageable() {
- final BucketEntity bucket = bucketRepository.findById("1").orElse(null);
- assertNotNull(bucket);
-
- final List<BucketItemEntity> entities = bucketItemRepository.findByBucket(bucket, PageRequest.of(0, 2, new Sort(Sort.Direction.ASC, "id")));
- assertNotNull(entities);
- assertEquals(2, entities.size());
- assertEquals("1", entities.get(0).getId());
- assertEquals("2", entities.get(1).getId());
- }
-
- @Test
- public void testFindByBucketSort() {
- final BucketEntity bucket = bucketRepository.findById("1").orElse(null);
- assertNotNull(bucket);
-
- final List<BucketItemEntity> entities = bucketItemRepository.findByBucket(bucket, new Sort(Sort.Direction.DESC, "id"));
- assertNotNull(entities);
- assertEquals(2, entities.size());
- assertEquals("2", entities.get(0).getId());
- assertEquals("1", entities.get(1).getId());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketRepository.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketRepository.java
deleted file mode 100644
index 7c1d74f..0000000
--- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestBucketRepository.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.registry.db.repository;
-
-import org.apache.nifi.registry.db.DatabaseBaseTest;
-import org.apache.nifi.registry.db.entity.BucketEntity;
-import org.apache.nifi.registry.db.entity.BucketItemEntity;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-public class TestBucketRepository extends DatabaseBaseTest {
-
- @Autowired
- private BucketRepository bucketRepository;
-
- @Test
- public void testCreate() {
- final BucketEntity bucket = new BucketEntity();
- bucket.setId(UUID.randomUUID().toString());
- bucket.setName("Some new bucket");
- bucket.setDescription("This is some new bucket");
- bucket.setCreated(new Date());
-
- final BucketEntity createdBucket = bucketRepository.save(bucket);
- assertNotNull(createdBucket);
- assertEquals(bucket.getId(), createdBucket.getId());
- assertEquals(bucket.getName(), createdBucket.getName());
- assertEquals(bucket.getDescription(), createdBucket.getDescription());
- assertEquals(bucket.getCreated(), createdBucket.getCreated());
- }
-
- @Test
- public void testUpdate() {
- final String id = "1";
-
- final BucketEntity existingBucket = bucketRepository.findById(id).orElse(null);
- assertNotNull(existingBucket);
-
- final String updatedDescription = existingBucket.getDescription() + " UPDATED";
- existingBucket.setDescription(updatedDescription);
-
- bucketRepository.save(existingBucket);
-
- final BucketEntity updatedBucket = bucketRepository.findById(id).orElse(null);
- assertNotNull(updatedBucket);
- assertEquals(updatedDescription, updatedBucket.getDescription());
-
- // create date should not have changed
- assertEquals(existingBucket.getCreated(), updatedBucket.getCreated());
- }
-
- @Test
- public void testDelete() {
- final String id = "6";
-
- final BucketEntity existingBucket = bucketRepository.findById(id).orElse(null);
- assertNotNull(existingBucket);
-
- bucketRepository.delete(existingBucket);
-
- final BucketEntity updatedBucket = bucketRepository.findById(id).orElse(null);
- assertNull(updatedBucket);
- }
-
- @Test
- public void testOneToManyWithBucketItems() {
- final String id = "1";
-
- final BucketEntity existingBucket = bucketRepository.findById(id).orElse(null);
- assertNotNull(existingBucket);
-
- final Set<BucketItemEntity> items = existingBucket.getItems();
- assertNotNull(items);
- assertEquals(2, items.size());
- }
-
- @Test
- public void testFindByNameCaseInsensitive() {
- final String bucketName = "bUcKEt 1";
-
- final List<BucketEntity> buckets = bucketRepository.findByNameIgnoreCase(bucketName);
- assertNotNull(buckets);
- assertEquals(1, buckets.size());
-
- final BucketEntity bucket = buckets.get(0);
- assertEquals(bucketName.toLowerCase(), bucket.getName().toLowerCase());
- }
-
- @Test
- public void testFindAllWithPaging() {
- final Sort sort = new Sort(Sort.Direction.ASC, "id");
-
- int pageIndex = 0;
- int pageSize = 2;
-
- // query for first page
- Pageable pageable = PageRequest.of(pageIndex, pageSize, sort);
-
- Page<BucketEntity> page = bucketRepository.findAll(pageable);
- assertNotNull(page);
- assertEquals(6, page.getTotalElements());
- assertEquals(3, page.getTotalPages());
-
- Iterable<BucketEntity> buckets = page.getContent();
- assertNotNull(buckets);
-
- List<String> ids = getIds(buckets);
- assertEquals(2, ids.size());
- assertEquals("1", ids.get(0));
- assertEquals("2", ids.get(1));
-
- // query for second page
- pageIndex++;
- pageable = PageRequest.of(pageIndex, pageSize, sort);
- buckets = bucketRepository.findAll(pageable);
- assertNotNull(buckets);
-
- ids = getIds(buckets);
- assertEquals(2, ids.size());
- assertEquals("3", ids.get(0));
- assertEquals("4", ids.get(1));
-
- // query for third page
- pageIndex++;
- pageable = PageRequest.of(pageIndex, pageSize, sort);
- buckets = bucketRepository.findAll(pageable);
- assertNotNull(buckets);
-
- ids = getIds(buckets);
- assertEquals(2, ids.size());
- assertEquals("5", ids.get(0));
- assertEquals("6", ids.get(1));
-
- // query for fourth page
- pageIndex++;
- pageable = PageRequest.of(pageIndex, pageSize, sort);
- buckets = bucketRepository.findAll(pageable);
- assertNotNull(buckets);
-
- ids = getIds(buckets);
- assertEquals(0, ids.size());
- }
-
- private List<String> getIds(final Iterable<BucketEntity> buckets) {
- List<String> ids = new ArrayList<>();
- buckets.forEach(b -> ids.add(b.getId()));
- return ids;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowRepository.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowRepository.java
deleted file mode 100644
index 5646966..0000000
--- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowRepository.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.registry.db.repository;
-
-import org.apache.nifi.registry.db.DatabaseBaseTest;
-import org.apache.nifi.registry.db.entity.BucketEntity;
-import org.apache.nifi.registry.db.entity.BucketItemEntityType;
-import org.apache.nifi.registry.db.entity.FlowEntity;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-public class TestFlowRepository extends DatabaseBaseTest {
-
- @Autowired
- private BucketRepository bucketRepository;
-
- @Autowired
- private FlowRepository flowRepository;
-
-
- @Test
- public void testCreateFlow() {
- final String bucketId = "1";
-
- final BucketEntity existingBucket = bucketRepository.findById(bucketId).orElse(null);
- assertNotNull(existingBucket);
- assertNotNull(existingBucket.getItems());
- assertEquals(2, existingBucket.getItems().size());
-
- // created, and modified should get set automatically
- final FlowEntity flow = new FlowEntity();
- flow.setId(UUID.randomUUID().toString());
- flow.setName("Flow 4");
- flow.setDescription("This is flow 4");
- flow.setBucket(existingBucket);
- flow.setCreated(new Date());
- flow.setModified(new Date());
-
- final FlowEntity createdFlow = flowRepository.save(flow);
- assertEquals(flow.getId(), createdFlow.getId());
- assertEquals(flow.getName(), createdFlow.getName());
- assertEquals(flow.getDescription(), createdFlow.getDescription());
- assertEquals(flow.getCreated(), createdFlow.getCreated());
- assertEquals(flow.getModified(), createdFlow.getModified());
- assertEquals(BucketItemEntityType.FLOW, flow.getType());
- }
-
- @Test
- public void testUpdateFlow() {
- final String flowId = "1";
-
- final FlowEntity flow = flowRepository.findById(flowId).orElse(null);
- assertNotNull(flow);
- assertEquals(flowId, flow.getId());
-
- flow.setName(flow.getName() + " UPDATED");
- flow.setDescription(flow.getDescription() + " UPDATED");
-
- flowRepository.save(flow);
-
- final FlowEntity updatedFlow = flowRepository.findById(flowId).orElse(null);
- assertEquals(flow.getName(), updatedFlow.getName());
- assertEquals(flow.getDescription(), updatedFlow.getDescription());
- assertEquals(flow.getCreated(), updatedFlow.getCreated());
- assertEquals(flow.getModified(), updatedFlow.getModified());
- assertEquals(BucketItemEntityType.FLOW, updatedFlow.getType());
- }
-
- @Test
- public void testDeleteFlow() {
- final String flowId = "1";
-
- final FlowEntity flow = flowRepository.findById(flowId).orElse(null);
- assertNotNull(flow);
-
- flowRepository.delete(flow);
-
- final FlowEntity deletedFlow = flowRepository.findById(flowId).orElse(null);
- assertNull(deletedFlow);
- }
-
- @Test
- public void testOneToManyWithFlowSnapshots() {
- final String flowId = "1";
-
- final FlowEntity flow = flowRepository.findById(flowId).orElse(null);
- assertNotNull(flow);
- assertNotNull(flow.getSnapshots());
- assertEquals(3, flow.getSnapshots().size());
- }
-
- @Test
- public void testFindFlowByNameCaseInsensitive() {
- final String flowName = "fLoW 1";
-
- final List<FlowEntity> flows = flowRepository.findByNameIgnoreCase(flowName);
- assertNotNull(flows);
- assertEquals(1, flows.size());
-
- final FlowEntity flow = flows.get(0);
- assertEquals(flowName.toLowerCase(), flow.getName().toLowerCase());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java
deleted file mode 100644
index c6bd827..0000000
--- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.registry.db.repository;
-
-import org.apache.nifi.registry.db.DatabaseBaseTest;
-import org.apache.nifi.registry.db.entity.BucketEntity;
-import org.apache.nifi.registry.db.entity.FlowEntity;
-import org.apache.nifi.registry.db.entity.FlowSnapshotCount;
-import org.apache.nifi.registry.db.entity.FlowSnapshotEntity;
-import org.apache.nifi.registry.db.entity.FlowSnapshotEntityKey;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.Date;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-public class TestFlowSnapshotRepository extends DatabaseBaseTest {
-
- @Autowired
- private BucketRepository bucketRepository;
-
- @Autowired
- private FlowRepository flowRepository;
-
- @Autowired
- private FlowSnapshotRepository flowSnapshotRepository;
-
-
- @Test
- public void testCreateFlowSnapshot() {
- final FlowSnapshotEntityKey key = new FlowSnapshotEntityKey();
- key.setFlowId("2");
- key.setVersion(1);
-
- final FlowSnapshotEntity flowSnapshot = new FlowSnapshotEntity();
- flowSnapshot.setId(key);
- flowSnapshot.setComments("This is snapshot 1 for flow 2");
- flowSnapshot.setCreated(new Date());
-
- flowSnapshotRepository.save(flowSnapshot);
-
- final FlowSnapshotEntity createdFlowSnapshot = flowSnapshotRepository.findById(key).orElse(null);
- assertNotNull(createdFlowSnapshot);
- }
-
- @Test
- public void testFindById() {
- final FlowSnapshotEntityKey key = new FlowSnapshotEntityKey();
- key.setFlowId("1");
- key.setVersion(1);
-
- final FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findById(key).orElse(null);
- assertNotNull(flowSnapshot);
- assertEquals(key, flowSnapshot.getId());
- assertNotNull(flowSnapshot.getFlow());
- assertEquals("user1", flowSnapshot.getCreatedBy());
- }
-
- @Test
- public void testDeleteFlowSnapshot() {
- final FlowSnapshotEntityKey key = new FlowSnapshotEntityKey();
- key.setFlowId("1");
- key.setVersion(1);
-
- final FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findById(key).orElse(null);
- assertNotNull(flowSnapshot);
-
- flowSnapshotRepository.delete(flowSnapshot);
-
- final FlowSnapshotEntity deletedFlowSnapshot = flowSnapshotRepository.findById(key).orElse(null);
- assertNull(deletedFlowSnapshot);
- }
-
- @Test
- public void testDeleteBucketCascadesToSnapshots() {
- final FlowSnapshotEntityKey key = new FlowSnapshotEntityKey();
- key.setFlowId("1");
- key.setVersion(1);
-
- final FlowSnapshotEntity flowSnapshot = flowSnapshotRepository.findById(key).orElse(null);
- assertNotNull(flowSnapshot);
-
- final FlowEntity flow = flowSnapshot.getFlow();
- assertNotNull(flow);
-
- final BucketEntity bucket = flow.getBucket();
- assertNotNull(bucket);
-
- bucketRepository.delete(bucket);
-
- assertNull(flowRepository.findById(flow.getId()).orElse(null));
- assertNull(flowSnapshotRepository.findById(key).orElse(null));
- }
-
- @Test
- public void testCountByFlow() {
- final List<FlowSnapshotCount> counts = flowSnapshotRepository.countByFlow();
- assertNotNull(counts);
- assertEquals(1, counts.size());
-
- final FlowSnapshotCount count = counts.get(0);
- assertEquals("1", count.getFlowIdentifier());
- assertEquals(3, count.getSnapshotCount());
- }
-
- @Test
- public void testFindFirstByFlow() {
- final FlowEntity flowEntity = flowRepository.findById("1").orElse(null);
- assertNotNull(flowEntity);
-
- final FlowSnapshotEntity latest = flowSnapshotRepository.findFirstByFlowOrderByIdVersionDesc(flowEntity);
- assertNotNull(latest);
- assertEquals(3, latest.getId().getVersion().intValue());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/2460c84b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestKeyRepository.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestKeyRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestKeyRepository.java
deleted file mode 100644
index 6bc4fef..0000000
--- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestKeyRepository.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.nifi.registry.db.repository;
-
-import org.apache.nifi.registry.db.DatabaseBaseTest;
-import org.apache.nifi.registry.db.entity.KeyEntity;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.UUID;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-public class TestKeyRepository extends DatabaseBaseTest {
-
- @Autowired
- private KeyRepository keyRepository;
-
- @Test
- public void testCreate() {
- final KeyEntity key = new KeyEntity();
- key.setId(UUID.randomUUID().toString());
- key.setTenantIdentity("user");
- key.setKeyValue(UUID.randomUUID().toString());
-
- final KeyEntity createdKey = keyRepository.save(key);
- assertNotNull(createdKey);
- assertEquals(key.getId(), createdKey.getId());
- assertEquals(key.getTenantIdentity(), createdKey.getTenantIdentity());
- assertEquals(key.getKeyValue(), createdKey.getKeyValue());
- }
-
- @Test
- public void testUpdate() {
- final String prepopulatedKeyId = "1"; // see test-setup.sql
-
- final KeyEntity existingKey = keyRepository.findById(prepopulatedKeyId).orElse(null);
- assertNotNull(existingKey);
-
- final String updatedKeyValue = existingKey.getKeyValue() + " UPDATED";
- existingKey.setKeyValue(updatedKeyValue);
-
- keyRepository.save(existingKey);
-
- final KeyEntity updatedKey = keyRepository.findById(prepopulatedKeyId).orElse(null);
- assertNotNull(updatedKey);
- assertEquals(updatedKeyValue, updatedKey.getKeyValue());
- }
-
- @Test
- @Transactional
- public void testDelete() {
- final String id = "1";
-
- final KeyEntity existingKey = keyRepository.findById("1").orElse(null);
- assertNotNull(existingKey);
-
- keyRepository.delete(existingKey);
-
- final KeyEntity deletedKey = keyRepository.findById("1").orElse(null);
- assertNull(deletedKey);
- }
-
- @Test
- public void testFindOneByTenantIdentity() {
- final String prepopulatedKeyTenantIdentity = "unit_test_tenant_identity"; // see test-setup.sql
-
- final KeyEntity existingKey = keyRepository.findOneByTenantIdentity(prepopulatedKeyTenantIdentity);
- assertNotNull(existingKey);
- assertEquals("1", existingKey.getId());
- }
-
- @Test
- @Transactional
- public void testDeleteByTenantIdentity() {
- final String prepopulatedKeyTenantIdentity = "unit_test_tenant_identity"; // see test-setup.sql
-
- final KeyEntity existingKey = keyRepository.findOneByTenantIdentity(prepopulatedKeyTenantIdentity);
- assertNotNull(existingKey);
-
- keyRepository.delete(existingKey);
-
- KeyEntity deletedKey = keyRepository.findOneByTenantIdentity(prepopulatedKeyTenantIdentity);
- assertNull(deletedKey);
- deletedKey = keyRepository.findById("1").orElse(null);
- assertNull(deletedKey);
- }
-
-}