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 java.util.UUID;
31 import org.junit.Test;
34 public class AxKeyInfoTest {
37 public void testAxKeyInfo() {
38 assertNotNull(new AxKeyInfo());
39 assertNotNull(new AxKeyInfo(new AxArtifactKey()));
40 assertNotNull(new AxKeyInfo(new AxArtifactKey(), UUID.randomUUID(), "Key description"));
42 AxKeyInfo testKeyInfo = new AxKeyInfo();
43 testKeyInfo.setKey((new AxArtifactKey("PN", "0.0.1")));
44 assertEquals("PN:0.0.1", testKeyInfo.getKey().getId());
45 assertTrue(testKeyInfo.matchesId("PN:0.0.1"));
47 AxArtifactKey key = new AxArtifactKey("key", "0.0.1");
48 testKeyInfo.setKey(key);
49 assertEquals(key, testKeyInfo.getKey());
51 UUID uuid = UUID.randomUUID();
52 testKeyInfo.setUuid(uuid);
53 assertEquals(uuid, testKeyInfo.getUuid());
54 testKeyInfo.setDescription("Key Description");
55 assertEquals("Key Description", testKeyInfo.getDescription());
57 AxKeyInfo clonedReferenceKey = new AxKeyInfo(testKeyInfo);
58 assertTrue(clonedReferenceKey.toString()
59 .startsWith("AxKeyInfo:(artifactId=AxArtifactKey:(name=key,version=0.0.1),uuid="));
61 assertFalse(testKeyInfo.hashCode() == 0);
63 assertTrue(testKeyInfo.equals(testKeyInfo));
64 assertTrue(testKeyInfo.equals(clonedReferenceKey));
65 assertFalse(testKeyInfo.equals(null));
66 assertFalse(testKeyInfo.equals((Object) new AxArtifactKey()));
67 assertFalse(testKeyInfo.equals(new AxKeyInfo(new AxArtifactKey())));
68 assertFalse(testKeyInfo.equals(new AxKeyInfo(key, UUID.randomUUID(), "Some Description")));
69 assertFalse(testKeyInfo.equals(new AxKeyInfo(key, uuid, "Some Description")));
70 assertTrue(testKeyInfo.equals(new AxKeyInfo(key, uuid, "Key Description")));
72 assertEquals(0, testKeyInfo.compareTo(testKeyInfo));
73 assertEquals(0, testKeyInfo.compareTo(clonedReferenceKey));
74 assertNotEquals(0, testKeyInfo.compareTo(null));
75 assertNotEquals(0, testKeyInfo.compareTo(new AxArtifactKey()));
76 assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(new AxArtifactKey())));
77 assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, UUID.randomUUID(), "Some Description")));
78 assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, uuid, "Some Description")));
79 assertEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, uuid, "Key Description")));
81 assertNotNull(testKeyInfo.getKeys());
83 AxValidationResult result = new AxValidationResult();
84 result = testKeyInfo.validate(result);
85 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
87 testKeyInfo.setDescription("");
88 result = testKeyInfo.validate(result);
89 assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
91 testKeyInfo.setUuid(new UUID(0, 0));
92 result = testKeyInfo.validate(result);
93 assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult());
95 testKeyInfo.setKey(AxArtifactKey.getNullKey());
96 result = testKeyInfo.validate(result);
97 assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult());
99 assertNotNull(AxKeyInfo.generateReproducibleUuid(null));
100 assertNotNull(AxKeyInfo.generateReproducibleUuid("SeedString"));
103 assertNotNull(testKeyInfo);