2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.listener.LCM1607.model;
27 import com.fasterxml.jackson.databind.ObjectMapper;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.onap.appc.listener.util.Mapper;
32 import java.io.IOException;
33 import java.util.HashMap;
37 public class TestJsonGenericMessages {/*
40 public void serializeIncomingMessage() {
42 final String expectedJson = "{\"CommonHeader\":{\"TimeStamp\":\"2016-05-02 19:50:37.09\",\"TransactionID\":\"1\",\"APIver\":\"1.01\",\"RequestTrack\":[\"1\",\"4\",\"12\",\"3\"],\"Flags\":null,\"SubrequestID\":null,\"OriginatorID\":\"2\"},\"Payload\":\"{ \\\"command\\\": \\\"start\\\", \\\"target-id\\\": \\\"111\\\", \\\"flag10\\\": {\\\"object-1\\\": {\\\"key-1\\\": \\\"key\\\", \\\"value-1\\\": \\\"value\\\" }} }\",\"Action\":\"CONFIGURE\",\"ObjectID\":\"200\",\"TargetID\":\"100\"}";
43 InputBody msg = createIncomingMessage();
45 String json = Mapper.toJsonObject(msg).toString();
46 //System.out.println(json);
47 Assert.assertEquals(expectedJson, json);
51 public void deserializeIncomingMessage() throws IOException {
52 final String originalJson = "{\"CommonHeader\":{\"TimeStamp\":\"2016-05-02 19:50:37.09\",\"TransactionID\":\"1\",\"Flags\":{\"FORCE\":\"Y\",\"TTL\":\"12\"},\"SubrequestID\":\"2345\",\"OriginatorID\":\"2\",\"APIver\":\"1.01\"}, \"Payload\": \" \\\"Graceful\\\" : \\\"Yes\\\" \",\"Action\":\"CONFIGURE\",\"ObjectID\":\"200\",\"TargetID\":\"100\"}";
54 ObjectMapper mapper = new ObjectMapper();
55 InputBody msg = mapper.readValue(originalJson, InputBody.class);
57 Assert.assertNotNull(msg);
58 Assert.assertEquals("2016-05-02 19:50:37.09", msg.getCommonHeader().getTimeStamp());
59 Assert.assertEquals("1", msg.getCommonHeader().getRequestID());
60 Assert.assertEquals("1.01", msg.getCommonHeader().getApiVer());
61 Assert.assertEquals("200", msg.getObjectId());
62 Assert.assertEquals("100", msg.getTargetId());
63 Assert.assertEquals(" \"Graceful\" : \"Yes\" ", msg.getPayload());
64 Assert.assertEquals("CONFIGURE", msg.getAction());
69 public void serializeResponseMessage() {
70 InputBody imsg = createIncomingMessage();
71 OutputBody omsg = new OutputBody(imsg);
72 omsg.setStatus(new ResponseStatus("200", "OK"));
74 String json = Mapper.toJsonObject(omsg).toString();
75 System.out.println(json);
76 //Assert.assertEquals(expectedJson, json);
77 Assert.assertNotEquals("", json);
81 private InputBody createIncomingMessage() {
82 InputBody msg = new InputBody();
83 CommonHeader rh = new CommonHeader();
84 rh.setTimeStamp("2016-05-02 19:50:37.09");
87 rh.setOriginatorId("2");
90 Map<String, String> flags = new HashMap<>();
91 flags.put("FORCE", "Y");
92 flags.put("TTL", "12");
94 msg.setCommonHeader(rh);
95 msg.setAction("CONFIGURE");
96 msg.setTargetId("100");
97 msg.setObjectId("200");
98 msg.setPayloadAsString("{ \"command\": \"start\", \"target-id\": \"111\", \"flag10\": {\"object-1\": {\"key-1\": \"key\", \"value-1\": \"value\" }} }");