Dmaap micro service jar
[appc.git] / services / appc-dmaap-service / appc-event-listener-bundle / src / test / java / org / onap / appc / listener / LCM1607 / model / TestJsonGenericMessages.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.listener.LCM1607.model;
25
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.onap.appc.listener.util.Mapper;
30
31 import java.io.IOException;
32 import java.util.HashMap;
33 import java.util.Map;
34
35
36 public class TestJsonGenericMessages {/*
37
38     @Test
39     public void serializeIncomingMessage() {
40
41         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\"}";
42         InputBody msg = createIncomingMessage();
43
44         String json = Mapper.toJsonObject(msg).toString();
45         //System.out.println(json);
46         Assert.assertEquals(expectedJson, json);
47     }
48
49     @Test
50     public void deserializeIncomingMessage() throws IOException {
51         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\"}";
52
53         ObjectMapper mapper = new ObjectMapper();
54         InputBody msg = mapper.readValue(originalJson, InputBody.class);
55
56         Assert.assertNotNull(msg);
57         Assert.assertEquals("2016-05-02 19:50:37.09", msg.getCommonHeader().getTimeStamp());
58         Assert.assertEquals("1", msg.getCommonHeader().getRequestID());
59         Assert.assertEquals("1.01", msg.getCommonHeader().getApiVer());
60         Assert.assertEquals("200", msg.getObjectId());
61         Assert.assertEquals("100", msg.getTargetId());
62         Assert.assertEquals(" \"Graceful\" : \"Yes\" ", msg.getPayload());
63         Assert.assertEquals("CONFIGURE", msg.getAction());
64
65     }
66
67     @Test
68     public void serializeResponseMessage() {
69         InputBody imsg = createIncomingMessage();
70         OutputBody omsg = new OutputBody(imsg);
71         omsg.setStatus(new ResponseStatus("200", "OK"));
72
73         String json = Mapper.toJsonObject(omsg).toString();
74         System.out.println(json);
75         //Assert.assertEquals(expectedJson, json);
76         Assert.assertNotEquals("", json);
77
78     }
79
80     private InputBody createIncomingMessage() {
81         InputBody msg = new InputBody();
82         CommonHeader rh = new CommonHeader();
83         rh.setTimeStamp("2016-05-02 19:50:37.09");
84         rh.setApiVer("1.01");
85         rh.setRequestID("1");
86         rh.setOriginatorId("2");
87
88
89         Map<String, String> flags = new HashMap<>();
90         flags.put("FORCE", "Y");
91         flags.put("TTL", "12");
92
93         msg.setCommonHeader(rh);
94         msg.setAction("CONFIGURE");
95         msg.setTargetId("100");
96         msg.setObjectId("200");
97         msg.setPayloadAsString("{ \"command\": \"start\", \"target-id\": \"111\", \"flag10\": {\"object-1\": {\"key-1\": \"key\", \"value-1\": \"value\" }} }");
98         return msg;
99     }
100 */
101 }