summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java21
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java12
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java77
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java2
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java34
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceRestUtils.java8
-rw-r--r--test-apis-ci/src/main/resources/ci/testSuites/service.xml1
8 files changed, 107 insertions, 55 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
index 2e94139b2b..22757d0944 100644
--- 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
@@ -66,13 +66,6 @@ public class InterfaceOperationValidation {
InterfaceDefinition storedInterfaceDefinition, Map<String, InterfaceDefinition> globalInterfaceTypes,
boolean isUpdate) {
- Either<Boolean, ResponseFormat> validateAllowedOperationCountOnLocalInterfaceType =
- validateAllowedOperationCountOnLocalInterfaceType(inputInterfaceDefinition, storedInterfaceDefinition,
- globalInterfaceTypes, isUpdate);
- if (validateAllowedOperationCountOnLocalInterfaceType.isRight()) {
- return validateAllowedOperationCountOnLocalInterfaceType;
- }
-
Either<Boolean, ResponseFormat> validateAllowedOperationsOnGlobalInterfaceType =
validateAllowedOperationsOnGlobalInterfaceType(inputInterfaceDefinition, globalInterfaceTypes);
if (validateAllowedOperationsOnGlobalInterfaceType.isRight()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
index 87c4bfa2a6..0360386158 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
@@ -45,6 +45,7 @@ import org.openecomp.sdc.be.tosca.model.ToscaProperty;
public class InterfacesOperationsToscaUtil {
private static final String DERIVED_FROM_STANDARD_INTERFACE = "tosca.interfaces.node.lifecycle.Standard";
+ private static final String DERIVED_FROM_BASE_DEFAULT = "org.openecomp.interfaces.node.lifecycle.";
private static final String OPERATIONS_KEY = "operations";
private static final String DEFAULT = "default";
@@ -53,6 +54,7 @@ public class InterfacesOperationsToscaUtil {
private static final String DEFAULTP = "defaultp";
public static final String SELF = "SELF";
+ private static final String LOCAL_INTERFACE_TYPE = "Local";
private InterfacesOperationsToscaUtil() {
}
@@ -91,7 +93,7 @@ public class InterfacesOperationsToscaUtil {
Map<String, Object> operationsMap = (Map<String, Object>) interfacesAsMap.remove(OPERATIONS_KEY);
interfacesAsMap.putAll(operationsMap);
- toscaInterfaceTypes.put(interfaceDefinition.getType(), interfacesAsMap);
+ toscaInterfaceTypes.put(getInterfaceType(component, LOCAL_INTERFACE_TYPE), interfacesAsMap);
}
}
return MapUtils.isNotEmpty(toscaInterfaceTypes) ? toscaInterfaceTypes : null;
@@ -139,7 +141,12 @@ public class InterfacesOperationsToscaUtil {
Map<String, Object> toscaInterfaceDefinitions = new HashMap<>();
for (InterfaceDefinition interfaceDefinition : interfaces.values()) {
ToscaInterfaceDefinition toscaInterfaceDefinition = new ToscaInterfaceDefinition();
- final String interfaceType = interfaceDefinition.getType();
+ String interfaceType;
+ if(componentInstance != null && LOCAL_INTERFACE_TYPE.equals(interfaceDefinition.getType())) {
+ interfaceType = DERIVED_FROM_BASE_DEFAULT + componentInstance.getSourceModelName();
+ } else {
+ interfaceType = getInterfaceType(component, interfaceDefinition.getType());
+ }
toscaInterfaceDefinition.setType(interfaceType);
final Map<String, OperationDataDefinition> operations = interfaceDefinition.getOperations();
Map<String, Object> toscaOperations = new HashMap<>();
@@ -282,6 +289,16 @@ public class InterfacesOperationsToscaUtil {
return toscaInputValue;
}
+ private static String getInterfaceType(Component component, String interfaceType) {
+ if (LOCAL_INTERFACE_TYPE.equals(interfaceType)) {
+ return DERIVED_FROM_BASE_DEFAULT
+ + component.getComponentMetadataDefinition()
+ .getMetadataDataDefinition().getSystemName();
+ }
+
+ return interfaceType;
+ }
+
private static Map<String, Object> getObjectAsMap(Object obj) {
ObjectMapper objectMapper = new ObjectMapper();
if (obj instanceof ToscaInterfaceDefinition) {
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
index 29bc8ec43f..826405ca87 100644
--- 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
@@ -292,18 +292,6 @@ public class InterfaceOperationValidationTest {
}
@Test
- public void shouldFailValidateAllowedOperationCountOnLocalInterfaceType() {
- InterfaceDefinition inputInterfaceDefinition =
- InterfaceOperationTestUtils.createMockInterface(interfaceType1
- , operationId, operationType1);
- Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(inputInterfaceDefinition, component,
- component.getInterfaces().get(interfaceType1),
- InterfaceOperationTestUtils.createMockInterfaceTypeMap(
- interfaceType2, operationType1), false).isRight());
- }
-
- @Test
public void shouldFailValidateAllowedOperationsOnGlobalInterfaceType() {
InterfaceDefinition inputInterfaceDefinition =
InterfaceOperationTestUtils.createMockInterface(interfaceType1
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
index 7ddf71a04a..5235b12219 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
@@ -25,11 +25,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import org.apache.commons.collections4.MapUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -46,6 +48,7 @@ import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.ServiceMetadataDefinition;
import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
import org.openecomp.sdc.be.tosca.ToscaRepresentation;
@@ -77,8 +80,11 @@ public class InterfacesOperationsToscaUtilTest {
public void addInterfaceTypeElementToResource() {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
+ component.setMetadataDefinition(new ServiceMetadataDefinition());
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().setName("NodeTypeName");
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("NodeTypeName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
- addedInterface.setType("interface.types.test_resource_name");
+ addedInterface.setType("Local");
addOperationsToInterface(component, addedInterface, 5, 3, true, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
@@ -92,15 +98,18 @@ public class InterfacesOperationsToscaUtilTest {
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("interface.types.test_resource_name"));
+ Assert.assertTrue(toscaRepresentation.getMainYaml().contains("NodeTypeName"));
}
@Test
public void addInterfaceTypeElementToService() {
Component component = new Service();
component.setNormalizedName("normalizedServiceComponentName");
+ component.setMetadataDefinition(new ServiceMetadataDefinition());
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().setName("NodeTypeName");
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("NodeTypeName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
- addedInterface.setType("interface.types.test_service_name");
+ addedInterface.setType("Local");
addOperationsToInterface(component, addedInterface, 5, 3, true, false);
final String interfaceType = "normalizedServiceComponentName-interface";
component.setInterfaces(new HashMap<>());
@@ -114,7 +123,7 @@ public class InterfacesOperationsToscaUtilTest {
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("interface.types.test_service_name"));
+ Assert.assertTrue(toscaRepresentation.getMainYaml().contains("NodeTypeName"));
}
@Test
@@ -213,36 +222,6 @@ public class InterfacesOperationsToscaUtilTest {
Assert.assertTrue(mainYaml.contains("com.some.resource.or.other.resourceName"));
}
-// @Test
-// public void addInterfaceDefinitionElementToService() {
-// Component component = new Service();
-// component.setNormalizedName("normalizedServiceComponentName");
-// InterfaceDefinition addedInterface = new InterfaceDefinition();
-// addedInterface.setToscaResourceName("com.some.service.or.other.serviceName");
-//
-// addOperationsToInterface(addedInterface, 3, 2, true);
-// final String interfaceType = "normalizedServiceComponentName-interface";
-// component.setInterfaces(new HashMap<>());
-// component.getInterfaces().put(interfaceType, addedInterface);
-// ToscaNodeType nodeType = new ToscaNodeType();
-// InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType);
-//
-// ToscaExportHandler handler = new ToscaExportHandler();
-// ToscaTemplate template = new ToscaTemplate("testService");
-// Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
-// nodeTypes.put("test", nodeType);
-// template.setNode_types(nodeTypes);
-// final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
-//
-// Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations"));
-// Assert.assertTrue(toscaRepresentation.getMainYaml().contains("serviceName:"));
-// Assert.assertTrue(toscaRepresentation.getMainYaml().contains("inputs:"));
-// Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp"));
-// Assert.assertTrue(toscaRepresentation.getMainYaml().contains("has description"));
-// Assert.assertTrue(toscaRepresentation.getMainYaml().contains("naming_function_"));
-// Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.service.or.other.serviceName"));
-// }
-
@Test
public void addInterfaceDefinitionElement_noInputs() {
Component component = new Resource();
@@ -521,4 +500,34 @@ public class InterfacesOperationsToscaUtilTest {
}
}
}
+
+ @Test
+ public void testAddInterfaceTypeElementGetCorrectLocalInterfaceName() {
+ Service service = new Service();
+ service.setMetadataDefinition(new ServiceMetadataDefinition());
+ service.getComponentMetadataDefinition().getMetadataDataDefinition().setName("LocalInterface");
+ service.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("LocalInterface");
+ service.setInterfaces(Collections.singletonMap("Local", new InterfaceDefinition("Local", null, new HashMap<>())));
+
+ Map<String, Object> resultMap = InterfacesOperationsToscaUtil.addInterfaceTypeElement(service,
+ Collections.singletonList("org.openecomp.interfaces.node.lifecycle.Standard"));
+
+ Assert.assertTrue(MapUtils.isNotEmpty(resultMap)
+ && resultMap.containsKey("org.openecomp.interfaces.node.lifecycle.LocalInterface"));
+ }
+
+ @Test
+ public void testAddInterfaceTypeElementNoTypeChangeIfNotLocal() {
+ Service service = new Service();
+ service.setMetadataDefinition(new ServiceMetadataDefinition());
+ service.getComponentMetadataDefinition().getMetadataDataDefinition().setName("LocalInterface");
+ service.setInterfaces(Collections.singletonMap("NotLocal", new InterfaceDefinition("NotLocal", null,
+ new HashMap<>())));
+
+ Map<String, Object> resultMap = InterfacesOperationsToscaUtil.getInterfacesMap(service, null,
+ service.getInterfaces(), null, false, false);
+
+ Assert.assertTrue(MapUtils.isNotEmpty(resultMap)
+ && resultMap.containsKey("NotLocal"));
+ }
}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java
index a4338fb272..956d9b1d8f 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java
@@ -424,4 +424,6 @@ public interface Urls {
//VSP Validation Operation
final String VSP_VALIDATION_CONFIGURATION = SDC_HTTP_METHOD + "://%s:%s/onboarding-api/v1.0/externaltesting/config";
+ final String GET_INSTANCE_TOSCA_ARTIFACTS = SDC_HTTP_METHOD
+ + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/filteredDataByParams?include=toscaArtifacts";
}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java
index d0513b5ad3..40ac187512 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java
@@ -15,6 +15,7 @@ import org.junit.rules.TestName;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
@@ -31,6 +32,7 @@ import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.InterfaceOperationsRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
+import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -281,6 +283,38 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
}
@Test
+ public void testCreateOperationWithLocalInterfaceAndDownloadArtifact() throws Exception{
+ Either<Service, RestResponse> createDefaultServiceEither =
+ AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true);
+ if (createDefaultServiceEither.isRight()) {
+ fail("Error creating default service");
+ }
+ Service service = createDefaultServiceEither.left().value();
+ String serviceUniqueId = service.getUniqueId();
+ Operation operation = new Operation();
+ operation.setName("LocalOper");
+ operation.setWorkflowAssociationType("NONE");
+ Map<String, Object> interfaceOperationMap = buildInterfaceDefinitionMap(operation, "Local", null, null);
+
+ RestResponse restResponse = InterfaceOperationsRestUtils.addInterfaceOperations(service, interfaceOperationMap,
+ user);
+
+ Integer responseCode = restResponse.getErrorCode();
+ Integer expectedCode = 200;
+ Assert.assertEquals(responseCode, expectedCode);
+
+ service = ResponseParser.convertServiceResponseToJavaObject(
+ ServiceRestUtils.getServiceToscaArtifacts(service.getUniqueId()).getResponse());
+ service.setUniqueId(serviceUniqueId);
+ service.setComponentType(ComponentTypeEnum.SERVICE);
+ service.setLastUpdaterUserId(user.getUserId());
+ Either<String, RestResponse> responseEither = AtomicOperationUtils
+ .getComponenetArtifactPayload(service, "assettoscacsar");
+
+ Assert.assertTrue(responseEither.isLeft());
+ }
+
+ @Test
public void addInterfaceOperationsOnService() throws Exception {
RestResponse restResponse = InterfaceOperationsRestUtils
.addInterfaceOperations(service, buildInterfaceDefinitionForService(),
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceRestUtils.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceRestUtils.java
index c82a772de3..ec132f0f5a 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceRestUtils.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ServiceRestUtils.java
@@ -136,6 +136,14 @@ public class ServiceRestUtils extends BaseRestUtils {
return getServiceFromUrl(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), false);
}
+ public static RestResponse getServiceToscaArtifacts(String serviceId) throws IOException {
+
+ Config config = Utils.getConfig();
+ String url = String.format(Urls.GET_INSTANCE_TOSCA_ARTIFACTS, config.getCatalogBeHost(),
+ config.getCatalogBePort(), "services", serviceId);
+ return getServiceFromUrl(url, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), false);
+ }
+
public static RestResponse getService(ServiceReqDetails serviceReqDetails, User sdncModifierDetails)
throws IOException {
diff --git a/test-apis-ci/src/main/resources/ci/testSuites/service.xml b/test-apis-ci/src/main/resources/ci/testSuites/service.xml
index 5c64fb49cb..770d2bebf0 100644
--- a/test-apis-ci/src/main/resources/ci/testSuites/service.xml
+++ b/test-apis-ci/src/main/resources/ci/testSuites/service.xml
@@ -16,6 +16,7 @@
<include name="getInterfaceOperationsFromService"/>
<include name="updateInterfaceOperationsOnService"/>
<include name="deleteInterfaceOperationsFromService"/>
+ <include name="testCreateOperationWithLocalInterfaceAndDownloadArtifact"/>
</methods>
</class>
</classes>