aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormojahidi <mojahidul.islam@amdocs.com>2018-03-15 18:45:49 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-03-25 12:32:47 +0000
commit5b0a36454780e8f29df5c7f2c0da91efc62e89a6 (patch)
tree43d979db3dba82428fa15363eb46c0e628395c16
parent4cc1b4508c04bfa71f7d7684050911d6372cc634 (diff)
Added validation for Interface Operation
Added validation for interface Operation, added input parameter names validation Change-Id: Ib02ec89f7fb53bd08481631c705c9f15757bf768 Issue-ID: SDC-1060 Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java254
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml54
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java57
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java217
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java8
5 files changed, 588 insertions, 2 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
new file mode 100644
index 0000000000..bf3385a076
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
@@ -0,0 +1,254 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.be.components.validation;
+
+import fj.data.Either;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+@Component("interfaceOperationValidation")
+public class InterfaceOperationValidation {
+
+ @Autowired
+ private ToscaOperationFacade toscaOperationFacade;
+ private static final String TYPE_VALIDATION_REGEX = "^[a-zA-Z]{1,200}$";
+ private static final int DESCRIPTION_MAX_LENGTH = 200;
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationValidation.class);
+
+ public Either<Boolean, ResponseFormat> validateInterfaceOperations(
+ Collection<Operation> interfaceOperations,
+ String resourceId, boolean isUpdate) {
+
+ for(Operation interfaceOperation : interfaceOperations) {
+ Either<Boolean, ResponseFormat> interfaceOperationValidatorResponse = validateInterfaceOperation(
+ interfaceOperation, resourceId, isUpdate);
+ if (interfaceOperationValidatorResponse.isRight()) {
+ return interfaceOperationValidatorResponse;
+ }
+ }
+ return Either.left(Boolean.TRUE);
+ }
+
+ private Either<Boolean, ResponseFormat> validateInterfaceOperation(Operation interfaceOperation,
+ String resourceId, boolean isUpdate) {
+ ResponseFormatManager responseFormatManager = getResponseFormatManager();
+
+ Either<Boolean, ResponseFormat> interfaceOperationTypeResponse = validateInterfaceOperationType(interfaceOperation,
+ responseFormatManager, resourceId, isUpdate);
+ if (interfaceOperationTypeResponse != null) {
+ return interfaceOperationTypeResponse;
+ }
+
+ Either<Boolean, ResponseFormat> descriptionResponseEither = validateDescription(responseFormatManager,
+ interfaceOperation.getDescription());
+ if (descriptionResponseEither != null) {
+ return descriptionResponseEither;
+ }
+
+ Either<Boolean, ResponseFormat> inputParametersResponse = validateInputParameters(interfaceOperation,
+ responseFormatManager);
+ if(inputParametersResponse != null) {
+ return inputParametersResponse;
+ }
+ return Either.left(true);
+ }
+
+ private Either<Boolean, ResponseFormat> validateInterfaceOperationType(Operation interfaceOperation,
+ ResponseFormatManager responseFormatManager,
+ String resourceId, boolean isUpdate) {
+
+ Either<Boolean, ResponseFormat> operationTypeEmptyEither = isOperationTypeEmpty(responseFormatManager,
+ interfaceOperation.getName()); // treating name as type for now
+ if (operationTypeEmptyEither != null) {
+ return operationTypeEmptyEither;
+ }
+
+ Either<Boolean, ResponseFormat> operationTypeRegexValidationResponse =
+ validateOperationTypeRegex(responseFormatManager, interfaceOperation.getName());
+ if (operationTypeRegexValidationResponse != null) {
+ return operationTypeRegexValidationResponse;
+ }
+
+ Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation,
+ resourceId, isUpdate, responseFormatManager );
+ if(operationTypeUniqueResponse.isRight()) {
+ return Either.right(operationTypeUniqueResponse.right().value());
+ }
+ if (!operationTypeUniqueResponse.left().value()) {
+ LOGGER.debug("Interface Operation type {} already in use ", interfaceOperation.getName());
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
+ .INTERFACE_OPERATION_TYPE_ALREADY_IN_USE, interfaceOperation.getName());
+ return Either.right(errorResponse);
+ }
+ return null;
+ }
+
+ private Either<Boolean, ResponseFormat> validateOperationTypeRegex(ResponseFormatManager responseFormatManager,
+ String operationType) {
+ if (!isValidOperationType(operationType)) {
+ LOGGER.debug("Interface Operation type {} is invalid, Operation type should not contain" +
+ "Special character, space and should not be greater than 200 characters", operationType);
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
+ .INTERFACE_OPERATION_TYPE_INVALID, operationType);
+ return Either.right(errorResponse);
+ }
+ return null;
+ }
+
+ private Either<Boolean, ResponseFormat> isOperationTypeEmpty(ResponseFormatManager responseFormatManager,
+ String operationType) {
+ if (StringUtils.isEmpty(operationType)) {
+ LOGGER.debug("Interface Operation type is mandatory, it can't be empty");
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
+ .INTERFACE_OPERATION_TYPE_MANDATORY);
+ return Either.right(errorResponse);
+ }
+ return null;
+ }
+
+ private Either<Boolean, ResponseFormat> validateDescription(ResponseFormatManager responseFormatManager,
+ String description) {
+ if (description.length() > DESCRIPTION_MAX_LENGTH) {
+ LOGGER.debug("Interface Operation description {} is invalid, maximum 200 characters allowed", description);
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
+ .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH);
+ return Either.right(errorResponse);
+ }
+ return null;
+ }
+
+ private boolean isValidOperationType(String operationType) {
+ return Pattern.matches(TYPE_VALIDATION_REGEX, operationType);
+ }
+
+ private Either<Boolean, ResponseFormat> validateOperationTypeUnique(Operation interfaceOperation,
+ String resourceId,
+ boolean isUpdate,
+ ResponseFormatManager responseFormatManager) {
+ boolean isOperationTypeUnique = false;
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreInterfaces(false);
+ Either<Resource, StorageOperationStatus> interfaceOperationOrigin = toscaOperationFacade
+ .getToscaElement(resourceId, filter);
+ if (interfaceOperationOrigin.isRight()){
+ LOGGER.debug("Failed to fetch interface operation information by resource id {} ", resourceId);
+ return Either.right(responseFormatManager.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ Collection<InterfaceDefinition> interfaceDefinitions = interfaceOperationOrigin.left().value()
+ .getInterfaces().values();
+ if(CollectionUtils.isEmpty(interfaceDefinitions)){
+ isOperationTypeUnique = true;
+ return Either.left(isOperationTypeUnique);
+ }
+ Collection<Operation> allOperations = interfaceDefinitions.stream()
+ .filter(a -> MapUtils.isNotEmpty(a.getOperationsMap()))
+ .map(a -> a.getOperationsMap().values()).flatMap(Collection::stream)
+ .collect(Collectors.toList());
+ if(CollectionUtils.isEmpty(allOperations)){
+ isOperationTypeUnique = true;
+ return Either.left(isOperationTypeUnique);
+ }
+
+ Map<String, String> operationTypes = new HashMap<>();
+ allOperations.forEach(operationType -> operationTypes.put(operationType.getUniqueId(),
+ operationType.getName()) );
+
+ if (isUpdate){
+ isOperationTypeUnique = validateOperationTypeUniqueForUpdate(interfaceOperation, operationTypes);
+ }
+ else
+ if (!operationTypes.values().contains(interfaceOperation.getName())){
+ isOperationTypeUnique = true;
+ }
+ return Either.left(isOperationTypeUnique);
+ }
+ private Either<Boolean, ResponseFormat> validateInputParameters(Operation interfaceOperation,
+ ResponseFormatManager responseFormatManager) {
+ Either<Boolean, Set<String>> validateInputParametersUniqueResponse = validateInputParametersUnique(interfaceOperation);
+ if(validateInputParametersUniqueResponse.isRight()) {
+ LOGGER.debug("Interface operation input parameter names {} are invalid, Input parameter names should be unique",
+ validateInputParametersUniqueResponse.right().value().toString());
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
+ .INTERFACE_OPERATION_INPUT_NAME_INVALID, validateInputParametersUniqueResponse.right().value().toString());
+ return Either.right(inputResponse);
+ }
+ return null;
+ }
+
+ private Either<Boolean, Set<String>> validateInputParametersUnique(Operation operationDataDefinition) {
+
+ Set<String> inputParamNamesSet = new HashSet<>();
+ Set<String> duplicateParamNamesToReturn = new HashSet<>();
+ operationDataDefinition.getInputs().getListToscaDataDefinition()
+ .forEach(inputParam -> {
+ if(!inputParamNamesSet.add(inputParam.getLabel())) {
+ duplicateParamNamesToReturn.add(inputParam.getLabel());
+ }
+ });
+ if(!duplicateParamNamesToReturn.isEmpty()) {
+ return Either.right(duplicateParamNamesToReturn);
+ }
+ return Either.left(Boolean.TRUE);
+ }
+
+
+ private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation,
+ Map<String, String> operationTypes) {
+ boolean isOperationTypeUnique = false;
+ for(Map.Entry<String, String> entry : operationTypes.entrySet()){
+ if (entry.getKey().equals(interfaceOperation.getUniqueId()) && entry.getValue().
+ equals(interfaceOperation.getName())) {
+ isOperationTypeUnique = true;
+ }
+
+ if(entry.getKey().equals(interfaceOperation.getUniqueId()) && !operationTypes.values()
+ .contains(interfaceOperation.getName())){
+ isOperationTypeUnique = true;
+ }
+ }
+ return isOperationTypeUnique;
+ }
+
+ protected ResponseFormatManager getResponseFormatManager() {
+ return ResponseFormatManager.getInstance();
+ }
+
+}
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
index 56d0e74b73..56eaaea830 100644
--- a/catalog-be/src/main/resources/config/error-configuration.yaml
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -2031,4 +2031,56 @@ errors:
message: "Error: External Reference '%1' was not found.",
messageId: "SVC4694"
}
-
+#---------SVC4695-----------------------------
+# %1 - Interface operation type
+ INTERFACE_OPERATION_TYPE_ALREADY_IN_USE: {
+ code: 400,
+ message: "Error: Interface Operation type %1 already in use",
+ messageId: "SVC4695"
+ }
+#---------SVC4696-----------------------------
+# %1 - workflow operation type
+ INTERFACE_OPERATION_TYPE_INVALID: {
+ code: 400,
+ message: "Error: Interface Operation type %1 is Invalid, Operation type should not contain
+ Special character, space and should not be greater than 200 characters ",
+ messageId: "SVC4696"
+ }
+#---------SVC4697-----------------------------
+ INTERFACE_OPERATION_TYPE_MANDATORY: {
+ code: 404,
+ message: "Error: Interface Operation type is mandatory, Operation type can't be empty",
+ messageId: "SVC4697"
+ }
+#---------SVC4698-----------------------------
+# %1 - workflow operation description
+ INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH: {
+ code: 400,
+ message: "Error: Interface Operation description %1 is invalid, maximum 200 characters allowed",
+ messageId: "SVC4698"
+ }
+#---------SVC4699-----------------------------
+ INTERFACE_OPERATION_INPUT_NAME_INVALID: {
+ code: 400,
+ message: "Error: Interface Operation input parameter names %1 are invalid ,Input parameters name should be unique",
+ messageId: "SVC4699"
+ }
+#---------SVC4700-----------------------------
+ INTERFACE_OPERATION_OUTPUT_NAME_INVALID: {
+ code: 400,
+ message: "Error: Interface Operation output parameters invalid, should be unique and mandatory",
+ messageId: "SVC4700"
+ }
+#---------SVC4701-----------------------------
+# %1 - resource Id
+ INTERFACE_OPERATION_NOT_FOUND: {
+ code: 404,
+ message: "Error: Interface operations not found in the resource %1",
+ messageId: "SVC4701"
+ }
+#---------SVC46702-----------------------------
+ INTERFACE_OPERATION_NOT_DELETED: {
+ code: 404,
+ message: "Error: Failed to delete interface operation.",
+ messageId: "SVC4702"
+ }
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
new file mode 100644
index 0000000000..30549a3809
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.be.components;
+
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.WorkflowOperationDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.WorkflowOperationParamDataDefinition;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Operation;
+
+import java.util.Map;
+
+public interface InterfaceOperationTestUtils {
+
+ default InterfaceDefinition createInterface(String uniqueID, String description, String type,
+ String toscaResourceName, Map<String, Operation> op) {
+ InterfaceDefinition id = new InterfaceDefinition();
+ id.setType(type);
+ id.setDescription(description);
+ id.setUniqueId(uniqueID);
+ id.setToscaResourceName(toscaResourceName);
+ id.setOperationsMap(op);
+ return id;
+ }
+
+
+ default Operation createInterfaceOperation(String uniqueID, String description, ArtifactDefinition artifactDefinition,
+ ListDataDefinition<OperationInputDefinition> inputs, String name) {
+ Operation operation = new Operation();
+
+ operation.setUniqueId(uniqueID);
+ operation.setDescription(description);
+ operation.setImplementation(artifactDefinition);
+ operation.setInputs(inputs);
+ operation.setName(name);
+
+ return operation;
+ }
+
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
new file mode 100644
index 0000000000..c05dbda974
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.be.components.validation;
+
+import com.google.common.collect.Sets;
+import fj.data.Either;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.InterfaceOperationTestUtils;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+public class InterfaceOperationValidationTest implements InterfaceOperationTestUtils {
+
+ private Resource resource = (Resource) getToscaFullElement().left().value();
+
+ ResponseFormatManager mock;
+ @Mock
+ ToscaOperationFacade toscaOperationFacade;
+
+ @InjectMocks
+ InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest();
+ private static final String RESOURCE_ID = "resource1";
+ ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ mock = Mockito.mock(ResponseFormatManager.class);
+ when(toscaOperationFacade.getToscaElement(any(), any(ComponentParametersView.class))).thenReturn(Either.left(resource));
+ when(mock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+ when(mock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
+ when(mock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
+ }
+
+
+ @Test
+ public void testValidInterfaceOperation() {
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"upgrade");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ Assert.assertTrue(booleanResponseFormatEither.isLeft());
+ }
+
+ @Test
+ public void testInterfaceOperationDescriptionLength() {
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2 - The Spring Initializer provides a project generator to make you " +
+ "productive with the certain technology stack from the beginning. You can create a skeleton project" +
+ "with web, data access (relational and NoSQL datastores), cloud, or messaging support",
+ new ArtifactDefinition(), operationInputDefinitionList,"update");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
+ }
+
+
+
+ @Test
+ public void testInterfaceOperationForEmptyType() {
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
+ }
+
+ @Test
+ public void testInterfaceOperationForEmptyInputParam() {
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"input2");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
+ }
+
+ @Test
+ public void testInterfaceOperationForNonUniqueType() {
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"CREATE");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
+ }
+
+ @Test
+ public void testInterfaceOperationTypeLength() {
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ "interface operation2 - The Spring Initializer provides a project generator to make you " +
+ "productive with the certain technology stack from the beginning. You can create a skeleton project" +
+ "with web, data access (relational and NoSQL datastores), cloud, or messaging support");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
+ }
+
+
+ @Test
+ public void testInterfaceOperationUniqueInputParamNameInvalid() {
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label2"));
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label2"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"create");
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
+ }
+
+ @Test
+ public void testInterfaceOperationUniqueInputParamNameValid() {
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label2"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"update");
+
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ Assert.assertTrue(booleanResponseFormatEither.isLeft());
+ }
+
+ private Set<Operation> createInterfaceOperationData( String uniqueID, String description, ArtifactDefinition artifactDefinition,
+ ListDataDefinition<OperationInputDefinition> inputs, String name) {
+ return Sets.newHashSet(createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, name));
+ }
+
+ private <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement() {
+
+ return Either.left((T) setUpResourceMock());
+ }
+
+ private Resource setUpResourceMock(){
+ Resource resource = new Resource();
+ resource.setInterfaces(createMockInterfaceDefinition());
+
+ return resource;
+ }
+
+ private Map<String, InterfaceDefinition> createMockInterfaceDefinition() {
+ Map<String, Operation> operationMap = createMockOperationMap();
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
+ interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1",
+ "lifecycle", "tosca", operationMap));
+
+ return interfaceDefinitionMap;
+ }
+
+ private Map<String, Operation> createMockOperationMap() {
+ Operation operation = new Operation();
+ operation.setDefinition(false);
+ operation.setName("CREATE");
+ Map<String, Operation> operationMap = new HashMap<>();
+ operationMap.put("op1", operation);
+ return operationMap;
+ }
+
+
+ private OperationInputDefinition createMockOperationInputDefinition(String label) {
+ OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
+ operationInputDefinition.setLabel(label);
+ return operationInputDefinition;
+ }
+
+ private class InterfaceOperationValidationUtilTest extends InterfaceOperationValidation {
+
+ protected ResponseFormatManager getResponseFormatManager() {
+ return mock;
+ }
+ }
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
index c2bff0a935..afe3e21650 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
@@ -106,5 +106,11 @@ public enum ActionStatus {
EXT_REF_ALREADY_EXIST,
EXT_REF_NOT_FOUND,
- POLICY_TARGET_DOES_NOT_EXIST, POLICY_TARGET_TYPE_DOES_NOT_EXIST;
+ POLICY_TARGET_DOES_NOT_EXIST, POLICY_TARGET_TYPE_DOES_NOT_EXIST,
+
+ //InterfaceOperation
+ INTERFACE_OPERATION_NOT_FOUND, INTERFACE_OPERATION_TYPE_ALREADY_IN_USE, INTERFACE_OPERATION_TYPE_MANDATORY, INTERFACE_OPERATION_TYPE_INVALID,
+ INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH, INTERFACE_OPERATION_INPUT_NAME_INVALID, INTERFACE_OPERATION_NOT_DELETED
+
+ ;
}