diff options
author | Marcin Migdal <marcin.migdal@nokia.com> | 2018-08-14 17:23:10 +0200 |
---|---|---|
committer | Marcin Migdal <marcin.migdal@nokia.com> | 2018-08-14 17:23:10 +0200 |
commit | 6e5e2818a7325b19e0757a4c4e11efd0f2798fb3 (patch) | |
tree | 85825616f561a42fff2857b185acd3ab87449357 | |
parent | 3d4020b85fa800b80ca569c2ed0c402562e69f7b (diff) |
Preparation for INT-622 code
Change-Id: I9e536254a5eeb06864792c6f67aa0c3e2029c24f
Issue-ID: INT-622
Signed-off-by: Marcin Migdal <marcin.migdal@nokia.com>
5 files changed, 124 insertions, 111 deletions
diff --git a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java new file mode 100644 index 000000000..0d158534d --- /dev/null +++ b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java @@ -0,0 +1,42 @@ +package org.onap.pnfsimulator.message; + +import static org.onap.pnfsimulator.message.MessageConstants.*; + +import org.json.JSONObject; + +final class JSONObjectFactory { + + static JSONObject generateConstantCommonEventHeader() { + JSONObject commonEventHeader = new JSONObject(); + long timestamp = System.currentTimeMillis(); + commonEventHeader.put(DOMAIN, PNF_REGISTRATION); + commonEventHeader.put(EVENT_ID, generateEventId()); + commonEventHeader.put(EVENT_TYPE, PNF_REGISTRATION); + commonEventHeader.put(LAST_EPOCH_MICROSEC, timestamp); + commonEventHeader.put(PRIORITY, PRIORITY_NORMAL); + commonEventHeader.put(SEQUENCE, SEQUENCE_NUMBER); + commonEventHeader.put(START_EPOCH_MICROSEC, timestamp); + commonEventHeader.put(INTERNAL_HEADER_FIELDS, new JSONObject()); + commonEventHeader.put(VERSION, VERSION_NUMBER); + return commonEventHeader; + } + + static JSONObject generateConstantOtherFields() { + JSONObject otherFields = new JSONObject(); + otherFields.put(OTHER_FIELDS_VERSION, OTHER_FIELDS_VERSION_VALUE); + otherFields.put(PNF_LAST_SERVICE_DATE, System.currentTimeMillis()); + otherFields.put(PNF_MANUFACTURE_DATE, System.currentTimeMillis()); + return otherFields; + } + + static String generateEventId() { + String timeAsString = String.valueOf(System.currentTimeMillis()); + return String.format("registration_%s", + timeAsString.substring(timeAsString.length() - 11, timeAsString.length() - 3)); + } + + private JSONObjectFactory(){ + + } + +} diff --git a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java index a0930a651..fd47520f4 100644 --- a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java +++ b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java @@ -2,34 +2,42 @@ package org.onap.pnfsimulator.message; public final class MessageConstants { - public static final String EVENT = "event"; - public static final String DOMAIN = "domain"; - public static final String EVENT_ID = "eventId"; - public static final String EVENT_TYPE = "eventType"; - public static final String LAST_EPOCH_MICROSEC = "lastEpochMicrosec"; - public static final String PRIORITY = "priority"; - public static final String SEQUENCE = "sequence"; - public static final String START_EPOCH_MICROSEC = "startEpochMicrosec"; - public static final String INTERNAL_HEADER_FIELDS = "internalHeaderFields"; - public static final String VERSION = "version"; - public static final String OTHER_FIELDS_VERSION = "otherFieldsVersion"; - public static final String PNF_LAST_SERVICE_DATE = "pnfLastServiceDate"; - public static final String PNF_MANUFACTURE_DATE = "pnfManufactureDate"; - public static final String SIMULATOR_PARAMS_CONTAINER = "simulatorParams"; public static final String MESSAGE_PARAMS_CONTAINER = "messageParams"; + static final String EVENT = "event"; + static final String DOMAIN = "domain"; + static final String EVENT_ID = "eventId"; + static final String EVENT_TYPE = "eventType"; + static final String LAST_EPOCH_MICROSEC = "lastEpochMicrosec"; + static final String PRIORITY = "priority"; + static final String SEQUENCE = "sequence"; + static final String START_EPOCH_MICROSEC = "startEpochMicrosec"; + static final String INTERNAL_HEADER_FIELDS = "internalHeaderFields"; + static final String VERSION = "version"; + static final String OTHER_FIELDS_VERSION = "otherFieldsVersion"; + static final String PNF_LAST_SERVICE_DATE = "pnfLastServiceDate"; + static final String PNF_MANUFACTURE_DATE = "pnfManufactureDate"; - // mandatory - public static final String PNF_OAM_IPV4_ADDRESS = "pnfOamIpv4Address"; - public static final String PNF_OAM_IPV6_ADDRESS = "pnfOamIpv6Address"; - public static final String PNF_SERIAL_NUMBER = "pnfSerialNumber"; - public static final String PNF_VENDOR_NAME = "pnfVendorName"; + // mandatory used in json file, but not in java logic + //public static final String PNF_OAM_IPV4_ADDRESS = "pnfOamIpv4Address"; + //public static final String PNF_OAM_IPV6_ADDRESS = "pnfOamIpv6Address"; + //public static final String PNF_SERIAL_NUMBER = "pnfSerialNumber"; + //public static final String PNF_VENDOR_NAME = "pnfVendorName"; public static final String VES_SERVER_URL = "vesServerUrl"; - public static final String PNF_PREFIX = "pnf"; - public static final String COMMON_EVENT_HEADER = "commonEventHeader"; - public static final String OTHER_FIELDS = "otherFields"; public static final String TEST_DURATION = "testDuration"; public static final String MESSAGE_INTERVAL = "messageInterval"; + static final String PNF_PREFIX = "pnf"; + static final String COMMON_EVENT_HEADER = "commonEventHeader"; + static final String OTHER_FIELDS = "otherFields"; + + + //=============================================================== + //constant values + static final String PNF_REGISTRATION ="pnfRegistration"; + static final String PRIORITY_NORMAL = "Normal"; + static final float VERSION_NUMBER = 3.0f; + static final int SEQUENCE_NUMBER = 0; + static final int OTHER_FIELDS_VERSION_VALUE = 1; private MessageConstants() { } 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 b21eed4fc..0c0b4b681 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 @@ -1,24 +1,10 @@ package org.onap.pnfsimulator.message; import static org.onap.pnfsimulator.message.MessageConstants.COMMON_EVENT_HEADER; -import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN; import static org.onap.pnfsimulator.message.MessageConstants.EVENT; -import static org.onap.pnfsimulator.message.MessageConstants.EVENT_ID; -import static org.onap.pnfsimulator.message.MessageConstants.EVENT_TYPE; -import static org.onap.pnfsimulator.message.MessageConstants.INTERNAL_HEADER_FIELDS; -import static org.onap.pnfsimulator.message.MessageConstants.LAST_EPOCH_MICROSEC; import static org.onap.pnfsimulator.message.MessageConstants.OTHER_FIELDS; -import static org.onap.pnfsimulator.message.MessageConstants.OTHER_FIELDS_VERSION; -import static org.onap.pnfsimulator.message.MessageConstants.PNF_LAST_SERVICE_DATE; -import static org.onap.pnfsimulator.message.MessageConstants.PNF_MANUFACTURE_DATE; import static org.onap.pnfsimulator.message.MessageConstants.PNF_PREFIX; -import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY; -import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE; -import static org.onap.pnfsimulator.message.MessageConstants.START_EPOCH_MICROSEC; -import static org.onap.pnfsimulator.message.MessageConstants.VERSION; - import java.util.Map; -import java.util.UUID; import org.json.JSONObject; public class MessageProvider { @@ -31,8 +17,8 @@ public class MessageProvider { Map<String, Object> paramsMap = params.toMap(); JSONObject root = new JSONObject(); - JSONObject commonEventHeader = generateConstantCommonEventHeader(); - JSONObject otherFields = generateConstantOtherFields(); + JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader(); + JSONObject otherFields = JSONObjectFactory.generateConstantOtherFields(); paramsMap.forEach((key, value) -> { @@ -50,32 +36,4 @@ public class MessageProvider { return root; } - private JSONObject generateConstantCommonEventHeader() { - - JSONObject commonEventHeader = new JSONObject(); - long timestamp = System.currentTimeMillis(); - - commonEventHeader.put(DOMAIN, "other"); - commonEventHeader.put(EVENT_ID, UUID.randomUUID() + "-reg"); - commonEventHeader.put(EVENT_TYPE, "pnfRegistration"); - commonEventHeader.put(LAST_EPOCH_MICROSEC, timestamp); - commonEventHeader.put(PRIORITY, "Normal"); - commonEventHeader.put(SEQUENCE, 0); - commonEventHeader.put(START_EPOCH_MICROSEC, timestamp); - commonEventHeader.put(INTERNAL_HEADER_FIELDS, new JSONObject()); - commonEventHeader.put(VERSION, 3); - - return commonEventHeader; - } - - private JSONObject generateConstantOtherFields() { - - JSONObject otherFields = new JSONObject(); - - otherFields.put(OTHER_FIELDS_VERSION, 1); - otherFields.put(PNF_LAST_SERVICE_DATE, System.currentTimeMillis()); - otherFields.put(PNF_MANUFACTURE_DATE, System.currentTimeMillis()); - - return otherFields; - } } diff --git a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java new file mode 100644 index 000000000..a7fa89ebf --- /dev/null +++ b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java @@ -0,0 +1,48 @@ +package org.onap.pnfsimulator.message; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.onap.pnfsimulator.message.MessageConstants.*; + +import org.json.JSONObject; +import org.junit.jupiter.api.Test; + +public class JSONObjectFactoryTest { + + @Test + public void generateConstantCommonEventHeader_shouldCreateProperly(){ + JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader(); + assertEquals(9,commonEventHeader.toMap().size()); + assertTrue(commonEventHeader.has(DOMAIN)); + assertTrue(commonEventHeader.has(EVENT_ID)); + assertTrue(commonEventHeader.has(EVENT_TYPE)); + assertTrue(commonEventHeader.has(LAST_EPOCH_MICROSEC)); + assertTrue(commonEventHeader.has(PRIORITY)); + assertTrue(commonEventHeader.has(SEQUENCE)); + assertTrue(commonEventHeader.has(START_EPOCH_MICROSEC)); + assertTrue(commonEventHeader.has(INTERNAL_HEADER_FIELDS)); + assertTrue(commonEventHeader.has(VERSION)); + assertEquals(commonEventHeader.get(DOMAIN),PNF_REGISTRATION); + assertEquals(commonEventHeader.get(EVENT_TYPE),PNF_REGISTRATION); + assertEquals(commonEventHeader.get(PRIORITY),PRIORITY_NORMAL); + assertEquals(commonEventHeader.get(SEQUENCE),SEQUENCE_NUMBER); + assertEquals(commonEventHeader.get(VERSION),VERSION_NUMBER); + } + + @Test + public void generateConstantOtherFields_shouldCreateProperly(){ + JSONObject otherFields = JSONObjectFactory.generateConstantOtherFields(); + assertEquals(3,otherFields.toMap().size()); + assertTrue(otherFields.has(OTHER_FIELDS_VERSION)); + assertEquals(otherFields.get(OTHER_FIELDS_VERSION),OTHER_FIELDS_VERSION_VALUE); + assertTrue(otherFields.has(PNF_LAST_SERVICE_DATE)); + assertTrue(otherFields.has(PNF_MANUFACTURE_DATE)); + } + + @Test + public void generateEventId_shouldCreateProperly(){ + String eventId = JSONObjectFactory.generateEventId(); + assertTrue(eventId.startsWith("registration_")); + } + +} 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 b08cc4ce6..8f7cd9380 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 @@ -4,22 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.onap.pnfsimulator.message.MessageConstants.COMMON_EVENT_HEADER; -import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN; import static org.onap.pnfsimulator.message.MessageConstants.EVENT; -import static org.onap.pnfsimulator.message.MessageConstants.EVENT_ID; -import static org.onap.pnfsimulator.message.MessageConstants.EVENT_TYPE; -import static org.onap.pnfsimulator.message.MessageConstants.INTERNAL_HEADER_FIELDS; -import static org.onap.pnfsimulator.message.MessageConstants.LAST_EPOCH_MICROSEC; import static org.onap.pnfsimulator.message.MessageConstants.OTHER_FIELDS; -import static org.onap.pnfsimulator.message.MessageConstants.OTHER_FIELDS_VERSION; -import static org.onap.pnfsimulator.message.MessageConstants.PNF_LAST_SERVICE_DATE; -import static org.onap.pnfsimulator.message.MessageConstants.PNF_MANUFACTURE_DATE; -import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY; -import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE; -import static org.onap.pnfsimulator.message.MessageConstants.START_EPOCH_MICROSEC; -import static org.onap.pnfsimulator.message.MessageConstants.VERSION; - -import java.util.UUID; import org.json.JSONObject; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -51,8 +37,8 @@ public class MessageProviderTest { JSONObject commonEventHeader = event.getJSONObject(COMMON_EVENT_HEADER); JSONObject otherFields = event.getJSONObject(OTHER_FIELDS); - JSONObject expectedCommonEventHeader = generateConstantCommonEventHeader(); - JSONObject expectedOtherFields = generateConstantOtherFields(); + JSONObject expectedCommonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader(); + JSONObject expectedOtherFields = JSONObjectFactory.generateConstantOtherFields(); expectedCommonEventHeader .toMap() @@ -81,33 +67,4 @@ public class MessageProviderTest { assertEquals("val4", commonEventHeader.getString("key4")); } - - private JSONObject generateConstantCommonEventHeader() { - - JSONObject commonEventHeader = new JSONObject(); - long timestamp = System.currentTimeMillis(); - - commonEventHeader.put(DOMAIN, "other"); - commonEventHeader.put(EVENT_ID, UUID.randomUUID() + "-reg"); - commonEventHeader.put(EVENT_TYPE, "pnfRegistration"); - commonEventHeader.put(LAST_EPOCH_MICROSEC, timestamp); - commonEventHeader.put(PRIORITY, "Normal"); - commonEventHeader.put(SEQUENCE, 0); - commonEventHeader.put(START_EPOCH_MICROSEC, timestamp); - commonEventHeader.put(INTERNAL_HEADER_FIELDS, new JSONObject()); - commonEventHeader.put(VERSION, 3); - - return commonEventHeader; - } - - private JSONObject generateConstantOtherFields() { - JSONObject otherFields = new JSONObject(); - - otherFields.put(OTHER_FIELDS_VERSION, 1); - otherFields.put(PNF_LAST_SERVICE_DATE, 1517206400); - otherFields.put(PNF_MANUFACTURE_DATE, 1516406400); - - return otherFields; - } - } |