diff options
Diffstat (limited to 'test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java')
-rw-r--r-- | test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java | 32 |
1 files changed, 22 insertions, 10 deletions
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")); } } |