24d1810ac67f2656789ef305d9f0e168e5aed9a2
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.pnf.dmaap;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import java.util.List;
26 import org.junit.Test;
27 import org.onap.so.bpmn.infrastructure.pnf.dmaap.JsonUtilForCorrelationId;
28
29 public class JsonUtilForCorrelationIdTest {
30
31     private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[\n"
32             + "    {\n"
33             + "        \"pnfRegistrationFields\" : {\n"
34             + "        \"correlationId\" : \"corrTest1\",\n"
35             + "        \"value\" : \"value1\"\n"
36             + "        }\n"
37             + "    },\n"
38             + "    {\n"
39             + "        \"pnfRegistrationFields\" : {\n"
40             + "        \"correlationId\" : \"corrTest2\",\n"
41             + "        \"value\" : \"value2\"\n"
42             + "        }\n"
43             + "    }\n"
44             + "]";
45
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\"}}";
51
52     @Test
53     public void parseJsonSuccessful() {
54         List<String> expectedResult = JsonUtilForCorrelationId
55                 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID);
56         assertThat(expectedResult).containsExactly("corrTest1", "corrTest2");
57
58         List<String> expectedResult2 = JsonUtilForCorrelationId
59                 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID2);
60         assertThat(expectedResult2).containsExactly("corrTest3");
61     }
62
63     @Test
64     public void parseJsonWithEscapeCharacters_Successful() {
65         List<String> expectedResult = JsonUtilForCorrelationId
66                 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID3);
67         assertThat(expectedResult).containsExactly("corrTest4", "corrTest5");
68     }
69
70     @Test
71     public void parseJson_emptyListReturnedWhenNothingFound() {
72         List<String> expectedResult = JsonUtilForCorrelationId
73                 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID4);
74         assertThat(expectedResult).isEmpty();
75     }
76
77 }