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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.basicmodel.concepts;
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;
30 import org.junit.Test;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxKey.Compatibility;
33 public class AxKeyUseTest {
37 assertNotNull(new AxKeyUse());
38 assertNotNull(new AxKeyUse(new AxArtifactKey()));
39 assertNotNull(new AxKeyUse(new AxReferenceKey()));
41 AxArtifactKey key = new AxArtifactKey("Key", "0.0.1");
42 AxKeyUse keyUse = new AxKeyUse();
44 assertEquals(key, keyUse.getKey());
45 assertEquals("Key:0.0.1", keyUse.getId());
46 assertEquals(key, keyUse.getKeys().get(0));
48 assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
49 assertTrue(keyUse.isCompatible(key));
52 assertNotNull(keyUse);
54 AxValidationResult result = new AxValidationResult();
55 result = keyUse.validate(result);
56 assertNotNull(result);
58 assertNotEquals(0, keyUse.hashCode());
60 AxKeyUse clonedKeyUse = new AxKeyUse(keyUse);
61 assertEquals("AxKeyUse:(usedKey=AxArtifactKey:(name=Key,version=0.0.1))", clonedKeyUse.toString());
63 assertFalse(keyUse.hashCode() == 0);
65 assertTrue(keyUse.equals(keyUse));
66 assertTrue(keyUse.equals(clonedKeyUse));
67 assertFalse(keyUse.equals((Object) "Hello"));
68 assertTrue(keyUse.equals(new AxKeyUse(key)));
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)));
75 AxKeyUse keyUseNull = new AxKeyUse(AxArtifactKey.getNullKey());
76 AxValidationResult resultNull = new AxValidationResult();
77 assertEquals(false, keyUseNull.validate(resultNull).isValid());