diff options
author | 2018-08-14 17:23:10 +0200 | |
---|---|---|
committer | 2018-08-14 17:23:10 +0200 | |
commit | 6e5e2818a7325b19e0757a4c4e11efd0f2798fb3 (patch) | |
tree | 85825616f561a42fff2857b185acd3ab87449357 /test/mocks/pnfsimulator/src/main | |
parent | 3d4020b85fa800b80ca569c2ed0c402562e69f7b (diff) |
Preparation for INT-622 code
Change-Id: I9e536254a5eeb06864792c6f67aa0c3e2029c24f
Issue-ID: INT-622
Signed-off-by: Marcin Migdal <marcin.migdal@nokia.com>
Diffstat (limited to 'test/mocks/pnfsimulator/src/main')
3 files changed, 74 insertions, 66 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; - } } |