summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavsad <david.sadlier@est.tech>2021-11-01 16:35:05 +0000
committerAndr� Schmid <andre.schmid@est.tech>2021-11-02 11:18:22 +0000
commit31bfab860800308a86430bd03628c3ea17cd9115 (patch)
treea52672c84fe7195deb73a81c77f76c4b4f06f71d
parent453eb2bd29e65a9f680580ab39b70ed361a80520 (diff)
Import VSP with non-standard policy types
Issue-ID: SDC-3715 Signed-off-by: davsad <david.sadlier@est.tech> Change-Id: I48e9831b8a27341db2d33d85125cb9d42043e71b
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java32
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java65
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java34
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java11
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java17
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java7
-rw-r--r--catalog-be/src/test/resources/csars/nonOnapCsar.csarbin14013 -> 14041 bytes
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java2
12 files changed, 178 insertions, 80 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
index 0571f55c32..dc6f7c4416 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
@@ -88,6 +88,7 @@ public class CsarInfo {
@Getter
private Map<String, Resource> createdNodes;
private Map<String, Object> datatypeDefinitions;
+ private Map<String, Object> policytypeDefinitions;
private List<Map.Entry<String, byte[]>> globalSubstitutes;
@@ -195,16 +196,24 @@ public class CsarInfo {
for (Map.Entry<String, byte[]> entry : globalSubstitutes) {
final String yamlFileContents = new String(entry.getValue());
final Map<String, Object> mappedToscaTemplate = new Yaml().load(yamlFileContents);
- datatypeDefinitions.putAll(getDataTypesFromTemplate(mappedToscaTemplate));
+ datatypeDefinitions.putAll(getTypesFromTemplate(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.DATA_TYPES));
}
- datatypeDefinitions.putAll(getDataTypesFromTemplate(mappedToscaMainTemplate));
+ datatypeDefinitions.putAll(getTypesFromTemplate(mappedToscaMainTemplate, TypeUtils.ToscaTagNamesEnum.DATA_TYPES));
}
return datatypeDefinitions;
}
+
+ public Map<String, Object> getPolicyTypes() {
+ if (policytypeDefinitions == null) {
+ policytypeDefinitions = new HashMap<>();
+ policytypeDefinitions.putAll(getTypesFromTemplate(mappedToscaMainTemplate, TypeUtils.ToscaTagNamesEnum.POLICY_TYPES));
+ }
+ return policytypeDefinitions;
+ }
@SuppressWarnings("unchecked")
- private Map<String, Object> getDataTypesFromTemplate(final Map<String, Object> mappedToscaTemplate) {
- final Either<Object, ResultStatusEnum> dataTypesEither = findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.DATA_TYPES,
+ private Map<String, Object> getTypesFromTemplate(final Map<String, Object> mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum type) {
+ final Either<Object, ResultStatusEnum> dataTypesEither = findToscaElement(mappedToscaTemplate, type,
ToscaElementTypeEnum.MAP);
if (dataTypesEither != null && dataTypesEither.isLeft()) {
return (Map<String, Object>) dataTypesEither.left().value();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java
index 401222861b..892536ffa7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java
@@ -40,12 +40,15 @@ import org.springframework.util.CollectionUtils;
@org.springframework.stereotype.Component("dataTypeBusinessLogic")
public class DataTypeBusinessLogic extends BaseBusinessLogic {
+ final DataTypeImportManager dataTypeImportManager;
+
@Autowired
public DataTypeBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation,
- InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation) {
+ InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation, DataTypeImportManager dataTypeImportManager) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
artifactToscaOperation);
+ this.dataTypeImportManager = dataTypeImportManager;
}
/**
@@ -139,4 +142,25 @@ public class DataTypeBusinessLogic extends BaseBusinessLogic {
// return deleted data type if ok
return Either.left(dataTypeResult.get());
}
+
+ /**
+ * Creates given data types. The data types must be provided in a yaml format, where each entry is one data type object, for
+ * example:
+ * <pre>
+ * tosca.datatypes.TimeInterval:
+ * derived_from: tosca.datatypes.Root
+ * [...]
+ *
+ * tosca.datatypes.network.NetworkInfo:
+ * derived_from: tosca.datatypes.Root
+ * [...]
+ * </pre>
+ *
+ * @param dataTypesYaml the data types to create in yaml format. It can contain multiple data types entries.
+ * @param model Model name to associate with data type
+ * @param includeToModelDefaultImports Add data type entry to default imports for model
+ */
+ public void createDataTypeFromYaml(final String dataTypesYaml, final String model, final boolean includeToModelDefaultImports) {
+ dataTypeImportManager.createDataTypes(dataTypesYaml, model, includeToModelDefaultImports);
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
index c80f993a71..b318f97c72 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
@@ -44,35 +44,10 @@ public class ModelBusinessLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(ModelBusinessLogic.class);
private final ModelOperation modelOperation;
- private final DataTypeImportManager dataTypeImportManager;
@Autowired
- public ModelBusinessLogic(final ModelOperation modelOperation, final DataTypeImportManager dataTypeImportManager) {
+ public ModelBusinessLogic(final ModelOperation modelOperation) {
this.modelOperation = modelOperation;
- this.dataTypeImportManager = dataTypeImportManager;
- }
-
- /**
- * Creates a model along with given data types. The data types must be provided in a yaml format, where each entry is one data type object, for
- * example:
- * <pre>
- * tosca.datatypes.TimeInterval:
- * derived_from: tosca.datatypes.Root
- * [...]
- *
- * tosca.datatypes.network.NetworkInfo:
- * derived_from: tosca.datatypes.Root
- * [...]
- * </pre>
- *
- * @param model the model to create
- * @param datatypesYaml the data types to create in yaml format. It can contain multiple data types entries.
- * @return the created model.
- */
- public Model createModel(final Model model, final String datatypesYaml) {
- createModel(model);
- dataTypeImportManager.createDataTypes(datatypesYaml, model.getName(), true);
- return model;
}
public Model createModel(final Model model) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java
index c7e6a98d92..224b01a04a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java
@@ -17,15 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.components.impl;
import static java.util.Collections.emptySet;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -39,15 +42,18 @@ import org.springframework.stereotype.Component;
@Component("policyTypeBusinessLogic")
public class PolicyTypeBusinessLogic {
- private PolicyTypeOperation policyTypeOperation;
- private JanusGraphDao janusGraphDao;
- private UserValidations userValidations;
+ private final PolicyTypeOperation policyTypeOperation;
+ private final JanusGraphDao janusGraphDao;
+ private final UserValidations userValidations;
+ private final PolicyTypeImportManager policyTypeImportManager;
@Autowired
- public PolicyTypeBusinessLogic(PolicyTypeOperation policyTypeOperation, JanusGraphDao janusGraphDao, UserValidations userValidations) {
+ public PolicyTypeBusinessLogic(final PolicyTypeOperation policyTypeOperation, final JanusGraphDao janusGraphDao,
+ final UserValidations userValidations, final PolicyTypeImportManager policyTypeImportManager) {
this.policyTypeOperation = policyTypeOperation;
this.janusGraphDao = janusGraphDao;
this.userValidations = userValidations;
+ this.policyTypeImportManager = policyTypeImportManager;
}
public List<PolicyTypeDefinition> getAllPolicyTypes(String userId, String internalComponentType, String modelName) {
@@ -57,19 +63,31 @@ public class PolicyTypeBusinessLogic {
}
public PolicyTypeDefinition getLatestPolicyTypeByType(String policyTypeName, String modelName) {
- return policyTypeOperation.getLatestPolicyTypeByType(policyTypeName, modelName).left().on(e -> failOnPolicyType(e, policyTypeName));
+ return policyTypeOperation.getLatestPolicyTypeByType(policyTypeName, modelName).left()
+ .on(e -> failOnPolicyType(e, policyTypeName));
}
public Set<String> getExcludedPolicyTypes(String internalComponentType) {
if (StringUtils.isEmpty(internalComponentType)) {
return emptySet();
}
- Map<String, Set<String>> excludedPolicyTypesMapping = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getExcludedPolicyTypesMapping();
+ Map<String, Set<String>> excludedPolicyTypesMapping =
+ ConfigurationManager.getConfigurationManager().getConfiguration().getExcludedPolicyTypesMapping();
Set<String> excludedTypes = excludedPolicyTypesMapping.get(internalComponentType);
return excludedTypes == null ? emptySet() : excludedTypes;
}
+ /**
+ * Create policy types based on yaml string.
+ * @param policyTypesYaml the policy types to create in yaml format. It can contain multiple entries.
+ * @param model Model name to associate with policy type
+ * @param includeToModelDefaultImports Add policy type entry to default imports for model
+ */
+ public void createPolicyTypeFromYaml(final String policyTypesYaml, final String model, final boolean includeToModelDefaultImports) {
+ policyTypeImportManager
+ .createPolicyTypes(new ToscaTypeImportData(policyTypesYaml, Collections.emptyMap()), model, includeToModelDefaultImports);
+ }
+
private List<PolicyTypeDefinition> getPolicyTypes(Set<String> excludedTypes, String modelName) {
return policyTypeOperation.getAllPolicyTypes(excludedTypes, modelName);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 9ba20f46a1..f7beca6200 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -29,6 +29,7 @@ import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStr
import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN;
import static org.openecomp.sdc.common.api.Constants.DEFAULT_GROUP_VF_MODULE;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -46,6 +47,7 @@ import java.util.Set;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@@ -124,6 +126,7 @@ import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RelationshipImpl;
import org.openecomp.sdc.be.model.RelationshipInfo;
@@ -182,7 +185,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
+
import com.google.common.annotations.VisibleForTesting;
+
import fj.data.Either;
@org.springframework.stereotype.Component("resourceBusinessLogic")
@@ -217,6 +222,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private final ModelBusinessLogic modelBusinessLogic;
private IInterfaceLifecycleOperation interfaceTypeOperation;
private LifecycleBusinessLogic lifecycleBusinessLogic;
+ private final DataTypeBusinessLogic dataTypeBusinessLogic;
+ private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
+
@Autowired
private ICapabilityTypeOperation capabilityTypeOperation;
@Autowired
@@ -247,7 +255,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
final ComponentValidator componentValidator, final ComponentIconValidator componentIconValidator,
final ComponentProjectCodeValidator componentProjectCodeValidator,
final ComponentDescriptionValidator componentDescriptionValidator, final PolicyBusinessLogic policyBusinessLogic,
- final ModelBusinessLogic modelBusinessLogic) {
+ final ModelBusinessLogic modelBusinessLogic,
+ final DataTypeBusinessLogic dataTypeBusinessLogic, final PolicyTypeBusinessLogic policyTypeBusinessLogic) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation,
interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
@@ -264,6 +273,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
this.propertyBusinessLogic = propertyBusinessLogic;
this.policyBusinessLogic = policyBusinessLogic;
this.modelBusinessLogic = modelBusinessLogic;
+ this.dataTypeBusinessLogic = dataTypeBusinessLogic;
+ this.policyTypeBusinessLogic = policyTypeBusinessLogic;
}
static <T> Either<T, RuntimeException> rollbackWithEither(final JanusGraphDao janusGraphDao, final ActionStatus actionStatus,
@@ -1031,19 +1042,18 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
user.getUserId());
CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, csarUIPayload, csarUUID);
Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
- if (StringUtils.isNotEmpty(resource.getModel())) {
- final Map<String, Object> dataTypesToCreate = new HashMap<>();
- for (final String dataType: csarInfo.getDataTypes().keySet()) {
- final Either<DataTypeDefinition, StorageOperationStatus> result = propertyOperation.getDataTypeByName(dataType, resource.getModel());
- if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
- dataTypesToCreate.put(dataType, csarInfo.getDataTypes().get(dataType));
- }
+ final String model = resource.getModel();
+ if (StringUtils.isNotEmpty(model)) {
+ final Map<String, Object> dataTypesToCreate = getDatatypesToCreate(model, csarInfo.getDataTypes());
+ final Map<String, Object> policyTypesToCreate = getPolicytypesToCreate(model, csarInfo.getPolicyTypes());
+ if (MapUtils.isNotEmpty(dataTypesToCreate) || MapUtils.isNotEmpty(policyTypesToCreate)) {
+ createModel(resource, csarInfo.getVfResourceName());
}
if (MapUtils.isNotEmpty(dataTypesToCreate)) {
- final String nameForGeneratedModel = resource.getModel() + "_" + csarInfo.getVfResourceName() + resource.getCsarVersion();
- final Model model = new Model(nameForGeneratedModel, resource.getModel(), ModelTypeEnum.NORMATIVE_EXTENSION);
- modelBusinessLogic.createModel(model, new Yaml().dump(dataTypesToCreate));
- resource.setModel(nameForGeneratedModel);
+ dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), model, true);
+ }
+ if (MapUtils.isNotEmpty(policyTypesToCreate)) {
+ policyTypeBusinessLogic.createPolicyTypeFromYaml(new Yaml().dump(policyTypesToCreate), model, true);
}
}
@@ -1148,6 +1158,37 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES).left().orValue(HashMap::new);
}
+ private void createModel(final Resource resource, final String vfResourcename) {
+ final String nameForGeneratedModel = resource.getModel() + "_" + vfResourcename + resource.getCsarVersion();
+ Model model = new Model(nameForGeneratedModel, resource.getModel(), ModelTypeEnum.NORMATIVE_EXTENSION);
+ modelBusinessLogic.createModel(model);
+ resource.setModel(nameForGeneratedModel);
+ }
+
+ private Map<String, Object> getDatatypesToCreate(final String model, final Map<String, Object> dataTypes) {
+ final Map<String, Object> dataTypesToCreate = new HashMap<>();
+ for (final String dataType : dataTypes.keySet()) {
+ final Either<DataTypeDefinition, StorageOperationStatus> result =
+ propertyOperation.getDataTypeByName(dataType, model);
+ if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ dataTypesToCreate.put(dataType, dataTypes.get(dataType));
+ }
+ }
+ return dataTypesToCreate;
+ }
+
+ private Map<String, Object> getPolicytypesToCreate(final String model, final Map<String, Object> policyTypes) {
+ final Map<String, Object> policyTypesToCreate = new HashMap<>();
+ for (final String policyType : policyTypes.keySet()) {
+ final Either<PolicyTypeDefinition, StorageOperationStatus> result =
+ policyTypeOperation.getLatestPolicyTypeByType(policyType, model);
+ if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ policyTypesToCreate.put(policyType, policyTypes.get(policyType));
+ }
+ }
+ return policyTypesToCreate;
+ }
+
private void createNodeTypes(String yamlName, Resource resource, boolean needLock,
Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java
index cc05eaf7b4..c870d3b7f2 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java
@@ -20,7 +20,19 @@
package org.openecomp.sdc.be.components.impl;
-import fj.data.Either;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -40,16 +52,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.user.UserBusinessLogic;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
+import fj.data.Either;
public class DataTypeBusinessLogicTest {
@@ -74,6 +77,9 @@ public class DataTypeBusinessLogicTest {
@Mock
private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
+ @Mock
+ private DataTypeImportManager dataTypeImportManager;
+
@InjectMocks
private DataTypeBusinessLogic testInstance;
@@ -107,6 +113,12 @@ public class DataTypeBusinessLogicTest {
}
@Test
+ public void createDataTypeByYaml() {
+ testInstance.createDataTypeFromYaml("test", "test", true);
+ verify(dataTypeImportManager, Mockito.times(1)).createDataTypes("test", "test", true);
+ }
+
+ @Test
public void test_getPrivateDataTypes() throws Exception {
setMockitoWhenGetToscaElementCalled();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java
index cbb0de8715..a1719d7a27 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java
@@ -82,17 +82,6 @@ class ModelBusinessLogicTest {
}
@Test
- void createModelWithDataTypesTest() {
- final String dataTypes = "dummyString";
- when(modelOperation.createModel(model, false)).thenReturn(model);
- final Model result = modelBusinessLogic.createModel(model, dataTypes);
- assertThat(result).isNotNull();
- assertThat(result.getName()).isEqualTo(model.getName());
-
- verify(dataTypeImportManager).createDataTypes(dataTypes, model.getName(), true);
- }
-
- @Test
void createModelFailTest() {
when(modelOperation.createModel(model, false))
.thenThrow(ModelOperationExceptionSupplier.modelAlreadyExists(model.getName()).get());
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java
index 88a16f6d96..48716c839b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java
@@ -23,23 +23,27 @@ package org.openecomp.sdc.be.components.impl;
import static com.google.common.collect.Sets.newHashSet;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.common.collect.ImmutableMap;
-import fj.data.Either;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
+
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.DummyConfigurationManager;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
import org.openecomp.sdc.be.components.utils.PolicyTypeBuilder;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
@@ -52,6 +56,10 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
import org.openecomp.sdc.exception.ResponseFormat;
+import com.google.common.collect.ImmutableMap;
+
+import fj.data.Either;
+
@RunWith(MockitoJUnitRunner.class)
public class PolicyTypeBusinessLogicTest {
@@ -66,6 +74,8 @@ public class PolicyTypeBusinessLogicTest {
@Mock
private PolicyTypeOperation policyTypeOperation;
@Mock
+ private PolicyTypeImportManager policyTypeImportManager;
+ @Mock
private ComponentsUtils componentsUtils;
@Mock
private UserValidations userValidations;
@@ -82,6 +92,12 @@ public class PolicyTypeBusinessLogicTest {
}
@Test
+ public void createPolicyByYaml() {
+ testInstance.createPolicyTypeFromYaml("test", "test", true);
+ verify(policyTypeImportManager, Mockito.times(1)).createPolicyTypes(any(ToscaTypeImportData.class), eq("test"), eq(true));
+ }
+
+ @Test
public void getAllPolicyTypes_userNotExist() {
ResponseFormat userNotExistResponse = new ResponseFormat();
when(userValidations.validateUserExists(eq(USER_ID))).thenThrow(new ByResponseFormatComponentException(userNotExistResponse));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index 2f4239f9cf..90c1864ba7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -34,7 +34,6 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
-import fj.data.Either;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
@@ -50,7 +49,9 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+
import javax.servlet.ServletContext;
+
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Assert;
import org.junit.Before;
@@ -85,8 +86,8 @@ import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -131,6 +132,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
@@ -151,6 +153,8 @@ import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.web.context.WebApplicationContext;
+import fj.data.Either;
+
public class ResourceBusinessLogicTest {
private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
@@ -208,7 +212,10 @@ public class ResourceBusinessLogicTest {
private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
private final ToscaExportHandler toscaExportHandler = Mockito.mock(ToscaExportHandler.class);
+ private final PolicyTypeOperation policyTypeOperation = Mockito.mock(PolicyTypeOperation.class);
private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
+ private final DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class);
+ private final PolicyTypeBusinessLogic policyTypeBusinessLogic = Mockito.mock(PolicyTypeBusinessLogic.class);
private YamlTemplateParsingHandler yamlTemplateParsingHandler = Mockito.mock(YamlTemplateParsingHandler.class);
@InjectMocks
@@ -306,7 +313,8 @@ public class ResourceBusinessLogicTest {
Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(emptyDataTypes));
when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
-
+ when(policyTypeOperation.getLatestPolicyTypeByType(any(String.class), any(String.class)))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
// BL object
artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
bl = new ResourceBusinessLogic(mockElementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
@@ -315,7 +323,7 @@ public class ResourceBusinessLogicTest {
csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator,
- componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic);
+ componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic, dataTypeBusinessLogic, policyTypeBusinessLogic);
bl.setElementDao(mockElementDao);
bl.setUserAdmin(mockUserAdmin);
bl.setCapabilityTypeOperation(capabilityTypeOperation);
@@ -334,6 +342,7 @@ public class ResourceBusinessLogicTest {
bl.setToscaOperationFacade(toscaOperationFacade);
bl.setUserValidations(userValidations);
bl.setInterfaceTypeOperation(interfaceTypeOperation);
+ bl.setPolicyTypeOperation(policyTypeOperation);
csarBusinessLogic.setCsarOperation(csarOperation);
Resource resourceCsar = createResourceObjectCsar(true);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
index 46040ca2d6..b1e17b8864 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
@@ -29,10 +29,12 @@ import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.CompositionBusinessLogic;
+import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
import org.openecomp.sdc.be.components.impl.ModelBusinessLogic;
import org.openecomp.sdc.be.components.impl.OutputsBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
@@ -70,6 +72,8 @@ public class CheckoutTest extends LifecycleTestBase {
private final ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
private final ModelBusinessLogic modelBusinessLogic = Mockito.mock(ModelBusinessLogic.class);
+ private final DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class);
+ private final PolicyTypeBusinessLogic policyTypeBusinessLogic = Mockito.mock(PolicyTypeBusinessLogic.class);
@InjectMocks
ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic,
@@ -77,7 +81,8 @@ public class CheckoutTest extends LifecycleTestBase {
resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils,
uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic,
componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic, modelBusinessLogic);
+ componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic, modelBusinessLogic,
+ dataTypeBusinessLogic, policyTypeBusinessLogic);
@Before
public void setup() {
diff --git a/catalog-be/src/test/resources/csars/nonOnapCsar.csar b/catalog-be/src/test/resources/csars/nonOnapCsar.csar
index 9e097051ec..b5902d5e7c 100644
--- a/catalog-be/src/test/resources/csars/nonOnapCsar.csar
+++ b/catalog-be/src/test/resources/csars/nonOnapCsar.csar
Binary files differ
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
index be6a8c270b..e2266bf7de 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
@@ -73,7 +73,7 @@ public class TypeUtils {
//functions
GET_INPUT("get_input"),
// Definitions
- DATA_TYPES("data_types"), NODE_TYPES("node_types"), IMPORTS("imports"),
+ DATA_TYPES("data_types"), NODE_TYPES("node_types"), POLICY_TYPES("policy_types"), IMPORTS("imports"),
//Operations
IMPLEMENTATION("implementation"),