aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src
diff options
context:
space:
mode:
authorRehanRaza <muhammad.rehan.raza@est.tech>2019-03-29 10:30:33 +0000
committerRehanRaza <muhammad.rehan.raza@est.tech>2019-03-29 10:30:33 +0000
commita2f942369425233e9029bdce452cd3a363e617cb (patch)
tree4fac3cc5f6c3a866c6ac561997dd6d5496798108 /test/mocks/mass-pnf-sim/pnf-sim-lightweight/src
parentb42c19352ae5659679ad8631bdcf5cd0f8291c52 (diff)
Update VES event with latest file in each ROP
Change-Id: I64e8ac7ba99c28d299a711741dcc1c6f8bc9e47e Issue-ID: DCAEGEN2-1225 Signed-off-by: RehanRaza <muhammad.rehan.raza@est.tech>
Diffstat (limited to 'test/mocks/mass-pnf-sim/pnf-sim-lightweight/src')
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java64
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java35
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java100
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java92
4 files changed, 61 insertions, 230 deletions
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java
index 9b4725fd1..5c6405742 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java
@@ -17,12 +17,20 @@
package org.onap.pnfsimulator.simulator;
+import com.github.fge.jsonschema.core.exceptions.ProcessingException;
+import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
+import java.util.List;
import java.util.Map;
+import java.util.Optional;
import org.json.JSONObject;
+import org.onap.pnfsimulator.FileProvider;
+import org.onap.pnfsimulator.message.MessageProvider;
import org.onap.pnfsimulator.simulator.client.HttpClientAdapter;
import org.onap.pnfsimulator.simulator.client.HttpClientAdapterImpl;
+import org.onap.pnfsimulator.simulator.validation.JSONValidator;
+import org.onap.pnfsimulator.simulator.validation.ValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@@ -41,6 +49,11 @@ public class Simulator extends Thread {
private Duration duration;
private Duration interval;
private Instant endTime;
+ private JSONObject commonEventHeaderParams;
+ private Optional<JSONObject> pnfRegistrationParams;
+ private Optional<JSONObject> notificationParams;
+ private String xnfUrl;
+ private static final String DEFAULT_OUTPUT_SCHEMA_PATH = "json_schema/output_validator_ves_schema_30.0.1.json";
private Simulator() {}
@@ -55,11 +68,19 @@ public class Simulator extends Thread {
endTime = Instant.now().plus(duration);
while (isEndless || runningTimeNotExceeded()) {
try {
+ List<String> fileList = FileProvider.getFiles();
+ MessageProvider messageProvider = new MessageProvider();
+ JSONValidator validator = new JSONValidator();
+
+ messageBody = messageProvider.createMessage(this.commonEventHeaderParams, this.pnfRegistrationParams,
+ this.notificationParams, fileList, this.xnfUrl);
+ validator.validate(messageBody.toString(), DEFAULT_OUTPUT_SCHEMA_PATH);
+
LOGGER.info("Message to be sent:\n" + getMessage());
httpClient.send(messageBody.toString(), vesUrl);
Thread.sleep(interval.toMillis());
- } catch (InterruptedException e) {
- LOGGER.info("Simulation interrupted");
+ } catch (InterruptedException | ValidationException | ProcessingException | IOException e) {
+ LOGGER.info("Simulation stopped due to an exception");
return;
}
}
@@ -96,16 +117,21 @@ public class Simulator extends Thread {
private String vesUrl;
private HttpClientAdapter httpClient;
- private JSONObject messageBody;
+ //private JSONObject messageBody;
private Duration duration;
private Duration interval;
+ private Optional<JSONObject> notificationParams;
+ private Optional<JSONObject> pnfRegistrationParams;
+ private JSONObject commonEventHeaderParams;
+ private String xnfUrl;
private Builder() {
this.vesUrl = "";
this.httpClient = new HttpClientAdapterImpl();
- this.messageBody = new JSONObject();
+ //this.messageBody = new JSONObject();
this.duration = Duration.ZERO;
this.interval = Duration.ZERO;
+ this.commonEventHeaderParams = new JSONObject();
}
public Builder withVesUrl(String vesUrl) {
@@ -118,10 +144,10 @@ public class Simulator extends Thread {
return this;
}
- public Builder withMessageBody(JSONObject messageBody) {
+ /*public Builder withMessageBody(JSONObject messageBody) {
this.messageBody = messageBody;
return this;
- }
+ }*/
public Builder withDuration(Duration duration) {
this.duration = duration;
@@ -134,13 +160,37 @@ public class Simulator extends Thread {
return this;
}
+ public Builder withCommonEventHeaderParams(JSONObject commonEventHeaderParams) {
+ this.commonEventHeaderParams = commonEventHeaderParams;
+ return this;
+ }
+
+ public Builder withNotificationParams(Optional<JSONObject> notificationParams) {
+ this.notificationParams = notificationParams;
+ return this;
+ }
+
+ public Builder withPnfRegistrationParams(Optional<JSONObject> pnfRegistrationParams) {
+ this.pnfRegistrationParams = pnfRegistrationParams;
+ return this;
+ }
+
+ public Builder withXnfUrl(String xnfUrl) {
+ this.xnfUrl = xnfUrl;
+ return this;
+ }
+
public Simulator build() {
Simulator simulator = new Simulator();
simulator.vesUrl = this.vesUrl;
simulator.httpClient = this.httpClient;
- simulator.messageBody = this.messageBody;
+ //simulator.messageBody = this.messageBody;
simulator.duration = this.duration;
simulator.interval = this.interval;
+ simulator.xnfUrl = this.xnfUrl;
+ simulator.commonEventHeaderParams = this.commonEventHeaderParams;
+ simulator.pnfRegistrationParams = this.pnfRegistrationParams;
+ simulator.notificationParams = this.notificationParams;
simulator.isEndless = duration.equals(Duration.ZERO);
return simulator;
}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java
index 54af2b9a0..a01c2e0c6 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java
@@ -20,42 +20,21 @@ package org.onap.pnfsimulator.simulator;
import static java.lang.Integer.parseInt;
import static org.onap.pnfsimulator.message.MessageConstants.MESSAGE_INTERVAL;
import static org.onap.pnfsimulator.message.MessageConstants.TEST_DURATION;
-import com.github.fge.jsonschema.core.exceptions.ProcessingException;
-import java.io.IOException;
import java.time.Duration;
-import java.util.List;
import java.util.Optional;
import org.json.JSONObject;
import org.onap.pnfsimulator.ConfigurationProvider;
-import org.onap.pnfsimulator.FileProvider;
import org.onap.pnfsimulator.PnfSimConfig;
-import org.onap.pnfsimulator.message.MessageProvider;
-import org.onap.pnfsimulator.simulator.validation.JSONValidator;
-import org.onap.pnfsimulator.simulator.validation.ValidationException;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SimulatorFactory {
- private static final String DEFAULT_OUTPUT_SCHEMA_PATH = "json_schema/output_validator_ves_schema_30.0.1.json";
-
- private MessageProvider messageProvider;
- private JSONValidator validator;
-
- @Autowired
- public SimulatorFactory(MessageProvider messageProvider, JSONValidator validator) {
- this.messageProvider = messageProvider;
- this.validator = validator;
- }
-
public Simulator create(JSONObject simulatorParams, JSONObject commonEventHeaderParams,
- Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams)
- throws ProcessingException, IOException, ValidationException {
+ Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams) {
PnfSimConfig configuration = ConfigurationProvider.getConfigInstance();
String xnfUrl = null;
-
if (configuration.getDefaultfileserver().equals("sftp")) {
xnfUrl = configuration.getUrlsftp() + "/";
} else if (configuration.getDefaultfileserver().equals("ftps")) {
@@ -63,17 +42,11 @@ public class SimulatorFactory {
}
String urlVes = configuration.getUrlves();
-
Duration duration = Duration.ofSeconds(parseInt(simulatorParams.getString(TEST_DURATION)));
Duration interval = Duration.ofSeconds(parseInt(simulatorParams.getString(MESSAGE_INTERVAL)));
- List<String> fileList = FileProvider.getFiles();
- JSONObject messageBody = messageProvider.createMessage(commonEventHeaderParams, pnfRegistrationParams,
- notificationParams, fileList, xnfUrl);
- validator.validate(messageBody.toString(), DEFAULT_OUTPUT_SCHEMA_PATH);
-
- return Simulator.builder().withVesUrl(urlVes).withDuration(duration).withInterval(interval)
- .withMessageBody(messageBody).build();
-
+ return Simulator.builder().withVesUrl(urlVes).withXnfUrl(xnfUrl).withDuration(duration)
+ .withCommonEventHeaderParams(commonEventHeaderParams).withNotificationParams(notificationParams)
+ .withPnfRegistrationParams(pnfRegistrationParams).withInterval(interval).build();
}
}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java
index ea7a09785..e69de29bb 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java
@@ -1,100 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 NOKIA 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.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_NOTIFICATION_PARAMS;
-import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_PNF_REGISTRATION_PARAMS_1;
-import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_PNF_REGISTRATION_PARAMS_2;
-import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_PNF_REGISTRATION_PARAMS_3;
-import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_SIMULATOR_PARAMS;
-import static org.onap.pnfsimulator.simulator.TestMessages.VALID_COMMON_EVENT_HEADER_PARAMS;
-import static org.onap.pnfsimulator.simulator.TestMessages.VALID_NOTIFICATION_PARAMS;
-import static org.onap.pnfsimulator.simulator.TestMessages.VALID_PNF_REGISTRATION_PARAMS;
-import static org.onap.pnfsimulator.simulator.TestMessages.VALID_SIMULATOR_PARAMS;
-
-import com.github.fge.jsonschema.core.exceptions.ProcessingException;
-import java.io.IOException;
-import java.util.Optional;
-import org.json.JSONException;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.onap.pnfsimulator.message.MessageProvider;
-import org.onap.pnfsimulator.simulator.validation.JSONValidator;
-import org.onap.pnfsimulator.simulator.validation.ValidationException;
-
-class SimulatorFactoryTest {
-
-
- private SimulatorFactory simulatorFactory;
-
- @BeforeEach
- void setUp() {
- simulatorFactory = new SimulatorFactory(new MessageProvider(), new JSONValidator());
- }
-
- @Test
- void should_successfully_create_simulator_given_valid_pnf_registration_params_and_valid_output_message()
- throws ValidationException, IOException, ProcessingException {
- assertNotNull(simulatorFactory.create(VALID_SIMULATOR_PARAMS,VALID_COMMON_EVENT_HEADER_PARAMS,
- VALID_PNF_REGISTRATION_PARAMS,Optional.empty()));
- }
-
- @Test
- void should_successfully_create_simulator_given_valid_notification_params_and_valid_output_message()
- throws ValidationException, IOException, ProcessingException {
- assertNotNull(simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
- Optional.empty(), VALID_NOTIFICATION_PARAMS));
- }
-
- @Test
- void should_throw_given_invalid_params() {
- assertThrows(
- JSONException.class,
- () -> simulatorFactory.create(INVALID_SIMULATOR_PARAMS,VALID_COMMON_EVENT_HEADER_PARAMS,
- VALID_PNF_REGISTRATION_PARAMS,Optional.empty()));
- }
-
- @Test
- void should_throw_given_valid_params_and_invalid_output_message() {
-
- assertThrows(
- ValidationException.class,
- () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
- INVALID_PNF_REGISTRATION_PARAMS_1, Optional.empty()));
-
- assertThrows(
- ValidationException.class,
- () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
- INVALID_PNF_REGISTRATION_PARAMS_2, Optional.empty()));
-
- assertThrows(
- ValidationException.class,
- () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
- INVALID_PNF_REGISTRATION_PARAMS_3, Optional.empty()));
-
- assertThrows(
- ValidationException.class,
- () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
- VALID_PNF_REGISTRATION_PARAMS, INVALID_NOTIFICATION_PARAMS));
- }
-} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java
index db9dbd785..e69de29bb 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java
@@ -1,92 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 NOKIA 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.pnfsimulator.simulator;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTimeout;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.verify;
-
-import java.time.Duration;
-import org.json.JSONObject;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.function.Executable;
-import org.mockito.Mockito;
-import org.onap.pnfsimulator.simulator.client.HttpClientAdapter;
-
-class SimulatorTest {
-
- private static final String TEST_VES_URL = "http://test-ves-url";
-
- @Test
- void builder_should_create_endless_simulator_when_duration_not_specified() {
- Simulator simulator = Simulator
- .builder()
- .withDuration(Duration.ofSeconds(1))
- .withVesUrl(TEST_VES_URL).build();
-
- assertFalse(simulator.isEndless());
-
- simulator = Simulator
- .builder()
- .withVesUrl(TEST_VES_URL).build();
-
- assertTrue(simulator.isEndless());
- }
-
- @Test
- void simulator_should_send_given_message() {
-
- JSONObject messageBody = new JSONObject("{\"key\":\"val\"}");
- HttpClientAdapter httpClientMock = Mockito.mock(HttpClientAdapter.class);
-
- Simulator simulator = Simulator.builder()
- .withDuration(Duration.ofMillis(100))
- .withInterval(Duration.ofMillis(10))
- .withMessageBody(messageBody)
- .withCustomHttpClientAdapter(httpClientMock)
- .withVesUrl(TEST_VES_URL).build();
-
- simulator.start();
-
- assertTimeout(Duration.ofMillis(150), (Executable) simulator::join);
- verify(httpClientMock, atLeast(2)).send(messageBody.toString(), TEST_VES_URL);
- }
-
- @Test
- void simulator_should_stop_when_interrupted() {
-
- JSONObject messageBody = new JSONObject("{\"key\":\"val\"}");
- HttpClientAdapter httpClientMock = Mockito.mock(HttpClientAdapter.class);
-
- Simulator simulator = Simulator.builder()
- .withInterval(Duration.ofSeconds(1))
- .withMessageBody(messageBody)
- .withCustomHttpClientAdapter(httpClientMock)
- .withVesUrl(TEST_VES_URL).build();
-
- simulator.start();
- simulator.interrupt();
-
- assertTimeout(Duration.ofSeconds(1), (Executable) simulator::join);
- }
-} \ No newline at end of file