Add DAO module for Models
[policy/models.git] / models-base / src / test / java / org / onap / policy / models / base / PfKeyUseTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
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.models.base;
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.models.base.PfKey.Compatibility;
31
32 public class PfKeyUseTest {
33
34     @Test
35     public void test() {
36         assertNotNull(new PfKeyUse());
37         assertNotNull(new PfKeyUse(new PfConceptKey()));
38         assertNotNull(new PfKeyUse(new PfReferenceKey()));
39
40         PfConceptKey key = new PfConceptKey("Key", "0.0.1");
41         PfKeyUse keyUse = new PfKeyUse();
42         keyUse.setKey(key);
43         assertEquals(key, keyUse.getKey());
44         assertEquals("Key:0.0.1", keyUse.getId());
45         assertEquals(key, keyUse.getKeys().get(0));
46
47         assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
48         assertTrue(keyUse.isCompatible(key));
49
50         keyUse.clean();
51         assertNotNull(keyUse);
52
53         PfValidationResult result = new PfValidationResult();
54         result = keyUse.validate(result);
55         assertNotNull(result);
56
57         assertNotEquals(0, keyUse.hashCode());
58
59         PfKeyUse clonedKeyUse = new PfKeyUse(keyUse);
60         assertEquals("PfKeyUse(usedKey=PfConceptKey(name=Key, version=0.0.1))", clonedKeyUse.toString());
61
62         assertFalse(keyUse.hashCode() == 0);
63
64         assertTrue(keyUse.equals(keyUse));
65         assertTrue(keyUse.equals(clonedKeyUse));
66         assertFalse(keyUse.equals("Hello"));
67         assertTrue(keyUse.equals(new PfKeyUse(key)));
68
69         assertEquals(0, keyUse.compareTo(keyUse));
70         assertEquals(0, keyUse.compareTo(clonedKeyUse));
71         assertNotEquals(0, keyUse.compareTo(new PfConceptKey()));
72         assertEquals(0, keyUse.compareTo(new PfKeyUse(key)));
73
74         PfKeyUse keyUseNull = new PfKeyUse(PfConceptKey.getNullKey());
75         PfValidationResult resultNull = new PfValidationResult();
76         assertEquals(false, keyUseNull.validate(resultNull).isValid());
77     }
78 }