4edee245312f31e6c15038ec28e0f9712e963b18
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / java / org / onap / so / bpmn / infrastructure / pnf / dmaap / JsonUtilForPnfCorrelationIdTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2018 Nokia.
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.pnf.dmaap;
24
25 import static org.assertj.core.api.Assertions.assertThat;
26 import java.util.List;
27 import org.junit.Test;
28
29 public class JsonUtilForPnfCorrelationIdTest {
30
31     private static final String JSON_EXAMPLE_WITH_PNF_CORRELATION_ID = "[{\"correlationId\": \"corrTest1\","
32             + "\"key1\":\"value1\"},{\"correlationId\": \"corrTest2\",\"key2\":\"value2\"}]";
33
34     private static final String JSON_WITH_ONE_PNF_CORRELATION_ID = "[{\"correlationId\":\"corrTest3\"}]";
35
36     private static final String JSON_WITH_TWO_PNF_CORRELATION_ID_AND_ESCAPED_CHARACTERS =
37             "[\"{\\\"correlationId\\\":\\\"corrTest4\\\"}\", \"{\\\"correlationId\\\":\\\"corrTest5\\\"}\"]";
38
39     private static final String JSON_WITH_NO_PNF_CORRELATION_ID = "[{\"key1\":\"value1\"}]";
40
41     @Test
42     public void parseJsonSuccessful() {
43         List<String> expectedResult =
44                 JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId(JSON_EXAMPLE_WITH_PNF_CORRELATION_ID);
45         assertThat(expectedResult).containsExactly("corrTest1", "corrTest2");
46
47         List<String> expectedResult2 =
48                 JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId(JSON_WITH_ONE_PNF_CORRELATION_ID);
49         assertThat(expectedResult2).containsExactly("corrTest3");
50     }
51
52     @Test
53     public void parseJsonWithEscapeCharacters_Successful() {
54         List<String> expectedResult = JsonUtilForPnfCorrelationId
55                 .parseJsonToGelAllPnfCorrelationId(JSON_WITH_TWO_PNF_CORRELATION_ID_AND_ESCAPED_CHARACTERS);
56         assertThat(expectedResult).containsExactly("corrTest4", "corrTest5");
57     }
58
59     @Test
60     public void parseJson_emptyListReturnedWhenNothingFound() {
61         List<String> expectedResult =
62                 JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId(JSON_WITH_NO_PNF_CORRELATION_ID);
63         assertThat(expectedResult).isEmpty();
64     }
65
66     @Test
67     public void shouldReturnEmptyListWhenInputIsNull() {
68         assertThat(JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId(null)).isEmpty();
69     }
70
71     @Test
72     public void shouldReturnEmptyListWhenInputIsEmpty() {
73         assertThat(JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId("")).isEmpty();
74     }
75 }