dbc925d66cef5ceb74e4afe420fcc2879e36aac8
[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 /**
36  * @author Liam Fallon (liam.fallon@ericsson.com)
37  */
38 public class TestAxReferenceKey {
39
40     @Test
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());
53
54         AxReferenceKey testReferenceKey = new AxReferenceKey();
55         testReferenceKey.setParentArtifactKey(new AxArtifactKey("PN", "0.0.1"));
56         assertEquals("PN:0.0.1", testReferenceKey.getParentArtifactKey().getID());
57         
58         testReferenceKey.setParentReferenceKey(new AxReferenceKey("PN", "0.0.1", "LN"));
59         assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getID());
60         
61         testReferenceKey.setParentKeyName("NPKN");
62         assertEquals("NPKN", testReferenceKey.getParentKeyName());
63         
64         testReferenceKey.setParentKeyVersion("0.0.1");
65         assertEquals("0.0.1", testReferenceKey.getParentKeyVersion());
66         
67         testReferenceKey.setParentLocalName("NPKLN");
68         assertEquals("NPKLN", testReferenceKey.getParentLocalName());
69         
70         testReferenceKey.setLocalName("NLN");
71         assertEquals("NLN", testReferenceKey.getLocalName());
72         
73         assertFalse(testReferenceKey.isCompatible(AxArtifactKey.getNullKey()));
74         assertFalse(testReferenceKey.isCompatible(AxReferenceKey.getNullKey()));
75         assertTrue(testReferenceKey.isCompatible(testReferenceKey));
76         
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));
80         
81         AxValidationResult result = new AxValidationResult();
82         result = testReferenceKey.validate(result);
83         assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
84         
85         testReferenceKey.clean();
86         
87         AxReferenceKey clonedReferenceKey = new AxReferenceKey(testReferenceKey);
88         assertEquals("AxReferenceKey:(parentKeyName=NPKN,parentKeyVersion=0.0.1,parentLocalName=NPKLN,localName=NLN)", clonedReferenceKey.toString());
89         
90         assertFalse(testReferenceKey.hashCode() == 0);
91         
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")));
100         
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")));
109         
110         assertNotNull(testReferenceKey.getKeys());
111     }
112 }