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
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.assertFalse;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
29 import org.junit.Test;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
36 * @author Liam Fallon (liam.fallon@ericsson.com)
38 public class TestAxReferenceKey {
41 public void testAxReferenceKey() {
42 assertNotNull(new AxReferenceKey());
43 assertNotNull(new AxReferenceKey(new AxArtifactKey()));
44 assertNotNull(new AxReferenceKey(new AxArtifactKey(), "LocalName"));
45 assertNotNull(new AxReferenceKey(new AxReferenceKey()));
46 assertNotNull(new AxReferenceKey(new AxReferenceKey(), "LocalName"));
47 assertNotNull(new AxReferenceKey(new AxArtifactKey(), "ParentLocalName", "LocalName"));
48 assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "LocalName"));
49 assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "ParentLocalName", "LocalName"));
50 assertNotNull(new AxReferenceKey("ParentKeyName:0.0.1:ParentLocalName:LocalName"));
51 assertEquals(AxReferenceKey.getNullKey().getKey(), AxReferenceKey.getNullKey());
52 assertEquals("NULL:0.0.0:NULL:NULL", AxReferenceKey.getNullKey().getID());
54 AxReferenceKey testReferenceKey = new AxReferenceKey();
55 testReferenceKey.setParentArtifactKey(new AxArtifactKey("PN", "0.0.1"));
56 assertEquals("PN:0.0.1", testReferenceKey.getParentArtifactKey().getID());
58 testReferenceKey.setParentReferenceKey(new AxReferenceKey("PN", "0.0.1", "LN"));
59 assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getID());
61 testReferenceKey.setParentKeyName("NPKN");
62 assertEquals("NPKN", testReferenceKey.getParentKeyName());
64 testReferenceKey.setParentKeyVersion("0.0.1");
65 assertEquals("0.0.1", testReferenceKey.getParentKeyVersion());
67 testReferenceKey.setParentLocalName("NPKLN");
68 assertEquals("NPKLN", testReferenceKey.getParentLocalName());
70 testReferenceKey.setLocalName("NLN");
71 assertEquals("NLN", testReferenceKey.getLocalName());
73 assertFalse(testReferenceKey.isCompatible(AxArtifactKey.getNullKey()));
74 assertFalse(testReferenceKey.isCompatible(AxReferenceKey.getNullKey()));
75 assertTrue(testReferenceKey.isCompatible(testReferenceKey));
77 assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxArtifactKey.getNullKey()));
78 assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxReferenceKey.getNullKey()));
79 assertEquals(AxKey.Compatibility.IDENTICAL, testReferenceKey.getCompatibility(testReferenceKey));
81 AxValidationResult result = new AxValidationResult();
82 result = testReferenceKey.validate(result);
83 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
85 testReferenceKey.clean();
87 AxReferenceKey clonedReferenceKey = new AxReferenceKey(testReferenceKey);
88 assertEquals("AxReferenceKey:(parentKeyName=NPKN,parentKeyVersion=0.0.1,parentLocalName=NPKLN,localName=NLN)", clonedReferenceKey.toString());
90 assertFalse(testReferenceKey.hashCode() == 0);
92 assertTrue(testReferenceKey.equals(testReferenceKey));
93 assertTrue(testReferenceKey.equals(clonedReferenceKey));
94 assertFalse(testReferenceKey.equals("Hello"));
95 assertFalse(testReferenceKey.equals(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN")));
96 assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN")));
97 assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN")));
98 assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN")));
99 assertTrue(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN")));
101 assertEquals(0, testReferenceKey.compareTo(testReferenceKey));
102 assertEquals(0, testReferenceKey.compareTo(clonedReferenceKey));
103 assertNotEquals(0, testReferenceKey.compareTo(new AxArtifactKey()));
104 assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN")));
105 assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN")));
106 assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN")));
107 assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN")));
108 assertEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN")));
110 assertNotNull(testReferenceKey.getKeys());