f28bd8cb3f10dd89fe4edfa8190aebb968d8de6f
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / test / java / org / openecomp / appc / listener / LCM1607 / model / TestJsonGenericMessages.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.listener.LCM1607.model;
26
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;
31
32 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.Map;
35
36
37 public class TestJsonGenericMessages {/*
38
39     @Test
40     public void serializeIncomingMessage() {
41
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();
44
45         String json = Mapper.toJsonObject(msg).toString();
46         //System.out.println(json);
47         Assert.assertEquals(expectedJson, json);
48     }
49
50     @Test
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\"}";
53
54         ObjectMapper mapper = new ObjectMapper();
55         InputBody msg = mapper.readValue(originalJson, InputBody.class);
56
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());
65
66     }
67
68     @Test
69     public void serializeResponseMessage() {
70         InputBody imsg = createIncomingMessage();
71         OutputBody omsg = new OutputBody(imsg);
72         omsg.setStatus(new ResponseStatus("200", "OK"));
73
74         String json = Mapper.toJsonObject(omsg).toString();
75         System.out.println(json);
76         //Assert.assertEquals(expectedJson, json);
77         Assert.assertNotEquals("", json);
78
79     }
80
81     private InputBody createIncomingMessage() {
82         InputBody msg = new InputBody();
83         CommonHeader rh = new CommonHeader();
84         rh.setTimeStamp("2016-05-02 19:50:37.09");
85         rh.setApiVer("1.01");
86         rh.setRequestID("1");
87         rh.setOriginatorId("2");
88
89
90         Map<String, String> flags = new HashMap<>();
91         flags.put("FORCE", "Y");
92         flags.put("TTL", "12");
93
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\" }} }");
99         return msg;
100     }
101 */
102 }