2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.pnf.dmaap;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import java.util.List;
26 import org.junit.Test;
27 import org.onap.so.bpmn.infrastructure.pnf.dmaap.JsonUtilForCorrelationId;
29 public class JsonUtilForCorrelationIdTest {
31 private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[\n"
33 + " \"pnfRegistrationFields\" : {\n"
34 + " \"correlationId\" : \"corrTest1\",\n"
35 + " \"value\" : \"value1\"\n"
39 + " \"pnfRegistrationFields\" : {\n"
40 + " \"correlationId\" : \"corrTest2\",\n"
41 + " \"value\" : \"value2\"\n"
46 private static final String JSON_EXAMPLE_WITH_CORRELATION_ID2 = "{\"pnfRegistrationFields\":{\"correlationId\":\"corrTest3\"}}";
47 private static final String JSON_EXAMPLE_WITH_CORRELATION_ID3 = "[\"{\\\"pnfRegistrationFields\\\":"
48 + "{\\\"correlationId\\\":\\\"corrTest4\\\"}}\", \"{\\\"pnfRegistrationFields\\\":"
49 + "{\\\"correlationId\\\":\\\"corrTest5\\\"}}\"]";
50 private static final String JSON_EXAMPLE_WITH_CORRELATION_ID4 = "{\"header\":{\"key\":\"value\"}}";
53 public void parseJsonSuccessful() {
54 List<String> expectedResult = JsonUtilForCorrelationId
55 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID);
56 assertThat(expectedResult).containsExactly("corrTest1", "corrTest2");
58 List<String> expectedResult2 = JsonUtilForCorrelationId
59 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID2);
60 assertThat(expectedResult2).containsExactly("corrTest3");
64 public void parseJsonWithEscapeCharacters_Successful() {
65 List<String> expectedResult = JsonUtilForCorrelationId
66 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID3);
67 assertThat(expectedResult).containsExactly("corrTest4", "corrTest5");
71 public void parseJson_emptyListReturnedWhenNothingFound() {
72 List<String> expectedResult = JsonUtilForCorrelationId
73 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID4);
74 assertThat(expectedResult).isEmpty();