8492ca898fc655ff69ae96f8f2ba7dfc474c2b91
[policy/apex-pdp.git] / testsuites / integration / integration-context-test / src / test / java / org / onap / policy / apex / testsuites / integration / context / entities / ReferenceKeyTestEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019,2022 Nordix Foundation.
5  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.testsuites.integration.context.entities;
24
25 import java.util.Arrays;
26 import java.util.List;
27 import javax.xml.bind.annotation.XmlElement;
28 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
29 import lombok.AllArgsConstructor;
30 import lombok.EqualsAndHashCode;
31 import lombok.Getter;
32 import lombok.Setter;
33 import lombok.ToString;
34 import org.apache.commons.lang3.builder.CompareToBuilder;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
37 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
38 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
39 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
40
41 /**
42  * The Class ReferenceKeyTestEntity provides a reference key test concept.
43  */
44 @Getter
45 @Setter
46 @ToString
47 @EqualsAndHashCode(callSuper = false)
48 @AllArgsConstructor
49 public class ReferenceKeyTestEntity extends AxConcept {
50     private static final long serialVersionUID = -2962570563281067895L;
51
52     @XmlElement(name = "key", required = true)
53     @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
54     protected AxReferenceKey key;
55
56     private double doubleValue;
57
58     /**
59      * Instantiates a new reference key test entity.
60      */
61     public ReferenceKeyTestEntity() {
62         this.key = new AxReferenceKey();
63         this.doubleValue = 0;
64     }
65
66     /**
67      * Instantiates a new reference key test entity.
68      *
69      * @param doubleValue the double value
70      */
71     public ReferenceKeyTestEntity(final Double doubleValue) {
72         this.key = new AxReferenceKey();
73         this.doubleValue = doubleValue;
74     }
75
76     /**
77      * {@inheritDoc}.
78      */
79     @Override
80     public List<AxKey> getKeys() {
81         return Arrays.asList((AxKey) getKey());
82     }
83
84     /**
85      * Check set key.
86      *
87      * @return true, if successful
88      */
89     public boolean checkSetKey() {
90         return (this.key != null);
91     }
92
93     /**
94      * {@inheritDoc}.
95      */
96     @Override
97     public AxValidationResult validate(final AxValidationResult result) {
98         return key.validate(result);
99     }
100
101     /**
102      * {@inheritDoc}.
103      */
104     @Override
105     public void clean() {
106         key.clean();
107     }
108
109     /**
110      * {@inheritDoc}.
111      */
112     @Override
113     public AxConcept copyTo(final AxConcept target) {
114         final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
115         if (copyObject instanceof ReferenceKeyTestEntity) {
116             final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
117             if (this.checkSetKey()) {
118                 copy.setKey(new AxReferenceKey(key));
119             } else {
120                 copy.key = null;
121             }
122             copy.doubleValue = doubleValue;
123             return copy;
124         } else {
125             return null;
126         }
127     }
128
129     /**
130      * {@inheritDoc}.
131      */
132     @Override
133     public int compareTo(final AxConcept otherObj) {
134         if (otherObj == null) {
135             return -1;
136         }
137         if (this == otherObj) {
138             return 0;
139         }
140         if (getClass() != otherObj.getClass()) {
141             return -1;
142         }
143         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
144         return new CompareToBuilder()
145                         .append(key, other.key)
146                         .append(doubleValue, other.doubleValue)
147                         .toComparison();
148     }
149 }