Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / handling / SupportConceptGetterTester.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.basicmodel.handling;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
26
27 import java.io.File;
28 import java.io.FileInputStream;
29 import java.io.IOException;
30 import java.util.UUID;
31 import org.junit.Test;
32 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
36
37 public class SupportConceptGetterTester {
38
39     @Test
40     public void testConceptGetter() throws IOException, ApexException {
41         AxModel basicModel = new DummyApexBasicModelCreator().getModel();
42         assertNotNull(basicModel);
43
44         AxKeyInfo intKI01 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey01", "0.0.1"), UUID.randomUUID(),
45                         "IntegerKIKey01 description");
46         AxKeyInfo intKI11 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey11", "0.0.1"), UUID.randomUUID(),
47                         "IntegerKIKey11 description");
48         AxKeyInfo intKI21 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey21", "0.0.1"), UUID.randomUUID(),
49                         "IntegerKIKey21 description");
50         AxKeyInfo intKI22 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey22", "0.0.2"), UUID.randomUUID(),
51                         "IntegerKIKey22 description");
52         AxKeyInfo intKI23 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey23", "0.0.3"), UUID.randomUUID(),
53                         "IntegerKIKey23 description");
54         AxKeyInfo intKI24 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey24", "0.0.4"), UUID.randomUUID(),
55                         "IntegerKIKey24 description");
56         AxKeyInfo intKI25 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey25", "0.0.5"), UUID.randomUUID(),
57                         "IntegerKIKey25 description");
58         AxKeyInfo intKI26 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey26", "0.0.6"), UUID.randomUUID(),
59                         "IntegerKIKey26 description");
60         AxKeyInfo intKI31 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey31", "0.0.1"), UUID.randomUUID(),
61                         "IntegerKIKey31 description");
62         AxKeyInfo intKI41 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey41", "0.0.1"), UUID.randomUUID(),
63                         "IntegerKIKey41 description");
64         AxKeyInfo intKI51 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey51", "0.0.1"), UUID.randomUUID(),
65                         "IntegerKIKey51 description");
66         AxKeyInfo intKI52 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey52", "0.0.2"), UUID.randomUUID(),
67                         "IntegerKIKey52 description");
68         AxKeyInfo intKI53 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey53", "0.0.3"), UUID.randomUUID(),
69                         "IntegerKIKey53 description");
70         AxKeyInfo intKI54 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey54", "0.0.4"), UUID.randomUUID(),
71                         "IntegerKIKey54 description");
72         AxKeyInfo intKI61 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey61", "0.0.1"), UUID.randomUUID(),
73                         "IntegerKIKey61 description");
74         AxKeyInfo intKI62 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey62", "0.0.2"), UUID.randomUUID(),
75                         "IntegerKIKey62 description");
76         AxKeyInfo intKI63 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey63", "0.0.3"), UUID.randomUUID(),
77                         "IntegerKIKey63 description");
78         AxKeyInfo intKI64 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey64", "0.0.4"), UUID.randomUUID(),
79                         "IntegerKIKey64 description");
80         AxKeyInfo intKI71 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey71", "0.0.1"), UUID.randomUUID(),
81                         "IntegerKIKey71 description");
82         AxKeyInfo intKI81 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey81", "0.0.1"), UUID.randomUUID(),
83                         "IntegerKIKey81 description");
84         AxKeyInfo intKI91 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey91", "0.0.1"), UUID.randomUUID(),
85                         "IntegerKIKey91 description");
86         basicModel.getKeyInformation().getKeyInfoMap().put(intKI31.getKey(), intKI31);
87         basicModel.getKeyInformation().getKeyInfoMap().put(intKI24.getKey(), intKI24);
88         basicModel.getKeyInformation().getKeyInfoMap().put(intKI11.getKey(), intKI11);
89         basicModel.getKeyInformation().getKeyInfoMap().put(intKI64.getKey(), intKI64);
90         basicModel.getKeyInformation().getKeyInfoMap().put(intKI41.getKey(), intKI41);
91         basicModel.getKeyInformation().getKeyInfoMap().put(intKI51.getKey(), intKI51);
92         basicModel.getKeyInformation().getKeyInfoMap().put(intKI23.getKey(), intKI23);
93         basicModel.getKeyInformation().getKeyInfoMap().put(intKI81.getKey(), intKI81);
94         basicModel.getKeyInformation().getKeyInfoMap().put(intKI71.getKey(), intKI71);
95         basicModel.getKeyInformation().getKeyInfoMap().put(intKI01.getKey(), intKI01);
96         basicModel.getKeyInformation().getKeyInfoMap().put(intKI91.getKey(), intKI91);
97         basicModel.getKeyInformation().getKeyInfoMap().put(intKI52.getKey(), intKI52);
98         basicModel.getKeyInformation().getKeyInfoMap().put(intKI53.getKey(), intKI53);
99         basicModel.getKeyInformation().getKeyInfoMap().put(intKI62.getKey(), intKI62);
100         basicModel.getKeyInformation().getKeyInfoMap().put(intKI54.getKey(), intKI54);
101         basicModel.getKeyInformation().getKeyInfoMap().put(intKI26.getKey(), intKI26);
102         basicModel.getKeyInformation().getKeyInfoMap().put(intKI22.getKey(), intKI22);
103         basicModel.getKeyInformation().getKeyInfoMap().put(intKI25.getKey(), intKI25);
104         basicModel.getKeyInformation().getKeyInfoMap().put(intKI21.getKey(), intKI21);
105         basicModel.getKeyInformation().getKeyInfoMap().put(intKI61.getKey(), intKI61);
106         basicModel.getKeyInformation().getKeyInfoMap().put(intKI63.getKey(), intKI63);
107
108         AxKeyInfo floatKI01 = new AxKeyInfo(new AxArtifactKey("FloatKIKey01", "0.0.1"), UUID.randomUUID(),
109                         "IntegerKIKey01 description");
110         AxKeyInfo floatKI11 = new AxKeyInfo(new AxArtifactKey("FloatKIKey11", "0.0.1"), UUID.randomUUID(),
111                         "IntegerKIKey11 description");
112         AxKeyInfo floatKI21 = new AxKeyInfo(new AxArtifactKey("FloatKIKey21", "0.0.1"), UUID.randomUUID(),
113                         "IntegerKIKey21 description");
114         AxKeyInfo floatKI31 = new AxKeyInfo(new AxArtifactKey("FloatKIKey31", "0.0.1"), UUID.randomUUID(),
115                         "IntegerKIKey31 description");
116         AxKeyInfo floatKI41 = new AxKeyInfo(new AxArtifactKey("FloatKIKey41", "0.0.1"), UUID.randomUUID(),
117                         "IntegerKIKey41 description");
118         AxKeyInfo floatKI51 = new AxKeyInfo(new AxArtifactKey("FloatKIKey51", "0.0.1"), UUID.randomUUID(),
119                         "IntegerKIKey51 description");
120         AxKeyInfo floatKI61 = new AxKeyInfo(new AxArtifactKey("FloatKIKey61", "0.0.1"), UUID.randomUUID(),
121                         "IntegerKIKey61 description");
122         AxKeyInfo floatKI71 = new AxKeyInfo(new AxArtifactKey("FloatKIKey71", "0.0.1"), UUID.randomUUID(),
123                         "IntegerKIKey71 description");
124         AxKeyInfo floatKI81 = new AxKeyInfo(new AxArtifactKey("FloatKIKey81", "0.0.1"), UUID.randomUUID(),
125                         "IntegerKIKey81 description");
126         AxKeyInfo floatKI82 = new AxKeyInfo(new AxArtifactKey("FloatKIKey82", "0.0.2"), UUID.randomUUID(),
127                         "IntegerKIKey82 description");
128         AxKeyInfo floatKI83 = new AxKeyInfo(new AxArtifactKey("FloatKIKey83", "0.0.3"), UUID.randomUUID(),
129                         "IntegerKIKey83 description");
130         AxKeyInfo floatKI91 = new AxKeyInfo(new AxArtifactKey("FloatKIKey91", "0.0.1"), UUID.randomUUID(),
131                         "IntegerKIKey91 description");
132         AxKeyInfo floatKI92 = new AxKeyInfo(new AxArtifactKey("FloatKIKey92", "0.0.2"), UUID.randomUUID(),
133                         "IntegerKIKey92 description");
134         AxKeyInfo floatKI93 = new AxKeyInfo(new AxArtifactKey("FloatKIKey93", "0.0.3"), UUID.randomUUID(),
135                         "IntegerKIKey93 description");
136         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI11.getKey(), floatKI11);
137         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI83.getKey(), floatKI83);
138         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI51.getKey(), floatKI51);
139         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI71.getKey(), floatKI71);
140         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI21.getKey(), floatKI21);
141         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI81.getKey(), floatKI81);
142         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI92.getKey(), floatKI92);
143         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI91.getKey(), floatKI91);
144         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI01.getKey(), floatKI01);
145         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI82.getKey(), floatKI82);
146         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI61.getKey(), floatKI61);
147         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI41.getKey(), floatKI41);
148         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI31.getKey(), floatKI31);
149         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI93.getKey(), floatKI93);
150
151         assertNull(basicModel.getKeyInformation().get("NonExistantKey", "0.0.6"));
152         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6").equals(intKI26));
153         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2").equals(intKI62));
154         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1").equals(intKI21));
155         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1").equals(intKI61));
156
157         assertNull(basicModel.getKeyInformation().get("NonExistantKey"));
158
159         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey01").equals(intKI01));
160         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey11").equals(intKI11));
161         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26").equals(intKI26));
162         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey31").equals(intKI31));
163         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey41").equals(intKI41));
164         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey54").equals(intKI54));
165         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey64").equals(intKI64));
166         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey71").equals(intKI71));
167         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey81").equals(intKI81));
168         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91));
169
170         assertTrue(basicModel.getKeyInformation().get("FloatKIKey01").equals(floatKI01));
171         assertTrue(basicModel.getKeyInformation().get("FloatKIKey11").equals(floatKI11));
172         assertTrue(basicModel.getKeyInformation().get("FloatKIKey21").equals(floatKI21));
173         assertTrue(basicModel.getKeyInformation().get("FloatKIKey31").equals(floatKI31));
174         assertTrue(basicModel.getKeyInformation().get("FloatKIKey41").equals(floatKI41));
175         assertTrue(basicModel.getKeyInformation().get("FloatKIKey51").equals(floatKI51));
176         assertTrue(basicModel.getKeyInformation().get("FloatKIKey61").equals(floatKI61));
177         assertTrue(basicModel.getKeyInformation().get("FloatKIKey71").equals(floatKI71));
178         assertTrue(basicModel.getKeyInformation().get("FloatKIKey83").equals(floatKI83));
179         assertTrue(basicModel.getKeyInformation().get("FloatKIKey93").equals(floatKI93));
180
181         // Ensure marshalling and unmarshalling is OK
182         ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class);
183         ApexModelFileWriter<AxModel> modelWriter = new ApexModelFileWriter<AxModel>(true);
184
185         modelReader.setValidateFlag(false);
186         modelWriter.setValidateFlag(false);
187
188         File tempXmlFile = File.createTempFile("ApexModel", "xml");
189         modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempXmlFile.getCanonicalPath());
190
191         FileInputStream xmlFileInputStream = new FileInputStream(tempXmlFile);
192         AxModel readXmlModel = modelReader.read(xmlFileInputStream);
193         xmlFileInputStream.close();
194         assertTrue(basicModel.equals(readXmlModel));
195         assertTrue(readXmlModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91));
196         assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey"));
197         tempXmlFile.delete();
198     }
199 }