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.openecomp.mso.bpmn.infrastructure.pnf.dmaap;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import java.util.List;
26 import org.junit.Test;
28 public class JsonUtilForCorrelationIdTest {
30 private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[\n"
32 + " \"pnfRegistrationFields\" : {\n"
33 + " \"correlationId\" : \"corrTest1\",\n"
34 + " \"value\" : \"value1\"\n"
38 + " \"pnfRegistrationFields\" : {\n"
39 + " \"correlationId\" : \"corrTest2\",\n"
40 + " \"value\" : \"value2\"\n"
45 private static final String JSON_EXAMPLE_WITH_CORRELATION_ID2 = "{\"pnfRegistrationFields\":{\"correlationId\":\"corrTest3\"}}";
46 private static final String JSON_EXAMPLE_WITH_CORRELATION_ID3 = "[\"\\{\\\"pnfRegistrationFields\\\":"
47 + "{\\\"correlationId\\\":\\\"corrTest4\\\"}}\", \"\\{\\\"pnfRegistrationFields\\\":"
48 + "{\\\"correlationId\\\":\\\"corrTest5\\\"}}\"]";
49 private static final String JSON_EXAMPLE_WITH_CORRELATION_ID4 = "{\"header\":{\"key\":\"value\"}}";
52 public void parseJsonSuccessful() {
53 List<String> expectedResult = JsonUtilForCorrelationId
54 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID);
55 assertThat(expectedResult).containsExactly("corrTest1", "corrTest2");
57 List<String> expectedResult2 = JsonUtilForCorrelationId
58 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID2);
59 assertThat(expectedResult2).containsExactly("corrTest3");
63 public void parseJsonWithEscapeCharacters_Successful() {
64 List<String> expectedResult = JsonUtilForCorrelationId
65 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID3);
66 assertThat(expectedResult).containsExactly("corrTest4", "corrTest5");
70 public void parseJson_emptyListReturnedWhenNothingFound() {
71 List<String> expectedResult = JsonUtilForCorrelationId
72 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID4);
73 assertThat(expectedResult).isEmpty();