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