Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / pnf / dmaap / JsonUtilForCorrelationIdTest.java
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.openecomp.mso.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
28 public class JsonUtilForCorrelationIdTest {
29
30     private static final String JSON_EXAMPLE_WITH_CORRELATION_ID = "[\n"
31             + "    {\n"
32             + "        \"pnfRegistrationFields\" : {\n"
33             + "        \"correlationId\" : \"corrTest1\",\n"
34             + "        \"value\" : \"value1\"\n"
35             + "        }\n"
36             + "    },\n"
37             + "    {\n"
38             + "        \"pnfRegistrationFields\" : {\n"
39             + "        \"correlationId\" : \"corrTest2\",\n"
40             + "        \"value\" : \"value2\"\n"
41             + "        }\n"
42             + "    }\n"
43             + "]";
44
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\"}}";
50
51     @Test
52     public void parseJsonSuccessful() {
53         List<String> expectedResult = JsonUtilForCorrelationId
54                 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID);
55         assertThat(expectedResult).containsExactly("corrTest1", "corrTest2");
56
57         List<String> expectedResult2 = JsonUtilForCorrelationId
58                 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID2);
59         assertThat(expectedResult2).containsExactly("corrTest3");
60     }
61
62     @Test
63     public void parseJsonWithEscapeCharacters_Successful() {
64         List<String> expectedResult = JsonUtilForCorrelationId
65                 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID3);
66         assertThat(expectedResult).containsExactly("corrTest4", "corrTest5");
67     }
68
69     @Test
70     public void parseJson_emptyListReturnedWhenNothingFound() {
71         List<String> expectedResult = JsonUtilForCorrelationId
72                 .parseJsonToGelAllCorrelationId(JSON_EXAMPLE_WITH_CORRELATION_ID4);
73         assertThat(expectedResult).isEmpty();
74     }
75
76 }