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