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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.base;
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;
29 import org.junit.Test;
30 import org.onap.policy.models.base.PfKey.Compatibility;
32 public class PfKeyUseTest {
36 assertNotNull(new PfKeyUse());
37 assertNotNull(new PfKeyUse(new PfConceptKey()));
38 assertNotNull(new PfKeyUse(new PfReferenceKey()));
40 PfConceptKey key = new PfConceptKey("Key", "0.0.1");
41 PfKeyUse keyUse = new PfKeyUse();
43 assertEquals(key, keyUse.getKey());
44 assertEquals("Key:0.0.1", keyUse.getId());
45 assertEquals(key, keyUse.getKeys().get(0));
47 assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
48 assertTrue(keyUse.isCompatible(key));
51 assertNotNull(keyUse);
53 PfValidationResult result = new PfValidationResult();
54 result = keyUse.validate(result);
55 assertNotNull(result);
57 assertNotEquals(0, keyUse.hashCode());
59 PfKeyUse clonedKeyUse = new PfKeyUse(keyUse);
60 assertEquals("PfKeyUse(usedKey=PfConceptKey(name=Key, version=0.0.1))", clonedKeyUse.toString());
62 assertFalse(keyUse.hashCode() == 0);
64 assertTrue(keyUse.equals(keyUse));
65 assertTrue(keyUse.equals(clonedKeyUse));
66 assertFalse(keyUse.equals("Hello"));
67 assertTrue(keyUse.equals(new PfKeyUse(key)));
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)));
74 PfKeyUse keyUseNull = new PfKeyUse(PfConceptKey.getNullKey());
75 PfValidationResult resultNull = new PfValidationResult();
76 assertEquals(false, keyUseNull.validate(resultNull).isValid());