2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.requesthandler;
26 import com.fasterxml.jackson.core.JsonProcessingException;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.onap.appc.domainmodel.lcm.*;
30 import org.onap.appc.executor.objects.LCMCommandStatus;
31 import org.onap.appc.requesthandler.conv.Converter;
33 import java.text.ParseException;
34 import java.util.Date;
35 import java.util.HashMap;
38 public class ConverterTest {
39 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\"}}}";
40 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\"}";
41 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\"}";
42 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\"}";
43 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\"}";
44 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\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"health-check\",\"type\":\"response\"}";
45 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\"}";
46 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\"}";
47 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\"}";
48 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\"}";
49 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\"}";
50 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\"}";
51 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\"}";
52 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\"}";
53 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\"}}}";
54 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\"}";
57 public void convDateToZuluStringTest(){
58 String dateToZuluString = Converter.convDateToZuluString(new Date(0L));
59 Assert.assertEquals("1970-01-01T00:00:00.000Z", dateToZuluString);
63 public void convAsyncResponseToBuilderTestTest() throws JsonProcessingException {
64 ResponseContext asyncResponse = buildAsyncResponse();
65 VNFOperation action = VNFOperation.Test;
66 String rpcName = action.name().toLowerCase();
67 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
68 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
72 public void convAsyncResponseToDmaapOutgoingMessageJsonStringTestTest() throws JsonProcessingException {
73 ResponseContext asyncResponse = buildAsyncResponse();
74 VNFOperation action = VNFOperation.Test;
75 String rpcName = action.name().toLowerCase();
76 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
77 System.out.println("jsonStr = " + jsonStr);
78 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringTest,jsonStr);
82 public void convPayloadObjectToJsonStringTest() throws JsonProcessingException, ParseException {
83 String jsonString = Converter.convPayloadObjectToJsonString("any valid JSON string value");
84 Assert.assertEquals("any valid JSON string value", jsonString);
86 HashMap<String, String> hashMap = new HashMap<>();
87 hashMap.put("key","value");
88 jsonString = Converter.convPayloadObjectToJsonString(hashMap);
89 Assert.assertEquals("{\"key\":\"value\"}", jsonString);
93 public void convAsyncResponseToBuilderRollbackTest() throws JsonProcessingException {
94 ResponseContext asyncResponse = buildAsyncResponse();
95 VNFOperation action = VNFOperation.Rollback;
96 String rpcName = action.name().toLowerCase();
97 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
98 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
102 public void convAsyncResponseToDmaapOutgoingMessageJsonStringRollbackTest() throws JsonProcessingException {
103 ResponseContext asyncResponse = buildAsyncResponse();
104 VNFOperation action = VNFOperation.Rollback;
105 String rpcName = action.name().toLowerCase();
106 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
107 System.out.println("jsonStr = " + jsonStr);
108 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringRollback,jsonStr);
112 public void convAsyncResponseToBuilderSnapshotTest() throws JsonProcessingException {
113 ResponseContext asyncResponse = buildAsyncResponse();
114 VNFOperation action = VNFOperation.Snapshot;
115 String rpcName = action.name().toLowerCase();
116 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
117 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
121 public void convAsyncResponseToDmaapOutgoingMessageJsonStringSnapshotTest() throws JsonProcessingException {
122 ResponseContext asyncResponse = buildAsyncResponse();
123 VNFOperation action = VNFOperation.Snapshot;
124 String rpcName = action.name().toLowerCase();
125 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
126 System.out.println("jsonStr = " + jsonStr);
127 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSnapshot,jsonStr);
130 public void convAsyncResponseToBuilderAuditTest() throws JsonProcessingException {
131 ResponseContext asyncResponse = buildAsyncResponsewithPayload();
132 VNFOperation action = VNFOperation.Audit;
133 String rpcName = action.name().toLowerCase();
134 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
135 Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
139 public void convAsyncResponseToDmaapOutgoingMessageJsonStringAuditTest() throws JsonProcessingException {
140 ResponseContext asyncResponse = buildAsyncResponsewithPayload();
141 VNFOperation action = VNFOperation.Audit;
142 String rpcName = action.name().toLowerCase();
143 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
144 System.out.println("jsonStr = " + jsonStr);
145 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringAudit,jsonStr);
148 public void convAsyncResponseToBuilderHealthCheckTest() throws JsonProcessingException {
149 ResponseContext asyncResponse = buildAsyncResponse();
150 VNFOperation action = VNFOperation.HealthCheck;
151 String rpcName = convertActionNameToUrl(action.name());
152 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
153 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
157 public void convAsyncResponseToDmaapOutgoingMessageJsonStringHealthCheckTest() throws JsonProcessingException {
158 ResponseContext asyncResponse = buildAsyncResponse();
159 VNFOperation action = VNFOperation.HealthCheck;
160 String rpcName = convertActionNameToUrl(action.name());
161 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
162 System.out.println("jsonStr = " + jsonStr);
163 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringHealthCheck,jsonStr);
166 public void convAsyncResponseToBuilderLiveUpgradeTest() throws JsonProcessingException {
167 ResponseContext asyncResponse = buildAsyncResponse();
168 VNFOperation action = VNFOperation.LiveUpgrade;
169 String rpcName = convertActionNameToUrl(action.name());
170 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
171 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
175 public void convAsyncResponseToDmaapOutgoingMessageJsonStringLiveUpgradeTest() throws JsonProcessingException {
176 ResponseContext asyncResponse = buildAsyncResponse();
177 VNFOperation action = VNFOperation.LiveUpgrade;
178 String rpcName = convertActionNameToUrl(action.name());
179 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
180 System.out.println("jsonStr = " + jsonStr);
181 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringLiveUpgrade,jsonStr);
184 public void convAsyncResponseToBuilderLockTest() throws JsonProcessingException {
185 ResponseContext asyncResponse = buildAsyncResponse();
186 VNFOperation action = VNFOperation.Lock;
187 String rpcName = convertActionNameToUrl(action.name());
189 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
190 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
194 public void convAsyncResponseToDmaapOutgoingMessageJsonStringLockTest() throws JsonProcessingException {
195 ResponseContext asyncResponse = buildAsyncResponse();
196 VNFOperation action = VNFOperation.Lock;
197 String rpcName = convertActionNameToUrl(action.name());
198 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
199 System.out.println("jsonStr = " + jsonStr);
200 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringLock,jsonStr);
203 public void convAsyncResponseToBuilderModifyConfigTest() throws JsonProcessingException {
204 ResponseContext asyncResponse = buildAsyncResponsewithPayload();
205 VNFOperation action = VNFOperation.ConfigModify;
206 String rpcName = convertActionNameToUrl(action.name());
207 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
208 Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
212 public void convAsyncResponseToDmaapOutgoingMessageJsonStringModifyConfigTest() throws JsonProcessingException {
213 ResponseContext asyncResponse = buildAsyncResponsewithPayload();
214 VNFOperation action = VNFOperation.ConfigModify;
215 String rpcName = convertActionNameToUrl(action.name());
216 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
217 System.out.println("jsonStr = " + jsonStr);
218 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringModifyConfig,jsonStr);
221 public void convAsyncResponseToBuilderSoftwareUploadTest() throws JsonProcessingException {
222 ResponseContext asyncResponse = buildAsyncResponse();
223 VNFOperation action = VNFOperation.SoftwareUpload;
224 String rpcName = convertActionNameToUrl(action.name());
226 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
227 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
231 public void convAsyncResponseToDmaapOutgoingMessageJsonStringSoftwareUploadTest() throws JsonProcessingException {
232 ResponseContext asyncResponse = buildAsyncResponse();
233 VNFOperation action = VNFOperation.SoftwareUpload;
234 String rpcName = convertActionNameToUrl(action.name());
235 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
236 System.out.println("jsonStr = " + jsonStr);
237 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSoftwareUpload,jsonStr);
240 public void convAsyncResponseToBuilderStopTest() throws JsonProcessingException {
241 ResponseContext asyncResponse = buildAsyncResponse();
242 VNFOperation action = VNFOperation.Stop;
243 String rpcName = convertActionNameToUrl(action.name());
244 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
245 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
249 public void convAsyncResponseToDmaapOutgoingMessageJsonStringStopTest() throws JsonProcessingException {
250 ResponseContext asyncResponse = buildAsyncResponse();
251 VNFOperation action = VNFOperation.Stop;
252 String rpcName = convertActionNameToUrl(action.name());
253 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
254 System.out.println("jsonStr = " + jsonStr);
255 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringStop,jsonStr);
258 public void convAsyncResponseToBuilderSync() throws JsonProcessingException {
259 ResponseContext asyncResponse = buildAsyncResponsewithPayload();
260 VNFOperation action = VNFOperation.Sync;
261 String rpcName = convertActionNameToUrl(action.name());
263 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
264 Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
268 public void convAsyncResponseToDmaapOutgoingMessageJsonStringSync() throws JsonProcessingException {
269 ResponseContext asyncResponse = buildAsyncResponsewithPayload();
270 VNFOperation action = VNFOperation.Sync;
271 String rpcName = convertActionNameToUrl(action.name());
272 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
273 System.out.println("jsonStr = " + jsonStr);
274 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringSync,jsonStr);
277 public void convAsyncResponseToBuilderTerminateTest() throws JsonProcessingException {
278 ResponseContext asyncResponse = buildAsyncResponsewithPayload();
279 VNFOperation action = VNFOperation.Sync;
280 String rpcName = convertActionNameToUrl(action.name());
281 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
282 Assert.assertEquals(expectedJsonBodyStrwithPayload,jsonStr);
286 public void convAsyncResponseToDmaapOutgoingMessageJsonStringTerminateTest() throws JsonProcessingException {
287 ResponseContext asyncResponse = buildAsyncResponse();
288 VNFOperation action = VNFOperation.Terminate;
289 String rpcName = convertActionNameToUrl(action.name());
290 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
291 System.out.println("jsonStr = " + jsonStr);
292 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringTerminate,jsonStr);
295 public void convAsyncResponseToBuilderUnlockTest() throws JsonProcessingException {
296 ResponseContext asyncResponse = buildAsyncResponse();
297 VNFOperation action = VNFOperation.Unlock;
298 String rpcName = convertActionNameToUrl(action.name());
299 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
300 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
304 public void convAsyncResponseToDmaapOutgoingMessageJsonStringUnlockTest() throws JsonProcessingException {
305 ResponseContext asyncResponse = buildAsyncResponse();
306 VNFOperation action = VNFOperation.Unlock;
307 String rpcName = convertActionNameToUrl(action.name());
308 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
309 System.out.println("jsonStr = " + jsonStr);
310 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUnlock,jsonStr);
313 public void convAsyncResponseToBuilderRebootTest() throws JsonProcessingException {
314 ResponseContext asyncResponse = buildAsyncResponse();
315 VNFOperation action = VNFOperation.Reboot;
316 String rpcName = convertActionNameToUrl(action.name());
318 String jsonStr = Converter.convAsyncResponseToJsonStringBody(action, rpcName, asyncResponse);
319 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
323 public void convAsyncResponseToDmaapOutgoingMessageJsonStringRebootTest() throws JsonProcessingException {
324 ResponseContext asyncResponse = buildAsyncResponse();
325 VNFOperation action = VNFOperation.Reboot;
326 String rpcName = convertActionNameToUrl(action.name());
327 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
328 System.out.println("jsonStr = " + jsonStr);
329 Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringReboot,jsonStr);
332 public void convAsyncResponseToBuilderTest() throws JsonProcessingException {
333 AsyncResponse asyncResponse = buildAsyncResponse();
334 String jsonStr = Converter.convAsyncResponseToJsonStringBody(asyncResponse);
335 Assert.assertEquals(expectedJsonBodyStr,jsonStr);
339 public void convAsyncResponseToDmaapOutgoingMessageJsonStringTest() throws JsonProcessingException {
340 AsyncResponse asyncResponse = buildAsyncResponse();
341 String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(asyncResponse);
342 System.out.println("jsonStr = " + jsonStr);
343 Assert.assertEquals(expectedDmaapOutgoingMessageJsonString,jsonStr);
347 private ResponseContext buildAsyncResponse() {
348 ResponseContext asyncResponse = createResponseContextWithSubObjects();
349 asyncResponse.getStatus().setCode(LCMCommandStatus.SUCCESS.getResponseCode());
350 asyncResponse.getStatus().setMessage(LCMCommandStatus.SUCCESS.getResponseMessage());
351 asyncResponse.getCommonHeader().setOriginatorId("oid");
352 asyncResponse.getCommonHeader().setApiVer("2.0.0");
353 asyncResponse.getCommonHeader().setRequestId("reqid");
354 asyncResponse.getCommonHeader().setTimestamp(new Date(1000L));
355 asyncResponse.setPayload("any valid JSON string value. Json escape characters need to be added to make it a valid json string value");
356 return asyncResponse;
359 private ResponseContext buildAsyncResponsewithPayload() {
360 ResponseContext asyncResponse = createResponseContextWithSubObjects();
361 asyncResponse.getStatus().setCode(LCMCommandStatus.SUCCESS.getResponseCode());
362 asyncResponse.getStatus().setMessage(LCMCommandStatus.SUCCESS.getResponseMessage());
363 asyncResponse.getCommonHeader().setOriginatorId("oid");
364 asyncResponse.getCommonHeader().setApiVer("2.0.0");
365 asyncResponse.getCommonHeader().setRequestId("reqid");
366 asyncResponse.getCommonHeader().setTimestamp(new Date(1000L));
367 asyncResponse.setPayload("{}");
368 return asyncResponse;
371 private ResponseContext createResponseContextWithSubObjects() {
373 ResponseContext responseContext = new ResponseContext();
374 CommonHeader commonHeader = new CommonHeader();
375 Flags flags = new Flags();
376 Status status = new Status();
377 responseContext.setCommonHeader(commonHeader);
378 responseContext.setStatus(status);
379 commonHeader.setFlags(flags);
380 return responseContext;
383 private String convertActionNameToUrl(String action) {
384 String regex = "([a-z])([A-Z]+)";
385 String replacement = "$1-$2";
386 return action.replaceAll(regex, replacement)