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.*;
27 import org.json.JSONObject;
28 import org.junit.jupiter.api.Test;
30 public class JSONObjectFactoryTest {
33 public void generateConstantCommonEventHeader_shouldCreateProperly(){
34 JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader();
35 assertEquals(8,commonEventHeader.toMap().size());
36 assertTrue(commonEventHeader.has(EVENT_ID));
37 assertTrue(commonEventHeader.has(LAST_EPOCH_MICROSEC));
38 assertTrue(commonEventHeader.has(PRIORITY));
39 assertTrue(commonEventHeader.has(SEQUENCE));
40 assertTrue(commonEventHeader.has(START_EPOCH_MICROSEC));
41 assertTrue(commonEventHeader.has(INTERNAL_HEADER_FIELDS));
42 assertTrue(commonEventHeader.has(VERSION));
43 assertEquals(commonEventHeader.get(PRIORITY),PRIORITY_NORMAL);
44 assertEquals(commonEventHeader.get(SEQUENCE),SEQUENCE_NUMBER);
45 assertEquals(commonEventHeader.get(VERSION),VERSION_NUMBER);
46 assertEquals(commonEventHeader.get(VES_EVENT_LISTENER_VERSION),VES_EVENT_LISTENER_VERSION_NUMBER);
50 public void generateConstantPnfRegistrationFields_shouldCreateProperly(){
51 JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields();
52 assertEquals(3,pnfRegistrationFields.toMap().size());
53 assertTrue(pnfRegistrationFields.has(PNF_REGISTRATION_FIELDS_VERSION));
54 assertEquals(pnfRegistrationFields.get(PNF_REGISTRATION_FIELDS_VERSION), PNF_REGISTRATION_FIELDS_VERSION_VALUE);
55 assertTrue(pnfRegistrationFields.has(PNF_LAST_SERVICE_DATE));
56 assertTrue(pnfRegistrationFields.has(PNF_MANUFACTURE_DATE));
60 public void generateEventId_shouldCreateProperly(){
61 String eventId = JSONObjectFactory.generateEventId();
62 assertTrue(eventId.startsWith("registration_"));
66 public void generateNotificationFields_shouldCreateProperly(){
67 JSONObject notificationFields = JSONObjectFactory.generateNotificationFields();
68 assertEquals(1,notificationFields.keySet().size());
69 assertEquals(NOTIFICATION_FIELDS_VERSION_VALUE,notificationFields.get(NOTIFICATION_FIELDS_VERSION));