Changes for checkstyle 8.32
[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.AxKey.Compatibility;
32
33 public class AxKeyUseTest {
34
35     @Test
36     public void test() {
37         assertNotNull(new AxKeyUse());
38         assertNotNull(new AxKeyUse(new AxArtifactKey()));
39         assertNotNull(new AxKeyUse(new AxReferenceKey()));
40         
41         AxArtifactKey key = new AxArtifactKey("Key", "0.0.1");
42         AxKeyUse keyUse = new AxKeyUse();
43         keyUse.setKey(key);
44         assertEquals(key, keyUse.getKey());
45         assertEquals("Key:0.0.1", keyUse.getId());
46         assertEquals(key, keyUse.getKeys().get(0));
47         
48         assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
49         assertTrue(keyUse.isCompatible(key));
50         
51         keyUse.clean();
52         assertNotNull(keyUse);
53         
54         AxValidationResult result = new AxValidationResult();
55         result = keyUse.validate(result);
56         assertNotNull(result);
57         
58         assertNotEquals(0, keyUse.hashCode());
59         
60         AxKeyUse clonedKeyUse = new AxKeyUse(keyUse);
61         assertEquals("AxKeyUse:(usedKey=AxArtifactKey:(name=Key,version=0.0.1))", clonedKeyUse.toString());
62         
63         assertFalse(keyUse.hashCode() == 0);
64         
65         assertTrue(keyUse.equals(keyUse));
66         assertTrue(keyUse.equals(clonedKeyUse));
67         assertFalse(keyUse.equals((Object) "Hello"));
68         assertTrue(keyUse.equals(new AxKeyUse(key)));
69         
70         assertEquals(0, keyUse.compareTo(keyUse));
71         assertEquals(0, keyUse.compareTo(clonedKeyUse));
72         assertNotEquals(0, keyUse.compareTo(new AxArtifactKey()));
73         assertEquals(0, keyUse.compareTo(new AxKeyUse(key)));
74         
75         AxKeyUse keyUseNull = new AxKeyUse(AxArtifactKey.getNullKey());
76         AxValidationResult resultNull = new AxValidationResult();
77         assertEquals(false, keyUseNull.validate(resultNull).isValid());
78     }
79 }