061df61a5be2bb80b6951a561fe6ec046039ff1c
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / concepts / AxKeyUseTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  * 
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  * 
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * 
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.basicmodel.concepts;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 import org.junit.Test;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxKey.Compatibility;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyUse;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
36
37 public class AxKeyUseTest {
38
39     @Test
40     public void test() {
41         assertNotNull(new AxKeyUse());
42         assertNotNull(new AxKeyUse(new AxArtifactKey()));
43         assertNotNull(new AxKeyUse(new AxReferenceKey()));
44         
45         AxArtifactKey key = new AxArtifactKey("Key", "0.0.1");
46         AxKeyUse keyUse = new AxKeyUse();
47         keyUse.setKey(key);
48         assertEquals(key, keyUse.getKey());
49         assertEquals("Key:0.0.1", keyUse.getId());
50         assertEquals(key, keyUse.getKeys().get(0));
51         
52         assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
53         assertTrue(keyUse.isCompatible(key));
54         
55         keyUse.clean();
56         assertNotNull(keyUse);
57         
58         AxValidationResult result = new AxValidationResult();
59         result = keyUse.validate(result);
60         assertNotNull(result);
61         
62         assertNotEquals(0, keyUse.hashCode());
63         
64         AxKeyUse clonedKeyUse = new AxKeyUse(keyUse);
65         assertEquals("AxKeyUse:(usedKey=AxArtifactKey:(name=Key,version=0.0.1))", clonedKeyUse.toString());
66         
67         assertFalse(keyUse.hashCode() == 0);
68         
69         assertTrue(keyUse.equals(keyUse));
70         assertTrue(keyUse.equals(clonedKeyUse));
71         assertFalse(keyUse.equals((Object)"Hello"));
72         assertTrue(keyUse.equals(new AxKeyUse(key)));
73         
74         assertEquals(0, keyUse.compareTo(keyUse));
75         assertEquals(0, keyUse.compareTo(clonedKeyUse));
76         assertNotEquals(0, keyUse.compareTo(new AxArtifactKey()));
77         assertEquals(0, keyUse.compareTo(new AxKeyUse(key)));
78         
79         AxKeyUse keyUseNull = new AxKeyUse(AxArtifactKey.getNullKey());
80         AxValidationResult resultNull = new AxValidationResult();
81         assertEquals(false, keyUseNull.validate(resultNull).isValid());
82     }
83 }