aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator
diff options
context:
space:
mode:
Diffstat (limited to 'test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator')
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java66
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java204
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java6
3 files changed, 273 insertions, 3 deletions
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 e69de29bb..d8e60c18d 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
@@ -0,0 +1,66 @@
+/*
+ * ============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.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+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 java.util.Optional;
+import org.json.JSONException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class SimulatorFactoryTest {
+
+
+ private SimulatorFactory simulatorFactory;
+
+ @BeforeEach
+ void setUp() {
+ simulatorFactory = new SimulatorFactory();
+ }
+
+ @Test
+ void should_successfully_create_simulator_given_valid_pnf_registration_params() {
+ 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() {
+ assertNotNull(simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
+ Optional.empty(), VALID_NOTIFICATION_PARAMS));
+ }
+
+ @Test
+ void should_throw_given_invalid_simulator_params() {
+ assertThrows(
+ JSONException.class,
+ () -> simulatorFactory.create(INVALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
+ VALID_PNF_REGISTRATION_PARAMS, VALID_NOTIFICATION_PARAMS));
+ }
+}
+
+
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 e69de29bb..7ed9f04c2 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
@@ -0,0 +1,204 @@
+/*
+ * ============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.Assert.assertNull;
+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.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+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.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 java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
+import org.mockito.Mockito;
+import org.onap.pnfsimulator.FileProvider;
+import org.onap.pnfsimulator.simulator.client.HttpClientAdapter;
+import org.onap.pnfsimulator.simulator.validation.NoRopFilesException;
+import org.onap.pnfsimulator.simulator.validation.ValidationException;
+
+public class SimulatorTest {
+
+ private static final String TEST_VES_URL = "http://localhost:10000/eventListener/v7";
+ private static final String TEST_XNF_URL = "sftp://onap:pano@10.11.0.68" + "/";
+ private FileProvider fileProvider = mock(FileProvider.class);
+
+ private void createSampleFileList() {
+ List<String> fileList = new ArrayList<>();
+ fileList.add("A20190401.1608+0000-1622+0000_excl-eeiwbue-perf-large-pnf-sim-lw-1.xml.gz");
+ fileList.add("A20190401.1623+0000-1637+0000_excl-eeiwbue-perf-large-pnf-sim-lw-1.xml.gz");
+
+ try {
+ doReturn(fileList).when(fileProvider).getFiles();
+ } catch (NoRopFilesException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @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_stop_when_interrupted() {
+ createSampleFileList();
+
+ HttpClientAdapter httpClientMock = Mockito.mock(HttpClientAdapter.class);
+ Simulator simulator = Simulator.builder()
+ .withInterval(Duration.ofSeconds(1))
+ .withCustomHttpClientAdapter(httpClientMock)
+ .withCommonEventHeaderParams(VALID_COMMON_EVENT_HEADER_PARAMS)
+ .withPnfRegistrationParams(Optional.empty())
+ .withNotificationParams(VALID_NOTIFICATION_PARAMS)
+ .withVesUrl(TEST_VES_URL)
+ .withXnfUrl(TEST_XNF_URL)
+ .withCustomHttpClientAdapter(httpClientMock)
+ .withFileProvider(fileProvider).build();
+
+ simulator.start();
+ simulator.interrupt();
+
+ assertTimeout(Duration.ofSeconds(1), (Executable) simulator::join);
+ }
+
+ @Test
+ void should_throw_noropfiles_exception_given_empty_filelist() {
+ Simulator simulator = Simulator.builder()
+ .withDuration(Duration.ofMillis(100))
+ .withInterval(Duration.ofMillis(10))
+ .withCommonEventHeaderParams(VALID_COMMON_EVENT_HEADER_PARAMS)
+ .withPnfRegistrationParams(VALID_PNF_REGISTRATION_PARAMS)
+ .withNotificationParams(Optional.empty())
+ .withVesUrl(TEST_VES_URL)
+ .withXnfUrl(TEST_XNF_URL)
+ .withFileProvider(new FileProvider()).build();
+ simulator.run();
+ Exception e = simulator.getThrownException();
+ assertTrue(e instanceof NoRopFilesException);
+ }
+
+ @Test
+ void should_throw_validation_exception_given_invalid_params() {
+ createSampleFileList();
+
+ Simulator simulator = Simulator.builder()
+ .withDuration(Duration.ofMillis(100))
+ .withInterval(Duration.ofMillis(10))
+ .withCommonEventHeaderParams(VALID_COMMON_EVENT_HEADER_PARAMS)
+ .withPnfRegistrationParams(INVALID_PNF_REGISTRATION_PARAMS_1)
+ .withNotificationParams(Optional.empty())
+ .withVesUrl(TEST_VES_URL)
+ .withXnfUrl(TEST_XNF_URL)
+ .withFileProvider(fileProvider).build();
+ simulator.run();
+ Exception e = simulator.getThrownException();
+ assertTrue(e instanceof ValidationException);
+
+ simulator = Simulator.builder()
+ .withDuration(Duration.ofMillis(100))
+ .withInterval(Duration.ofMillis(10))
+ .withCommonEventHeaderParams(VALID_COMMON_EVENT_HEADER_PARAMS)
+ .withPnfRegistrationParams(INVALID_PNF_REGISTRATION_PARAMS_2)
+ .withNotificationParams(Optional.empty())
+ .withVesUrl(TEST_VES_URL)
+ .withXnfUrl(TEST_XNF_URL)
+ .withFileProvider(fileProvider).build();
+ simulator.run();
+ e = simulator.getThrownException();
+ assertTrue(e instanceof ValidationException);
+
+ simulator = Simulator.builder()
+ .withDuration(Duration.ofMillis(100))
+ .withInterval(Duration.ofMillis(10))
+ .withCommonEventHeaderParams(VALID_COMMON_EVENT_HEADER_PARAMS)
+ .withPnfRegistrationParams(INVALID_PNF_REGISTRATION_PARAMS_3)
+ .withNotificationParams(Optional.empty())
+ .withVesUrl(TEST_VES_URL)
+ .withXnfUrl(TEST_XNF_URL)
+ .withFileProvider(fileProvider).build();
+ simulator.run();
+ e = simulator.getThrownException();
+ assertTrue(e instanceof ValidationException);
+
+ simulator = Simulator.builder()
+ .withDuration(Duration.ofMillis(100))
+ .withInterval(Duration.ofMillis(10))
+ .withCommonEventHeaderParams(VALID_COMMON_EVENT_HEADER_PARAMS)
+ .withPnfRegistrationParams(VALID_PNF_REGISTRATION_PARAMS)
+ .withNotificationParams(INVALID_NOTIFICATION_PARAMS)
+ .withVesUrl(TEST_VES_URL)
+ .withXnfUrl(TEST_XNF_URL)
+ .withFileProvider(fileProvider).build();
+ simulator.run();
+ e = simulator.getThrownException();
+ assertTrue(e instanceof ValidationException);
+ }
+
+ @Test
+ void simulator_should_send_fileready_message() {
+ createSampleFileList();
+
+ HttpClientAdapter httpClientMock = Mockito.mock(HttpClientAdapter.class);
+ Simulator simulator = Simulator.builder()
+ .withDuration(Duration.ofMillis(100))
+ .withInterval(Duration.ofMillis(10))
+ .withCommonEventHeaderParams(VALID_COMMON_EVENT_HEADER_PARAMS)
+ .withPnfRegistrationParams(Optional.empty())
+ .withNotificationParams(VALID_NOTIFICATION_PARAMS)
+ .withVesUrl(TEST_VES_URL)
+ .withXnfUrl(TEST_XNF_URL)
+ .withCustomHttpClientAdapter(httpClientMock)
+ .withFileProvider(fileProvider).build();
+ simulator.run();
+ Exception e = simulator.getThrownException();
+ assertNull(e);
+
+ assertTimeout(Duration.ofMillis(150), (Executable) simulator::join);
+ verify(httpClientMock, times(1)).send(anyString(), eq(TEST_VES_URL));
+ }
+}
+
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java
index 7511084c4..d92b3c2c5 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java
@@ -26,13 +26,13 @@ import java.nio.file.Paths;
import java.util.Optional;
import org.json.JSONObject;
-final class TestMessages {
+public final class TestMessages {
static final JSONObject VALID_SIMULATOR_PARAMS = new JSONObject(getContent("validSimulatorParams.json"));
- static final JSONObject VALID_COMMON_EVENT_HEADER_PARAMS = new JSONObject(getContent("validCommonEventHeaderParams.json"));
+ public static final JSONObject VALID_COMMON_EVENT_HEADER_PARAMS = new JSONObject(getContent("validCommonEventHeaderParams.json"));
static final Optional<JSONObject> VALID_PNF_REGISTRATION_PARAMS = Optional
.of(new JSONObject(getContent("validPnfRegistrationParams.json")));
- static final Optional<JSONObject> VALID_NOTIFICATION_PARAMS = Optional
+ public static final Optional<JSONObject> VALID_NOTIFICATION_PARAMS = Optional
.of(new JSONObject(getContent("validNotificationParams.json")));
static final JSONObject INVALID_SIMULATOR_PARAMS = new JSONObject(