2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.core;
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;
34 public class RollbackDataTest {
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";
43 public void shouldReturnStringRepresentationOfDataInAnyPermutation() throws Exception {
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");
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}]")));
58 public void shouldBeEmptyOnCreation() throws Exception {
60 RollbackData data = new RollbackData();
62 assertFalse(data.hasType(TYPE_A));
63 assertNull(data.get(TYPE_A, KEY_1));
67 public void shouldHaveTypeAfterPuttingDataOfThatType() throws Exception {
69 RollbackData data = new RollbackData();
71 data.put(TYPE_A, KEY_1, VALUE_1);
73 assertTrue(data.hasType(TYPE_A));
74 assertFalse(data.hasType(TYPE_B));
75 assertEquals(VALUE_1, data.get(TYPE_A, KEY_1));
79 public void shouldKeepTwoValuesWithSameKeysButDifferentTypes() throws Exception {
81 RollbackData data = new RollbackData();
83 data.put(TYPE_A, KEY_1, VALUE_1);
84 data.put(TYPE_B, KEY_1, VALUE_2);
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)));