summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2022-07-25 23:01:50 +0100
committerAndr� Schmid <andre.schmid@est.tech>2022-08-11 10:32:47 +0000
commit0f6ae59460165381a8b5da2eea58c2c2efa75f2f (patch)
tree41774a70177ac52405599f80bd47373103ee1e0b /catalog-be/src/test/java
parenta39a0026eebabe4866c81bcd12143ca40aa30e31 (diff)
Support unknown data types in service import
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-4119 Change-Id: I426ebb96e7b354dfd5dfb06a10845c3162055968
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfoTest.java (renamed from catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java)12
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java81
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypesImportManagerTest.java121
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java7
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java63
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java3
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java36
8 files changed, 293 insertions, 36 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfoTest.java
index 07a8ded378..abdf153155 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfoTest.java
@@ -58,9 +58,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
-public class CsarInfoTest {
+public class OnboardedCsarInfoTest {
- private CsarInfo csarInfo;
+ private OnboardedCsarInfo csarInfo;
@Mock
private User user;
@@ -81,12 +81,12 @@ public class CsarInfoTest {
new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
}
- private CsarInfo createCsarInfo(final String csarFileName, final String mainTemplateName) throws URISyntaxException, ZipException {
- final File csarFile = new File(CsarInfoTest.class.getClassLoader().getResource(csarFileName).toURI());
+ private OnboardedCsarInfo createCsarInfo(final String csarFileName, final String mainTemplateName) throws URISyntaxException, ZipException {
+ final File csarFile = new File(OnboardedCsarInfoTest.class.getClassLoader().getResource(csarFileName).toURI());
final Map<String, byte[]> payload = ZipUtils.readZip(csarFile, false);
String mainTemplateContent = new String(payload.get(mainTemplateName));
- return new CsarInfo(user, CSAR_UUID, payload, RESOURCE_NAME,
+ return new OnboardedCsarInfo(user, CSAR_UUID, payload, RESOURCE_NAME,
mainTemplateName, mainTemplateContent, true);
}
@@ -149,7 +149,7 @@ public class CsarInfoTest {
@Test
public void getSoftwareInformationPathTest() {
final NonManoConfiguration nonManoConfigurationMock = Mockito.mock(NonManoConfiguration.class);
- final CsarInfo csarInfo = new CsarInfo(nonManoConfigurationMock);
+ final CsarInfo csarInfo = new OnboardedCsarInfo(nonManoConfigurationMock);
final NonManoFolderType testNonManoFolderType = new NonManoFolderType();
testNonManoFolderType.setLocation("sw-location-test");
testNonManoFolderType.setType("informational-test");
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java
new file mode 100644
index 0000000000..80ecc212f1
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java
@@ -0,0 +1,81 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.csar;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import java.io.File;
+import java.net.URISyntaxException;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.common.zip.ZipUtils;
+import org.openecomp.sdc.common.zip.exception.ZipException;
+
+@ExtendWith(MockitoExtension.class)
+class ServiceCsarInfoTest {
+
+ private ServiceCsarInfo csarInfo;
+
+ @Mock
+ private User user;
+
+ private static final String CSAR_UUID = "csarUUID";
+ private static final String PAYLOAD_NAME = "csars/serviceWithUnknownDataTypes.csar";
+ private static final String SERVICE_NAME = "serviceWithDataType";
+ private static final String MAIN_TEMPLATE_NAME = "Definitions/service-Servicewithdatatype-template.yml";
+
+ @BeforeEach
+ void setup() throws ZipException, URISyntaxException {
+ csarInfo = createCsarInfo(PAYLOAD_NAME, MAIN_TEMPLATE_NAME);
+
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ }
+
+ private ServiceCsarInfo createCsarInfo(final String csarFileName, final String mainTemplateName) throws URISyntaxException, ZipException {
+ final File csarFile = new File(ServiceCsarInfoTest.class.getClassLoader().getResource(csarFileName).toURI());
+ final Map<String, byte[]> payload = ZipUtils.readZip(csarFile, false);
+ String mainTemplateContent = new String(payload.get(mainTemplateName));
+
+return new ServiceCsarInfo(user, CSAR_UUID, payload, SERVICE_NAME, mainTemplateName, mainTemplateContent, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ void testGetDataTypes() {
+ final Map<String, Object> dataTypes = csarInfo.getDataTypes();
+ assertEquals(184, dataTypes.size());
+ final Map<String, Object> dataTypeDefinition = (Map<String, Object>) dataTypes.get("tosca.datatypes.test_g");
+ assertNotNull(dataTypeDefinition);
+ assertEquals("tosca.datatypes.Root", dataTypeDefinition.get("derived_from"));
+ assertEquals("tosca.datatypes.test_h",
+ ((Map<String, Object>) ((Map<String, Object>) dataTypeDefinition.get("properties")).get("prop2")).get("type"));
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java
index d9525b1590..967beb2235 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java
@@ -148,7 +148,7 @@ public class YamlTemplateParsingHandlerTest {
when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
- CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
+ CsarInfo csarInfo = new OnboardedCsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
MAIN_TEMPLATE_NAME, main_template_content, true);
Resource resource = new Resource();
@@ -163,7 +163,7 @@ public class YamlTemplateParsingHandlerTest {
void parseServicePropertiesInfoFromYamlTest() {
when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
- CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
+ CsarInfo csarInfo = new OnboardedCsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
MAIN_TEMPLATE_NAME, main_template_content, true);
Service service = new Service();
@@ -183,7 +183,7 @@ public class YamlTemplateParsingHandlerTest {
void parseRelationshipTemplateInfoFromYamlTest() {
when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
- CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
+ CsarInfo csarInfo = new OnboardedCsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
MAIN_TEMPLATE_NAME, main_template_content, true);
Service service = new Service();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypesImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypesImportManagerTest.java
new file mode 100644
index 0000000000..e4e63fc3b7
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypesImportManagerTest.java
@@ -0,0 +1,121 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+import fj.data.Either;
+import java.util.Collections;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+
+public class DataTypesImportManagerTest {
+
+ private static final ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
+ private static final JanusGraphGenericDao janusGraphGenericDao = mock(JanusGraphGenericDao.class);
+ private static final PropertyOperation propertyOperation = mock(PropertyOperation.class);
+ private static final ModelOperation modelOperation = mock(ModelOperation.class);
+ @Spy
+ private CommonImportManager commonImportManager = new CommonImportManager(componentsUtils, propertyOperation, modelOperation);
+
+ @InjectMocks
+ private DataTypeImportManager dataTypeImportManager = new DataTypeImportManager();
+
+ private AutoCloseable closeable;
+
+ @BeforeEach
+ public void openMocks() {
+ closeable = MockitoAnnotations.openMocks(this);
+ }
+
+ @AfterEach
+ public void releaseMocks() throws Exception {
+ closeable.close();
+ }
+
+ @Test
+ public void testCreateDataTypes() {
+
+ DataTypeDefinition rootDataTypeDef = new DataTypeDefinition();
+ rootDataTypeDef.setName("tosca.datatypes.Root");
+ rootDataTypeDef.setProperties(Collections.emptyList());
+ DataTypeDefinition testADataTypeDef = new DataTypeDefinition();
+ testADataTypeDef.setName("tosca.datatypes.test_a");
+ testADataTypeDef.setProperties(Collections.emptyList());
+ DataTypeDefinition testCDataTypeDef = new DataTypeDefinition();
+ testCDataTypeDef.setName("tosca.datatypes.test_c");
+ testCDataTypeDef.setProperties(Collections.emptyList());
+ when(propertyOperation.getDataTypeByName("tosca.datatypes.Root", null)).thenReturn(Either.left(rootDataTypeDef));
+ when(propertyOperation.getDataTypeByName("tosca.datatypes.test_c", null)).thenReturn(Either.left(testCDataTypeDef));
+
+ when(propertyOperation.getJanusGraphGenericDao()).thenReturn(janusGraphGenericDao);
+ when(propertyOperation.getDataTypeByUidWithoutDerived("tosca.datatypes.Root.datatype", true)).thenReturn(Either.left(rootDataTypeDef));
+ when(propertyOperation.getDataTypeByUidWithoutDerived("tosca.datatypes.test_a.datatype", true))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(propertyOperation.getDataTypeByUidWithoutDerived("tosca.datatypes.test_b.datatype", true))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(propertyOperation.getDataTypeByUidWithoutDerived("tosca.datatypes.test_c.datatype", true))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(propertyOperation.addDataType(any())).thenReturn(Either.left(testADataTypeDef));
+
+ String dataTypeYml =
+ "tosca.datatypes.test_a:\n" +
+ " derived_from: tosca.datatypes.Root\n" +
+ " properties:\n" +
+ " prop2:\n" +
+ " type: tosca.datatypes.test_b\n" +
+ "tosca.datatypes.test_b:\n" +
+ " derived_from: tosca.datatypes.test_c\n" +
+ " properties:\n" +
+ " prop2:\n" +
+ " type: string\n" +
+ "tosca.datatypes.test_c:\n" +
+ " derived_from: tosca.datatypes.Root\n" +
+ " properties:\n" +
+ " prop1:\n" +
+ " type: string";
+ dataTypeImportManager.createDataTypes(dataTypeYml, "", false);
+
+ ArgumentCaptor<DataTypeDefinition> dataTypeDefinitionCaptor = ArgumentCaptor.forClass(DataTypeDefinition.class);
+ Mockito.verify(propertyOperation, times(3)).addDataType(dataTypeDefinitionCaptor.capture());
+
+ assertEquals("tosca.datatypes.test_c", dataTypeDefinitionCaptor.getAllValues().get(0).getName());
+ assertEquals("tosca.datatypes.test_b", dataTypeDefinitionCaptor.getAllValues().get(1).getName());
+ assertEquals("tosca.datatypes.test_a", dataTypeDefinitionCaptor.getAllValues().get(2).getName());
+ }
+
+
+}
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 ff47d75509..cee47ec984 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
@@ -64,6 +64,7 @@ import org.openecomp.sdc.be.components.ArtifactsResolver;
import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
+import org.openecomp.sdc.be.components.csar.OnboardedCsarInfo;
import org.openecomp.sdc.be.components.csar.YamlTemplateParsingHandler;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
@@ -387,7 +388,7 @@ class ResourceBusinessLogicTest {
nodeTypesArtifactsToHandle,
nodeTypesNewCreatedArtifacts,
nodeTypesInfo,
- new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name",
+ new OnboardedCsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name",
ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml"), true), "");
});
}
@@ -1876,7 +1877,7 @@ class ResourceBusinessLogicTest {
Resource resourceToUpdate = createResourceObject(false);
String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
- CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
+ CsarInfo csarInfo = new OnboardedCsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
true);
String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
.name(), csarInfo.getVfResourceName(), nodeName)
@@ -1914,7 +1915,7 @@ class ResourceBusinessLogicTest {
setCanWorkOnResource(resourceResponse);
String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
- CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
+ CsarInfo csarInfo = new OnboardedCsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
true);
String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
.name(), csarInfo.getVfResourceName(), nodeName)
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
index 1f45f77f3f..d40bac1585 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
@@ -19,21 +19,28 @@ package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyList;
import static org.mockito.Mockito.anyMap;
-import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.contains;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.matches;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.isNull;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.openecomp.sdc.be.components.impl.ServiceImportBusinessLogic.CREATE_RESOURCE;
import fj.data.Either;
+import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.net.URISyntaxException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -43,6 +50,7 @@ import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.map.HashedMap;
@@ -50,9 +58,11 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.csar.CsarInfo;
+import org.openecomp.sdc.be.components.csar.ServiceCsarInfo;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter;
@@ -96,6 +106,7 @@ import org.openecomp.sdc.be.model.UploadPropInfo;
import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.UploadResourceInfo;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
@@ -104,7 +115,10 @@ import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.zip.ZipUtils;
+import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.yaml.snakeyaml.Yaml;
class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTestSetup {
@@ -115,6 +129,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
private final ServletUtils servletUtils = mock(ServletUtils.class);
private final AbstractValidationsServlet servlet = new ArtifactExternalServlet(userBusinessLogic,
componentInstanceBusinessLogic, componentsUtils, servletUtils, resourceImportManager, artifactsBusinessLogic);
+ private final ApplicationDataTypeCache applicationDataTypeCache = mock(ApplicationDataTypeCache.class);
+ private final DataTypeBusinessLogic dataTypeBusinessLogic = mock(DataTypeBusinessLogic.class);
+
@InjectMocks
private ServiceImportBusinessLogic sIBL;
@@ -148,7 +165,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceBusinessLogic.validateServiceBeforeCreate(eq(newService), any(User.class), any(AuditingActionEnum.class)))
.thenReturn(Either.left(newService));
when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK);
- CsarInfo csarInfo = getCsarInfo();
+ ServiceCsarInfo csarInfo = getCsarInfo();
when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString())).thenReturn(csarInfo);
when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class)))
.thenReturn(Either.left(new HashMap<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>>()));
@@ -183,7 +200,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
when(graphLockOperation.unlockComponentByName(anyString(), anyString(), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
when(serviceImportParseLogic.createOutputsOnService(any(Service.class), any(), anyString())).thenReturn(newService);
-
+
+ when(applicationDataTypeCache.get(any(), contains("tosca.datatypes.test_"))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ when(applicationDataTypeCache.get(any(), matches("^((?!tosca.datatypes.test_).)*$"))).thenReturn(Either.left(new DataTypeDefinition()));
+
Service result = sIBL.createService(oldService, AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName);
assertNotNull(result);
assertNotNull(result.getComponentInstances());
@@ -195,6 +215,13 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
assertEquals(1, result.getComponentInstances().get(0).getRequirements().size());
assertNotNull(result.getCategories());
assertEquals(1, result.getCategories().size());
+
+ ArgumentCaptor<String> yaml = ArgumentCaptor.forClass(String.class);
+ verify(dataTypeBusinessLogic).createDataTypeFromYaml(yaml.capture(), isNull(), anyBoolean());
+ Map<String, Object> yamlMap = new Yaml().load(yaml.getValue());
+ assertEquals(2, yamlMap.size());
+ assertNotNull(yamlMap.get("tosca.datatypes.test_a"));
+ assertNotNull(yamlMap.get("tosca.datatypes.test_b"));
}
@Test
@@ -222,7 +249,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Service oldService = createServiceObject(true);
String csarUUID = "valid_vf";
Map<String, byte[]> payload = crateCsarFromPayload();
- CsarInfo csarInfo = getCsarInfo();
+ ServiceCsarInfo csarInfo = getCsarInfo();
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> map =
new HashedMap();
@@ -240,7 +267,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource resource = createOldResource();
String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml");
String yamlName = "group.yml";
- CsarInfo csarInfo = getCsarInfo();
+ ServiceCsarInfo csarInfo = getCsarInfo();
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
@@ -2342,14 +2369,28 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
return mainTemplateContent;
}
- protected CsarInfo getCsarInfo() {
+ protected ServiceCsarInfo getCsarInfo() {
String csarUuid = "0010";
User user = new User("jh0003");
- Map<String, byte[]> csar = crateCsarFromPayload();
- String vfReousrceName = "resouceName";
- String mainTemplateName = "mainTemplateName";
- String mainTemplateContent = getMainTemplateContent("service_import_template.yml");
- return new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
+
+ try {
+ File csarFile = new File(
+ ServiceImportBusinessLogicTest.class.getClassLoader().getResource("csars/service-Ser09080002-csar.csar").toURI());
+ Map<String, byte[]> csar = ZipUtils.readZip(csarFile, false);
+
+ String vfReousrceName = "resouceName";
+ String mainTemplateName = "Definitions/service_import_template.yml";
+
+ Optional<String> keyOp = csar.keySet().stream().filter(k -> k.endsWith("service-Ser09080002-template.yml")).findAny();
+ byte[] mainTemplateService = keyOp.map(csar::get).orElse(null);
+ assertNotNull(mainTemplateService);
+ final String mainTemplateContent = new String(mainTemplateService);
+
+ return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
+ } catch (URISyntaxException | ZipException e) {
+ fail(e);
+ }
+ return null;
}
protected CsarUtils.NonMetaArtifactInfo getNonMetaArtifactInfo() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
index c8fd87ca3b..06594dc180 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
@@ -44,6 +44,7 @@ import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
+import org.openecomp.sdc.be.components.csar.OnboardedCsarInfo;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter;
import org.openecomp.sdc.be.components.validation.UserValidations;
@@ -673,7 +674,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
String mainTemplateName = "mainTemplateName";
String mainTemplateContent = getMainTemplateContent();
final Service service = createServiceObject(false);
- CsarInfo csarInfo = new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
+ CsarInfo csarInfo = new OnboardedCsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
return csarInfo;
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
index c564f59398..b3154efe62 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyMap;
@@ -33,7 +34,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import fj.data.Either;
+import java.io.File;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.ArrayList;
@@ -44,6 +47,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
+import java.util.Optional;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.glassfish.grizzly.http.util.HttpStatus;
@@ -54,6 +58,7 @@ import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
import org.openecomp.sdc.be.components.csar.CsarInfo;
+import org.openecomp.sdc.be.components.csar.ServiceCsarInfo;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
@@ -103,16 +108,14 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.zip.ZipUtils;
+import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.exception.ResponseFormat;
class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSetup {
private static final String RESOURCE_NAME = "My-Resource_Name with space";
private static final String RESOURCE_TOSCA_NAME = "My-Resource_Tosca_Name";
- private static final String GENERIC_ROOT_NAME = "tosca.nodes.Root";
- private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
- private static final String GENERIC_CR_NAME = "org.openecomp.resource.abstract.nodes.CR";
- private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
private static final String RESOURCE_SUBCATEGORY = "Router";
@@ -2074,16 +2077,25 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
protected CsarInfo getCsarInfo() {
String csarUuid = "0010";
User user = new User();
- Map<String, byte[]> csar = new HashMap<>();
- String vfReousrceName = "resouceName";
- String mainTemplateName = "mainTemplateName";
- String mainTemplateContent = null;
+ File csarFile;
try {
- mainTemplateContent = loadFileNameToJsonString("service_import_template.yml");
- } catch (IOException e) {
- e.printStackTrace();
+ csarFile = new File(
+ ServiceImportBusinessLogicTest.class.getClassLoader().getResource("csars/service-Ser09080002-csar.csar").toURI());
+ Map<String, byte[]> csar = ZipUtils.readZip(csarFile, false);
+
+ String vfReousrceName = "resouceName";
+ String mainTemplateName = "Definitions/service_import_template.yml";
+
+ Optional<String> keyOp = csar.keySet().stream().filter(k -> k.endsWith("service-Ser09080002-template.yml")).findAny();
+ byte[] mainTemplateService = keyOp.map(csar::get).orElse(null);
+ assertNotNull(mainTemplateService);
+ final String mainTemplateContent = new String(mainTemplateService);
+
+ return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
+ } catch (URISyntaxException | ZipException e) {
+ fail(e);
}
- return new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
+ return null;
}
private String loadFileNameToJsonString(String fileName) throws IOException {