From 0f6ae59460165381a8b5da2eea58c2c2efa75f2f Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Mon, 25 Jul 2022 23:01:50 +0100 Subject: Support unknown data types in service import Signed-off-by: MichaelMorris Issue-ID: SDC-4119 Change-Id: I426ebb96e7b354dfd5dfb06a10845c3162055968 --- .../sdc/be/components/csar/CsarInfoTest.java | 197 --------------------- .../be/components/csar/OnboardedCsarInfoTest.java | 197 +++++++++++++++++++++ .../be/components/csar/ServiceCsarInfoTest.java | 81 +++++++++ .../csar/YamlTemplateParsingHandlerTest.java | 6 +- .../impl/DataTypesImportManagerTest.java | 121 +++++++++++++ .../components/impl/ResourceBusinessLogicTest.java | 7 +- .../impl/ServiceImportBusinessLogicTest.java | 63 +++++-- .../ServiceImportBussinessLogicBaseTestSetup.java | 3 +- .../impl/ServiceImportParseLogicTest.java | 36 ++-- 9 files changed, 484 insertions(+), 227 deletions(-) delete mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfoTest.java create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypesImportManagerTest.java (limited to 'catalog-be/src/test/java/org/openecomp') 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/CsarInfoTest.java deleted file mode 100644 index 07a8ded378..0000000000 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/*- - * ============LICENSE_START=============================================== - * ONAP SDC - * ======================================================================== - * Copyright (C) 2019 Samsung. 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.csar; - -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.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; -import org.openecomp.sdc.be.config.ConfigurationManager; -import org.openecomp.sdc.be.config.NonManoArtifactType; -import org.openecomp.sdc.be.config.NonManoConfiguration; -import org.openecomp.sdc.be.config.NonManoFolderType; -import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.model.NodeTypeInfo; -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; -import com.datastax.oss.driver.shaded.guava.common.collect.Lists; -import java.io.File; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -public class CsarInfoTest { - - private CsarInfo csarInfo; - - @Mock - private User user; - - private static final String CSAR_UUID = "csarUUID"; - private static final String PAYLOAD_NAME = "mock_service.csar"; - private static final String RESOURCE_NAME = "resourceName"; - private static final String MAIN_TEMPLATE_NAME = "Definitions/tosca_mock_vf.yaml"; - private static final String NEW_NODE_NAME = "new_db"; - private static final String NODE_TYPE = "tosca.nodes.Compute"; - private static final String DELIVER_FOR = "tosca.nodes.Root"; - - @BeforeEach - public void setup() throws ZipException, URISyntaxException { - // given - csarInfo = createCsarInfo(PAYLOAD_NAME, MAIN_TEMPLATE_NAME); - - 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()); - final Map payload = ZipUtils.readZip(csarFile, false); - String mainTemplateContent = new String(payload.get(mainTemplateName)); - - return new CsarInfo(user, CSAR_UUID, payload, RESOURCE_NAME, - mainTemplateName, mainTemplateContent, true); - } - - @Test - public void add2TimesTheSameNodeTest() { - - try { - // when - csarInfo.addNodeToQueue(NEW_NODE_NAME); - csarInfo.addNodeToQueue(NEW_NODE_NAME); - fail("AddNodeToQueue not throw the exception!"); - } catch (ByActionStatusComponentException e) { - List expectParam = Arrays.asList(NEW_NODE_NAME, RESOURCE_NAME); - - // then - assertEquals(ActionStatus.CFVC_LOOP_DETECTED, e.getActionStatus()); - assertTrue(Arrays.stream(e.getParams()).allMatch(expectParam::contains)); - } - } - - @Test - public void addMultipleTimesNodeTest() { - - // when - csarInfo.addNodeToQueue(NEW_NODE_NAME); - csarInfo.removeNodeFromQueue(); - csarInfo.addNodeToQueue(NEW_NODE_NAME); - } - - @Test - public void setUpdateTest() { - - csarInfo.setUpdate(true); - assertTrue(csarInfo.isUpdate()); - - csarInfo.setUpdate(false); - assertFalse(csarInfo.isUpdate()); - } - - @Test - public void csarCheckTypesInfoTest() { - - // when - Map nodeTypeInfoMap = csarInfo.extractTypesInfo(); - NodeTypeInfo nodeTypeInfo = nodeTypeInfoMap.get(NODE_TYPE); - - // then - assertNotNull(nodeTypeInfo); - assertTrue(nodeTypeInfo.getDerivedFrom().contains(DELIVER_FOR)); - assertEquals(NODE_TYPE, nodeTypeInfo.getType()); - - assertEquals(MAIN_TEMPLATE_NAME, csarInfo.getMainTemplateName()); - assertEquals(csarInfo.getMainTemplateName(), nodeTypeInfo.getTemplateFileName()); - - Map dataTypes = csarInfo.getDataTypes(); - assertTrue(dataTypes.containsKey("tosca.datatypes.testDataType.FromMainTemplate")); - assertTrue(dataTypes.containsKey("tosca.datatypes.testDataType.FromGlobalSub")); - } - - @Test - public void getSoftwareInformationPathTest() { - final NonManoConfiguration nonManoConfigurationMock = Mockito.mock(NonManoConfiguration.class); - final CsarInfo csarInfo = new CsarInfo(nonManoConfigurationMock); - final NonManoFolderType testNonManoFolderType = new NonManoFolderType(); - testNonManoFolderType.setLocation("sw-location-test"); - testNonManoFolderType.setType("informational-test"); - when(nonManoConfigurationMock.getNonManoType(NonManoArtifactType.ONAP_SW_INFORMATION)).thenReturn(testNonManoFolderType); - final Map csarFileMap = new HashMap<>(); - final String expectedPath = testNonManoFolderType.getPath() + "/" + "software-file.yaml"; - csarFileMap.put(expectedPath, new byte[0]); - csarInfo.setCsar(csarFileMap); - final Optional softwareInformationPath = csarInfo.getSoftwareInformationPath(); - assertThat("The software information yaml path should be present", softwareInformationPath.isPresent(), is(true)); - softwareInformationPath.ifPresent(path -> { - assertThat("The software information yaml ", path, is(equalTo(expectedPath))); - }); - } - - @Test - public void getSoftwareInformationPathTest_emptyCsar() { - csarInfo.setCsar(new HashMap<>()); - final Optional softwareInformationPath = csarInfo.getSoftwareInformationPath(); - assertThat("The software information yaml path should not be present", softwareInformationPath.isPresent(), is(false)); - } - - @SuppressWarnings("unchecked") - @Test - public void testCreateCsarInfoEtsiVnf() throws URISyntaxException, ZipException { - final CsarInfo csarInfo = createCsarInfo("etsi_vnf.csar", "Definitions/MainServiceTemplate.yaml"); - - final String nodeTypeInSubstitutionMapping = (String) ((Map)((Map)csarInfo.getMappedToscaMainTemplate().get("topology_template")).get("substitution_mappings")).get("node_type"); - assertTrue(((Map) csarInfo.getMappedToscaMainTemplate().get("node_types")).containsKey(nodeTypeInSubstitutionMapping)); - - assertTrue(csarInfo.extractTypesInfo().isEmpty()); - } - - @Test - public void testCreateCsarInfoVnfWithNodeTypeInGlobalSub() throws URISyntaxException, ZipException { - final CsarInfo csarInfo = createCsarInfo("nodeTypeInGlobalSub.csar", "Definitions/MainServiceTemplate.yaml"); - - assertEquals(1, csarInfo.extractTypesInfo().size()); - final NodeTypeInfo nodeTypeInfo = csarInfo.extractTypesInfo().get("tosca.nodes.l3vpn"); - assertNotNull(nodeTypeInfo); - assertEquals("Definitions/GlobalSubstitutionTypesServiceTemplate.yaml", nodeTypeInfo.getTemplateFileName()); - assertEquals("tosca.nodes.l3vpn", nodeTypeInfo.getType()); - assertEquals(Lists.newArrayList("tosca.nodes.Root"), nodeTypeInfo.getDerivedFrom()); - } -} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfoTest.java new file mode 100644 index 0000000000..abdf153155 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfoTest.java @@ -0,0 +1,197 @@ +/*- + * ============LICENSE_START=============================================== + * ONAP SDC + * ======================================================================== + * Copyright (C) 2019 Samsung. 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.csar; + +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.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.config.NonManoArtifactType; +import org.openecomp.sdc.be.config.NonManoConfiguration; +import org.openecomp.sdc.be.config.NonManoFolderType; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.model.NodeTypeInfo; +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; +import com.datastax.oss.driver.shaded.guava.common.collect.Lists; +import java.io.File; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +public class OnboardedCsarInfoTest { + + private OnboardedCsarInfo csarInfo; + + @Mock + private User user; + + private static final String CSAR_UUID = "csarUUID"; + private static final String PAYLOAD_NAME = "mock_service.csar"; + private static final String RESOURCE_NAME = "resourceName"; + private static final String MAIN_TEMPLATE_NAME = "Definitions/tosca_mock_vf.yaml"; + private static final String NEW_NODE_NAME = "new_db"; + private static final String NODE_TYPE = "tosca.nodes.Compute"; + private static final String DELIVER_FOR = "tosca.nodes.Root"; + + @BeforeEach + public void setup() throws ZipException, URISyntaxException { + // given + csarInfo = createCsarInfo(PAYLOAD_NAME, MAIN_TEMPLATE_NAME); + + new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be")); + } + + 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 payload = ZipUtils.readZip(csarFile, false); + String mainTemplateContent = new String(payload.get(mainTemplateName)); + + return new OnboardedCsarInfo(user, CSAR_UUID, payload, RESOURCE_NAME, + mainTemplateName, mainTemplateContent, true); + } + + @Test + public void add2TimesTheSameNodeTest() { + + try { + // when + csarInfo.addNodeToQueue(NEW_NODE_NAME); + csarInfo.addNodeToQueue(NEW_NODE_NAME); + fail("AddNodeToQueue not throw the exception!"); + } catch (ByActionStatusComponentException e) { + List expectParam = Arrays.asList(NEW_NODE_NAME, RESOURCE_NAME); + + // then + assertEquals(ActionStatus.CFVC_LOOP_DETECTED, e.getActionStatus()); + assertTrue(Arrays.stream(e.getParams()).allMatch(expectParam::contains)); + } + } + + @Test + public void addMultipleTimesNodeTest() { + + // when + csarInfo.addNodeToQueue(NEW_NODE_NAME); + csarInfo.removeNodeFromQueue(); + csarInfo.addNodeToQueue(NEW_NODE_NAME); + } + + @Test + public void setUpdateTest() { + + csarInfo.setUpdate(true); + assertTrue(csarInfo.isUpdate()); + + csarInfo.setUpdate(false); + assertFalse(csarInfo.isUpdate()); + } + + @Test + public void csarCheckTypesInfoTest() { + + // when + Map nodeTypeInfoMap = csarInfo.extractTypesInfo(); + NodeTypeInfo nodeTypeInfo = nodeTypeInfoMap.get(NODE_TYPE); + + // then + assertNotNull(nodeTypeInfo); + assertTrue(nodeTypeInfo.getDerivedFrom().contains(DELIVER_FOR)); + assertEquals(NODE_TYPE, nodeTypeInfo.getType()); + + assertEquals(MAIN_TEMPLATE_NAME, csarInfo.getMainTemplateName()); + assertEquals(csarInfo.getMainTemplateName(), nodeTypeInfo.getTemplateFileName()); + + Map dataTypes = csarInfo.getDataTypes(); + assertTrue(dataTypes.containsKey("tosca.datatypes.testDataType.FromMainTemplate")); + assertTrue(dataTypes.containsKey("tosca.datatypes.testDataType.FromGlobalSub")); + } + + @Test + public void getSoftwareInformationPathTest() { + final NonManoConfiguration nonManoConfigurationMock = Mockito.mock(NonManoConfiguration.class); + final CsarInfo csarInfo = new OnboardedCsarInfo(nonManoConfigurationMock); + final NonManoFolderType testNonManoFolderType = new NonManoFolderType(); + testNonManoFolderType.setLocation("sw-location-test"); + testNonManoFolderType.setType("informational-test"); + when(nonManoConfigurationMock.getNonManoType(NonManoArtifactType.ONAP_SW_INFORMATION)).thenReturn(testNonManoFolderType); + final Map csarFileMap = new HashMap<>(); + final String expectedPath = testNonManoFolderType.getPath() + "/" + "software-file.yaml"; + csarFileMap.put(expectedPath, new byte[0]); + csarInfo.setCsar(csarFileMap); + final Optional softwareInformationPath = csarInfo.getSoftwareInformationPath(); + assertThat("The software information yaml path should be present", softwareInformationPath.isPresent(), is(true)); + softwareInformationPath.ifPresent(path -> { + assertThat("The software information yaml ", path, is(equalTo(expectedPath))); + }); + } + + @Test + public void getSoftwareInformationPathTest_emptyCsar() { + csarInfo.setCsar(new HashMap<>()); + final Optional softwareInformationPath = csarInfo.getSoftwareInformationPath(); + assertThat("The software information yaml path should not be present", softwareInformationPath.isPresent(), is(false)); + } + + @SuppressWarnings("unchecked") + @Test + public void testCreateCsarInfoEtsiVnf() throws URISyntaxException, ZipException { + final CsarInfo csarInfo = createCsarInfo("etsi_vnf.csar", "Definitions/MainServiceTemplate.yaml"); + + final String nodeTypeInSubstitutionMapping = (String) ((Map)((Map)csarInfo.getMappedToscaMainTemplate().get("topology_template")).get("substitution_mappings")).get("node_type"); + assertTrue(((Map) csarInfo.getMappedToscaMainTemplate().get("node_types")).containsKey(nodeTypeInSubstitutionMapping)); + + assertTrue(csarInfo.extractTypesInfo().isEmpty()); + } + + @Test + public void testCreateCsarInfoVnfWithNodeTypeInGlobalSub() throws URISyntaxException, ZipException { + final CsarInfo csarInfo = createCsarInfo("nodeTypeInGlobalSub.csar", "Definitions/MainServiceTemplate.yaml"); + + assertEquals(1, csarInfo.extractTypesInfo().size()); + final NodeTypeInfo nodeTypeInfo = csarInfo.extractTypesInfo().get("tosca.nodes.l3vpn"); + assertNotNull(nodeTypeInfo); + assertEquals("Definitions/GlobalSubstitutionTypesServiceTemplate.yaml", nodeTypeInfo.getTemplateFileName()); + assertEquals("tosca.nodes.l3vpn", nodeTypeInfo.getType()); + assertEquals(Lists.newArrayList("tosca.nodes.Root"), nodeTypeInfo.getDerivedFrom()); + } +} 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 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 dataTypes = csarInfo.getDataTypes(); + assertEquals(184, dataTypes.size()); + final Map dataTypeDefinition = (Map) dataTypes.get("tosca.datatypes.test_g"); + assertNotNull(dataTypeDefinition); + assertEquals("tosca.datatypes.Root", dataTypeDefinition.get("derived_from")); + assertEquals("tosca.datatypes.test_h", + ((Map) ((Map) 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 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>>())); @@ -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 yaml = ArgumentCaptor.forClass(String.class); + verify(dataTypeBusinessLogic).createDataTypeFromYaml(yaml.capture(), isNull(), anyBoolean()); + Map 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 payload = crateCsarFromPayload(); - CsarInfo csarInfo = getCsarInfo(); + ServiceCsarInfo csarInfo = getCsarInfo(); Map>> 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>> 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 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 csar = ZipUtils.readZip(csarFile, false); + + String vfReousrceName = "resouceName"; + String mainTemplateName = "Definitions/service_import_template.yml"; + + Optional 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 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 csar = ZipUtils.readZip(csarFile, false); + + String vfReousrceName = "resouceName"; + String mainTemplateName = "Definitions/service_import_template.yml"; + + Optional 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 { -- cgit 1.2.3-korg