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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.model.basicmodel.concepts;
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;
28 import java.util.NavigableMap;
29 import java.util.TreeMap;
30 import java.util.TreeSet;
32 import org.junit.Test;
35 * Test the AxConceptGetterImpl class.
37 public class AxConceptGetterImplTest {
40 public void testAxConceptGetterImpl() {
41 NavigableMap<AxArtifactKey, AxArtifactKey> keyMap = new TreeMap<>();
43 AxConceptGetterImpl<AxArtifactKey> getter = new AxConceptGetterImpl<>(keyMap);
44 assertNotNull(getter);
46 AxArtifactKey keyA = new AxArtifactKey("A", "0.0.1");
47 assertNull(getter.get(keyA));
50 getter.get((String)null);
51 fail("test should throw an exception here");
53 catch (Exception getException) {
54 assertEquals("conceptKeyName may not be null", getException.getMessage());
57 assertNull(getter.get("W"));
59 AxArtifactKey keyZ = new AxArtifactKey("Z", "0.0.1");
60 keyMap.put(keyZ, keyZ);
61 assertNull(getter.get("W"));
63 AxArtifactKey keyW001 = new AxArtifactKey("W", "0.0.1");
64 keyMap.put(keyW001, keyW001);
65 assertEquals(keyW001, getter.get("W"));
67 AxArtifactKey keyW002 = new AxArtifactKey("W", "0.0.2");
68 keyMap.put(keyW002, keyW002);
69 assertEquals(keyW002, getter.get("W"));
72 assertEquals(keyW002, getter.get("W"));
75 getter.get((String)null, "0.0.1");
76 fail("test should throw an exception here");
78 catch (Exception getException) {
79 assertEquals("conceptKeyName may not be null", getException.getMessage());
82 assertEquals(keyW002, getter.get("W", "0.0.2"));
83 assertEquals(keyW002, getter.get("W", (String)null));
85 assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null));
86 assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null, null));
88 assertEquals(keyW001, getter.getAll("W", null).iterator().next());
89 assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());
90 assertEquals(0, getter.getAll("A", null).size());
91 assertEquals(0, getter.getAll("Z", null).size());
93 keyMap.put(keyZ, keyZ);
94 assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());