import java.util.LinkedHashMap;
import java.util.List;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.onap.nbi.exceptions.TechnicalException;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
+@ActiveProfiles("test")
public class ToscaInfosProcessorTest {
+ @Autowired
+ ToscaInfosProcessor toscaInfosProcessor;
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson databind
- ToscaInfosProcessor toscaInfosProcessor = new ToscaInfosProcessor();
-
-
@Test
public void buildResponseWithSdcToscaParser() {
assertThat(resources.get(1).get("modelCustomizationId")).isNull();
}
+
+ @Test
+ public void testBuildAndSaveResponseWithSdcToscaParser() {
+
+ ClassLoader classLoader = getClass().getClassLoader();
+ Path path = new File(
+ classLoader.getResource("toscafile/service-Sotnvpninfraservice-csar.csar").getFile())
+ .toPath().toAbsolutePath();
+
+ LinkedHashMap response = new LinkedHashMap();
+ response.put("version", "1.0");
+ response.put("name", "Service_vMME");
+ response.put("description", "some service characteristics schema");
+ response.put("id", "7f5e5139-768d-4410-a871-c41430785214");
+
+ List<LinkedHashMap> resources = new ArrayList<>();
+ LinkedHashMap resource1 = new LinkedHashMap();
+ resource1.put("id", "7baa7742-3a13-4288-8330-868015adc340");
+ resources.add(resource1);
+ LinkedHashMap resource2 = new LinkedHashMap();
+ resource2.put("id", "81b9430b-8abe-45d6-8bf9-f41a8f5c735f");
+ resources.add(resource2);
+
+ response.put("resourceSpecification", resources);
+
+ LinkedHashMap serviceSpecCharacteristicValue = new LinkedHashMap();
+ serviceSpecCharacteristicValue.put("valueType", "object");
+ serviceSpecCharacteristicValue.put("@schemaLocation",
+ "/serviceSpecification/7f5e5139-768d-4410-a871-c41430785214/specificationInputSchema");
+ serviceSpecCharacteristicValue.put("@type", "Service_vMME_ServiceCharacteristic");
+
+ LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap();
+ serviceSpecCharacteristic.put("name", "Service_vMME_ServiceCharacteristics");
+ serviceSpecCharacteristic.put("description",
+ "This object describes all the inputs needed from the client to interact with the Service_vMME Service Topology");
+ // using object to match examples in specifications
+ serviceSpecCharacteristic.put("valueType", "object");
+ serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic");
+ serviceSpecCharacteristic.put("@schemaLocation", "null");
+ serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", serviceSpecCharacteristicValue);
+ try {
+ toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(path, response);
+ } catch (SdcToscaParserException ex) {
+ throw new TechnicalException("unable to build response " + ex.getMessage());
+ }
+ assertThat(response.get("serviceSpecCharacteristic")).isEqualTo(serviceSpecCharacteristic);
+ }
+
+
+ @Test
+ public void testBuildAndSaveResponseWithSdcToscaParserWithInputListType() {
+
+ ClassLoader classLoader = getClass().getClassLoader();
+ Path path = new File(
+ classLoader.getResource("toscafile/service-MscmEvplService-csar.csar").getFile())
+ .toPath().toAbsolutePath();
+
+ LinkedHashMap response = new LinkedHashMap();
+ response.put("version", "1.0");
+ response.put("name", "MSCM-EVPL-Service");
+ response.put("description", "MSCM EVPL Service");
+ response.put("id", "66a66cc3-178c-45fd-82c2-494336cb3665");
+
+ List<LinkedHashMap> resources = new ArrayList<>();
+ LinkedHashMap resource1 = new LinkedHashMap();
+ resource1.put("id", "f5f487df-8c02-4485-81d4-695c50e24b22");
+ resources.add(resource1);
+ LinkedHashMap resource2 = new LinkedHashMap();
+ resource2.put("id", "65c34b35-e8ab-426a-b048-d707467f68b2");
+ resources.add(resource2);
+
+ response.put("resourceSpecification", resources);
+
+ LinkedHashMap serviceSpecCharacteristicValue = new LinkedHashMap();
+ serviceSpecCharacteristicValue.put("valueType", "object");
+ serviceSpecCharacteristicValue.put("@schemaLocation",
+ "/serviceSpecification/66a66cc3-178c-45fd-82c2-494336cb3665/specificationInputSchema");
+ serviceSpecCharacteristicValue.put("@type", "MSCM-EVPL-Service_ServiceCharacteristic");
+
+ LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap();
+ serviceSpecCharacteristic.put("name", "MSCM-EVPL-Service_ServiceCharacteristics");
+ serviceSpecCharacteristic.put("description",
+ "This object describes all the inputs needed from the client to interact with the MSCM-EVPL-Service Service Topology");
+ // using object to match examples in specifications
+ serviceSpecCharacteristic.put("valueType", "object");
+ serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic");
+ serviceSpecCharacteristic.put("@schemaLocation", "null");
+ serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", serviceSpecCharacteristicValue);
+ try {
+ toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(path, response);
+ } catch (SdcToscaParserException ex) {
+ throw new TechnicalException("unable to build response " + ex.getMessage());
+ }
+ assertThat(response.get("serviceSpecCharacteristic")).isEqualTo(serviceSpecCharacteristic);
+ }
}