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;
31 import org.junit.Test;
34 * Test the AxConceptGetterImpl class.
36 public class AxConceptGetterImplTest {
39 public void testAxConceptGetterImpl() {
40 NavigableMap<AxArtifactKey, AxArtifactKey> keyMap = new TreeMap<>();
42 AxConceptGetterImpl<AxArtifactKey> getter = new AxConceptGetterImpl<>(keyMap);
43 assertNotNull(getter);
45 AxArtifactKey keyA = new AxArtifactKey("A", "0.0.1");
46 assertNull(getter.get(keyA));
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());
55 assertNull(getter.get("W"));
57 AxArtifactKey keyZ = new AxArtifactKey("Z", "0.0.1");
58 keyMap.put(keyZ, keyZ);
59 assertNull(getter.get("W"));
61 AxArtifactKey keyW001 = new AxArtifactKey("W", "0.0.1");
62 keyMap.put(keyW001, keyW001);
63 assertEquals(keyW001, getter.get("W"));
65 AxArtifactKey keyW002 = new AxArtifactKey("W", "0.0.2");
66 keyMap.put(keyW002, keyW002);
67 assertEquals(keyW002, getter.get("W"));
70 assertEquals(keyW002, getter.get("W"));
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());
79 assertEquals(keyW002, getter.get("W", "0.0.2"));
80 assertEquals(keyW002, getter.get("W", (String) null));
82 assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null));
83 assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null, null));
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());
90 keyMap.put(keyZ, keyZ);
91 assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());