Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / concepts / AxConceptGetterImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 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.basicmodel.concepts;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.fail;
27
28 import java.util.NavigableMap;
29 import java.util.TreeMap;
30 import java.util.TreeSet;
31 import org.junit.Test;
32
33 /**
34  * Test the AxConceptGetterImpl class.
35  */
36 public class AxConceptGetterImplTest {
37
38     @Test
39     public void testAxConceptGetterImpl() {
40         NavigableMap<AxArtifactKey, AxArtifactKey> keyMap = new TreeMap<>();
41
42         AxConceptGetterImpl<AxArtifactKey> getter = new AxConceptGetterImpl<>(keyMap);
43         assertNotNull(getter);
44         
45         AxArtifactKey keyA = new AxArtifactKey("A", "0.0.1");
46         assertNull(getter.get(keyA));
47         
48         try {
49             getter.get((String) null);
50             fail("test should throw an exception here");
51         } catch (Exception getException) {
52             assertEquals("conceptKeyName may not be null", getException.getMessage());
53         }
54
55         assertNull(getter.get("W"));
56
57         AxArtifactKey keyZ = new AxArtifactKey("Z", "0.0.1");
58         keyMap.put(keyZ, keyZ);
59         assertNull(getter.get("W"));
60
61         AxArtifactKey keyW001 = new AxArtifactKey("W", "0.0.1");
62         keyMap.put(keyW001, keyW001);
63         assertEquals(keyW001, getter.get("W"));
64
65         AxArtifactKey keyW002 = new AxArtifactKey("W", "0.0.2");
66         keyMap.put(keyW002, keyW002);
67         assertEquals(keyW002, getter.get("W"));
68
69         keyMap.remove(keyZ);
70         assertEquals(keyW002, getter.get("W"));
71
72         try {
73             getter.get((String) null, "0.0.1");
74             fail("test should throw an exception here");
75         } catch (Exception getException) {
76             assertEquals("conceptKeyName may not be null", getException.getMessage());
77         }
78
79         assertEquals(keyW002, getter.get("W", "0.0.2"));
80         assertEquals(keyW002, getter.get("W", (String) null));
81         
82         assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null));
83         assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null, null));
84         
85         assertEquals(keyW001, getter.getAll("W", null).iterator().next());
86         assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());
87         assertEquals(0, getter.getAll("A", null).size());
88         assertEquals(0, getter.getAll("Z", null).size());
89
90         keyMap.put(keyZ, keyZ);
91         assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());
92     }
93 }