Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / MSOCoreBPMN / src / test / java / org / onap / so / bpmn / core / RollbackDataTest.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.onap.so.bpmn.core;
22
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertThat;
28 import static org.junit.Assert.assertTrue;
29 import static org.hamcrest.Matchers.isIn;
30 import java.util.Arrays;
31 import java.util.Collections;
32 import org.junit.Test;
33
34 public class RollbackDataTest {
35
36     private final static String TYPE_A = "typeA";
37     private final static String TYPE_B = "typeB";
38     private static final String KEY_1 = "key1";
39     private static final String VALUE_1 = "value1";
40     private static final String VALUE_2 = "value2";
41
42     @Test
43     public void shouldReturnStringRepresentationOfDataInAnyPermutation() throws Exception {
44         // given
45         RollbackData data = new RollbackData();
46         data.put(TYPE_A, KEY_1, VALUE_1);
47         data.put(TYPE_A, "key2", "value2");
48         data.put(TYPE_B, "key3", "value3");
49         // when, then
50         assertThat(data.toString(),
51                 isIn(Arrays.asList("[typeB{key3=value3},typeA{key1=value1, key2=value2}]",
52                         "[typeB{key3=value3},typeA{key2=value2, key1=value1}]",
53                         "[typeA{key1=value1, key2=value2},typeB{key3=value3}]",
54                         "[typeA{key2=value2, key1=value1},typeB{key3=value3}]")));
55     }
56
57     @Test
58     public void shouldBeEmptyOnCreation() throws Exception {
59         // given
60         RollbackData data = new RollbackData();
61         // then
62         assertFalse(data.hasType(TYPE_A));
63         assertNull(data.get(TYPE_A, KEY_1));
64     }
65
66     @Test
67     public void shouldHaveTypeAfterPuttingDataOfThatType() throws Exception {
68         // given
69         RollbackData data = new RollbackData();
70         // when
71         data.put(TYPE_A, KEY_1, VALUE_1);
72         // then
73         assertTrue(data.hasType(TYPE_A));
74         assertFalse(data.hasType(TYPE_B));
75         assertEquals(VALUE_1, data.get(TYPE_A, KEY_1));
76     }
77
78     @Test
79     public void shouldKeepTwoValuesWithSameKeysButDifferentTypes() throws Exception {
80         // given
81         RollbackData data = new RollbackData();
82         // when
83         data.put(TYPE_A, KEY_1, VALUE_1);
84         data.put(TYPE_B, KEY_1, VALUE_2);
85         // then
86         assertEquals(VALUE_1, data.get(TYPE_A, KEY_1));
87         assertThat(data.get(TYPE_A), is(Collections.singletonMap(KEY_1, VALUE_1)));
88         assertEquals(VALUE_2, data.get(TYPE_B, KEY_1));
89         assertThat(data.get(TYPE_B), is(Collections.singletonMap(KEY_1, VALUE_2)));
90     }
91 }