aboutsummaryrefslogtreecommitdiffstats
path: root/pnfsimulator/integration
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-04-09 11:49:18 +0200
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-04-27 14:00:38 +0200
commit85bedddf8340cbbe57f941a919a980540aeeef59 (patch)
tree583203fc8de877736c1e54d8ada304bef4871454 /pnfsimulator/integration
parented68a0ba2a4836f8963e9f4973a440f096af19e8 (diff)
Add variables to PNF simulator events and update logging
Issue-ID: INT-1517 Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> Change-Id: I48931c0b4c68cd4de548cfa7dbaa950a24d13545
Diffstat (limited to 'pnfsimulator/integration')
-rw-r--r--pnfsimulator/integration/src/test/java/org/onap/pnfsimulator/integration/VariablesReplacement.java86
-rw-r--r--pnfsimulator/integration/src/test/java/org/onap/pnfsimulator/integration/suites/DockerBasedTestsSuite.java3
-rw-r--r--pnfsimulator/integration/src/test/resources/templates/cmNotification.json32
3 files changed, 120 insertions, 1 deletions
diff --git a/pnfsimulator/integration/src/test/java/org/onap/pnfsimulator/integration/VariablesReplacement.java b/pnfsimulator/integration/src/test/java/org/onap/pnfsimulator/integration/VariablesReplacement.java
new file mode 100644
index 0000000..c0bd989
--- /dev/null
+++ b/pnfsimulator/integration/src/test/java/org/onap/pnfsimulator/integration/VariablesReplacement.java
@@ -0,0 +1,86 @@
+package org.onap.pnfsimulator.integration;
+
+import static io.restassured.RestAssured.given;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+import com.google.gson.JsonObject;
+import java.net.Inet4Address;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.Collections;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = {Main.class, TestConfiguration.class},
+ webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+public class VariablesReplacement {
+
+ @Autowired
+ private VesSimulatorService vesSimulatorService;
+
+ private String currentVesSimulatorIp;
+
+ @Before
+ public void setUp() throws Exception {
+ currentVesSimulatorIp = getCurrentIpAddress();
+ }
+
+ @Test
+ public void whenTriggeredSimulatorShouldReplaceStringKeyword() {
+ String startUrl = prepareRequestUrl();
+ String body = "{\n" + "\"templateName\": \"cmNotification.json\",\n" + "\"patch\":{},\n" + "\"variables\":{\n"
+ + "\"dN\": \"NRNB=5, NRCEL=1234\",\n" + "\"attributeList\":{\n"
+ + "\"threshXHighQ\": \"50\",\n" + "\"threshXHighP\": \"52\"\n" + "}\n" + "},\n"
+ + "\"simulatorParams\": {\n" + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp
+ + ":9443/ves-simulator/eventListener/v5\",\n" + "\"repeatInterval\": 1,\n"
+ + "\"repeatCount\": 1\n" + "}\n" + "}";
+ ArgumentCaptor<JsonObject> parameterCaptor = ArgumentCaptor.forClass(JsonObject.class);
+
+ given().contentType("application/json").body(body).when().post(startUrl).then().statusCode(200)
+ .body("message", equalTo("Request started"));
+
+ Mockito.verify(vesSimulatorService, Mockito.timeout(3000)).sendEventToDmaapV5(parameterCaptor.capture());
+
+ assertAttributeList(parameterCaptor);
+ assertDn(parameterCaptor);
+ }
+
+ private void assertDn(ArgumentCaptor<JsonObject> parameterCaptor) {
+ String dn = parameterCaptor.getValue().getAsJsonObject("event").getAsJsonObject("otherFields")
+ .getAsJsonArray("jsonObjects").get(0)
+ .getAsJsonObject().getAsJsonArray("objectInstances")
+ .get(0).getAsJsonObject().getAsJsonObject("objectInstance")
+ .getAsJsonObject("cm3gppNotifyFields").getAsJsonPrimitive("dN").getAsString();
+ assertThat(dn).isEqualTo("NRNB=5, NRCEL=1234");
+ }
+
+ private void assertAttributeList(ArgumentCaptor<JsonObject> parameterCaptor) {
+ JsonObject attributeList = parameterCaptor.getValue().getAsJsonObject("event").getAsJsonObject("otherFields")
+ .getAsJsonArray("jsonObjects").get(0).getAsJsonObject()
+ .getAsJsonArray("objectInstances").get(0).getAsJsonObject()
+ .getAsJsonObject("objectInstance").getAsJsonObject("cm3gppNotifyFields")
+ .getAsJsonObject("attributeList");
+ assertThat(attributeList.get("threshXHighQ").getAsString()).isEqualTo("50");
+ assertThat(attributeList.get("threshXHighP").getAsString()).isEqualTo("52");
+ }
+
+ private String prepareRequestUrl() {
+ return "http://0.0.0.0:5000/simulator/start";
+ }
+
+ private String getCurrentIpAddress() throws SocketException {
+ return Collections.list(NetworkInterface.getNetworkInterfaces()).stream()
+ .flatMap(i -> Collections.list(i.getInetAddresses()).stream())
+ .filter(ip -> ip instanceof Inet4Address).map(e -> (Inet4Address) e).findFirst()
+ .orElseThrow(RuntimeException::new).getHostAddress();
+ }
+
+}
diff --git a/pnfsimulator/integration/src/test/java/org/onap/pnfsimulator/integration/suites/DockerBasedTestsSuite.java b/pnfsimulator/integration/src/test/java/org/onap/pnfsimulator/integration/suites/DockerBasedTestsSuite.java
index cc2ac58..9ca7f60 100644
--- a/pnfsimulator/integration/src/test/java/org/onap/pnfsimulator/integration/suites/DockerBasedTestsSuite.java
+++ b/pnfsimulator/integration/src/test/java/org/onap/pnfsimulator/integration/suites/DockerBasedTestsSuite.java
@@ -30,10 +30,11 @@ import org.onap.pnfsimulator.integration.BasicAvailabilityTest;
import org.onap.pnfsimulator.integration.OptionalTemplatesTest;
import org.onap.pnfsimulator.integration.SearchInTemplatesTest;
import org.onap.pnfsimulator.integration.TemplatesManagementTest;
+import org.onap.pnfsimulator.integration.VariablesReplacement;
@RunWith(Suite.class)
@SuiteClasses({BasicAvailabilityTest.class, TemplatesManagementTest.class, OptionalTemplatesTest.class,
- SearchInTemplatesTest.class})
+ SearchInTemplatesTest.class, VariablesReplacement.class})
public class DockerBasedTestsSuite {
@ClassRule
diff --git a/pnfsimulator/integration/src/test/resources/templates/cmNotification.json b/pnfsimulator/integration/src/test/resources/templates/cmNotification.json
new file mode 100644
index 0000000..750ce30
--- /dev/null
+++ b/pnfsimulator/integration/src/test/resources/templates/cmNotification.json
@@ -0,0 +1,32 @@
+{
+ "event": {
+ "otherFields": {
+ "otherFieldsVersion": "3.0",
+ "jsonObjects": [
+ {
+ "objectName": "CustomNotification",
+ "objectInstances": [
+ {
+ "objectInstance": {
+ "cm3gppNotifyFields": {
+ "dN": "#dN",
+ "notificationType": "notifyMOIAttributeValueChange",
+ "notificationId": "notificationID123121312323",
+ "sourceIndicator": "sONOperation",
+ "eventTime": "#Timestamp",
+ "systemDN": "NRNB=5",
+ "attributeList": "#attributeList",
+ "correlatedNotifications": {
+ "notificationID-notifyMOIAttributeValueChange": "sONOperation"
+ },
+ "additionalText": "sometext",
+ "cm3gppNotifyFieldsVersion": "1.0"
+ }
+ }
+ }
+ ]
+ }
+ ]
+ }
+ }
+}