0bfd4d6ad5fbb59ea3ff04509de38ebb0e5e40b4
[appc.git] / appc-dispatcher / appc-request-handler / appc-request-handler-core / src / test / java / org / onap / appc / requesthandler / ConverterTest.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  * Modifications Copyright (C) 2018-2019 Orange
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.requesthandler;
27
28 import com.fasterxml.jackson.core.JsonProcessingException;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.onap.appc.domainmodel.lcm.*;
32 import org.onap.appc.executor.objects.LCMCommandStatus;
33 import org.onap.appc.requesthandler.conv.Converter;
34
35 import java.text.ParseException;
36 import java.util.Date;
37 import java.util.HashMap;
38
39
40 public class ConverterTest {
41     private String expectedJsonBodyStr ="{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}}";
42     private String expectedDmaapOutgoingMessageJsonStringTest ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"test\",\"type\":\"response\"}";
43     private String expectedDmaapOutgoingMessageJsonStringRollback ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"rollback\",\"type\":\"response\"}";
44     private String expectedDmaapOutgoingMessageJsonStringSnapshot ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"snapshot\",\"type\":\"response\"}";
45     private String expectedDmaapOutgoingMessageJsonStringAudit ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"audit\",\"type\":\"response\"}";
46     private String expectedDmaapOutgoingMessageJsonStringHealthCheck ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"health-check\",\"type\":\"response\"}";
47     private String expectedDmaapOutgoingMessageJsonStringLiveUpgrade ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"live-upgrade\",\"type\":\"response\"}";
48     private String expectedDmaapOutgoingMessageJsonStringLock ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"lock\",\"type\":\"response\"}";
49     private String expectedDmaapOutgoingMessageJsonStringModifyConfig ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"config-modify\",\"type\":\"response\"}";
50     private String expectedDmaapOutgoingMessageJsonStringSoftwareUpload ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"software-upload\",\"type\":\"response\"}";
51     private String expectedDmaapOutgoingMessageJsonStringStop ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"stop\",\"type\":\"response\"}";
52     private String expectedDmaapOutgoingMessageJsonStringSync ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"sync\",\"type\":\"response\"}";
53     private String expectedDmaapOutgoingMessageJsonStringTerminate ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"terminate\",\"type\":\"response\"}";
54     private String expectedDmaapOutgoingMessageJsonStringUnlock ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"unlock\",\"type\":\"response\"}";
55     private String expectedDmaapOutgoingMessageJsonStringUpgradePreCheck ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgrade-pre-check\",\"type\":\"response\"}";
56     private String expectedDmaapOutgoingMessageJsonStringUpgradePostCheck ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgrade-post-check\",\"type\":\"response\"}";
57     private String expectedDmaapOutgoingMessageJsonStringUpgradeSoftware ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgradesoftware\",\"type\":\"response\"}";
58     private String expectedDmaapOutgoingMessageJsonStringUpgradeBackout ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgradebackout\",\"type\":\"response\"}";
59     private String expectedDmaapOutgoingMessageJsonStringUpgradeBackup ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"upgradebackup\",\"type\":\"response\"}";
60
61     private String expectedJsonBodyStrwithPayload ="{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}}";
62     private String expectedDmaapOutgoingMessageJsonStringReboot ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"reboot\",\"type\":\"response\"}";
63     private String expectedDmaapOutgoingMessageJsonStringDistributeTraffic = "{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"distribute-traffic\",\"type\":\"response\"}";
64     private String expectedDmaapOutgoingMessageJsonStringDistributeTrafficCheck = "{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"distribute-traffic-check\",\"type\":\"response\"}";
65
66
67     @Test
68     public void convDateToZuluStringTest(){
69         String dateToZuluString = Converter.convDateToZuluString(new Date(0L));
70         Assert.assertEquals("1970-01-01T00:00:00.000Z", dateToZuluString);
71     }
72
73     @Test
74     public void convAsyncResponseToBuilderTestTest() throws JsonProcessingException {
75         ResponseContext asyncResponse = buildAsyncResponse();
76         VNFOperation action = VNFOperation.Test;
77         String rpcName = action.name().toLowerCase();
78         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
79         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
80     }
81
82     @Test
83     public void convAsyncResponseToDmaapOutgoingMessageJsonStringTestTest() throws JsonProcessingException {
84         ResponseContext asyncResponse = buildAsyncResponse();
85         VNFOperation action = VNFOperation.Test;
86         String rpcName = action.name().toLowerCase();
87         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
88         System.out.println("jsonStr = " + jsonStr);
89         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringTest,jsonStr);
90     }
91
92     @Test
93     public void convPayloadObjectToJsonStringTest() throws JsonProcessingException, ParseException {
94         String jsonString = Converter.convPayloadObjectToJsonString("any valid JSON string value");
95         Assert.assertEquals("any valid JSON string value", jsonString);
96
97         HashMap<String, String> hashMap = new HashMap<>();
98         hashMap.put("key","value");
99         jsonString = Converter.convPayloadObjectToJsonString(hashMap);
100         Assert.assertEquals("{\"key\":\"value\"}", jsonString);
101     }
102
103     @Test
104     public void convAsyncResponseToBuilderRollbackTest() throws JsonProcessingException {
105         ResponseContext asyncResponse = buildAsyncResponse();
106         VNFOperation action = VNFOperation.Rollback;
107         String rpcName = action.name().toLowerCase();
108         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
109         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
110     }
111
112     @Test
113     public void convAsyncResponseToDmaapOutgoingMessageJsonStringRollbackTest() throws JsonProcessingException {
114         ResponseContext asyncResponse = buildAsyncResponse();
115         VNFOperation action = VNFOperation.Rollback;
116         String rpcName = action.name().toLowerCase();
117         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
118         System.out.println("jsonStr = " + jsonStr);
119         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringRollback,jsonStr);
120     }
121
122     @Test
123     public void convAsyncResponseToBuilderSnapshotTest() throws JsonProcessingException {
124         ResponseContext asyncResponse = buildAsyncResponse();
125         VNFOperation action = VNFOperation.Snapshot;
126         String rpcName = action.name().toLowerCase();
127         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
128         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
129     }
130
131     @Test
132     public void convAsyncResponseToDmaapOutgoingMessageJsonStringSnapshotTest() throws JsonProcessingException {
133         ResponseContext asyncResponse = buildAsyncResponse();
134         VNFOperation action = VNFOperation.Snapshot;
135         String rpcName = action.name().toLowerCase();
136         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
137         System.out.println("jsonStr = " + jsonStr);
138         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSnapshot,jsonStr);
139     }
140     @Test
141     public void convAsyncResponseToBuilderAuditTest() throws JsonProcessingException {
142         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
143         VNFOperation action = VNFOperation.Audit;
144         String rpcName = action.name().toLowerCase();
145         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
146         Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
147     }
148
149     @Test
150     public void convAsyncResponseToDmaapOutgoingMessageJsonStringAuditTest() throws JsonProcessingException {
151         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
152         VNFOperation action = VNFOperation.Audit;
153         String rpcName = action.name().toLowerCase();
154         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
155         System.out.println("jsonStr = " + jsonStr);
156         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringAudit,jsonStr);
157     }
158     @Test
159     public void convAsyncResponseToBuilderHealthCheckTest() throws JsonProcessingException {
160         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
161         VNFOperation action = VNFOperation.HealthCheck;
162         String rpcName = convertActionNameToUrl(action.name());
163         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
164         Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
165     }
166
167     @Test
168     public void convAsyncResponseToDmaapOutgoingMessageJsonStringHealthCheckTest() throws JsonProcessingException {
169         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
170         VNFOperation action = VNFOperation.HealthCheck;
171         String rpcName = convertActionNameToUrl(action.name());
172         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
173         System.out.println("jsonStr = " + jsonStr);
174         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringHealthCheck,jsonStr);
175     }
176     @Test
177     public void convAsyncResponseToBuilderLiveUpgradeTest() throws JsonProcessingException {
178         ResponseContext asyncResponse = buildAsyncResponse();
179         VNFOperation action = VNFOperation.LiveUpgrade;
180         String rpcName = convertActionNameToUrl(action.name());
181         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
182         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
183     }
184
185     @Test
186     public void convAsyncResponseToDmaapOutgoingMessageJsonStringLiveUpgradeTest() throws JsonProcessingException {
187         ResponseContext asyncResponse = buildAsyncResponse();
188         VNFOperation action = VNFOperation.LiveUpgrade;
189         String rpcName = convertActionNameToUrl(action.name());
190         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
191         System.out.println("jsonStr = " + jsonStr);
192         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringLiveUpgrade,jsonStr);
193     }
194     @Test
195     public void convAsyncResponseToBuilderLockTest() throws JsonProcessingException {
196         ResponseContext asyncResponse = buildAsyncResponse();
197         VNFOperation action = VNFOperation.Lock;
198         String rpcName = convertActionNameToUrl(action.name());
199
200         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
201         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
202     }
203
204     @Test
205     public void convAsyncResponseToDmaapOutgoingMessageJsonStringLockTest() throws JsonProcessingException {
206         ResponseContext asyncResponse = buildAsyncResponse();
207         VNFOperation action = VNFOperation.Lock;
208         String rpcName = convertActionNameToUrl(action.name());
209         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
210         System.out.println("jsonStr = " + jsonStr);
211         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringLock,jsonStr);
212     }
213     @Test
214     public void convAsyncResponseToBuilderModifyConfigTest() throws JsonProcessingException {
215         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
216         VNFOperation action = VNFOperation.ConfigModify;
217         String rpcName = convertActionNameToUrl(action.name());
218         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
219         Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
220     }
221
222     @Test
223     public void convAsyncResponseToDmaapOutgoingMessageJsonStringModifyConfigTest() throws JsonProcessingException {
224         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
225         VNFOperation action = VNFOperation.ConfigModify;
226         String rpcName = convertActionNameToUrl(action.name());
227         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
228         System.out.println("jsonStr = " + jsonStr);
229         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringModifyConfig,jsonStr);
230     }
231     @Test
232     public void convAsyncResponseToBuilderSoftwareUploadTest() throws JsonProcessingException {
233         ResponseContext asyncResponse = buildAsyncResponse();
234         VNFOperation action = VNFOperation.SoftwareUpload;
235         String rpcName = convertActionNameToUrl(action.name());
236
237         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
238         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
239     }
240
241     @Test
242     public void convAsyncResponseToDmaapOutgoingMessageJsonStringSoftwareUploadTest() throws JsonProcessingException {
243         ResponseContext asyncResponse = buildAsyncResponse();
244         VNFOperation action = VNFOperation.SoftwareUpload;
245         String rpcName = convertActionNameToUrl(action.name());
246         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
247         System.out.println("jsonStr = " + jsonStr);
248         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSoftwareUpload,jsonStr);
249     }
250     @Test
251     public void convAsyncResponseToBuilderStopTest() throws JsonProcessingException {
252         ResponseContext asyncResponse = buildAsyncResponse();
253         VNFOperation action = VNFOperation.Stop;
254         String rpcName = convertActionNameToUrl(action.name());
255         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
256         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
257     }
258
259     @Test
260     public void convAsyncResponseToDmaapOutgoingMessageJsonStringStopTest() throws JsonProcessingException {
261         ResponseContext asyncResponse = buildAsyncResponse();
262         VNFOperation action = VNFOperation.Stop;
263         String rpcName = convertActionNameToUrl(action.name());
264         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
265         System.out.println("jsonStr = " + jsonStr);
266         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringStop,jsonStr);
267     }
268     @Test
269     public void convAsyncResponseToBuilderSync() throws JsonProcessingException {
270         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
271         VNFOperation action = VNFOperation.Sync;
272         String rpcName = convertActionNameToUrl(action.name());
273
274         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
275         Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
276     }
277
278     @Test
279     public void convAsyncResponseToDmaapOutgoingMessageJsonStringSync() throws JsonProcessingException {
280         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
281         VNFOperation action = VNFOperation.Sync;
282         String rpcName = convertActionNameToUrl(action.name());
283         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
284         System.out.println("jsonStr = " + jsonStr);
285         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSync,jsonStr);
286     }
287     @Test
288     public void convAsyncResponseToBuilderTerminateTest() throws JsonProcessingException {
289         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
290         VNFOperation action = VNFOperation.Sync;
291         String rpcName = convertActionNameToUrl(action.name());
292         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
293         Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
294     }
295
296     @Test
297     public void convAsyncResponseToDmaapOutgoingMessageJsonStringTerminateTest() throws JsonProcessingException {
298         ResponseContext asyncResponse = buildAsyncResponse();
299         VNFOperation action = VNFOperation.Terminate;
300         String rpcName = convertActionNameToUrl(action.name());
301         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
302         System.out.println("jsonStr = " + jsonStr);
303         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringTerminate,jsonStr);
304     }
305     @Test
306     public void convAsyncResponseToBuilderUnlockTest() throws JsonProcessingException {
307         ResponseContext asyncResponse = buildAsyncResponse();
308         VNFOperation action = VNFOperation.Unlock;
309         String rpcName = convertActionNameToUrl(action.name());
310         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
311         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
312     }
313
314     @Test
315     public void convAsyncResponseToDmaapOutgoingMessageJsonStringUnlockTest() throws JsonProcessingException {
316         ResponseContext asyncResponse = buildAsyncResponse();
317         VNFOperation action = VNFOperation.Unlock;
318         String rpcName = convertActionNameToUrl(action.name());
319         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
320         System.out.println("jsonStr = " + jsonStr);
321         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUnlock,jsonStr);
322     }
323     @Test
324     public void convAsyncResponseToBuilderRebootTest() throws JsonProcessingException {
325         ResponseContext asyncResponse = buildAsyncResponse();
326         VNFOperation action = VNFOperation.Reboot;
327         String rpcName = convertActionNameToUrl(action.name());
328
329         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
330         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
331     }
332
333     @Test
334     public void convAsyncResponseToDmaapOutgoingMessageJsonStringRebootTest() throws JsonProcessingException {
335         ResponseContext asyncResponse = buildAsyncResponse();
336         VNFOperation action = VNFOperation.Reboot;
337         String rpcName = convertActionNameToUrl(action.name());
338         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
339         System.out.println("jsonStr = " + jsonStr);
340         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringReboot,jsonStr);
341     }
342     @Test
343     public void convAsyncResponseToBuilderUpgradePreCheckTest() throws JsonProcessingException {
344         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
345         VNFOperation action = VNFOperation.UpgradePreCheck;
346         String rpcName = convertActionNameToUrl(action.name());
347         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
348         Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
349     }
350
351     @Test
352     public void convAsyncResponseToDmaapOutgoingMessageJsonStringUpgradePreCheckTest() throws JsonProcessingException {
353         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
354         VNFOperation action = VNFOperation.UpgradePreCheck;
355         String rpcName = convertActionNameToUrl(action.name());
356         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
357         System.out.println("jsonStr = " + jsonStr);
358         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradePreCheck,jsonStr);
359     }
360
361     @Test
362     public void convAsyncResponseToBuilderUpgradePostCheckTest() throws JsonProcessingException {
363         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
364         VNFOperation action = VNFOperation.UpgradePostCheck;
365         String rpcName = convertActionNameToUrl(action.name());
366         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
367         Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
368     }
369
370     @Test
371     public void convAsyncResponseToDmaapOutgoingMessageJsonStringUpgradePostCheckTest() throws JsonProcessingException {
372         ResponseContext asyncResponse = buildAsyncResponsewithPayload();
373         VNFOperation action = VNFOperation.UpgradePostCheck;
374         String rpcName = convertActionNameToUrl(action.name());
375         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
376         System.out.println("jsonStr = " + jsonStr);
377         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradePostCheck,jsonStr);
378     }
379     @Test
380     public void convAsyncResponseToBuilderUpgradeSoftwareTest() throws JsonProcessingException {
381         ResponseContext asyncResponse = buildAsyncResponse();
382         VNFOperation action = VNFOperation.UpgradeSoftware;
383         String rpcName = action.name().toLowerCase();
384         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
385         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
386     }
387
388     @Test
389     public void convAsyncResponseToDmaapOutgoingMessageJsonStringUpgradeSoftwareTest() throws JsonProcessingException {
390         ResponseContext asyncResponse = buildAsyncResponse();
391         VNFOperation action = VNFOperation.UpgradeSoftware;
392         String rpcName = action.name().toLowerCase();
393         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
394         System.out.println("jsonStr = " + jsonStr);
395         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeSoftware,jsonStr);
396     }
397
398     @Test
399     public void convAsyncResponseToBuilderUpgradeBackoutTest() throws JsonProcessingException {
400         ResponseContext asyncResponse = buildAsyncResponse();
401         VNFOperation action = VNFOperation.UpgradeBackout;
402         String rpcName = action.name().toLowerCase();
403         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
404         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
405     }
406
407     @Test
408     public void convAsyncResponseToDmaapOutgoingMessageJsonStringUpgradeBackoutTest() throws JsonProcessingException {
409         ResponseContext asyncResponse = buildAsyncResponse();
410         VNFOperation action = VNFOperation.UpgradeBackout;
411         String rpcName = action.name().toLowerCase();
412         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
413         System.out.println("jsonStr = " + jsonStr);
414         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeBackout,jsonStr);
415     }
416     @Test
417     public void convAsyncResponseToBuilderUpgradeBackupTest() throws JsonProcessingException {
418         ResponseContext asyncResponse = buildAsyncResponse();
419         VNFOperation action = VNFOperation.UpgradeBackup;
420         String rpcName = action.name().toLowerCase();
421         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
422         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
423     }
424
425     @Test
426     public void convAsyncResponseToDmaapOutgoingMessageJsonStringUpgradeBackupTest() throws JsonProcessingException {
427         ResponseContext asyncResponse = buildAsyncResponse();
428         VNFOperation action = VNFOperation.UpgradeBackup;
429         String rpcName = action.name().toLowerCase();
430         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
431         System.out.println("jsonStr = " + jsonStr);
432         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeBackup,jsonStr);
433     }
434
435     @Test
436     public void convAsyncResponseToBuilderDistributeTrafficTest() throws JsonProcessingException {
437         ResponseContext asyncResponse = buildAsyncResponse();
438         VNFOperation action = VNFOperation.DistributeTraffic;
439         String rpcName = convertActionNameToUrl(action.name());
440         String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
441         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
442     }
443
444     @Test
445     public void convAsyncResponseToDmaapOutgoingMessageJsonStringDistributeTrafficTest() throws JsonProcessingException {
446         ResponseContext asyncResponse = buildAsyncResponse();
447         VNFOperation action = VNFOperation.DistributeTraffic;
448         String rpcName = convertActionNameToUrl(action.name());
449         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
450         System.out.println("jsonStr = " + jsonStr);
451         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringDistributeTraffic,jsonStr);
452     }
453
454     @Test
455     public void convAsyncResponseToDmaapOutgoingMessageJsonStringDistributeTrafficCheckTest() throws JsonProcessingException {
456         ResponseContext asyncResponse = buildAsyncResponse();
457         VNFOperation action = VNFOperation.DistributeTrafficCheck;
458         String rpcName = convertActionNameToUrl(action.name());
459         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
460         Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringDistributeTrafficCheck,jsonStr);
461     }
462
463     /*@Test
464     public void convAsyncResponseToBuilderTest() throws JsonProcessingException {
465         AsyncResponse asyncResponse = buildAsyncResponse();
466         String jsonStr = Converter.convAsyncResponseToJsonStringBody(asyncResponse);
467         Assert.assertEquals(expectedJsonBodyStr,jsonStr);
468     }
469
470     @Test
471     public void convAsyncResponseToDmaapOutgoingMessageJsonStringTest() throws JsonProcessingException {
472         AsyncResponse asyncResponse = buildAsyncResponse();
473         String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(asyncResponse);
474         System.out.println("jsonStr = " + jsonStr);
475         Assert.assertEquals(expectedDmaapOutgoingMessageJsonString,jsonStr);
476     }*/
477
478
479     private ResponseContext buildAsyncResponse() {
480         ResponseContext asyncResponse = createResponseContextWithSubObjects();
481         asyncResponse.getStatus().setCode(LCMCommandStatus.SUCCESS.getResponseCode());
482         asyncResponse.getStatus().setMessage(LCMCommandStatus.SUCCESS.getResponseMessage());
483         asyncResponse.getCommonHeader().setOriginatorId("oid");
484         asyncResponse.getCommonHeader().setApiVer("2.0.0");
485         asyncResponse.getCommonHeader().setRequestId("reqid");
486         asyncResponse.getCommonHeader().setTimestamp(new Date(1000L));
487         asyncResponse.setPayload("any valid JSON string value. Json escape characters need to be added to make it a valid json string value");
488         return asyncResponse;
489     }
490
491     private ResponseContext buildAsyncResponsewithPayload() {
492         ResponseContext asyncResponse = createResponseContextWithSubObjects();
493         asyncResponse.getStatus().setCode(LCMCommandStatus.SUCCESS.getResponseCode());
494         asyncResponse.getStatus().setMessage(LCMCommandStatus.SUCCESS.getResponseMessage());
495         asyncResponse.getCommonHeader().setOriginatorId("oid");
496         asyncResponse.getCommonHeader().setApiVer("2.0.0");
497         asyncResponse.getCommonHeader().setRequestId("reqid");
498         asyncResponse.getCommonHeader().setTimestamp(new Date(1000L));
499         asyncResponse.setPayload("{}");
500         return asyncResponse;
501     }
502
503     private ResponseContext createResponseContextWithSubObjects() {
504
505         ResponseContext responseContext = new ResponseContext();
506         CommonHeader commonHeader = new CommonHeader();
507         Flags flags = new Flags();
508         Status status = new Status();
509         responseContext.setCommonHeader(commonHeader);
510         responseContext.setStatus(status);
511         commonHeader.setFlags(flags);
512         return responseContext;
513     }
514
515     private String convertActionNameToUrl(String action) {
516         String regex = "([a-z])([A-Z]+)";
517         String replacement = "$1-$2";
518         return action.replaceAll(regex, replacement)
519                 .toLowerCase();
520     }
521
522
523 }
524
525
526