Merge "Reorder modifiers"
[so.git] / bpmn / MSOCoreBPMN / src / test / java / org / openecomp / mso / 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.openecomp.mso.bpmn.core;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.entry;
25
26 import org.junit.Test;
27
28 public class RollbackDataTest {
29
30     private final static String TYPE_A = "typeA";
31     private final static String TYPE_B = "typeB";
32     private static final String KEY_1 = "key1";
33     private static final String VALUE_1 = "value1";
34     private static final String VALUE_2 = "value2";
35
36     @Test
37     public void shouldReturnStringRepresentationOfDataInAnyPermutation() throws Exception {
38         // given
39         RollbackData data = new RollbackData();
40         data.put(TYPE_A, KEY_1, VALUE_1);
41         data.put(TYPE_A, "key2", "value2");
42         data.put(TYPE_B, "key3", "value3");
43         // when, then
44         assertThat(data.toString()).isIn(
45                 "[typeB{key3=value3},typeA{key1=value1, key2=value2}]",
46                 "[typeB{key3=value3},typeA{key2=value2, key1=value1}]",
47                 "[typeA{key1=value1, key2=value2},typeB{key3=value3}]",
48                 "[typeA{key2=value2, key1=value1},typeB{key3=value3}]");
49     }
50
51     @Test
52     public void shouldBeEmptyOnCreation() throws Exception {
53         // given
54         RollbackData data = new RollbackData();
55         // then
56         assertThat(data.hasType(TYPE_A)).isFalse();
57         assertThat(data.get(TYPE_A, KEY_1)).isNull();
58     }
59
60     @Test
61     public void shouldHaveTypeAfterPuttingDataOfThatType() throws Exception {
62         // given
63         RollbackData data = new RollbackData();
64         // when
65         data.put(TYPE_A, KEY_1, VALUE_1);
66         // then
67         assertThat(data.hasType(TYPE_A)).isTrue();
68         assertThat(data.hasType(TYPE_B)).isFalse();
69         assertThat(data.get(TYPE_A, KEY_1)).isEqualTo(VALUE_1);
70     }
71
72     @Test
73     public void shouldKeepTwoValuesWithSameKeysButDifferentTypes() throws Exception {
74         // given
75         RollbackData data = new RollbackData();
76         // when
77         data.put(TYPE_A, KEY_1, VALUE_1);
78         data.put(TYPE_B, KEY_1, VALUE_2);
79         // then
80         assertThat(data.get(TYPE_A, KEY_1)).isEqualTo(VALUE_1);
81         assertThat(data.get(TYPE_A)).containsExactly(entry(KEY_1, VALUE_1));
82         assertThat(data.get(TYPE_B, KEY_1)).isEqualTo(VALUE_2);
83         assertThat(data.get(TYPE_B)).containsExactly(entry(KEY_1, VALUE_2));
84     }
85 }