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