Remove try/catch blocks with assertj - apex-pdp
[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  *  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.basicmodel.concepts;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28
29 import java.util.NavigableMap;
30 import java.util.TreeMap;
31 import java.util.TreeSet;
32 import org.junit.Test;
33
34 /**
35  * Test the AxConceptGetterImpl class.
36  */
37 public class AxConceptGetterImplTest {
38
39     @Test
40     public void testAxConceptGetterImpl() {
41         NavigableMap<AxArtifactKey, AxArtifactKey> keyMap = new TreeMap<>();
42
43         AxConceptGetterImpl<AxArtifactKey> getter = new AxConceptGetterImpl<>(keyMap);
44         assertNotNull(getter);
45
46         AxArtifactKey keyA = new AxArtifactKey("A", "0.0.1");
47         assertNull(getter.get(keyA));
48
49         assertThatThrownBy(() -> getter.get((String) null))
50             .hasMessage("conceptKeyName may not be null");
51         assertNull(getter.get("W"));
52
53         AxArtifactKey keyZ = new AxArtifactKey("Z", "0.0.1");
54         keyMap.put(keyZ, keyZ);
55         assertNull(getter.get("W"));
56
57         AxArtifactKey keyW001 = new AxArtifactKey("W", "0.0.1");
58         keyMap.put(keyW001, keyW001);
59         assertEquals(keyW001, getter.get("W"));
60
61         AxArtifactKey keyW002 = new AxArtifactKey("W", "0.0.2");
62         keyMap.put(keyW002, keyW002);
63         assertEquals(keyW002, getter.get("W"));
64
65         keyMap.remove(keyZ);
66         assertEquals(keyW002, getter.get("W"));
67
68         assertThatThrownBy(() -> getter.get((String) null, "0.0.1"))
69             .hasMessage("conceptKeyName may not be null");
70         assertEquals(keyW002, getter.get("W", "0.0.2"));
71         assertEquals(keyW002, getter.get("W", (String) null));
72
73         assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null));
74         assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null, null));
75
76         assertEquals(keyW001, getter.getAll("W", null).iterator().next());
77         assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());
78         assertEquals(0, getter.getAll("A", null).size());
79         assertEquals(0, getter.getAll("Z", null).size());
80
81         keyMap.put(keyZ, keyZ);
82         assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());
83     }
84 }