f9e4cb4c8887031e4d4f86d54b8a6c9449b45e9f
[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.ArrayList;
27 import java.util.List;
28 import org.junit.Test;
29
30 public class JsonUtilForPnfCorrelationIdTest {
31     private static final List<String> LIST_EXAMPLE_WITH_PNF_CORRELATION_ID = new ArrayList<>();
32     private static final List<String> LIST_WITH_ONE_PNF_CORRELATION_ID = new ArrayList<>();
33     private static final List<String> LIST_WITH_TWO_PNF_CORRELATION_ID_AND_ESCAPED_CHARACTERS = new ArrayList<>();
34     private static final List<String> LIST_WITH_NO_PNF_CORRELATION_ID = new ArrayList<>();
35
36     static {
37         LIST_EXAMPLE_WITH_PNF_CORRELATION_ID.add("{\"correlationId\": \"corrTest1\",\"key1\":\"value1\"}");
38         LIST_EXAMPLE_WITH_PNF_CORRELATION_ID.add("{\"correlationId\": \"corrTest2\",\"key2\":\"value2\"}");
39         LIST_WITH_ONE_PNF_CORRELATION_ID.add("{\"correlationId\":\"corrTest3\"}");
40         LIST_WITH_TWO_PNF_CORRELATION_ID_AND_ESCAPED_CHARACTERS.add("\"{\\\"correlationId\\\":\\\"corrTest4\\\"}\"");
41         LIST_WITH_TWO_PNF_CORRELATION_ID_AND_ESCAPED_CHARACTERS.add("\"{\\\"correlationId\\\":\\\"corrTest5\\\"}\"");
42         LIST_WITH_NO_PNF_CORRELATION_ID.add("{\"key1\":\"value1\"}");
43     }
44
45     @Test
46     public void parseJsonSuccessful() {
47         List<String> expectedResult =
48                 JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId(LIST_EXAMPLE_WITH_PNF_CORRELATION_ID);
49         assertThat(expectedResult).containsExactly("corrTest1", "corrTest2");
50
51         List<String> expectedResult2 =
52                 JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId(LIST_WITH_ONE_PNF_CORRELATION_ID);
53         assertThat(expectedResult2).containsExactly("corrTest3");
54     }
55
56     @Test
57     public void parseJsonWithEscapeCharacters_Successful() {
58         List<String> expectedResult = JsonUtilForPnfCorrelationId
59                 .parseJsonToGelAllPnfCorrelationId(LIST_WITH_TWO_PNF_CORRELATION_ID_AND_ESCAPED_CHARACTERS);
60         assertThat(expectedResult).containsExactly("corrTest4", "corrTest5");
61     }
62
63     @Test
64     public void parseJson_emptyListReturnedWhenNothingFound() {
65         List<String> expectedResult =
66                 JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId(LIST_WITH_NO_PNF_CORRELATION_ID);
67         assertThat(expectedResult).isEmpty();
68     }
69
70     @Test
71     public void shouldReturnEmptyListWhenInputIsNull() {
72         assertThat(JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId(null)).isEmpty();
73     }
74
75     @Test
76     public void shouldReturnEmptyListWhenInputIsEmpty() {
77         assertThat(JsonUtilForPnfCorrelationId.parseJsonToGelAllPnfCorrelationId(null)).isEmpty();
78     }
79 }