From b0140364e491df1009cf00e50c0207d2e9ca3453 Mon Sep 17 00:00:00 2001 From: aribeiro Date: Mon, 15 Jun 2020 17:23:42 +0100 Subject: Add Node Filter Servlets Unit Tests Issue-ID: SDC-3117 Signed-off-by: aribeiro Change-Id: I84e728f21290a59c7674f97d5977b945b93ef546 --- .../sdc/be/components/impl/BaseBusinessLogic.java | 2 +- .../components/validation/NodeFilterValidator.java | 31 +++++++++++----------- .../be/servlets/ComponentNodeFilterServlet.java | 12 +++------ 3 files changed, 20 insertions(+), 25 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index 544f030d91..85453e33d2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -120,7 +120,7 @@ public abstract class BaseBusinessLogic { protected IGroupInstanceOperation groupInstanceOperation; protected InterfaceLifecycleOperation interfaceLifecycleTypeOperation; protected PolicyTypeOperation policyTypeOperation; - protected ArtifactsOperations artifactToscaOperation; + protected ArtifactsOperations artifactToscaOperation; protected UserValidations userValidations; DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance(); 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 3c770d15aa..27daaf2aae 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 @@ -7,9 +7,9 @@ * Licensed 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. @@ -96,22 +96,21 @@ public class NodeFilterValidator { final List uiConstraints, final NodeFilterConstraintAction action) { try { - for (final String uiConstraint : uiConstraints) { - if (NodeFilterConstraintAction.ADD != action && NodeFilterConstraintAction.UPDATE != action) { - break; - } - final UIConstraint constraint = new ConstraintConvertor().convert(uiConstraint); - if (ConstraintConvertor.PROPERTY_CONSTRAINT.equals(constraint.getSourceType())) { - final Either booleanResponseFormatEither = + if (NodeFilterConstraintAction.ADD == action || NodeFilterConstraintAction.UPDATE == action) { + for (final String uiConstraint : uiConstraints) { + final UIConstraint constraint = new ConstraintConvertor().convert(uiConstraint); + if (ConstraintConvertor.PROPERTY_CONSTRAINT.equals(constraint.getSourceType())) { + final Either booleanResponseFormatEither = validatePropertyConstraint(parentComponent, componentInstanceId, constraint); - if (booleanResponseFormatEither.isRight()) { - return booleanResponseFormatEither; - } - } else if (ConstraintConvertor.STATIC_CONSTRAINT.equals(constraint.getSourceType())) { - final Either booleanResponseFormatEither = + if (booleanResponseFormatEither.isRight()) { + return booleanResponseFormatEither; + } + } else if (ConstraintConvertor.STATIC_CONSTRAINT.equals(constraint.getSourceType())) { + final Either booleanResponseFormatEither = validateStaticValueAndOperator(parentComponent, componentInstanceId, constraint); - if (booleanResponseFormatEither.isRight()) { - return booleanResponseFormatEither; + if (booleanResponseFormatEither.isRight()) { + return booleanResponseFormatEither; + } } } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java index 4a43ab23a6..7141379fe3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java @@ -145,9 +145,9 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { LOGGER.debug(FAILED_TO_PARSE_COMPONENT); return buildErrorResponse(convertResponse.right().value()); } - final Optional actionResponse; final String constraint = new ConstraintConvertor().convert(uiConstraint); - actionResponse = componentNodeFilterBusinessLogic + + final Optional actionResponse = componentNodeFilterBusinessLogic .addNodeFilter(componentId.toLowerCase(), componentInstanceId, NodeFilterConstraintAction.ADD, uiConstraint.getServicePropertyName(), constraint, true, componentTypeEnum); @@ -163,7 +163,6 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { BeEcompErrorManager.getInstance().logBeRestApiGeneralError(NODE_FILTER_CREATION); LOGGER.error(CREATE_NODE_FILTER_WITH_AN_ERROR, e); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); - } } @@ -214,10 +213,8 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { LOGGER.debug("failed to parse data"); return buildErrorResponse(convertResponse.right().value()); } - final Optional actionResponse; final List constraints = new ConstraintConvertor().convertToList(uiConstraints); - - actionResponse = componentNodeFilterBusinessLogic + final Optional actionResponse = componentNodeFilterBusinessLogic .updateNodeFilter(componentId.toLowerCase(), componentInstanceId, constraints, true, componentTypeEnum); @@ -262,8 +259,7 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet { componentNodeFilterBusinessLogic.validateUser(userId); try { - final Optional actionResponse; - actionResponse = componentNodeFilterBusinessLogic + final OptionalactionResponse = componentNodeFilterBusinessLogic .deleteNodeFilter(componentId.toLowerCase(), componentInstanceId, NodeFilterConstraintAction.DELETE, null, index, true, ComponentTypeEnum.findByParamName(componentType)); -- cgit 1.2.3-korg