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.openecomp.mso.bpmn.core;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.entry;
26 import org.junit.Test;
28 public class RollbackDataTest {
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";
37 public void shouldReturnStringRepresentationOfDataInAnyPermutation() throws Exception {
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");
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}]");
52 public void shouldBeEmptyOnCreation() throws Exception {
54 RollbackData data = new RollbackData();
56 assertThat(data.hasType(TYPE_A)).isFalse();
57 assertThat(data.get(TYPE_A, KEY_1)).isNull();
61 public void shouldHaveTypeAfterPuttingDataOfThatType() throws Exception {
63 RollbackData data = new RollbackData();
65 data.put(TYPE_A, KEY_1, VALUE_1);
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);
73 public void shouldKeepTwoValuesWithSameKeysButDifferentTypes() throws Exception {
75 RollbackData data = new RollbackData();
77 data.put(TYPE_A, KEY_1, VALUE_1);
78 data.put(TYPE_B, KEY_1, VALUE_2);
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));