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