2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.appc.listener.LCM1607.model;
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;
29 import java.io.IOException;
30 import java.util.HashMap;
34 public class TestJsonGenericMessages {/*
37 public void serializeIncomingMessage() {
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();
42 String json = Mapper.toJsonObject(msg).toString();
43 //System.out.println(json);
44 Assert.assertEquals(expectedJson, json);
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\"}";
51 ObjectMapper mapper = new ObjectMapper();
52 InputBody msg = mapper.readValue(originalJson, InputBody.class);
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());
66 public void serializeResponseMessage() {
67 InputBody imsg = createIncomingMessage();
68 OutputBody omsg = new OutputBody(imsg);
69 omsg.setStatus(new ResponseStatus("200", "OK"));
71 String json = Mapper.toJsonObject(omsg).toString();
72 System.out.println(json);
73 //Assert.assertEquals(expectedJson, json);
74 Assert.assertNotEquals("", json);
78 private InputBody createIncomingMessage() {
79 InputBody msg = new InputBody();
80 CommonHeader rh = new CommonHeader();
81 rh.setTimeStamp("2016-05-02 19:50:37.09");
84 rh.setOriginatorId("2");
87 Map<String, String> flags = new HashMap<>();
88 flags.put("FORCE", "Y");
89 flags.put("TTL", "12");
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\" }} }");