summaryrefslogtreecommitdiffstats
path: root/jtosca/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'jtosca/src/test')
-rw-r--r--jtosca/src/test/java/org/onap/sdc/toscaparser/api/GetValidationIssues.java100
-rw-r--r--jtosca/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java309
-rw-r--r--jtosca/src/test/java/org/onap/sdc/toscaparser/api/JToscaMetadataParse.java127
-rw-r--r--jtosca/src/test/java/org/onap/sdc/toscaparser/api/elements/CalculatePropertyByPathTest.java167
-rw-r--r--jtosca/src/test/java/org/onap/sdc/toscaparser/api/elements/EntityTypeTest.java75
-rw-r--r--jtosca/src/test/java/org/onap/sdc/toscaparser/api/functions/GetInputTest.java96
-rw-r--r--jtosca/src/test/resources/csars/csar_hello_world.csarbin0 -> 936 bytes
-rw-r--r--jtosca/src/test/resources/csars/dataTypes-test-service.csarbin0 -> 46307 bytes
-rw-r--r--jtosca/src/test/resources/csars/emptyCsar.csarbin0 -> 22 bytes
-rw-r--r--jtosca/src/test/resources/csars/listed_input.csarbin0 -> 46229 bytes
-rw-r--r--jtosca/src/test/resources/csars/listed_input_ng.csarbin0 -> 46232 bytes
-rw-r--r--jtosca/src/test/resources/csars/resource-Spgw-csar-ZTE.csarbin0 -> 31639 bytes
-rw-r--r--jtosca/src/test/resources/csars/sdc-onboarding_csar.csarbin0 -> 79654 bytes
-rw-r--r--jtosca/src/test/resources/csars/service-AdiodVmxVpeBvService-csar.csarbin0 -> 117439 bytes
-rw-r--r--jtosca/src/test/resources/csars/service-JennyVtsbcKarunaSvc-csar.csarbin0 -> 145576 bytes
-rw-r--r--jtosca/src/test/resources/csars/service-NetworkCloudVnfServiceMock-csar.csarbin0 -> 60223 bytes
-rw-r--r--jtosca/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csarbin0 -> 45116 bytes
-rw-r--r--jtosca/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_without_required_inputs.csarbin0 -> 43627 bytes
18 files changed, 874 insertions, 0 deletions
diff --git a/jtosca/src/test/java/org/onap/sdc/toscaparser/api/GetValidationIssues.java b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/GetValidationIssues.java
new file mode 100644
index 0000000..140a6e9
--- /dev/null
+++ b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/GetValidationIssues.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.sdc.toscaparser.api;
+
+import com.opencsv.CSVWriter;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+
+//Generate excel file, include all validation issues errors in jtosca
+//the error java code, the line number and file name for each error.
+public class GetValidationIssues {
+
+ public static CSVWriter fileWriter = null;
+ public static List<String[]> data = new ArrayList<>();
+
+ public static void main(String[] args) {
+ System.out.println("GetAllValidationIssues - path to project files Directory is " + Arrays.toString(args));
+ File jtoscaFiles = new File(args[0] + "\\jtosca\\src\\main\\java\\org\\onap\\sdc\\toscaparser\\api");
+
+ try {
+ printFiles(jtoscaFiles);
+ fileWriter = new CSVWriter(new FileWriter(args[1] + "\\JToscaValidationIssues_" + System.currentTimeMillis() + ".csv"), '\t');
+ fileWriter.writeNext(new String[]{"Error Message", "Class Name", "Line No."}, false);
+ fileWriter.writeAll(data, false);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ fileWriter.flush();
+ fileWriter.close();
+ } catch (IOException e) {
+ System.out.println("Error while flushing/closing fileWriter !!!");
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static void printFiles(File dir) {
+ if (dir != null && dir.exists()) {
+ for (File file : dir.listFiles()) {
+ if (file.isDirectory())
+ printFiles(file);
+ else {
+ Scanner scanner = null;
+ try {
+ scanner = new Scanner(file);
+
+ int lineNum = 0;
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ lineNum++;
+ if (line.startsWith("/*python"))
+ break;
+
+ if (!line.trim().startsWith("//") && !line.trim().startsWith("#") && line.contains("ThreadLocalsHolder.getCollector().appendValidationIssue")) {
+ String errMsg = line.trim();
+ if (!errMsg.contains(";")) {
+ String nextLine = null;
+ while (scanner.hasNextLine() && (nextLine == null || !nextLine.contains(";"))) {
+ nextLine = scanner.nextLine();
+ errMsg += nextLine.trim();
+ }
+ }
+
+ data.add(new String[]{errMsg, file.getName(), String.valueOf(lineNum)});
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+}
+
diff --git a/jtosca/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
new file mode 100644
index 0000000..5876ac7
--- /dev/null
+++ b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
@@ -0,0 +1,309 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2017 AT&T Intellectual Property.
+ * ================================================================================
+ * 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=========================================================
+ * Modifications copyright (c) 2019 Fujitsu Limited.
+ * ================================================================================
+ */
+package org.onap.sdc.toscaparser.api;
+
+import org.junit.Test;
+import org.onap.sdc.toscaparser.api.common.JToscaException;
+import org.onap.sdc.toscaparser.api.elements.DataType;
+import org.onap.sdc.toscaparser.api.elements.PropertyDef;
+import org.onap.sdc.toscaparser.api.elements.constraints.Schema;
+import org.onap.sdc.toscaparser.api.parameters.Annotation;
+import org.onap.sdc.toscaparser.api.parameters.Input;
+import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder;
+
+import java.io.File;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.*;
+
+public class JToscaImportTest {
+
+ @Test
+ public void testNoMissingTypeValidationError() throws JToscaException {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/sdc-onboarding_csar.csar")
+ .getFile();
+ File file = new File(fileStr);
+ new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ List<String> missingTypeErrors = ThreadLocalsHolder.getCollector().getValidationIssueReport().stream()
+ .filter(s -> s.contains("JE136")).collect(Collectors.toList());
+ assertEquals(0, missingTypeErrors.size());
+ }
+
+ @Test
+ public void testNoStackOverFlowError() {
+ Exception jte = null;
+ try {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/sdc-onboarding_csar.csar")
+ .getFile();
+ File file = new File(fileStr);
+ new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ } catch (Exception e) {
+ jte = e;
+ }
+ assertEquals(null, jte);
+ }
+
+ @Test
+ public void testNoInvalidImports() throws JToscaException {
+ List<String> fileNames = new ArrayList<>();
+ fileNames.add("csars/tmpCSAR_Huawei_vSPGW_fixed.csar");
+ fileNames.add("csars/sdc-onboarding_csar.csar");
+ fileNames.add("csars/resource-Spgw-csar-ZTE.csar");
+
+ for (String fileName : fileNames) {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource(fileName).getFile();
+ File file = new File(fileStr);
+ new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ List<String> invalidImportErrors = ThreadLocalsHolder.getCollector().getValidationIssueReport().stream()
+ .filter(s -> s.contains("JE195")).collect(Collectors.toList());
+ assertEquals(0, invalidImportErrors.size());
+ }
+ }
+
+ @Test
+ public void testParseAnnotations() throws JToscaException {
+
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-AdiodVmxVpeBvService-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+
+ List<Input> inputs = toscaTemplate.getInputs();
+ assertNotNull(inputs);
+ assertTrue(inputs.stream().filter(i -> i.getAnnotations() != null).collect(Collectors.toList()).isEmpty());
+
+ inputs.forEach(Input::parseAnnotations);
+ assertTrue(!inputs.stream().filter(i -> i.getAnnotations() != null).collect(Collectors.toList()).isEmpty());
+ }
+
+ @Test
+ public void testGetInputsWithAndWithoutAnnotations() throws JToscaException {
+
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-AdiodVmxVpeBvService-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ List<Input> inputs = toscaTemplate.getInputs();
+ assertNotNull(inputs);
+ assertTrue(inputs.stream().filter(i -> i.getAnnotations() != null).collect(Collectors.toList()).isEmpty());
+
+ inputs = toscaTemplate.getInputs(true);
+ assertNotNull(inputs);
+ validateInputsAnnotations(inputs);
+
+ inputs = toscaTemplate.getInputs(false);
+ assertNotNull(inputs);
+ assertTrue(inputs.stream().filter(i -> i.getAnnotations() != null).collect(Collectors.toList()).isEmpty());
+ }
+
+ @Test
+ public void testGetPropertyNameTest() throws JToscaException {
+
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-AdiodVmxVpeBvService-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ NodeTemplate nodeTemplate = toscaTemplate.getNodeTemplates().get(0);
+
+ ArrayList<String> valueList = (ArrayList<String>) nodeTemplate.getPropertyValueFromTemplatesByName("vmxvpfe_sriov41_0_port_vlanfilter");
+ assertEquals(4, valueList.size());
+
+ assertEquals("vPE", (String) nodeTemplate.getPropertyValueFromTemplatesByName("nf_role"));
+
+ assertNull(nodeTemplate.getPropertyValueFromTemplatesByName("test"));
+ }
+
+ @Test
+ public void testGetParentNodeTemplateTest() throws JToscaException {
+
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-AdiodVmxVpeBvService-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ NodeTemplate nodeTemplate = toscaTemplate.getNodeTemplates().get(0);
+ //parent of this VF is service (null)
+ assertNull(nodeTemplate.getParentNodeTemplate());
+ List<NodeTemplate> children = nodeTemplate.getSubMappingToscaTemplate().getNodeTemplates();
+ assertFalse(children.isEmpty());
+ NodeTemplate cVFC = children.get(4);
+ //parent is the VF above
+ assertEquals("2017-488_ADIOD-vPE 0", cVFC.getParentNodeTemplate().getName());
+ List<NodeTemplate> children1 = cVFC.getSubMappingToscaTemplate().getNodeTemplates();
+ assertFalse(children1.isEmpty());
+ //parent is the CVFC above
+ assertEquals(cVFC, children1.get(0).getParentNodeTemplate());
+
+/*
+
+ TopologyTemplate tt = nodeTemplate.getOriginComponentTemplate();
+ List<Group> groups = tt.getGroups();
+ List<Policy> policies = tt.getPolicies();
+
+ TopologyTemplate tt1 = cVFC.getOriginComponentTemplate();
+ groups = tt.getGroups();
+ policies = tt.getPolicies();
+*/
+
+ }
+
+ @Test
+ public void testNullValueHasNoNullPointerException() throws JToscaException {
+
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-JennyVtsbcKarunaSvc-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ List<Input> inputs = toscaTemplate.getInputs();
+ assertNotNull(inputs);
+ }
+
+ @Test
+ public void testGetPolicyMetadata() throws JToscaException {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-NetworkCloudVnfServiceMock-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ ArrayList<Policy> policies = toscaTemplate.getPolicies();
+ assertNotNull(policies);
+ assertEquals(1, policies.size());
+ assertEquals("org.openecomp.policies.External", policies.get(0).getType());
+ assertEquals("adf03496-bf87-43cf-b20a-450e47cb44bd", policies.get(0).getMetaData().getOrDefault("UUID", "").toString());
+ assertTrue(policies.get(0).getMetaData().getOrDefault("UUID_test", "").toString().isEmpty());
+ }
+
+ @Test
+ public void testGetPolicyMetadataObj() throws JToscaException {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-NetworkCloudVnfServiceMock-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ ArrayList<Policy> policies = toscaTemplate.getPolicies();
+ assertNotNull(policies);
+ assertEquals(1, policies.size());
+ assertEquals("adf03496-bf87-43cf-b20a-450e47cb44bd", policies.get(0).getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString());
+ assertTrue(policies.get(0).getMetaDataObj().getAllProperties().getOrDefault("name_test", "").toString().isEmpty());
+ }
+
+ private void validateInputsAnnotations(List<Input> inputs) {
+ List<Input> inputsWithAnnotations = inputs.stream().filter(i -> i.getAnnotations() != null)
+ .collect(Collectors.toList());
+ assertTrue(!inputs.isEmpty());
+ inputsWithAnnotations.stream().forEach(i -> validateAnnotations(i));
+ }
+
+ private void validateAnnotations(Input input) {
+ assertNotNull(input.getAnnotations());
+ assertEquals(input.getAnnotations().size(), 1);
+ Annotation annotation = input.getAnnotations().get("source");
+ assertEquals(annotation.getName(), "source");
+ assertEquals(annotation.getType().toLowerCase(), "org.openecomp.annotations.source");
+ assertNotNull(annotation.getProperties());
+ Optional<Property> source_type = annotation.getProperties().stream()
+ .filter(p -> p.getName().equals("source_type")).findFirst();
+ assertTrue(source_type.isPresent());
+ assertEquals(source_type.get().getValue(), "HEAT");
+ }
+
+ private static final String TEST_DATATYPE_FILENAME = "csars/dataTypes-test-service.csar";
+ private static final String TEST_DATATYPE_TEST1 = "TestType1";
+ private static final String TEST_DATATYPE_TEST2 = "TestType2";
+ private static final String TEST_DATATYPE_PROPERTY_STR = "strdata";
+ private static final String TEST_DATATYPE_PROPERTY_INT = "intdata";
+ private static final String TEST_DATATYPE_PROPERTY_LIST = "listdata";
+ private static final String TEST_DATATYPE_PROPERTY_TYPE = "type";
+ private static final String TEST_DATATYPE_PROPERTY_ENTRY_SCHEMA = "entry_schema";
+ private static final String TEST_DATATYPE_TOSTRING = "data_types=";
+
+ @Test
+ public void testGetDataType() throws JToscaException {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource(TEST_DATATYPE_FILENAME).getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ HashSet<DataType> dataTypes = toscaTemplate.getDataTypes();
+ assertThat(dataTypes, notNullValue());
+ assertThat(dataTypes.size(), is(2));
+
+ for (DataType dataType : dataTypes) {
+ LinkedHashMap<String, PropertyDef> properties;
+ PropertyDef property;
+ if (dataType.getType().equals(TEST_DATATYPE_TEST1)) {
+ properties = dataType.getAllProperties();
+ property = properties.get(TEST_DATATYPE_PROPERTY_STR);
+ assertThat(property, notNullValue());
+ assertThat(property.getName(), is(TEST_DATATYPE_PROPERTY_STR));
+ assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_TYPE), is(Schema.STRING));
+ }
+ if (dataType.getType().equals(TEST_DATATYPE_TEST2)) {
+ properties = dataType.getAllProperties();
+ property = properties.get(TEST_DATATYPE_PROPERTY_INT);
+ assertThat(property, notNullValue());
+ assertThat(property.getName(), is(TEST_DATATYPE_PROPERTY_INT));
+ assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_TYPE), is(Schema.INTEGER));
+
+ property = properties.get(TEST_DATATYPE_PROPERTY_LIST);
+ assertThat(property, notNullValue());
+ assertThat(property.getName(), is(TEST_DATATYPE_PROPERTY_LIST));
+ assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_TYPE), is(Schema.LIST));
+ assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_ENTRY_SCHEMA), is(TEST_DATATYPE_TEST1));
+
+ assertThat((LinkedHashMap<String, Object>) toscaTemplate.getTopologyTemplate().getCustomDefs().get(TEST_DATATYPE_TEST1), notNullValue());
+ assertThat((LinkedHashMap<String, Object>) toscaTemplate.getTopologyTemplate().getCustomDefs().get(TEST_DATATYPE_TEST2), notNullValue());
+ assertThat(toscaTemplate.toString(), containsString(TEST_DATATYPE_TOSTRING));
+ }
+ }
+
+ }
+
+ @Test
+ public void testGetInputValidate() throws JToscaException {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource(TEST_DATATYPE_FILENAME).getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ HashSet<DataType> dataTypes = toscaTemplate.getDataTypes();
+ assertThat(dataTypes, notNullValue());
+ assertThat(dataTypes.size(), is(2));
+
+ for (DataType dataType : dataTypes) {
+ LinkedHashMap<String, PropertyDef> properties;
+ PropertyDef property;
+ if (dataType.getType().equals(TEST_DATATYPE_TEST1)) {
+ properties = dataType.getAllProperties();
+ property = properties.get(TEST_DATATYPE_PROPERTY_STR);
+ assertThat(property, notNullValue());
+ assertThat(property.getName(), is(TEST_DATATYPE_PROPERTY_STR));
+ assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_TYPE), is(Schema.STRING));
+ }
+ if (dataType.getType().equals(TEST_DATATYPE_TEST2)) {
+ properties = dataType.getAllProperties();
+ property = properties.get(TEST_DATATYPE_PROPERTY_INT);
+ assertThat(property, notNullValue());
+ assertThat(property.getName(), is(TEST_DATATYPE_PROPERTY_INT));
+ assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_TYPE), is(Schema.INTEGER));
+
+ property = properties.get(TEST_DATATYPE_PROPERTY_LIST);
+ assertThat(property, notNullValue());
+ assertThat(property.getName(), is(TEST_DATATYPE_PROPERTY_LIST));
+ assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_TYPE), is(Schema.LIST));
+ assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_ENTRY_SCHEMA), is(TEST_DATATYPE_TEST1));
+
+ assertThat((LinkedHashMap<String, Object>) toscaTemplate.getTopologyTemplate().getCustomDefs().get(TEST_DATATYPE_TEST1), notNullValue());
+ assertThat((LinkedHashMap<String, Object>) toscaTemplate.getTopologyTemplate().getCustomDefs().get(TEST_DATATYPE_TEST2), notNullValue());
+ assertThat(toscaTemplate.toString(), containsString(TEST_DATATYPE_TOSTRING));
+ }
+ }
+ }
+}
diff --git a/jtosca/src/test/java/org/onap/sdc/toscaparser/api/JToscaMetadataParse.java b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/JToscaMetadataParse.java
new file mode 100644
index 0000000..2ec41b2
--- /dev/null
+++ b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/JToscaMetadataParse.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.sdc.toscaparser.api;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+
+import java.util.Map;
+import org.junit.Test;
+import org.onap.sdc.toscaparser.api.common.JToscaException;
+import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue;
+import org.onap.sdc.toscaparser.api.utils.JToscaErrorCodes;
+import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder;
+
+public class JToscaMetadataParse {
+
+ @Test
+ public void testMetadataParsedCorrectly() throws JToscaException {
+ final File file = loadCsar("csars/csar_hello_world.csar");
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ LinkedHashMap<String, Object> metadataProperties = toscaTemplate.getMetaProperties("TOSCA.meta");
+ assertNotNull(metadataProperties);
+ Object entryDefinition = metadataProperties.get("Entry-Definitions");
+ assertNotNull(entryDefinition);
+ assertEquals("tosca_helloworld.yaml", entryDefinition);
+ }
+
+ @Test
+ public void noWarningsAfterParse() throws JToscaException {
+ final File file = loadCsar("csars/tmpCSAR_Huawei_vSPGW_fixed.csar");
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught();
+ assertTrue(validationIssuesCaught == 0);
+ }
+
+ @Test
+ public void requiredInputErrorsAfterParse() throws JToscaException {
+ final File file = loadCsar("csars/tmpCSAR_Huawei_vSPGW_without_required_inputs.csar");
+ new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+
+ final Map<String, JToscaValidationIssue> validationIssues = ThreadLocalsHolder.getCollector()
+ .getValidationIssues();
+ final Collection<JToscaValidationIssue> actualValidationIssueList = validationIssues.values();
+
+ final Collection<JToscaValidationIssue> expectedValidationIssueList = new ArrayList<>();
+ final String errorCode = "JE003";
+ final String errorFormat = "MissingRequiredFieldError: The required input \"%s\" was not provided";
+ expectedValidationIssueList.add(new JToscaValidationIssue(errorCode
+ , String.format(errorFormat, "nf_naming_code")));
+ expectedValidationIssueList.add(new JToscaValidationIssue(errorCode
+ , String.format(errorFormat, "nf_type")));
+ expectedValidationIssueList.add(new JToscaValidationIssue(errorCode
+ , String.format(errorFormat, "nf_role")));
+ expectedValidationIssueList.add(new JToscaValidationIssue(errorCode
+ , String.format(errorFormat, "min_instances")));
+ expectedValidationIssueList.add(new JToscaValidationIssue(errorCode
+ , String.format(errorFormat, "max_instances")));
+ expectedValidationIssueList.add(new JToscaValidationIssue(errorCode
+ , String.format(errorFormat, "nf_function")));
+
+ assertThat("The actual and the expected validation issue lists should have the same size"
+ , actualValidationIssueList, hasSize(expectedValidationIssueList.size())
+ );
+
+ assertThat("The actual and the expected validation issue lists should be the same"
+ , actualValidationIssueList, containsInAnyOrder(expectedValidationIssueList.toArray(new JToscaValidationIssue[0]))
+ );
+ }
+
+ @Test
+ public void testEmptyCsar() throws JToscaException {
+ final File file = loadCsar("csars/emptyCsar.csar");
+ try {
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ } catch (JToscaException e) {
+ assertTrue(e.getCode().equals(JToscaErrorCodes.INVALID_CSAR_FORMAT.getValue()));
+ }
+ int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught();
+ assertTrue(validationIssuesCaught == 0);
+ }
+
+ @Test
+ public void testEmptyPath() throws JToscaException {
+ String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("").getFile();
+ File file = new File(fileStr);
+ try {
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ } catch (JToscaException e) {
+ assertTrue(e.getCode().equals(JToscaErrorCodes.PATH_NOT_VALID.getValue()));
+ }
+ }
+
+ private File loadCsar(final String csarFilePath) {
+ final URL resourceUrl = JToscaMetadataParse.class.getClassLoader().getResource(csarFilePath);
+ assertNotNull(String.format("Could not load CSAR file '%s'", csarFilePath), resourceUrl);
+
+ return new File(resourceUrl.getFile());
+ }
+}
diff --git a/jtosca/src/test/java/org/onap/sdc/toscaparser/api/elements/CalculatePropertyByPathTest.java b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/elements/CalculatePropertyByPathTest.java
new file mode 100644
index 0000000..fd84d6e
--- /dev/null
+++ b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/elements/CalculatePropertyByPathTest.java
@@ -0,0 +1,167 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.sdc.toscaparser.api.elements;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.sdc.toscaparser.api.JToscaImportTest;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.Property;
+import org.onap.sdc.toscaparser.api.ToscaTemplate;
+import org.onap.sdc.toscaparser.api.common.JToscaException;
+
+import java.io.File;
+import java.net.URL;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class CalculatePropertyByPathTest {
+ private static ToscaTemplate toscaTemplate;
+
+ @BeforeClass
+ public static void setUpClass() throws JToscaException {
+ URL scarUrl = JToscaImportTest.class.getClassLoader().getResource("csars/service-NetworkCloudVnfServiceMock-csar.csar");
+ if (scarUrl != null) {
+ File file = new File(scarUrl.getFile());
+ toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ }
+
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsNotEmpty() throws JToscaException {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("related_networks");
+ List<String> propertyValueList = property.getLeafPropertyValue("related_network_role");
+ assertEquals(3, propertyValueList.size());
+ assertTrue(propertyValueList.contains("cor_direct_2"));
+ assertTrue(propertyValueList.contains("sgi_direct_2"));
+ assertTrue(propertyValueList.contains("int_imbl_2"));
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasDataTypeAndPathIsEmpty() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(1); //testVM_testVM_SRIOVNonTrunk0_port
+
+ Property property = cp.getProperties().get("exCP_naming");
+ List<String> propertyValueList = property.getLeafPropertyValue("");
+ assertTrue(propertyValueList.isEmpty());
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasSimpleTypeAndValueAsGetInputIsNotResolvedCorrectlyAndPathIsEmpty() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(1); //testVM_testVM_SRIOVNonTrunk0_port
+
+ Property property = cp.getProperties().get("network");
+ List<String> propertyValueList = property.getLeafPropertyValue("");
+ assertTrue(propertyValueList.isEmpty());
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasSimpleTypeAndPathIsEmpty() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(1); //testVM_testVM_SRIOVNonTrunk0_port
+
+ Property property = cp.getProperties().get("subinterface_indicator");
+ List<String> propertyValueList = property.getLeafPropertyValue("");
+ assertEquals(1, propertyValueList.size());
+ assertEquals("false", propertyValueList.get(0));
+ }
+
+
+ @Test
+ public void testGetPropertyWhenPropertyHasDataTypeAndPathIsNotEmpty() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(2); //testVM_testVM_OVS_port
+
+ Property property = cp.getProperties().get("ip_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("ip_version");
+ assertEquals(1, propertyValueList.size());
+ assertEquals("4", propertyValueList.get(0));
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsNull() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(2); //testVM_testVM_OVS_port
+
+ Property property = cp.getProperties().get("ip_requirements");
+ assertTrue(property.getLeafPropertyValue(null).isEmpty());
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsComplex() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("ip_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("ip_count_required#is_required");
+ assertEquals(1, propertyValueList.size());
+ assertEquals("false", propertyValueList.get(0));
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsWrong() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("ip_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("ip_count_required#is_required_1");
+ assertEquals(0, propertyValueList.size());
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasDataTypeWithoutSchemaAndComplexPath() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("mac_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("mac_count_required#is_required");
+ assertEquals(1, propertyValueList.size());
+ assertEquals("false", propertyValueList.get(0));
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasDataTypeWithoutSchemaAndSimplePath() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("mac_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("mac_count_required");
+ assertEquals(0, propertyValueList.size());
+ }
+}
diff --git a/jtosca/src/test/java/org/onap/sdc/toscaparser/api/elements/EntityTypeTest.java b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/elements/EntityTypeTest.java
new file mode 100644
index 0000000..d65de28
--- /dev/null
+++ b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/elements/EntityTypeTest.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.sdc.toscaparser.api.elements;
+
+import org.junit.After;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class EntityTypeTest {
+
+ private static final Map<String, Object> origMap = EntityType.TOSCA_DEF;
+
+ @Test
+ public void testUpdateDefinitions() throws Exception {
+
+ Map<String, Object> testData = new HashMap<>();
+ testData.put("tosca.nodes.nfv.VNF", "{derived_from=tosca.nodes.Root, properties={id={type=string, description=ID of this VNF}, vendor={type=string, description=name of the vendor who generate this VNF}, version={type=version, description=version of the software for this VNF}}, requirements=[{virtualLink={capability=tosca.capabilities.nfv.VirtualLinkable, relationship=tosca.relationships.nfv.VirtualLinksTo, node=tosca.nodes.nfv.VL}}]}");
+ testData.put("tosca.nodes.nfv.VDU", "{derived_from=tosca.nodes.Compute, capabilities={high_availability={type=tosca.capabilities.nfv.HA}, virtualbinding={type=tosca.capabilities.nfv.VirtualBindable}, monitoring_parameter={type=tosca.capabilities.nfv.Metric}}, requirements=[{high_availability={capability=tosca.capabilities.nfv.HA, relationship=tosca.relationships.nfv.HA, node=tosca.nodes.nfv.VDU, occurrences=[0, 1]}}]}");
+ testData.put("tosca.nodes.nfv.CP", "{derived_from=tosca.nodes.network.Port, properties={type={type=string, required=false}}, requirements=[{virtualLink={capability=tosca.capabilities.nfv.VirtualLinkable, relationship=tosca.relationships.nfv.VirtualLinksTo, node=tosca.nodes.nfv.VL}}, {virtualBinding={capability=tosca.capabilities.nfv.VirtualBindable, relationship=tosca.relationships.nfv.VirtualBindsTo, node=tosca.nodes.nfv.VDU}}], attributes={address={type=string}}}");
+ testData.put("tosca.nodes.nfv.VL", "{derived_from=tosca.nodes.network.Network, properties={vendor={type=string, required=true, description=name of the vendor who generate this VL}}, capabilities={virtual_linkable={type=tosca.capabilities.nfv.VirtualLinkable}}}");
+ testData.put("tosca.nodes.nfv.VL.ELine", "{derived_from=tosca.nodes.nfv.VL, capabilities={virtual_linkable={occurrences=2}}}");
+ testData.put("tosca.nodes.nfv.VL.ELAN", "{derived_from=tosca.nodes.nfv.VL}");
+ testData.put("tosca.nodes.nfv.VL.ETree", "{derived_from=tosca.nodes.nfv.VL}");
+ testData.put("tosca.nodes.nfv.FP", "{derived_from=tosca.nodes.Root, properties={policy={type=string, required=false, description=name of the vendor who generate this VL}}, requirements=[{forwarder={capability=tosca.capabilities.nfv.Forwarder, relationship=tosca.relationships.nfv.ForwardsTo}}]}");
+ testData.put("tosca.groups.nfv.VNFFG", "{derived_from=tosca.groups.Root, properties={vendor={type=string, required=true, description=name of the vendor who generate this VNFFG}, version={type=string, required=true, description=version of this VNFFG}, number_of_endpoints={type=integer, required=true, description=count of the external endpoints included in this VNFFG}, dependent_virtual_link={type=list, entry_schema={type=string}, required=true, description=Reference to a VLD used in this Forwarding Graph}, connection_point={type=list, entry_schema={type=string}, required=true, description=Reference to Connection Points forming the VNFFG}, constituent_vnfs={type=list, entry_schema={type=string}, required=true, description=Reference to a list of VNFD used in this VNF Forwarding Graph}}}");
+ testData.put("tosca.relationships.nfv.VirtualLinksTo", "{derived_from=tosca.relationships.network.LinksTo, valid_target_types=[tosca.capabilities.nfv.VirtualLinkable]}");
+ testData.put("tosca.relationships.nfv.VirtualBindsTo", "{derived_from=tosca.relationships.network.BindsTo, valid_target_types=[tosca.capabilities.nfv.VirtualBindable]}");
+ testData.put("tosca.relationships.nfv.HA", "{derived_from=tosca.relationships.Root, valid_target_types=[tosca.capabilities.nfv.HA]}");
+ testData.put("tosca.relationships.nfv.Monitor", "{derived_from=tosca.relationships.ConnectsTo, valid_target_types=[tosca.capabilities.nfv.Metric]}");
+ testData.put("tosca.relationships.nfv.ForwardsTo", "{derived_from=tosca.relationships.root, valid_target_types=[tosca.capabilities.nfv.Forwarder]}");
+ testData.put("tosca.capabilities.nfv.VirtualLinkable", "{derived_from=tosca.capabilities.network.Linkable}");
+ testData.put("tosca.capabilities.nfv.VirtualBindable", "{derived_from=tosca.capabilities.network.Bindable}");
+ testData.put("tosca.capabilities.nfv.HA", "{derived_from=tosca.capabilities.Root, valid_source_types=[tosca.nodes.nfv.VDU]}");
+ testData.put("tosca.capabilities.nfv.HA.ActiveActive", "{derived_from=tosca.capabilities.nfv.HA}");
+ testData.put("tosca.capabilities.nfv.HA.ActivePassive", "{derived_from=tosca.capabilities.nfv.HA}");
+ testData.put("tosca.capabilities.nfv.Metric", "{derived_from=tosca.capabilities.Root}");
+ testData.put("tosca.capabilities.nfv.Forwarder", "{derived_from=tosca.capabilities.Root}");
+
+ Map<String, Object> expectedDefMap = origMap;
+ expectedDefMap.putAll(testData);
+ EntityType.updateDefinitions("tosca_simple_profile_for_nfv_1_0_0");
+
+ assertEquals(expectedDefMap, EntityType.TOSCA_DEF);
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ EntityType.TOSCA_DEF = (LinkedHashMap<String, Object>) origMap;
+ }
+
+}
diff --git a/jtosca/src/test/java/org/onap/sdc/toscaparser/api/functions/GetInputTest.java b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/functions/GetInputTest.java
new file mode 100644
index 0000000..98e5102
--- /dev/null
+++ b/jtosca/src/test/java/org/onap/sdc/toscaparser/api/functions/GetInputTest.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2019 Fujitsu Limited.
+ * ================================================================================
+ * 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.onap.sdc.toscaparser.api.functions;
+
+import org.junit.Test;
+import org.onap.sdc.toscaparser.api.*;
+import org.onap.sdc.toscaparser.api.common.JToscaException;
+import org.onap.sdc.toscaparser.api.elements.constraints.Schema;
+import org.onap.sdc.toscaparser.api.parameters.Input;
+import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.*;
+
+public class GetInputTest {
+
+ private static final String TEST_FILENAME = "csars/listed_input.csar";
+ private static final String TEST_FILENAME_NG = "csars/listed_input_ng.csar";
+ private static final String TEST_PROPERTY_ROLE = "role";
+ private static final String TEST_PROPERTY_LONGITUDE = "longitude";
+ private static final String TEST_DEFAULT_VALUE = "dsvpn-hub";
+ private static final String TEST_DESCRIPTION_VALUE = "This is used for SDWAN only";
+ private static final String TEST_INPUT_TYPE = "type";
+ private static final String TEST_INPUT_SCHEMA_TYPE = "tosca.datatypes.siteresource.site";
+ private static final String TEST_TOSTRING = "get_input:[sites, 1, longitude]";
+ private static final String TEST_INPUT_SITES = "sites";
+
+ @Test
+ public void validate() throws JToscaException {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource(TEST_FILENAME).getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null, false);
+ NodeTemplate nodeTemplate = toscaTemplate.getNodeTemplates().get(1).getSubMappingToscaTemplate().getNodeTemplates().get(0);
+ ArrayList<Input> inputs = toscaTemplate.getNodeTemplates().get(1).getSubMappingToscaTemplate().getInputs();
+ LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
+ assertThat(properties, notNullValue());
+ assertThat(properties.size(), is(14));
+
+ Property property = properties.get(TEST_PROPERTY_ROLE);
+ assertThat(properties, notNullValue());
+ assertThat(property.getName(), is(TEST_PROPERTY_ROLE));
+ assertThat(property.getType(), is(Schema.STRING));
+ assertThat(property.getDefault(), is(TEST_DEFAULT_VALUE));
+ assertThat(property.getDescription(), is(TEST_DESCRIPTION_VALUE));
+ GetInput getInput = (GetInput) property.getValue();
+ assertThat(getInput.getEntrySchema().get(TEST_INPUT_TYPE).toString(), is(TEST_INPUT_SCHEMA_TYPE));
+
+ property = properties.get(TEST_PROPERTY_LONGITUDE);
+ assertThat(properties, notNullValue());
+ assertThat(property.getName(), is(TEST_PROPERTY_LONGITUDE));
+ assertThat(property.getValue().toString(), is(TEST_TOSTRING));
+ getInput = (GetInput) property.getValue();
+ ArrayList<Object> getInputArguments = getInput.getArguments();
+ assertThat(getInputArguments.size(), is(3));
+ assertThat(getInputArguments.get(0).toString(), is(TEST_INPUT_SITES));
+ assertThat(getInputArguments.get(1).toString(), is("1"));
+ assertThat(getInputArguments.get(2).toString(), is(TEST_PROPERTY_LONGITUDE));
+
+ Input in = inputs.get(10);
+ assertThat(in.getEntrySchema().get(TEST_INPUT_TYPE), is(TEST_INPUT_SCHEMA_TYPE));
+ assertThat(in.getName(), is(TEST_INPUT_SITES));
+ assertThat(in.getType(), is(Input.LIST));
+ }
+
+ @Test
+ public void validate_ng() throws JToscaException {
+ //invalid file
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource(TEST_FILENAME_NG).getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null, false);
+
+ List<String> issues = ThreadLocalsHolder.getCollector().getValidationIssueReport();
+ assertTrue(issues.stream().anyMatch(x -> x.contains("JE282")));
+ }
+}
diff --git a/jtosca/src/test/resources/csars/csar_hello_world.csar b/jtosca/src/test/resources/csars/csar_hello_world.csar
new file mode 100644
index 0000000..43ffbbc
--- /dev/null
+++ b/jtosca/src/test/resources/csars/csar_hello_world.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/dataTypes-test-service.csar b/jtosca/src/test/resources/csars/dataTypes-test-service.csar
new file mode 100644
index 0000000..b4de177
--- /dev/null
+++ b/jtosca/src/test/resources/csars/dataTypes-test-service.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/emptyCsar.csar b/jtosca/src/test/resources/csars/emptyCsar.csar
new file mode 100644
index 0000000..15cb0ec
--- /dev/null
+++ b/jtosca/src/test/resources/csars/emptyCsar.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/listed_input.csar b/jtosca/src/test/resources/csars/listed_input.csar
new file mode 100644
index 0000000..445b91a
--- /dev/null
+++ b/jtosca/src/test/resources/csars/listed_input.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/listed_input_ng.csar b/jtosca/src/test/resources/csars/listed_input_ng.csar
new file mode 100644
index 0000000..6b3402e
--- /dev/null
+++ b/jtosca/src/test/resources/csars/listed_input_ng.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/resource-Spgw-csar-ZTE.csar b/jtosca/src/test/resources/csars/resource-Spgw-csar-ZTE.csar
new file mode 100644
index 0000000..58c3ddd
--- /dev/null
+++ b/jtosca/src/test/resources/csars/resource-Spgw-csar-ZTE.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/sdc-onboarding_csar.csar b/jtosca/src/test/resources/csars/sdc-onboarding_csar.csar
new file mode 100644
index 0000000..f12605d
--- /dev/null
+++ b/jtosca/src/test/resources/csars/sdc-onboarding_csar.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/service-AdiodVmxVpeBvService-csar.csar b/jtosca/src/test/resources/csars/service-AdiodVmxVpeBvService-csar.csar
new file mode 100644
index 0000000..28aa6f4
--- /dev/null
+++ b/jtosca/src/test/resources/csars/service-AdiodVmxVpeBvService-csar.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/service-JennyVtsbcKarunaSvc-csar.csar b/jtosca/src/test/resources/csars/service-JennyVtsbcKarunaSvc-csar.csar
new file mode 100644
index 0000000..ee01780
--- /dev/null
+++ b/jtosca/src/test/resources/csars/service-JennyVtsbcKarunaSvc-csar.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/service-NetworkCloudVnfServiceMock-csar.csar b/jtosca/src/test/resources/csars/service-NetworkCloudVnfServiceMock-csar.csar
new file mode 100644
index 0000000..aabf83c
--- /dev/null
+++ b/jtosca/src/test/resources/csars/service-NetworkCloudVnfServiceMock-csar.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar b/jtosca/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar
new file mode 100644
index 0000000..9dc29c7
--- /dev/null
+++ b/jtosca/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_fixed.csar
Binary files differ
diff --git a/jtosca/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_without_required_inputs.csar b/jtosca/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_without_required_inputs.csar
new file mode 100644
index 0000000..194fabb
--- /dev/null
+++ b/jtosca/src/test/resources/csars/tmpCSAR_Huawei_vSPGW_without_required_inputs.csar
Binary files differ