aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java3
-rw-r--r--src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java5
-rw-r--r--src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java20
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java2
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java155
-rw-r--r--src/test/java/org/onap/clamp/clds/util/XmlToolsTest.java72
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java90
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphTest.java77
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java80
-rw-r--r--src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java178
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java4
-rw-r--r--src/test/resources/application.properties2
-rw-r--r--src/test/resources/clds/util/file.xml6
-rw-r--r--src/test/resources/example/sdc/service-Simsfoimap0112.csarbin52391 -> 52568 bytes
14 files changed, 657 insertions, 37 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java
index 8fd817cbe..9b83e7216 100644
--- a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.gson.JsonSyntaxException;
+
import java.io.IOException;
import java.util.Map;
@@ -35,6 +36,7 @@ import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration;
import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;
@@ -43,6 +45,7 @@ import org.springframework.test.util.ReflectionTestUtils;
*/
@RunWith(SpringRunner.class)
@SpringBootTest
+@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller")
public class SdcControllersConfigurationItCase {
@Autowired
diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java
index c6dbce4c5..55657c974 100644
--- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java
@@ -41,19 +41,18 @@ import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.notification.IResourceInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
+@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller")
public class SdcSingleControllerItCase {
- private static final String SDC_FOLDER = "/tmp/csar-handler-tests";
private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar";
private static final String SERVICE_UUID = "serviceUUID";
private static final String RESOURCE1_UUID = "resource1UUID";
private static final String RESOURCE1_INSTANCE_NAME = "sim-1802 0";
- private static final String RESOURCE1_INSTANCE_NAME_IN_CSAR = "sim18020";
- private static final String BLUEPRINT1_NAME = "FOI.Simfoimap223S0112.event_proc_bp.yaml";
@Autowired
private ClampProperties clampProp;
diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java
index 0df252388..d3a823fbc 100644
--- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java
@@ -30,6 +30,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -60,13 +61,14 @@ import org.onap.sdc.toscaparser.api.elements.Metadata;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
+@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller")
public class CsarInstallerItCase {
- private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar";
private static final String INVARIANT_SERVICE_UUID = "4cc5b45a-1f63-4194-8100-cd8e14248c92";
private static final String INVARIANT_RESOURCE1_UUID = "07e266fc-49ab-4cd7-8378-ca4676f1b9ec";
private static final String INVARIANT_RESOURCE2_UUID = "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad";
@@ -87,7 +89,8 @@ public class CsarInstallerItCase {
blueprintMap.put("resourceid", blueprintArtifact);
Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap);
Mockito.when(blueprintArtifact.getDcaeBlueprint()).thenReturn(
- IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/not-recognized.yaml")));
+ IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/not-recognized.yaml"),
+ StandardCharsets.UTF_8));
csarInstaller.installTheCsar(csarHandler);
fail("Should have raised an SdcArtifactInstallerException");
}
@@ -162,16 +165,17 @@ public class CsarInstallerItCase {
csarInstaller.installTheCsar(csar);
CldsModel cldsModel1 = verifyClosedLoopModelLoadedInDb(csar, "tca.yaml");
JSONAssert.assertEquals(
- IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json")),
+ IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json"),
+ StandardCharsets.UTF_8),
cldsModel1.getPropText(), true);
CldsModel cldsModel2 = verifyClosedLoopModelLoadedInDb(csar, "tca_2.yaml");
- JSONAssert.assertEquals(
- IOUtils
- .toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-2.json")),
- cldsModel2.getPropText(), true);
+ JSONAssert.assertEquals(IOUtils.toString(
+ ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-2.json"),
+ StandardCharsets.UTF_8), cldsModel2.getPropText(), true);
CldsModel cldsModel3 = verifyClosedLoopModelLoadedInDb(csar, "tca_3.yaml");
JSONAssert.assertEquals(
- IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json")),
+ IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json"),
+ StandardCharsets.UTF_8),
cldsModel3.getPropText(), true);
}
diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java
index 544c8ca1d..e00887478 100644
--- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java
+++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java
@@ -161,7 +161,7 @@ public class CsarHandlerTest {
CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests");
csar.save(buildFakeSdcResut());
String policyModelYaml = csar.getPolicyModelYaml().get();
- assertTrue(policyModelYaml.contains("tosca_simple_yaml_1_1"));
+ assertTrue(policyModelYaml.contains("tosca_simple_yaml_1_0_0"));
}
@Test
diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java
index a995c523d..1fe3ff3d9 100644
--- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java
+++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java
@@ -17,50 +17,161 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * * Modifications copyright (c) 2019 Nokia
* ===================================================================
*
*/
-package org.onap.clamp.clds.sdc.controller.installer;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+package org.onap.clamp.clds.sdc.controller.installer;
import com.google.gson.JsonObject;
import java.io.IOException;
+import java.io.InputStream;
+import org.apache.commons.io.IOUtils;
+import org.assertj.core.api.Assertions;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.clamp.clds.client.DcaeInventoryServices;
+import org.onap.clamp.clds.config.sdc.BlueprintParserFilesConfiguration;
+import org.onap.clamp.clds.dao.CldsDao;
+import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
+import org.onap.clamp.clds.service.CldsService;
+import org.onap.clamp.clds.service.CldsTemplateService;
+import org.onap.clamp.clds.transform.XslTransformer;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.sdc.api.notification.INotificationData;
+import org.onap.sdc.api.notification.IResourceInstance;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.io.Resource;
+@RunWith(MockitoJUnitRunner.class)
public class CsarInstallerImplTest {
+ @Mock
+ private CsarHandler csarHandler;
+
+ @Mock
+ private ApplicationContext applicationContext;
+
+ @Mock
+ private DcaeInventoryServices dcaeInventoryServices;
+
+ @Mock
+ private IResourceInstance resourceInstance;
+
+ @Mock
+ private CldsService cldsService;
+
+ @Mock
+ private INotificationData notificationData;
+
+ @Mock
+ private Metadata metadata;
+
+ @Mock
+ private ISdcCsarHelper sdcCsarHelper;
+
+ private CsarInstallerImpl csarInstaller;
+ private BlueprintArtifact artifact;
+
+ /**
+ * Set up method.
+ * throws: Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ String dceaBlueprint = ResourceFileUtil.getResourceAsString("tosca/dcea_blueprint.yml");
+ artifact = prepareBlueprintArtifact(dceaBlueprint);
+ csarInstaller = new CsarInstallerImpl(applicationContext, new CldsDao(), new CldsTemplateService(),
+ cldsService, dcaeInventoryServices, new XslTransformer());
+ }
+
@Test
- public void shouldReturnInputParametersFromBlueprint() throws IOException {
+ public void shouldReturnInputParametersFromBlueprint() {
//given
String expectedBlueprintInputsText = "{\"aaiEnrichmentHost\":\"aai.onap.svc.cluster.local\""
- + ",\"aaiEnrichmentPort\":\"8443\""
- + ",\"enableAAIEnrichment\":true"
- + ",\"dmaap_host\":\"message-router\""
- + ",\"dmaap_port\":\"3904\""
- + ",\"enableRedisCaching\":false"
- + ",\"redisHosts\":\"dcae-redis:6379\""
- + ",\"tag_version\":\"nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.1.0\""
- + ",\"consul_host\":\"consul-server\""
- + ",\"consul_port\":\"8500\",\"cbs_host\":\"{\\\"test\\\":"
- + "{\\\"test\\\":\\\"test\\\"}}\",\"cbs_port\":\"10000\""
- + ",\"external_port\":\"32010\",\"policy_id\":\"AUTO_GENERATED_POLICY_ID_AT_SUBMIT\"}";
+ + ",\"aaiEnrichmentPort\":\"8443\""
+ + ",\"enableAAIEnrichment\":true"
+ + ",\"dmaap_host\":\"message-router\""
+ + ",\"dmaap_port\":\"3904\""
+ + ",\"enableRedisCaching\":false"
+ + ",\"redisHosts\":\"dcae-redis:6379\""
+ + ",\"tag_version\":"
+ + "\"nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.1.0\""
+ + ",\"consul_host\":\"consul-server\""
+ + ",\"consul_port\":\"8500\",\"cbs_host\":\"{\\\"test\\\":"
+ + "{\\\"test\\\":\\\"test\\\"}}\",\"cbs_port\":\"10000\""
+ + ",\"external_port\":\"32010\",\"policy_id\":\"AUTO_GENERATED_POLICY_ID_AT_SUBMIT\"}";
JsonObject expectedBlueprintInputs = JsonUtils.GSON.fromJson(expectedBlueprintInputsText, JsonObject.class);
- String dceaBlueprint = ResourceFileUtil.getResourceAsString("tosca/dcea_blueprint.yml");
- BlueprintArtifact blueprintArtifact = mock(BlueprintArtifact.class);
- when(blueprintArtifact.getDcaeBlueprint()).thenReturn(dceaBlueprint);
- CsarInstallerImpl csarInstaller = new CsarInstallerImpl();
+ //when
+ String parametersInJson = csarInstaller.getAllBlueprintParametersInJson(artifact);
+ //then
+ Assertions.assertThat(JsonUtils.GSON.fromJson(parametersInJson, JsonObject.class))
+ .isEqualTo(expectedBlueprintInputs);
+ }
+ @Test
+ public void shouldReturnBuildModelName() throws SdcArtifactInstallerException {
+ //given
+ String expectedModelName = "CLAMP_test_name_"
+ + "vtest_service_version_"
+ + "test_resource_instance_name_"
+ + "test_artifact_name";
+ prepareMockCsarHandler("name", "test_name",
+ "test_service_version");
+ Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn("test_resource_instance_name");
//when
- String parametersInJson = csarInstaller.getAllBlueprintParametersInJson(blueprintArtifact);
+ String actualModelName = CsarInstallerImpl.buildModelName(csarHandler, artifact);
+ //then
+ Assertions.assertThat(actualModelName).isEqualTo(expectedModelName);
+ }
+
+ @Test
+ public void shouldReturnRightMapping() throws SdcArtifactInstallerException, IOException {
+ //given
+ String input = "[{\"blueprintKey\":\"tca_k8s\","
+ + "\"dcaeDeployable\":false,"
+ + "\"files\":{\"svgXmlFilePath\":\"samplePath\",\"bpmnXmlFilePath\":\"samplePath\"}}]";
+ BlueprintParserFilesConfiguration filesConfiguration = new BlueprintParserFilesConfiguration();
+ filesConfiguration.setBpmnXmlFilePath("samplePath");
+ filesConfiguration.setSvgXmlFilePath("samplePath");
+ Resource resource = Mockito.mock(Resource.class);
+ InputStream inputStream = IOUtils.toInputStream(input, "UTF-8");
+ Mockito.when(applicationContext.getResource(Mockito.any(String.class))).thenReturn(resource);
+ Mockito.when(resource.getInputStream()).thenReturn(inputStream);
+ csarInstaller.loadConfiguration();
+ //when
+ BlueprintParserFilesConfiguration configuration = csarInstaller.searchForRightMapping(artifact);
//then
- assertThat(JsonUtils.GSON.fromJson(parametersInJson, JsonObject.class)).isEqualTo(expectedBlueprintInputs);
+ Assertions.assertThat(configuration.getBpmnXmlFilePath()).isEqualTo("samplePath");
+ Assertions.assertThat(configuration.getSvgXmlFilePath()).isEqualTo("samplePath");
+ }
+
+ private BlueprintArtifact prepareBlueprintArtifact(String dceaBlueprint) {
+ artifact = new BlueprintArtifact();
+ artifact.setBlueprintArtifactName("test_artifact_name");
+ artifact.setBlueprintInvariantServiceUuid("test_inv_uuid");
+ artifact.setResourceAttached(resourceInstance);
+ artifact.setDcaeBlueprint(dceaBlueprint);
+ return artifact;
+ }
+
+ private void prepareMockCsarHandler(String metadataNameMockInput, String metadataNameMockOutput,
+ String serviceVersion) {
+ Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(sdcCsarHelper);
+ Mockito.when(sdcCsarHelper.getServiceMetadata()).thenReturn(metadata);
+ Mockito.when(metadata.getValue(metadataNameMockInput)).thenReturn(metadataNameMockOutput);
+ Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData);
+ Mockito.when(notificationData.getServiceVersion()).thenReturn(serviceVersion);
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/util/XmlToolsTest.java b/src/test/java/org/onap/clamp/clds/util/XmlToolsTest.java
new file mode 100644
index 000000000..4351a80d4
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/util/XmlToolsTest.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.clamp.clds.util;
+
+import java.io.IOException;
+import java.io.StringReader;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.apache.batik.anim.dom.SVGDOMImplementation;
+import org.apache.batik.util.SVGConstants;
+import org.junit.Assert;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class XmlToolsTest {
+
+ @Test
+ public void exportXmlDocumentAsStringTest() throws IOException, ParserConfigurationException, SAXException {
+ String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml");
+ Document document = parseStringToXmlDocument(expected);
+ String actual = XmlTools.exportXmlDocumentAsString(document);
+ Assert.assertEquals(expected.trim(), actual.trim());
+ }
+
+ @Test
+ public void createEmptySvgDocumentTest() {
+ Document doc = XmlTools.createEmptySvgDocument();
+ Assert.assertEquals(SVGDOMImplementation.SVG_NAMESPACE_URI, doc.getDocumentElement().getNamespaceURI());
+ Assert.assertEquals(SVGConstants.SVG_SVG_TAG, doc.getDocumentElement().getNodeName());
+ Assert.assertNull(doc.getDoctype());
+ }
+
+
+ public static Document parseStringToXmlDocument(String res)
+ throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setValidating(false);
+ dbf.setNamespaceAware(true);
+ dbf.setFeature("http://xml.org/sax/features/namespaces", false);
+ dbf.setFeature("http://xml.org/sax/features/validation", false);
+ dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
+ dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ InputSource is = new InputSource(new StringReader(res));
+ return db.parse(is);
+ }
+
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
new file mode 100644
index 000000000..477e6a73f
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.clamp.clds.util.drawing;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ClampGraphBuilderTest {
+ @Mock
+ private Painter mockPainter;
+
+ @Captor
+ private ArgumentCaptor<String> collectorCaptor;
+
+ @Captor
+ private ArgumentCaptor<List<String>> microServicesCaptor;
+
+ @Captor
+ private ArgumentCaptor<String> policyCaptor;
+
+ @Test
+ public void clampGraphBuilderCompleteChainTest() {
+ String collector = "VES";
+ String ms1 = "ms1";
+ String ms2 = "ms2";
+ String policy = "Policy";
+ List<String> microServices = Arrays.asList(ms1, ms2);
+
+ ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
+ clampGraphBuilder.collector(collector).microService(ms1).microService(ms2).policy(policy).build();
+
+ verify(mockPainter, times(1))
+ .doPaint(collectorCaptor.capture(), microServicesCaptor.capture(), policyCaptor.capture());
+
+ Assert.assertEquals(collector, collectorCaptor.getValue());
+ Assert.assertEquals(microServices, microServicesCaptor.getValue());
+ Assert.assertEquals(policy, policyCaptor.getValue());
+ }
+
+ @Test(expected = InvalidStateException.class)
+ public void clampGraphBuilderNoPolicyGivenTest() {
+ String collector = "VES";
+ String ms1 = "ms1";
+ String ms2 = "ms2";
+
+ ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
+ clampGraphBuilder.collector(collector).microService(ms1).microService(ms2).build();
+ }
+
+ @Test(expected = InvalidStateException.class)
+ public void clampGraphBuilderNoMicroServiceGivenTest() {
+ String collector = "VES";
+ String policy = "Policy";
+
+ ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
+ clampGraphBuilder.collector(collector).policy(policy).build();
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphTest.java
new file mode 100644
index 000000000..6bbebdfde
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphTest.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.clamp.clds.util.drawing;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import javax.xml.parsers.ParserConfigurationException;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.clamp.clds.util.XmlToolsTest;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ClampGraphTest {
+ @Mock
+ private DocumentBuilder mockDocumentBuilder;
+
+ @Test
+ public void getAsSVGTest() throws IOException, ParserConfigurationException, SAXException {
+ String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml");
+ Document document = XmlToolsTest.parseStringToXmlDocument(expected);
+
+ when(mockDocumentBuilder.getGroupingDocument()).thenReturn(document);
+
+ String actual = new ClampGraph(mockDocumentBuilder).getAsSVG();
+ Assert.assertEquals(expected.trim(), actual.trim());
+ }
+
+ @Test
+ public void getAsSVGLazyTest() throws IOException, ParserConfigurationException, SAXException {
+ String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml");
+ Document document = XmlToolsTest.parseStringToXmlDocument(expected);
+
+ when(mockDocumentBuilder.getGroupingDocument()).thenReturn(document);
+ ClampGraph cg = new ClampGraph(mockDocumentBuilder);
+
+ String actualFirst = cg.getAsSVG();
+ verify(mockDocumentBuilder, times(1)).getGroupingDocument();
+
+ String actualSecond = cg.getAsSVG();
+ verifyNoMoreInteractions(mockDocumentBuilder);
+
+ Assert.assertEquals(expected.trim(), actualFirst.trim());
+ Assert.assertEquals(expected.trim(), actualSecond.trim());
+
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java
new file mode 100644
index 000000000..6546553c7
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.clamp.clds.util.drawing;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import javax.xml.parsers.ParserConfigurationException;
+import org.apache.batik.svggen.SVGGraphics2D;
+import org.apache.batik.util.SVGConstants;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.clamp.clds.util.XmlToolsTest;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DocumentBuilderTest {
+ @Mock
+ private SVGGraphics2D mockG2d;
+
+ @Mock
+ private Document mockDomImpl;
+
+ @Test
+ public void pushChangestoDocumentTest() throws IOException, ParserConfigurationException, SAXException {
+ String dataElementId = "someId";
+ String newNodeTag = "tagged";
+ String newNodeText = "Sample text";
+ String xml = ResourceFileUtil.getResourceAsString("clds/util/file.xml");
+ Document document = XmlToolsTest.parseStringToXmlDocument(xml);
+ Node newNode = document.createElement(newNodeTag);
+ newNode.appendChild(document.createTextNode(newNodeText));
+
+ when(mockG2d.getRoot(any(Element.class))).then(a -> a.getArgumentAt(0, Element.class).appendChild(newNode));
+
+ DocumentBuilder db = new DocumentBuilder(document, document);
+ db.pushChangestoDocument(mockG2d, dataElementId);
+ Document actualDocument = db.getGroupingDocument();
+
+ Node addedActualNode = actualDocument.getDocumentElement().getLastChild();
+ String actualDataElementId =
+ addedActualNode.getAttributes().getNamedItem(DocumentBuilder.DATA_ELEMENT_ID_ATTRIBUTE).getTextContent();
+
+ Assert.assertEquals(dataElementId, actualDataElementId);
+ Assert.assertEquals(SVGConstants.SVG_G_TAG, addedActualNode.getNodeName());
+
+ Node addedActualNodeChild = addedActualNode.getLastChild();
+ Assert.assertEquals(newNodeTag, addedActualNodeChild.getNodeName());
+ Assert.assertEquals(newNodeText, addedActualNodeChild.getTextContent());
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
new file mode 100644
index 000000000..d1a4bdc56
--- /dev/null
+++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
@@ -0,0 +1,178 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * 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.clamp.loop;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import javax.transaction.Transactional;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.json.JSONException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.clamp.clds.Application;
+import org.onap.clamp.clds.exception.policy.PolicyModelException;
+import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
+import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
+import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
+import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
+import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;
+import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.sdc.api.notification.INotificationData;
+import org.onap.sdc.api.notification.IResourceInstance;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = Application.class)
+@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller-new")
+public class CsarInstallerItCase {
+
+ private static final String CSAR_ARTIFACT_NAME = "example/sdc/service-Simsfoimap0112.csar";
+ private static final String INVARIANT_SERVICE_UUID = "4cc5b45a-1f63-4194-8100-cd8e14248c92";
+ private static final String INVARIANT_RESOURCE1_UUID = "07e266fc-49ab-4cd7-8378-ca4676f1b9ec";
+ private static final String INVARIANT_RESOURCE2_UUID = "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad";
+ private static final String RESOURCE_INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName1";
+ private static final String RESOURCE_INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2";
+
+ @Autowired
+ private LoopsRepository loopsRepo;
+
+ @Autowired
+ private CsarInstaller csarInstaller;
+
+ private BlueprintArtifact buildFakeBuildprintArtifact(String instanceName, String invariantResourceUuid,
+ String blueprintFilePath, String artifactName, String invariantServiceUuid) throws IOException {
+ IResourceInstance resource = Mockito.mock(IResourceInstance.class);
+ Mockito.when(resource.getResourceInstanceName()).thenReturn(instanceName);
+ Mockito.when(resource.getResourceInvariantUUID()).thenReturn(invariantResourceUuid);
+ BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class);
+ Mockito.when(blueprintArtifact.getDcaeBlueprint())
+ .thenReturn(ResourceFileUtil.getResourceAsString(blueprintFilePath));
+ Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(artifactName);
+ Mockito.when(blueprintArtifact.getBlueprintInvariantServiceUuid()).thenReturn(invariantServiceUuid);
+ Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(resource);
+ return blueprintArtifact;
+ }
+
+ private CsarHandler buildFakeCsarHandler(String generatedName) throws IOException, SdcToscaParserException {
+ // Create fake notification
+ INotificationData notificationData = Mockito.mock(INotificationData.class);
+ Mockito.when(notificationData.getServiceVersion()).thenReturn("1.0");
+ // Create fake resource in notification
+ CsarHandler csarHandler = Mockito.mock(CsarHandler.class);
+ List<IResourceInstance> listResources = new ArrayList<>();
+ Mockito.when(notificationData.getResources()).thenReturn(listResources);
+ Map<String, BlueprintArtifact> blueprintMap = new HashMap<>();
+ Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap);
+ // Create fake blueprint artifact 1 on resource1
+ BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1,
+ INVARIANT_RESOURCE1_UUID, "example/sdc/blueprint-dcae/tca.yaml", "tca.yaml", INVARIANT_SERVICE_UUID);
+ listResources.add(blueprintArtifact.getResourceAttached());
+ blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact);
+ // Create fake blueprint artifact 2 on resource2
+ blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE2, INVARIANT_RESOURCE2_UUID,
+ "example/sdc/blueprint-dcae/tca_2.yaml", "tca_2.yaml", INVARIANT_SERVICE_UUID);
+ listResources.add(blueprintArtifact.getResourceAttached());
+ blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact);
+
+ // Create fake blueprint artifact 3 on resource 1 so that it's possible to
+ // test multiple CL deployment per Service/vnf
+ blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, INVARIANT_RESOURCE1_UUID,
+ "example/sdc/blueprint-dcae/tca_3.yaml", "tca_3.yaml", INVARIANT_SERVICE_UUID);
+ blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact);
+
+ // Build fake csarhandler
+ Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData);
+ // Build fake csar Helper
+ ISdcCsarHelper csarHelper = Mockito.mock(ISdcCsarHelper.class);
+ Metadata data = Mockito.mock(Metadata.class);
+ Mockito.when(data.getValue("name")).thenReturn(generatedName);
+ Mockito.when(notificationData.getServiceName()).thenReturn(generatedName);
+ Mockito.when(csarHelper.getServiceMetadata()).thenReturn(data);
+
+ // Create helper based on real csar to test policy yaml and global properties
+ // set
+ SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
+ ISdcCsarHelper sdcHelper = factory
+ .getSdcCsarHelper(Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME).getFile());
+ Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(sdcHelper);
+
+ // Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper);
+ Mockito.when(csarHandler.getPolicyModelYaml())
+ .thenReturn(Optional.ofNullable(ResourceFileUtil.getResourceAsString("tosca/tca-policy-test.yaml")));
+ return csarHandler;
+ }
+
+ @Test
+ @Transactional
+ public void testIsCsarAlreadyDeployedTca() throws SdcArtifactInstallerException, SdcToscaParserException,
+ CsarHandlerException, IOException, InterruptedException, PolicyModelException {
+ String generatedName = RandomStringUtils.randomAlphanumeric(5);
+ CsarHandler csarHandler = buildFakeCsarHandler(generatedName);
+ assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isFalse();
+ csarInstaller.installTheCsar(csarHandler);
+ assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isTrue();
+ }
+
+ @Test
+ @Transactional
+ public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException,
+ CsarHandlerException, IOException, JSONException, InterruptedException, PolicyModelException {
+ String generatedName = RandomStringUtils.randomAlphanumeric(5);
+ CsarHandler csar = buildFakeCsarHandler(generatedName);
+ csarInstaller.installTheCsar(csar);
+ assertThat(loopsRepo
+ .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml")))
+ .isTrue();
+ assertThat(loopsRepo
+ .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml")))
+ .isTrue();
+ assertThat(loopsRepo
+ .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml")))
+ .isTrue();
+ // Verify now that policy and json representation, global properties are well
+ // set
+ Loop loop = loopsRepo
+ .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml")).get();
+
+ assertThat(loop.getModelPropertiesJson().get("serviceDetails")).isNotNull();
+ assertThat(loop.getModelPropertiesJson().get("resourceDetails")).isNotNull();
+ }
+
+}
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
index a9c308737..b7781bf2c 100644
--- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
@@ -70,7 +70,7 @@ public class LoopServiceTestItCase {
testLoop.setLastComputedState(LoopState.DESIGN);
//when
- Loop actualLoop = loopService.addNewLoop(testLoop);
+ Loop actualLoop = loopService.saveOrUpdateLoop(testLoop);
//then
assertThat(actualLoop).isNotNull();
@@ -166,7 +166,7 @@ public class LoopServiceTestItCase {
private void saveTestLoopToDb() {
Loop testLoop = createTestLoop(EXAMPLE_LOOP_NAME, "blueprint", "representation");
testLoop.setGlobalPropertiesJson(JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
- loopService.addNewLoop(testLoop);
+ loopService.saveOrUpdateLoop(testLoop);
}
@Test
diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties
index 49ed897a9..e15b8737a 100644
--- a/src/test/resources/application.properties
+++ b/src/test/resources/application.properties
@@ -62,7 +62,7 @@ server.port=${clamp.it.tests.http}
server.servlet.context-path=/
#Modified engine-rest applicationpath
-spring.profiles.active=clamp-default,clamp-default-user,clamp-sdc-controller
+spring.profiles.active=clamp-default,clamp-default-user
spring.http.converters.preferred-json-mapper=gson
#The max number of active threads in this pool
diff --git a/src/test/resources/clds/util/file.xml b/src/test/resources/clds/util/file.xml
new file mode 100644
index 000000000..81560bab4
--- /dev/null
+++ b/src/test/resources/clds/util/file.xml
@@ -0,0 +1,6 @@
+<note>
+ <to>Tove</to>
+ <from>Jani</from>
+ <heading>Reminder</heading>
+ <body>Message body</body>
+</note>
diff --git a/src/test/resources/example/sdc/service-Simsfoimap0112.csar b/src/test/resources/example/sdc/service-Simsfoimap0112.csar
index ea0e44a22..8c16d31ee 100644
--- a/src/test/resources/example/sdc/service-Simsfoimap0112.csar
+++ b/src/test/resources/example/sdc/service-Simsfoimap0112.csar
Binary files differ