diff options
author | Gary Wu <gary.i.wu@huawei.com> | 2018-09-14 15:01:04 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-14 15:01:04 +0000 |
commit | 48687fdb042942218082c677a061c62144706bed (patch) | |
tree | 21b764a6ba4e43c2b48c9ef4728f41bcb34fadb4 /test/mocks | |
parent | 831baffde96cd7f644375a2e24f3c39fdd2b7616 (diff) | |
parent | 00ec84dcfe64733fdf503f0ed92f61f77b6a1c07 (diff) |
Merge "PNF Simulator SFTP support"
Diffstat (limited to 'test/mocks')
5 files changed, 76 insertions, 43 deletions
diff --git a/test/mocks/pnfsimulator/pom.xml b/test/mocks/pnfsimulator/pom.xml index 03b3883d8..cddbbbafa 100644 --- a/test/mocks/pnfsimulator/pom.xml +++ b/test/mocks/pnfsimulator/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - + <parent> <groupId>org.onap.oparent</groupId> <artifactId>oparent</artifactId> diff --git a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java index 4931c3b91..13114eefb 100644 --- a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java +++ b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java @@ -31,13 +31,12 @@ import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FI import java.util.Map; import java.util.Optional; -import javax.annotation.Nonnull; import org.json.JSONObject; public class MessageProvider { - public JSONObject createMessage(@Nonnull JSONObject commonEventHeaderParams,@Nonnull Optional<JSONObject> pnfRegistrationParams, - @Nonnull Optional<JSONObject> notificationParams) { + public JSONObject createMessage(JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams, + Optional<JSONObject> notificationParams) { if (!pnfRegistrationParams.isPresent() && !notificationParams.isPresent()) { throw new IllegalArgumentException( diff --git a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java index d40e29cee..aadb54cdc 100644 --- a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java +++ b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java @@ -35,8 +35,11 @@ import org.junit.jupiter.api.Test; public class MessageProviderTest { - private static final String testParamsJson = - "{\"key1\": \"val1\",\"key2\": \"val2\",\"pnf_key3\": \"pnfVal3\",\"key4\": \"val4\"}"; + private static final String testParamsPnfRegistration = + "{\"pnfKey1\": \"pnfVal1\",\"pnfKey2\": \"pnfVal2\",\"pnfKey3\": \"pnfVal3\",\"pnfKey4\": \"pnfVal4\"}"; + + private static final String testParamsNotification = + "{\"notKey1\": \"notVal1\",\"notKey2\": \"notVal2\",\"notKey3\": \"notVal3\",\"notKey4\": \"notVal4\"}"; private static MessageProvider messageProvider; @@ -48,13 +51,14 @@ public class MessageProviderTest { @Test public void createMessage_should_throw_when_given_empty_arguments() { assertThrows(IllegalArgumentException.class, - () -> messageProvider.createMessage(new JSONObject(),Optional.empty(),Optional.empty()), + () -> messageProvider.createMessage(new JSONObject(), Optional.empty(), Optional.empty()), "Params object cannot be null"); } @Test public void createMessage_should_create_constant_message_when_no_params_specified() { - JSONObject message = messageProvider.createMessage(new JSONObject(),Optional.ofNullable(new JSONObject()),Optional.ofNullable(new JSONObject())); + JSONObject message = messageProvider.createMessage(new JSONObject(), Optional.ofNullable(new JSONObject()), + Optional.ofNullable(new JSONObject())); JSONObject event = message.getJSONObject(EVENT); JSONObject commonEventHeader = event.getJSONObject(COMMON_EVENT_HEADER); @@ -83,21 +87,29 @@ public class MessageProviderTest { @Test public void createMessage_should_throw_exception_when_params_specified_as_empty() { - assertThrows(IllegalArgumentException.class, () ->messageProvider.createMessage(new JSONObject(), Optional.empty(), - Optional.empty())); + assertThrows(IllegalArgumentException.class, + () -> messageProvider.createMessage(new JSONObject(), Optional.empty(), + Optional.empty())); } @Test public void createMessage_should_add_specified_params_to_valid_subobjects() { - JSONObject params = new JSONObject(testParamsJson); - JSONObject message = messageProvider.createMessage(new JSONObject(),Optional.of(params),Optional.empty()); + JSONObject message = messageProvider + .createMessage(new JSONObject(), Optional.of(new JSONObject(testParamsPnfRegistration)), + Optional.of(new JSONObject(testParamsNotification))); JSONObject event = message.getJSONObject(EVENT); JSONObject commonEventHeader = event.getJSONObject(COMMON_EVENT_HEADER); + assertEquals(10, commonEventHeader.keySet().size()); + JSONObject pnfRegistrationFields = event.getJSONObject(PNF_REGISTRATION_FIELDS); + assertEquals("pnfVal1", pnfRegistrationFields.getString("pnfKey1")); + assertEquals("pnfVal2", pnfRegistrationFields.getString("pnfKey2")); + + JSONObject notificationFields = event.getJSONObject(NOTIFICATION_FIELDS); + assertEquals("notVal1", notificationFields.getString("notKey1")); + assertEquals("notVal2", notificationFields.getString("notKey2")); - assertEquals("val1", pnfRegistrationFields.getString("key1")); - assertEquals("val2", pnfRegistrationFields.getString("key2")); } } diff --git a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java index 26f66b7e0..ea7a09785 100644 --- a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java +++ b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java @@ -22,13 +22,15 @@ 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_MESSAGE_PARAMS_1; -import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_MESSAGE_PARAMS_2; -import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_MESSAGE_PARAMS_3; +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 static org.onap.pnfsimulator.simulator.TestMessages.VALID_COMMON_EVENT_HEADER_PARAMS; import com.github.fge.jsonschema.core.exceptions.ProcessingException; import java.io.IOException; @@ -51,13 +53,20 @@ class SimulatorFactoryTest { } @Test - void should_successfully_create_simulator_given_valid_params_and_valid_output_message() + 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, @@ -70,14 +79,22 @@ class SimulatorFactoryTest { assertThrows( ValidationException.class, - () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS ,INVALID_MESSAGE_PARAMS_1,Optional.empty())); + () -> 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_MESSAGE_PARAMS_2,Optional.empty())); + () -> 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, INVALID_MESSAGE_PARAMS_3,Optional.empty())); + () -> 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/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java index 7f33e179d..7511084c4 100644 --- a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java +++ b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java @@ -22,7 +22,6 @@ package org.onap.pnfsimulator.simulator; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Optional; import org.json.JSONObject; @@ -31,23 +30,10 @@ 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")); - static final Optional<JSONObject> VALID_PNF_REGISTRATION_PARAMS = Optional.ofNullable(new JSONObject(getContent("validPnfRegistrationParams.json"))); - - private static String getContent(String fileName){ - - try { - String pathAsString = TestMessages.class.getResource(fileName).getPath(); - Path path = Paths.get(pathAsString); - StringBuilder stringBuilder = new StringBuilder(); - Files.readAllLines(path).forEach(line -> { - stringBuilder.append(line); - }); - return stringBuilder.toString(); - } catch (IOException e) { - throw new RuntimeException(String.format("Cannot read JSON file %s",fileName)); - } - - } + static final Optional<JSONObject> VALID_PNF_REGISTRATION_PARAMS = Optional + .of(new JSONObject(getContent("validPnfRegistrationParams.json"))); + static final Optional<JSONObject> VALID_NOTIFICATION_PARAMS = Optional + .of(new JSONObject(getContent("validNotificationParams.json"))); static final JSONObject INVALID_SIMULATOR_PARAMS = new JSONObject( "{\n" + @@ -56,7 +42,7 @@ final class TestMessages { "}"); - static final Optional<JSONObject> INVALID_MESSAGE_PARAMS_1 = Optional.ofNullable(new JSONObject( + static final Optional<JSONObject> INVALID_PNF_REGISTRATION_PARAMS_1 = Optional.of(new JSONObject( "{\n" + " \"pnfSerialNumber\": \"val1\",\n" + " \"pnfVendorName\": \"val2\",\n" + @@ -72,7 +58,7 @@ final class TestMessages { " \"reportingEntityName\": \"val14\"\n" + "}")); - static final Optional<JSONObject> INVALID_MESSAGE_PARAMS_2 = Optional.ofNullable(new JSONObject( + static final Optional<JSONObject> INVALID_PNF_REGISTRATION_PARAMS_2 = Optional.of(new JSONObject( "{\n" + " \"pnfVendorName\": \"val2\",\n" + " \"pnfOamIpv4Address\": \"val3\",\n" + @@ -89,7 +75,7 @@ final class TestMessages { " \"reportingEntityName\": \"val14\"\n" + "}")); - static final Optional<JSONObject> INVALID_MESSAGE_PARAMS_3 = Optional.ofNullable(new JSONObject( + static final Optional<JSONObject> INVALID_PNF_REGISTRATION_PARAMS_3 = Optional.of(new JSONObject( "{\n" + " \"pnfSerialNumber\": \"val1\",\n" + " \"pnfOamIpv4Address\": \"val3\",\n" + @@ -105,7 +91,26 @@ final class TestMessages { " \"reportingEntityName\": \"val14\"\n" + "}")); + static final Optional<JSONObject> INVALID_NOTIFICATION_PARAMS = Optional.of(new JSONObject( + "{\n" + + " \"mother\": \"val1\",\n" + + " \"father\": \"val3\",\n" + + "}")); + private TestMessages() { } + + private static String getContent(String fileName) { + try { + String pathAsString = TestMessages.class.getResource(fileName).getPath(); + StringBuilder stringBuilder = new StringBuilder(); + Files.readAllLines(Paths.get(pathAsString)).forEach(line -> { + stringBuilder.append(line); + }); + return stringBuilder.toString(); + } catch (IOException e) { + throw new RuntimeException(String.format("Cannot read JSON file %s", fileName)); + } + } } |