fb32d938308ca752a96a48d02fdbcecbe2adb1ca
[policy/apex-pdp.git] / model / utilities / src / test / java / org / onap / policy / apex / model / utilities / KeyedMapComparerTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.utilities;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27
28 import java.util.TreeMap;
29
30 import org.junit.Test;
31 import org.onap.policy.apex.model.utilities.comparison.KeyedMapComparer;
32 import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference;
33
34 /**
35  * Test key map comparisons.
36  *
37  * @author Liam Fallon (liam.fallon@ericsson.com)
38  */
39 public class KeyedMapComparerTest {
40
41     @Test
42     public void test() {
43         TreeMap<String, String> leftMap = new TreeMap<String, String>();
44         leftMap.put("B", "BBBBB");
45         leftMap.put("C", "CCCCC");
46         leftMap.put("E", "EEEEE");
47         leftMap.put("G", "GGGGG");
48
49         TreeMap<String, String> rightMap = new TreeMap<String, String>();
50         rightMap.put("A", "AAAAA");
51         rightMap.put("B", "B");
52         rightMap.put("D", "DDDDD");
53         rightMap.put("E", "EEEEE");
54         rightMap.put("F", "FFFFF");
55         rightMap.put("G", "G");
56
57         KeyedMapDifference<String, String> kmComparedSame =
58                 new KeyedMapComparer<String, String>().compareMaps(leftMap, leftMap);
59         KeyedMapDifference<String, String> kmComparedDiff =
60                 new KeyedMapComparer<String, String>().compareMaps(leftMap, rightMap);
61
62         assertTrue(kmComparedSame.getIdenticalValues().equals(leftMap));
63         assertEquals(1, kmComparedDiff.getLeftOnly().size());
64         assertEquals(3, kmComparedDiff.getRightOnly().size());
65         assertEquals(2, kmComparedDiff.getDifferentValues().size());
66         assertEquals(1, kmComparedDiff.getIdenticalValues().size());
67
68         assertNotNull(kmComparedSame.asString(true, true));
69         assertNotNull(kmComparedSame.asString(true, false));
70         assertNotNull(kmComparedSame.asString(false, false));
71         assertNotNull(kmComparedSame.asString(false, true));
72
73         assertNotNull(kmComparedDiff.asString(true, true));
74         assertNotNull(kmComparedDiff.asString(true, false));
75         assertNotNull(kmComparedDiff.asString(false, false));
76         assertNotNull(kmComparedDiff.asString(false, true));
77     }
78 }