Moving all files to root directory
[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  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.listener.LCM1607.model;
23
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.openecomp.appc.listener.util.Mapper;
28
29 import java.io.IOException;
30 import java.util.HashMap;
31 import java.util.Map;
32
33
34 public class TestJsonGenericMessages {/*
35
36     @Test
37     public void serializeIncomingMessage() {
38
39         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\"}";
40         InputBody msg = createIncomingMessage();
41
42         String json = Mapper.toJsonObject(msg).toString();
43         //System.out.println(json);
44         Assert.assertEquals(expectedJson, json);
45     }
46
47     @Test
48     public void deserializeIncomingMessage() throws IOException {
49         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\"}";
50
51         ObjectMapper mapper = new ObjectMapper();
52         InputBody msg = mapper.readValue(originalJson, InputBody.class);
53
54         Assert.assertNotNull(msg);
55         Assert.assertEquals("2016-05-02 19:50:37.09", msg.getCommonHeader().getTimeStamp());
56         Assert.assertEquals("1", msg.getCommonHeader().getRequestID());
57         Assert.assertEquals("1.01", msg.getCommonHeader().getApiVer());
58         Assert.assertEquals("200", msg.getObjectId());
59         Assert.assertEquals("100", msg.getTargetId());
60         Assert.assertEquals(" \"Graceful\" : \"Yes\" ", msg.getPayload());
61         Assert.assertEquals("CONFIGURE", msg.getAction());
62
63     }
64
65     @Test
66     public void serializeResponseMessage() {
67         InputBody imsg = createIncomingMessage();
68         OutputBody omsg = new OutputBody(imsg);
69         omsg.setStatus(new ResponseStatus("200", "OK"));
70
71         String json = Mapper.toJsonObject(omsg).toString();
72         System.out.println(json);
73         //Assert.assertEquals(expectedJson, json);
74         Assert.assertNotEquals("", json);
75
76     }
77
78     private InputBody createIncomingMessage() {
79         InputBody msg = new InputBody();
80         CommonHeader rh = new CommonHeader();
81         rh.setTimeStamp("2016-05-02 19:50:37.09");
82         rh.setApiVer("1.01");
83         rh.setRequestID("1");
84         rh.setOriginatorId("2");
85
86
87         Map<String, String> flags = new HashMap<>();
88         flags.put("FORCE", "Y");
89         flags.put("TTL", "12");
90
91         msg.setCommonHeader(rh);
92         msg.setAction("CONFIGURE");
93         msg.setTargetId("100");
94         msg.setObjectId("200");
95         msg.setPayloadAsString("{ \"command\": \"start\", \"target-id\": \"111\", \"flag10\": {\"object-1\": {\"key-1\": \"key\", \"value-1\": \"value\" }} }");
96         return msg;
97     }
98 */
99 }