diff options
author | Bogumil Zebek <bogumil.zebek@nokia.com> | 2021-03-10 12:55:08 +0100 |
---|---|---|
committer | Zebek Bogumil <bogumil.zebek@nokia.com> | 2021-03-10 12:55:08 +0100 |
commit | bae12bf7d5a92a4d6be22e9ce8c3dc9878c59f36 (patch) | |
tree | 5cbb50a4c336d7ebee4c402f20f0e036a3bca814 /integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java | |
parent | 4af5241ab25b0103d8ea680789aaf9a8696dfc75 (diff) |
Package rename
Step 2: package rename, fix pom.xml, fix integration tests
Issue-ID: INT-1869
Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
Change-Id: Ia4c6823e4facc3791583fb39caba3bcc125b3af7
Diffstat (limited to 'integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java')
-rw-r--r-- | integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java new file mode 100644 index 0000000..da93e60 --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java @@ -0,0 +1,75 @@ +package org.onap.integration.simulators.nfsimulator.vesclient.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 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 = TestUtils.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"; + } + +} |