79f3984c348f7154b5f07cd335f756b5085dc18d
[policy/apex-pdp.git] /
1 /*
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
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.assertFalse;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
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;
34
35 public class TestAxReferenceKey {
36
37     @Test
38     public void testAxReferenceKey() {
39         assertNotNull(new AxReferenceKey());
40         assertNotNull(new AxReferenceKey(new AxArtifactKey()));
41         assertNotNull(new AxReferenceKey(new AxArtifactKey(), "LocalName"));
42         assertNotNull(new AxReferenceKey(new AxReferenceKey()));
43         assertNotNull(new AxReferenceKey(new AxReferenceKey(), "LocalName"));
44         assertNotNull(new AxReferenceKey(new AxArtifactKey(), "ParentLocalName", "LocalName"));
45         assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "LocalName"));
46         assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "ParentLocalName", "LocalName"));
47         assertNotNull(new AxReferenceKey("ParentKeyName:0.0.1:ParentLocalName:LocalName"));
48         assertEquals(AxReferenceKey.getNullKey().getKey(), AxReferenceKey.getNullKey());
49         assertEquals("NULL:0.0.0:NULL:NULL", AxReferenceKey.getNullKey().getId());
50
51         AxReferenceKey testReferenceKey = new AxReferenceKey();
52         testReferenceKey.setParentArtifactKey(new AxArtifactKey("PN", "0.0.1"));
53         assertEquals("PN:0.0.1", testReferenceKey.getParentArtifactKey().getId());
54
55         testReferenceKey.setParentReferenceKey(new AxReferenceKey("PN", "0.0.1", "LN"));
56         assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getId());
57
58         testReferenceKey.setParentKeyName("NPKN");
59         assertEquals("NPKN", testReferenceKey.getParentKeyName());
60
61         testReferenceKey.setParentKeyVersion("0.0.1");
62         assertEquals("0.0.1", testReferenceKey.getParentKeyVersion());
63
64         testReferenceKey.setParentLocalName("NPKLN");
65         assertEquals("NPKLN", testReferenceKey.getParentLocalName());
66
67         testReferenceKey.setLocalName("NLN");
68         assertEquals("NLN", testReferenceKey.getLocalName());
69
70         assertFalse(testReferenceKey.isCompatible(AxArtifactKey.getNullKey()));
71         assertFalse(testReferenceKey.isCompatible(AxReferenceKey.getNullKey()));
72         assertTrue(testReferenceKey.isCompatible(testReferenceKey));
73
74         assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxArtifactKey.getNullKey()));
75         assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxReferenceKey.getNullKey()));
76         assertEquals(AxKey.Compatibility.IDENTICAL, testReferenceKey.getCompatibility(testReferenceKey));
77
78         AxValidationResult result = new AxValidationResult();
79         result = testReferenceKey.validate(result);
80         assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
81
82         testReferenceKey.clean();
83
84         AxReferenceKey clonedReferenceKey = new AxReferenceKey(testReferenceKey);
85         assertEquals("AxReferenceKey:(parentKeyName=NPKN,parentKeyVersion=0.0.1,parentLocalName=NPKLN,localName=NLN)",
86                         clonedReferenceKey.toString());
87
88         assertFalse(testReferenceKey.hashCode() == 0);
89
90         assertTrue(testReferenceKey.equals(testReferenceKey));
91         assertTrue(testReferenceKey.equals(clonedReferenceKey));
92         assertFalse(testReferenceKey.equals("Hello"));
93         assertFalse(testReferenceKey.equals(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN")));
94         assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN")));
95         assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN")));
96         assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN")));
97         assertTrue(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN")));
98
99         assertEquals(0, testReferenceKey.compareTo(testReferenceKey));
100         assertEquals(0, testReferenceKey.compareTo(clonedReferenceKey));
101         assertNotEquals(0, testReferenceKey.compareTo(new AxArtifactKey()));
102         assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN")));
103         assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN")));
104         assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN")));
105         assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN")));
106         assertEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN")));
107
108         assertNotNull(testReferenceKey.getKeys());
109     }
110 }