aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/clamp/clds
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-02-17 15:31:28 -0800
committersebdet <sebastien.determe@intl.att.com>2020-02-25 01:04:12 -0800
commit4e8e11afced0693e24074fd6bb8d5b2cace98ab6 (patch)
treec177c0cccbe404a818188e954ce65848b2fb6d8c /src/test/java/org/onap/clamp/clds
parent3b7f669088d5867056578b275bf4314af3a439c6 (diff)
Operational policy modification
policyModel added to Operational policy object so that a user in the UI can add op policies, guard or whatever Issue-ID: CLAMP-647 Change-Id: I57521bc1c3afaf5ca5a2acf5c59823df06fd4cd9 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/test/java/org/onap/clamp/clds')
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java56
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java77
2 files changed, 109 insertions, 24 deletions
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
index 65eb2696..63209e9f 100644
--- a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
@@ -26,12 +26,12 @@
package org.onap.clamp.clds.util.drawing;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import java.util.Arrays;
-import java.util.List;
-
+import com.google.gson.JsonObject;
+import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,7 +39,10 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.clamp.clds.sdc.controller.installer.BlueprintMicroService;
+import org.onap.clamp.loop.Loop;
+import org.onap.clamp.loop.template.PolicyModel;
+import org.onap.clamp.policy.microservice.MicroServicePolicy;
+import org.onap.clamp.policy.operational.OperationalPolicy;
@RunWith(MockitoJUnitRunner.class)
public class ClampGraphBuilderTest {
@@ -50,47 +53,52 @@ public class ClampGraphBuilderTest {
private ArgumentCaptor<String> collectorCaptor;
@Captor
- private ArgumentCaptor<List<BlueprintMicroService>> microServicesCaptor;
+ private ArgumentCaptor<Set<MicroServicePolicy>> microServicesCaptor;
@Captor
- private ArgumentCaptor<String> policyCaptor;
+ private ArgumentCaptor<Set<OperationalPolicy>> policyCaptor;
+ /**
+ * Do a quick test of the graphBuilder chain.
+ */
@Test
public void clampGraphBuilderCompleteChainTest() {
String collector = "VES";
- BlueprintMicroService ms1 = new BlueprintMicroService("ms1", "", "", "1.0.0");
- BlueprintMicroService ms2 = new BlueprintMicroService("ms2", "", "", "1.0.0");
+ MicroServicePolicy ms1 = new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0"), false,
+ null);
+ MicroServicePolicy ms2 = new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0"), false,
+ null);
- String policy = "OperationalPolicy";
- final List<BlueprintMicroService> microServices = Arrays.asList(ms1, ms2);
+ OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new Loop(), new JsonObject(),
+ new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1"));
+ final Set<OperationalPolicy> opPolicies = Set.of(opPolicy);
+ final Set<MicroServicePolicy> microServices = Set.of(ms1, ms2);
ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
- clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).policy(policy).build();
+ clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).addPolicy(opPolicy).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());
+ Assert.assertEquals(opPolicies, policyCaptor.getValue());
}
- @Test(expected = InvalidStateException.class)
+ /**
+ * Do a quick test of the graphBuilder chain when no policy is given.
+ */
+ @Test
public void clampGraphBuilderNoPolicyGivenTest() {
String collector = "VES";
- BlueprintMicroService ms1 = new BlueprintMicroService("ms1", "", "", "1.0.0");
- BlueprintMicroService ms2 = new BlueprintMicroService("ms2", "", "", "1.0.0");
+ MicroServicePolicy ms1 =
+ new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0"), false, null);
+ MicroServicePolicy ms2 =
+ new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0"), false, null);
ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
- clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).build();
- }
+ assertThat(clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).build())
+ .isNotNull();
- @Test(expected = InvalidStateException.class)
- public void clampGraphBuilderNoMicroServiceGivenTest() {
- String collector = "VES";
- String policy = "OperationalPolicy";
-
- ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
- clampGraphBuilder.collector(collector).policy(policy).build();
}
}
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java
new file mode 100644
index 00000000..aad11adb
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java
@@ -0,0 +1,77 @@
+/*-
+ * ============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.clds.util.drawing;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.gson.JsonObject;
+import java.io.IOException;
+import java.util.HashSet;
+import javax.xml.parsers.ParserConfigurationException;
+import org.junit.Test;
+import org.onap.clamp.loop.Loop;
+import org.onap.clamp.loop.template.PolicyModel;
+import org.onap.clamp.policy.microservice.MicroServicePolicy;
+import org.onap.clamp.policy.operational.OperationalPolicy;
+import org.xml.sax.SAXException;
+
+public class SvgLoopGeneratorTest {
+ private Loop getLoop() {
+ MicroServicePolicy ms1 =
+ new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0", "short.ms1"),
+ false,
+ new HashSet<Loop>());
+ MicroServicePolicy ms2 =
+ new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0", "short.ms2"),
+ false, new HashSet<Loop>());
+ OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new Loop(), new JsonObject(),
+ new PolicyModel("org.onap.opolicy", null, "1.0.0", "short.OperationalPolicy"));
+ Loop loop = new Loop();
+ loop.addMicroServicePolicy(ms1);
+ loop.addMicroServicePolicy(ms2);
+ loop.addOperationalPolicy(opPolicy);
+ return loop;
+ }
+
+ /**
+ * Test a Svg rendering with all objects.
+ *
+ * @throws IOException In case of isssues
+ * @throws ParserConfigurationException In case of isssues
+ * @throws SAXException In case of isssues
+ */
+ @Test
+ public void getAsSvgTest() throws IOException, ParserConfigurationException, SAXException {
+ String xml = SvgLoopGenerator.getSvgImage(getLoop());
+ assertThat(xml).contains("data-element-id=\"VES\"");
+ assertThat(xml).contains(">VES<");
+ assertThat(xml).contains("data-element-id=\"ms1\"");
+ assertThat(xml).contains("data-element-id=\"ms2\"");
+ assertThat(xml).contains(">short.ms1<");
+ assertThat(xml).contains(">short.ms2<");
+ assertThat(xml).contains("data-element-id=\"OperationalPolicy\"");
+ assertThat(xml).contains(">short.OperationalPolicy<");
+
+ }
+}