Merge "Convert models to JUnit 5"
[policy/models.git] / models-base / src / test / java / org / onap / policy / models / base / testconcepts / DummyPfModel.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.base.testconcepts;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import lombok.Data;
27 import lombok.EqualsAndHashCode;
28 import lombok.NonNull;
29 import org.onap.policy.common.parameters.BeanValidationResult;
30 import org.onap.policy.models.base.PfConcept;
31 import org.onap.policy.models.base.PfConceptKey;
32 import org.onap.policy.models.base.PfKey;
33 import org.onap.policy.models.base.PfModel;
34 import org.onap.policy.models.base.PfUtils;
35
36 @Data
37 @EqualsAndHashCode(callSuper = true)
38 public class DummyPfModel extends PfModel {
39     private static final long serialVersionUID = 8800599637708309945L;
40
41     private List<PfKey> keyList;
42
43     /**
44      * The Default Constructor creates a {@link DummyPfModel} object with a null concept key and
45      * creates an empty TOSCA model.
46      */
47     public DummyPfModel() {
48         super();
49         super.setKey(new PfConceptKey());
50         this.keyList = new ArrayList<>();
51     }
52
53     /**
54      * The Key Constructor creates a {@link DummyPfModel} object with the given concept key and
55      * creates an empty TOSCA model.
56      *
57      * @param key the TOSCA model key
58      */
59     public DummyPfModel(final PfConceptKey key) {
60         super(key);
61         this.keyList = new ArrayList<>();
62     }
63
64     /**
65      * Constructor that initiates a {@link ToscaModel} with all its fields.
66      *
67      * @param key the TOSCA model key
68      * @param keyList the service templates in the event model
69      */
70     public DummyPfModel(final PfConceptKey key, final List<PfKey> keyList) {
71         super(key);
72         this.keyList = keyList;
73     }
74
75     /**
76      * Copy constructor.
77      *
78      * @param copyConcept the concept to copy from
79      */
80     public DummyPfModel(final DummyPfModel copyConcept) {
81         super(copyConcept);
82
83         this.keyList = new ArrayList<>();
84         for (final PfKey pfKey : copyConcept.keyList) {
85             keyList.add(PfUtils.makeCopy(pfKey));
86         }
87     }
88
89     @Override
90     public void register() {
91         // nothing to do
92     }
93
94     @Override
95     public List<PfKey> getKeys() {
96         final List<PfKey> listOfKeys = super.getKeys();
97
98         listOfKeys.addAll(keyList);
99
100         return listOfKeys;
101     }
102
103     @Override
104     public void clean() {
105         super.clean();
106         for (PfKey pfKey : keyList) {
107             pfKey.clean();
108         }
109     }
110
111     @Override
112     public BeanValidationResult validate(@NonNull String fieldName) {
113         BeanValidationResult result = super.validate(fieldName);
114
115         int count = 0;
116         for (PfKey pfKey : keyList) {
117             result.addResult(pfKey.validate("keyList." + (count++)));
118         }
119
120         return result;
121     }
122
123     @Override
124     public int compareTo(final PfConcept otherConcept) {
125         if (super.compareTo(otherConcept) != 0) {
126             return super.compareTo(otherConcept);
127         }
128
129         if (otherConcept == null) {
130             return -1;
131         }
132
133         if (this == otherConcept) {
134             return 0;
135         }
136
137         if (getClass() != otherConcept.getClass()) {
138             return this.hashCode() - otherConcept.hashCode();
139         }
140
141         final DummyPfModel other = (DummyPfModel) otherConcept;
142         if (!super.equals(other)) {
143             return super.compareTo(other);
144         }
145
146         if (!keyList.equals(other.keyList)) {
147             return (keyList.hashCode() - other.keyList.hashCode());
148         }
149
150         return 0;
151     }
152 }