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.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;
37 public class AxKeyUseTest {
41 assertNotNull(new AxKeyUse());
42 assertNotNull(new AxKeyUse(new AxArtifactKey()));
43 assertNotNull(new AxKeyUse(new AxReferenceKey()));
45 AxArtifactKey key = new AxArtifactKey("Key", "0.0.1");
46 AxKeyUse keyUse = new AxKeyUse();
48 assertEquals(key, keyUse.getKey());
49 assertEquals("Key:0.0.1", keyUse.getId());
50 assertEquals(key, keyUse.getKeys().get(0));
52 assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
53 assertTrue(keyUse.isCompatible(key));
56 assertNotNull(keyUse);
58 AxValidationResult result = new AxValidationResult();
59 result = keyUse.validate(result);
60 assertNotNull(result);
62 assertNotEquals(0, keyUse.hashCode());
64 AxKeyUse clonedKeyUse = new AxKeyUse(keyUse);
65 assertEquals("AxKeyUse:(usedKey=AxArtifactKey:(name=Key,version=0.0.1))", clonedKeyUse.toString());
67 assertFalse(keyUse.hashCode() == 0);
69 assertTrue(keyUse.equals(keyUse));
70 assertTrue(keyUse.equals(clonedKeyUse));
71 assertFalse(keyUse.equals((Object)"Hello"));
72 assertTrue(keyUse.equals(new AxKeyUse(key)));
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)));
79 AxKeyUse keyUseNull = new AxKeyUse(AxArtifactKey.getNullKey());
80 AxValidationResult resultNull = new AxValidationResult();
81 assertEquals(false, keyUseNull.validate(resultNull).isValid());