summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-06-17 14:20:46 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-24 08:07:08 +0000
commit7027b33eb41947e6799392d392283b09110158d1 (patch)
tree8b65f36d70c4f69002d9a65a90d4a4d5ea0a4ae8 /catalog-be/src/main
parentcb30f3a566b73c78c3ea666acfcd3f288098684a (diff)
Add Node Filter Business Logic Unit Tests
Issue-ID: SDC-3125 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: I80c755f4fffa813396ceb85c6aa7fde5b32590cd
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java13
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java32
2 files changed, 22 insertions, 23 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java
index 0356b63793..48cb80d11d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java
@@ -276,11 +276,6 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
throw new BusinessLogicException(componentsUtils
.getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
}
- boolean wasLocked = false;
- if (shouldLock) {
- lockComponent(component.getUniqueId(), component,"Update Node Filter on Component");
- wasLocked = true;
- }
final Optional<ComponentInstance> componentInstance = getComponentInstance(componentInstanceId,
component);
if (!componentInstance.isPresent()) {
@@ -289,10 +284,14 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
}
CINodeFilterDataDefinition nodeFilterDataDefinition = componentInstance.get().getNodeFilter();
if (nodeFilterDataDefinition == null) {
- throw new BusinessLogicException(componentsUtils
- .getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND));
}
+ boolean wasLocked = false;
try {
+ if (shouldLock) {
+ lockComponent(component.getUniqueId(), component,"Update Node Filter on Component");
+ wasLocked = true;
+ }
final List<RequirementNodeFilterPropertyDataDefinition> properties = constraints.stream()
.map(this::getRequirementNodeFilterPropertyDataDefinition).collect(Collectors.toList());
final Either<CINodeFilterDataDefinition, StorageOperationStatus> result = nodeFilterOperation
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
index 27daaf2aae..30632e9012 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
@@ -59,28 +59,28 @@ public class NodeFilterValidator {
public static final Set<String> comparableConstraintsOperators =
ImmutableSet.of(ConstraintConvertor.GREATER_THAN_OPERATOR, ConstraintConvertor.LESS_THAN_OPERATOR);
- @Autowired
- protected ToscaOperationFacade toscaOperationFacade;
-
- @Autowired
- protected ComponentsUtils componentsUtils;
+ protected final ToscaOperationFacade toscaOperationFacade;
+ protected final ComponentsUtils componentsUtils;
private static final Logger LOGGER = LoggerFactory.getLogger(NodeFilterValidator.class);
- public Either<Boolean, ResponseFormat> validateComponentInstanceExist(
- final Component component,
- final String componentInstanceId) {
+ @Autowired
+ public NodeFilterValidator(final ToscaOperationFacade toscaOperationFacade,
+ final ComponentsUtils componentsUtils) {
+ this.toscaOperationFacade = toscaOperationFacade;
+ this.componentsUtils = componentsUtils;
+ }
+
+ public Either<Boolean, ResponseFormat> validateComponentInstanceExist(final Component component,
+ final String componentInstanceId) {
if (component == null || StringUtils.isEmpty(componentInstanceId)) {
- LOGGER.debug("Input data cannot be empty");
- return getErrorResponse(ActionStatus.NODE_FILTER_NOT_FOUND);
- }
- if (CollectionUtils.isEmpty(component.getComponentInstances())) {
- LOGGER.debug("Component Instance list is empty");
+ LOGGER.error("Input data cannot be empty");
return getErrorResponse(ActionStatus.NODE_FILTER_NOT_FOUND);
}
- if (component.getComponentInstances().stream()
- .noneMatch(ci -> ci.getUniqueId().equals(componentInstanceId))) {
- LOGGER.debug("Component Instance list is empty");
+ if (CollectionUtils.isEmpty(component.getComponentInstances()) ||
+ component.getComponentInstances().stream()
+ .noneMatch(ci -> ci.getUniqueId().equals(componentInstanceId))) {
+ LOGGER.error("Component Instance list is empty");
return getErrorResponse(ActionStatus.NODE_FILTER_NOT_FOUND);
}
return Either.left(Boolean.TRUE);