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