aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorLiang Ding <liang.ding@intel.com>2019-04-15 00:05:05 -0700
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-10-30 07:56:21 +0000
commit8ff60789e080dd99c604d31a6e754be164fba11e (patch)
treebae4286ab2b19a0d0a3a6ebedd57e17aa42dceea /catalog-be/src/test/java
parentc42c9f75adb72f80e57694b5bf67db7c94f33a89 (diff)
add artifacts support in TOSCA exported yml file
Change-Id: I56f8a6a1ce758876e83a7ee8318b79644ae7d5cb Issue-ID: SDC-1952 Signed-off-by: Liang Ding <liang.ding@intel.com>
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java80
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java17
2 files changed, 97 insertions, 0 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
index 347c95217d..19d1a17e84 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.be.components.impl.utils;
+import mockit.Deencapsulation;
+import org.apache.commons.collections.MapUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.eq;
@@ -31,10 +33,12 @@ import java.util.*;
import java.util.stream.Collectors;
import org.assertj.core.util.Lists;
+import org.junit.Assert;
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.junit.MockitoJUnitRunner;
@@ -49,6 +53,14 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.*;
@RunWith(MockitoJUnitRunner.class)
public class YamlTemplateParsingHandlerTest {
@@ -87,6 +99,9 @@ public class YamlTemplateParsingHandlerTest {
private static final String MAIN_GROUP_NAME = "x_group";
private static final String NESTED_GROUP_NAME = "nested_mg_vepdg_group";
+ @InjectMocks
+ YamlTemplateParsingHandler testSubject;
+
@BeforeClass()
public static void prepareData() throws IOException, URISyntaxException {
csar = ZipUtil.readData(CSAR_FILE_PATH);
@@ -249,4 +264,69 @@ public class YamlTemplateParsingHandlerTest {
return property;
}
+ @Test
+ public void testSetArtifacts() throws Exception {
+ UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
+ Map<String, Object> nodeTemplateJsonMap = new HashMap<>();
+ Map<String, String> nodeMap = new HashMap<>();
+ nodeMap.put("name","test_name");
+ nodeMap.put("type","test_type");
+ nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), nodeMap);
+ Deencapsulation.invoke(testSubject, "setArtifacts", nodeTemplateInfo, nodeTemplateJsonMap);
+ Assert.assertTrue(nodeTemplateInfo.getArtifacts() != null);
+ }
+
+ @Test
+ public void testCreateArtifactsModuleFromYaml() throws Exception {
+ Map<String, Map<String, Map<String, String>>> nodeTemplateJsonMap = new HashMap<>();
+ Map<String, Map<String,String>> map0 = new HashMap<>();
+ Map<String, String> map1 = new HashMap<>();
+ map1.put("file", "test_file");
+ map1.put("type", "test_type");
+ map0.put("test_art", map1);
+ nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), map0);
+ Map<String, Map<String, UploadArtifactInfo>> result;
+ result = Deencapsulation.invoke(testSubject, "createArtifactsModuleFromYaml", nodeTemplateJsonMap);
+ Assert.assertTrue(MapUtils.isNotEmpty(result));
+ Assert.assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
+ Assert.assertTrue(result.get(ARTIFACTS.getElementName()).get("test_art").getFile().equals("test_file"));
+ Assert.assertTrue(result.get(ARTIFACTS.getElementName()).get("test_art").getType().equals("test_type"));
+ }
+
+ @Test
+ public void testAddModuleNodeTemplateArtifacts() throws Exception {
+ Map<String, Map<String, UploadArtifactInfo>> result = new HashMap<>();
+ Map<String, String> map1 = new HashMap<>();
+ map1.put("file", "test_file");
+ map1.put("type", "test_type");
+ Deencapsulation.invoke(testSubject, "addModuleNodeTemplateArtifacts", result, map1, "test_art");
+ Assert.assertTrue(MapUtils.isNotEmpty(result));
+ Assert.assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
+ Assert.assertTrue(result.get(ARTIFACTS.getElementName()).get("test_art").getFile().equals("test_file"));
+ Assert.assertTrue(result.get(ARTIFACTS.getElementName()).get("test_art").getType().equals("test_type"));
+ }
+
+ @Test
+ public void testBuildModuleNodeTemplateArtifact() throws Exception {
+ Map<String, String> map1 = new HashMap<>();
+ map1.put("file", "test_file");
+ map1.put("type", "test_type");
+ UploadArtifactInfo result;
+ result = Deencapsulation.invoke(testSubject, "buildModuleNodeTemplateArtifact", map1);
+ Assert.assertTrue(result != null);
+ Assert.assertTrue(result.getFile().equals("test_file"));
+ Assert.assertTrue(result.getType().equals("test_type"));
+ }
+
+ @Test
+ public void testFillArtifact() throws Exception {
+ Map<String, String> map1 = new HashMap<>();
+ map1.put("file", "test_file");
+ map1.put("type", "test_type");
+ UploadArtifactInfo result = new UploadArtifactInfo();
+ Deencapsulation.invoke(testSubject, "fillArtifact", result, map1);
+ Assert.assertTrue(result != null);
+ Assert.assertTrue(result.getFile().equals("test_file"));
+ Assert.assertTrue(result.getType().equals("test_type"));
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
index f319643fd6..5521f8683b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
@@ -29,6 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import mockit.Deencapsulation;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Triple;
import org.junit.Assert;
@@ -47,6 +48,7 @@ import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefiniti
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
@@ -81,6 +83,7 @@ import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateArtifact;
import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
import org.openecomp.sdc.be.tosca.utils.InputConverter;
@@ -1349,4 +1352,18 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
// default test
result = Deencapsulation.invoke(testSubject, "convertCapabilities", component, nodeType, dataTypes);
}
+
+ @Test
+ public void testConvertToNodeTemplateArtifacts() throws Exception {
+ Map<String, ToscaArtifactDataDefinition> container = new HashMap<>();
+ ToscaArtifactDataDefinition art = new ToscaArtifactDataDefinition();
+ art.setFile("test_file");
+ art.setType("test_type");
+ Map<String, ToscaTemplateArtifact> result;
+ container.put("test_art", art);
+ result = Deencapsulation.invoke(testSubject, "convertToNodeTemplateArtifacts", container);
+ Assert.assertTrue(MapUtils.isNotEmpty(result));
+ Assert.assertTrue(result.get("test_art").getFile().equals("test_file"));
+ Assert.assertTrue(result.get("test_art").getType().equals("test_type"));
+ }
}