2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
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.apex.context.test.entities;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
34 * Test the AxArtifactKey test entity.
37 public class ReferenceTestEntityTest {
40 public void testTestEntity() {
41 ReferenceKeyTestEntity testEntity = new ReferenceKeyTestEntity();
43 ReferenceKeyTestEntity testEntityCopy = new ReferenceKeyTestEntity();
44 assertEquals(-192063539, testEntityCopy.hashCode());
46 testEntity.setKey(null);
47 testEntity.copyTo(testEntityCopy);
48 assertTrue(testEntity.equals((testEntityCopy)));
49 assertFalse(testEntity.checkSetKey());
50 AxReferenceKey key = new AxReferenceKey("TestKey", "0.0.1", "ParentLocalName", "LocalName");
52 testEntity.setKey(key);
54 AxValidationResult result = testEntity.validate(new AxValidationResult());
55 assertEquals(ValidationResult.VALID, result.getValidationResult());
56 assertEquals(key, testEntity.getKey());
57 assertEquals(key, testEntity.getKeys().get(0));
58 assertEquals(key.getId(), testEntity.getId());
59 assertEquals((Double) 0.0, (Double) testEntity.getDoubleValue());
60 assertTrue(testEntity.checkSetKey());
61 assertEquals((Double) 0.0, (Double) testEntity.getDoubleValue());
62 testEntity.setDoubleValue(3.14);
63 assertEquals((Double) 3.14, (Double) testEntity.getDoubleValue());
64 assertTrue(testEntity.checkSetKey());
65 assertEquals("ReferenceKeyTestEntity [key=AxReferenceKey:(parentKeyName=TestKey,parentKeyVersion=0.0.1,"
66 + "parentLocalName=ParentLocalName,localName=LocalName), doubleValue=3.14]",
67 testEntity.toString());
68 ReferenceKeyTestEntity testEntityClone = new ReferenceKeyTestEntity();
69 testEntity.copyTo(testEntityClone);
70 assertTrue(testEntity.equals(testEntity));
71 assertTrue(testEntity.equals(testEntityClone));
72 ReferenceKeyTestEntity testEntityNew = null;
73 testEntityNew = (ReferenceKeyTestEntity) testEntity.copyTo(testEntityNew);
74 assertTrue(testEntityNew.equals(testEntityNew));
75 assertTrue(testEntity.equals(testEntityNew));
76 ArtifactKeyTestEntity testEntityBad = new ArtifactKeyTestEntity();
77 testEntityBad = (ArtifactKeyTestEntity) testEntity.copyTo(testEntityBad);
78 assertNull(testEntityBad);
80 testEntityBad = new ArtifactKeyTestEntity();
81 assertEquals(-49094350, testEntity.hashCode());
82 assertFalse(testEntity.equals(null));
83 assertEquals(-1, testEntity.compareTo(null));
84 assertTrue(testEntity.equals(testEntity));
85 assertEquals(0, testEntity.compareTo(testEntity));
86 assertFalse(testEntity.equals(testEntityBad));
87 assertEquals(-1, testEntity.compareTo(testEntityBad));
88 assertFalse(testEntityCopy.equals(testEntity));
89 assertEquals(1, testEntityCopy.compareTo(testEntity));
90 testEntityClone.setKey(key);
91 testEntityNew.setKey(AxReferenceKey.getNullKey());
92 assertFalse(testEntityNew.equals(testEntityClone));
93 assertEquals(-6, testEntityNew.compareTo(testEntityClone));
94 testEntityClone.setKey(null);
95 testEntityNew.setKey(null);
96 assertTrue(testEntityNew.equals(testEntityClone));
97 assertEquals(0, testEntityNew.compareTo(testEntityClone));
98 testEntityCopy.setKey(AxReferenceKey.getNullKey());
99 assertFalse(testEntityCopy.equals(testEntity));
100 assertEquals(-6, testEntityCopy.compareTo(testEntity));
101 testEntityClone.setKey(key);
102 testEntityClone.setDoubleValue(1.23);
103 assertFalse(testEntity.equals(testEntityClone));
104 assertEquals(1, testEntity.compareTo(testEntityClone));
106 ReferenceKeyTestEntity entity2 = new ReferenceKeyTestEntity(3.14);
107 assertEquals((Double) 3.14, (Double) entity2.getDoubleValue());
108 ReferenceKeyTestEntity entity3 = new ReferenceKeyTestEntity(key, 3.14);
109 assertEquals(key, entity3.getKey());
111 entity3.setKey(null);
112 assertEquals(31, entity3.hashCode());