2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.pnfsimulator.message;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.onap.pnfsimulator.message.MessageConstants.EVENT_ID;
26 import static org.onap.pnfsimulator.message.MessageConstants.INTERNAL_HEADER_FIELDS;
27 import static org.onap.pnfsimulator.message.MessageConstants.LAST_EPOCH_MICROSEC;
28 import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS_VERSION;
29 import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS_VERSION_VALUE;
30 import static org.onap.pnfsimulator.message.MessageConstants.PNF_LAST_SERVICE_DATE;
31 import static org.onap.pnfsimulator.message.MessageConstants.PNF_MANUFACTURE_DATE;
32 import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS_VERSION;
33 import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS_VERSION_VALUE;
34 import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY;
35 import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY_NORMAL;
36 import static org.onap.pnfsimulator.message.MessageConstants.REPORTING_ENTITY_NAME;
37 import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE;
38 import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE_NUMBER;
39 import static org.onap.pnfsimulator.message.MessageConstants.SOURCE_NAME;
40 import static org.onap.pnfsimulator.message.MessageConstants.START_EPOCH_MICROSEC;
41 import static org.onap.pnfsimulator.message.MessageConstants.TIME_ZONE_OFFSET;
42 import static org.onap.pnfsimulator.message.MessageConstants.VERSION;
43 import static org.onap.pnfsimulator.message.MessageConstants.VERSION_NUMBER;
44 import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION;
45 import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION_NUMBER;
46 import org.json.JSONObject;
47 import org.junit.jupiter.api.Test;
49 public class JSONObjectFactoryTest {
52 public void generateConstantCommonEventHeader_shouldCreateProperly(){
53 JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader();
54 assertEquals(11,commonEventHeader.toMap().size());
55 assertTrue(commonEventHeader.has(EVENT_ID));
56 assertTrue(commonEventHeader.has(TIME_ZONE_OFFSET));
57 assertTrue(commonEventHeader.has(LAST_EPOCH_MICROSEC));
58 assertTrue(commonEventHeader.has(PRIORITY));
59 assertTrue(commonEventHeader.has(SEQUENCE));
60 assertTrue(commonEventHeader.has(START_EPOCH_MICROSEC));
61 assertTrue(commonEventHeader.has(INTERNAL_HEADER_FIELDS));
62 assertTrue(commonEventHeader.has(VERSION));
63 assertTrue(commonEventHeader.has(SOURCE_NAME));
64 assertTrue(commonEventHeader.has(REPORTING_ENTITY_NAME));
65 assertEquals(commonEventHeader.get(PRIORITY),PRIORITY_NORMAL);
66 assertEquals(commonEventHeader.get(SEQUENCE),SEQUENCE_NUMBER);
67 assertEquals(commonEventHeader.get(VERSION),VERSION_NUMBER);
68 assertEquals(commonEventHeader.get(VES_EVENT_LISTENER_VERSION),VES_EVENT_LISTENER_VERSION_NUMBER);
72 public void generateConstantPnfRegistrationFields_shouldCreateProperly(){
73 JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields();
74 assertEquals(3,pnfRegistrationFields.toMap().size());
75 assertTrue(pnfRegistrationFields.has(PNF_REGISTRATION_FIELDS_VERSION));
76 assertEquals(pnfRegistrationFields.get(PNF_REGISTRATION_FIELDS_VERSION), PNF_REGISTRATION_FIELDS_VERSION_VALUE);
77 assertTrue(pnfRegistrationFields.has(PNF_LAST_SERVICE_DATE));
78 assertTrue(pnfRegistrationFields.has(PNF_MANUFACTURE_DATE));
82 public void generateEventId_shouldCreateProperly(){
83 String eventId = JSONObjectFactory.generateEventId();
84 assertTrue(eventId.startsWith("FileReady_"));
88 public void generateNotificationFields_shouldCreateProperly(){
89 JSONObject notificationFields = JSONObjectFactory.generateNotificationFields();
90 assertEquals(1,notificationFields.keySet().size());
91 assertEquals(NOTIFICATION_FIELDS_VERSION_VALUE,notificationFields.get(NOTIFICATION_FIELDS_VERSION));