83545bf066c664a86bc984c47722756acf436156
[policy/apex-pdp.git] /
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
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;
39
40 /**
41  * @author Liam Fallon (liam.fallon@ericsson.com)
42  */
43 public class TestConceptGetter {
44
45     @Test
46     public void testConceptGetter() throws IOException, ApexException {
47         AxModel basicModel = new TestApexBasicModelCreator().getModel();
48         assertNotNull(basicModel);
49        
50         AxKeyInfo intKI01 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey01", "0.0.1"), UUID.randomUUID(), "IntegerKIKey01 description");
51         AxKeyInfo intKI11 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey11", "0.0.1"), UUID.randomUUID(), "IntegerKIKey11 description");
52         AxKeyInfo intKI21 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey21", "0.0.1"), UUID.randomUUID(), "IntegerKIKey21 description");
53         AxKeyInfo intKI22 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey22", "0.0.2"), UUID.randomUUID(), "IntegerKIKey22 description");
54         AxKeyInfo intKI23 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey23", "0.0.3"), UUID.randomUUID(), "IntegerKIKey23 description");
55         AxKeyInfo intKI24 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey24", "0.0.4"), UUID.randomUUID(), "IntegerKIKey24 description");
56         AxKeyInfo intKI25 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey25", "0.0.5"), UUID.randomUUID(), "IntegerKIKey25 description");
57         AxKeyInfo intKI26 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey26", "0.0.6"), UUID.randomUUID(), "IntegerKIKey26 description");
58         AxKeyInfo intKI31 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey31", "0.0.1"), UUID.randomUUID(), "IntegerKIKey31 description");
59         AxKeyInfo intKI41 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey41", "0.0.1"), UUID.randomUUID(), "IntegerKIKey41 description");
60         AxKeyInfo intKI51 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey51", "0.0.1"), UUID.randomUUID(), "IntegerKIKey51 description");
61         AxKeyInfo intKI52 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey52", "0.0.2"), UUID.randomUUID(), "IntegerKIKey52 description");
62         AxKeyInfo intKI53 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey53", "0.0.3"), UUID.randomUUID(), "IntegerKIKey53 description");
63         AxKeyInfo intKI54 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey54", "0.0.4"), UUID.randomUUID(), "IntegerKIKey54 description");
64         AxKeyInfo intKI61 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey61", "0.0.1"), UUID.randomUUID(), "IntegerKIKey61 description");
65         AxKeyInfo intKI62 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey62", "0.0.2"), UUID.randomUUID(), "IntegerKIKey62 description");
66         AxKeyInfo intKI63 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey63", "0.0.3"), UUID.randomUUID(), "IntegerKIKey63 description");
67         AxKeyInfo intKI64 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey64", "0.0.4"), UUID.randomUUID(), "IntegerKIKey64 description");
68         AxKeyInfo intKI71 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey71", "0.0.1"), UUID.randomUUID(), "IntegerKIKey71 description");
69         AxKeyInfo intKI81 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey81", "0.0.1"), UUID.randomUUID(), "IntegerKIKey81 description");
70         AxKeyInfo intKI91 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey91", "0.0.1"), UUID.randomUUID(), "IntegerKIKey91 description");
71         basicModel.getKeyInformation().getKeyInfoMap().put(intKI31.getKey(), intKI31);
72         basicModel.getKeyInformation().getKeyInfoMap().put(intKI24.getKey(), intKI24);
73         basicModel.getKeyInformation().getKeyInfoMap().put(intKI11.getKey(), intKI11);
74         basicModel.getKeyInformation().getKeyInfoMap().put(intKI64.getKey(), intKI64);
75         basicModel.getKeyInformation().getKeyInfoMap().put(intKI41.getKey(), intKI41);
76         basicModel.getKeyInformation().getKeyInfoMap().put(intKI51.getKey(), intKI51);
77         basicModel.getKeyInformation().getKeyInfoMap().put(intKI23.getKey(), intKI23);
78         basicModel.getKeyInformation().getKeyInfoMap().put(intKI81.getKey(), intKI81);
79         basicModel.getKeyInformation().getKeyInfoMap().put(intKI71.getKey(), intKI71);
80         basicModel.getKeyInformation().getKeyInfoMap().put(intKI01.getKey(), intKI01);
81         basicModel.getKeyInformation().getKeyInfoMap().put(intKI91.getKey(), intKI91);
82         basicModel.getKeyInformation().getKeyInfoMap().put(intKI52.getKey(), intKI52);
83         basicModel.getKeyInformation().getKeyInfoMap().put(intKI53.getKey(), intKI53);
84         basicModel.getKeyInformation().getKeyInfoMap().put(intKI62.getKey(), intKI62);
85         basicModel.getKeyInformation().getKeyInfoMap().put(intKI54.getKey(), intKI54);
86         basicModel.getKeyInformation().getKeyInfoMap().put(intKI26.getKey(), intKI26);
87         basicModel.getKeyInformation().getKeyInfoMap().put(intKI22.getKey(), intKI22);
88         basicModel.getKeyInformation().getKeyInfoMap().put(intKI25.getKey(), intKI25);
89         basicModel.getKeyInformation().getKeyInfoMap().put(intKI21.getKey(), intKI21);
90         basicModel.getKeyInformation().getKeyInfoMap().put(intKI61.getKey(), intKI61);
91         basicModel.getKeyInformation().getKeyInfoMap().put(intKI63.getKey(), intKI63);
92
93         AxKeyInfo floatKI01 = new AxKeyInfo(new AxArtifactKey("FloatKIKey01", "0.0.1"), UUID.randomUUID(), "IntegerKIKey01 description");
94         AxKeyInfo floatKI11 = new AxKeyInfo(new AxArtifactKey("FloatKIKey11", "0.0.1"), UUID.randomUUID(), "IntegerKIKey11 description");
95         AxKeyInfo floatKI21 = new AxKeyInfo(new AxArtifactKey("FloatKIKey21", "0.0.1"), UUID.randomUUID(), "IntegerKIKey21 description");
96         AxKeyInfo floatKI31 = new AxKeyInfo(new AxArtifactKey("FloatKIKey31", "0.0.1"), UUID.randomUUID(), "IntegerKIKey31 description");
97         AxKeyInfo floatKI41 = new AxKeyInfo(new AxArtifactKey("FloatKIKey41", "0.0.1"), UUID.randomUUID(), "IntegerKIKey41 description");
98         AxKeyInfo floatKI51 = new AxKeyInfo(new AxArtifactKey("FloatKIKey51", "0.0.1"), UUID.randomUUID(), "IntegerKIKey51 description");
99         AxKeyInfo floatKI61 = new AxKeyInfo(new AxArtifactKey("FloatKIKey61", "0.0.1"), UUID.randomUUID(), "IntegerKIKey61 description");
100         AxKeyInfo floatKI71 = new AxKeyInfo(new AxArtifactKey("FloatKIKey71", "0.0.1"), UUID.randomUUID(), "IntegerKIKey71 description");
101         AxKeyInfo floatKI81 = new AxKeyInfo(new AxArtifactKey("FloatKIKey81", "0.0.1"), UUID.randomUUID(), "IntegerKIKey81 description");
102         AxKeyInfo floatKI82 = new AxKeyInfo(new AxArtifactKey("FloatKIKey82", "0.0.2"), UUID.randomUUID(), "IntegerKIKey82 description");
103         AxKeyInfo floatKI83 = new AxKeyInfo(new AxArtifactKey("FloatKIKey83", "0.0.3"), UUID.randomUUID(), "IntegerKIKey83 description");
104         AxKeyInfo floatKI91 = new AxKeyInfo(new AxArtifactKey("FloatKIKey91", "0.0.1"), UUID.randomUUID(), "IntegerKIKey91 description");
105         AxKeyInfo floatKI92 = new AxKeyInfo(new AxArtifactKey("FloatKIKey92", "0.0.2"), UUID.randomUUID(), "IntegerKIKey92 description");
106         AxKeyInfo floatKI93 = new AxKeyInfo(new AxArtifactKey("FloatKIKey93", "0.0.3"), UUID.randomUUID(), "IntegerKIKey93 description");
107         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI11.getKey(), floatKI11);
108         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI83.getKey(), floatKI83);
109         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI51.getKey(), floatKI51);
110         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI71.getKey(), floatKI71);
111         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI21.getKey(), floatKI21);
112         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI81.getKey(), floatKI81);
113         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI92.getKey(), floatKI92);
114         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI91.getKey(), floatKI91);
115         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI01.getKey(), floatKI01);
116         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI82.getKey(), floatKI82);
117         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI61.getKey(), floatKI61);
118         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI41.getKey(), floatKI41);
119         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI31.getKey(), floatKI31);
120         basicModel.getKeyInformation().getKeyInfoMap().put(floatKI93.getKey(), floatKI93);
121
122         assertNull(basicModel.getKeyInformation().get("NonExistantKey", "0.0.6"));
123         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6").equals(intKI26));
124         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2").equals(intKI62));
125         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1").equals(intKI21));
126         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1").equals(intKI61));
127        
128         assertNull(basicModel.getKeyInformation().get("NonExistantKey"));
129        
130         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey01").equals(intKI01));
131         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey11").equals(intKI11));
132         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26").equals(intKI26));
133         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey31").equals(intKI31));
134         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey41").equals(intKI41));
135         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey54").equals(intKI54));
136         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey64").equals(intKI64));
137         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey71").equals(intKI71));
138         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey81").equals(intKI81));
139         assertTrue(basicModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91));
140        
141         assertTrue(basicModel.getKeyInformation().get("FloatKIKey01").equals(floatKI01));
142         assertTrue(basicModel.getKeyInformation().get("FloatKIKey11").equals(floatKI11));
143         assertTrue(basicModel.getKeyInformation().get("FloatKIKey21").equals(floatKI21));
144         assertTrue(basicModel.getKeyInformation().get("FloatKIKey31").equals(floatKI31));
145         assertTrue(basicModel.getKeyInformation().get("FloatKIKey41").equals(floatKI41));
146         assertTrue(basicModel.getKeyInformation().get("FloatKIKey51").equals(floatKI51));
147         assertTrue(basicModel.getKeyInformation().get("FloatKIKey61").equals(floatKI61));
148         assertTrue(basicModel.getKeyInformation().get("FloatKIKey71").equals(floatKI71));
149         assertTrue(basicModel.getKeyInformation().get("FloatKIKey83").equals(floatKI83));
150         assertTrue(basicModel.getKeyInformation().get("FloatKIKey93").equals(floatKI93));
151
152    
153         // Ensure marshalling and unmarshalling is OK
154         ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class);
155         ApexModelFileWriter<AxModel> modelWriter = new ApexModelFileWriter<AxModel>(true);
156        
157         modelReader.setValidateFlag(false);
158         modelWriter.setValidateFlag(false);
159        
160         File tempXMLFile = File.createTempFile("ApexModel", "xml");
161         modelWriter.apexModelWriteJSONFile(basicModel, AxModel.class, tempXMLFile.getCanonicalPath());
162        
163         FileInputStream xmlFileInputStream = new FileInputStream(tempXMLFile);
164         AxModel readXMLModel = modelReader.read(xmlFileInputStream);
165         xmlFileInputStream.close();
166         assertTrue(basicModel.equals(readXMLModel));
167         assertTrue(readXMLModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91));
168         assertNotNull(readXMLModel.getKeyInformation().get("FloatKIKey"));
169         tempXMLFile.delete();
170     }
171 }