summaryrefslogtreecommitdiffstats
path: root/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestConceptGetter.java
blob: f95c0b41d2613ebf53cb34dff665fa65b4b854bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.apex.model.basicmodel.handling;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;

import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelFileWriter;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;

public class TestConceptGetter {

    @Test
    public void testConceptGetter() throws IOException, ApexException {
        AxModel basicModel = new TestApexBasicModelCreator().getModel();
        assertNotNull(basicModel);

        AxKeyInfo intKI01 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey01", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey01 description");
        AxKeyInfo intKI11 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey11", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey11 description");
        AxKeyInfo intKI21 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey21", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey21 description");
        AxKeyInfo intKI22 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey22", "0.0.2"), UUID.randomUUID(),
                        "IntegerKIKey22 description");
        AxKeyInfo intKI23 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey23", "0.0.3"), UUID.randomUUID(),
                        "IntegerKIKey23 description");
        AxKeyInfo intKI24 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey24", "0.0.4"), UUID.randomUUID(),
                        "IntegerKIKey24 description");
        AxKeyInfo intKI25 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey25", "0.0.5"), UUID.randomUUID(),
                        "IntegerKIKey25 description");
        AxKeyInfo intKI26 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey26", "0.0.6"), UUID.randomUUID(),
                        "IntegerKIKey26 description");
        AxKeyInfo intKI31 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey31", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey31 description");
        AxKeyInfo intKI41 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey41", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey41 description");
        AxKeyInfo intKI51 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey51", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey51 description");
        AxKeyInfo intKI52 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey52", "0.0.2"), UUID.randomUUID(),
                        "IntegerKIKey52 description");
        AxKeyInfo intKI53 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey53", "0.0.3"), UUID.randomUUID(),
                        "IntegerKIKey53 description");
        AxKeyInfo intKI54 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey54", "0.0.4"), UUID.randomUUID(),
                        "IntegerKIKey54 description");
        AxKeyInfo intKI61 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey61", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey61 description");
        AxKeyInfo intKI62 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey62", "0.0.2"), UUID.randomUUID(),
                        "IntegerKIKey62 description");
        AxKeyInfo intKI63 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey63", "0.0.3"), UUID.randomUUID(),
                        "IntegerKIKey63 description");
        AxKeyInfo intKI64 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey64", "0.0.4"), UUID.randomUUID(),
                        "IntegerKIKey64 description");
        AxKeyInfo intKI71 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey71", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey71 description");
        AxKeyInfo intKI81 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey81", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey81 description");
        AxKeyInfo intKI91 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey91", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey91 description");
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI31.getKey(), intKI31);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI24.getKey(), intKI24);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI11.getKey(), intKI11);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI64.getKey(), intKI64);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI41.getKey(), intKI41);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI51.getKey(), intKI51);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI23.getKey(), intKI23);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI81.getKey(), intKI81);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI71.getKey(), intKI71);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI01.getKey(), intKI01);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI91.getKey(), intKI91);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI52.getKey(), intKI52);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI53.getKey(), intKI53);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI62.getKey(), intKI62);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI54.getKey(), intKI54);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI26.getKey(), intKI26);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI22.getKey(), intKI22);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI25.getKey(), intKI25);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI21.getKey(), intKI21);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI61.getKey(), intKI61);
        basicModel.getKeyInformation().getKeyInfoMap().put(intKI63.getKey(), intKI63);

        AxKeyInfo floatKI01 = new AxKeyInfo(new AxArtifactKey("FloatKIKey01", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey01 description");
        AxKeyInfo floatKI11 = new AxKeyInfo(new AxArtifactKey("FloatKIKey11", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey11 description");
        AxKeyInfo floatKI21 = new AxKeyInfo(new AxArtifactKey("FloatKIKey21", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey21 description");
        AxKeyInfo floatKI31 = new AxKeyInfo(new AxArtifactKey("FloatKIKey31", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey31 description");
        AxKeyInfo floatKI41 = new AxKeyInfo(new AxArtifactKey("FloatKIKey41", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey41 description");
        AxKeyInfo floatKI51 = new AxKeyInfo(new AxArtifactKey("FloatKIKey51", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey51 description");
        AxKeyInfo floatKI61 = new AxKeyInfo(new AxArtifactKey("FloatKIKey61", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey61 description");
        AxKeyInfo floatKI71 = new AxKeyInfo(new AxArtifactKey("FloatKIKey71", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey71 description");
        AxKeyInfo floatKI81 = new AxKeyInfo(new AxArtifactKey("FloatKIKey81", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey81 description");
        AxKeyInfo floatKI82 = new AxKeyInfo(new AxArtifactKey("FloatKIKey82", "0.0.2"), UUID.randomUUID(),
                        "IntegerKIKey82 description");
        AxKeyInfo floatKI83 = new AxKeyInfo(new AxArtifactKey("FloatKIKey83", "0.0.3"), UUID.randomUUID(),
                        "IntegerKIKey83 description");
        AxKeyInfo floatKI91 = new AxKeyInfo(new AxArtifactKey("FloatKIKey91", "0.0.1"), UUID.randomUUID(),
                        "IntegerKIKey91 description");
        AxKeyInfo floatKI92 = new AxKeyInfo(new AxArtifactKey("FloatKIKey92", "0.0.2"), UUID.randomUUID(),
                        "IntegerKIKey92 description");
        AxKeyInfo floatKI93 = new AxKeyInfo(new AxArtifactKey("FloatKIKey93", "0.0.3"), UUID.randomUUID(),
                        "IntegerKIKey93 description");
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI11.getKey(), floatKI11);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI83.getKey(), floatKI83);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI51.getKey(), floatKI51);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI71.getKey(), floatKI71);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI21.getKey(), floatKI21);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI81.getKey(), floatKI81);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI92.getKey(), floatKI92);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI91.getKey(), floatKI91);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI01.getKey(), floatKI01);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI82.getKey(), floatKI82);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI61.getKey(), floatKI61);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI41.getKey(), floatKI41);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI31.getKey(), floatKI31);
        basicModel.getKeyInformation().getKeyInfoMap().put(floatKI93.getKey(), floatKI93);

        assertNull(basicModel.getKeyInformation().get("NonExistantKey", "0.0.6"));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6").equals(intKI26));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2").equals(intKI62));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1").equals(intKI21));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1").equals(intKI61));

        assertNull(basicModel.getKeyInformation().get("NonExistantKey"));

        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey01").equals(intKI01));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey11").equals(intKI11));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26").equals(intKI26));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey31").equals(intKI31));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey41").equals(intKI41));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey54").equals(intKI54));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey64").equals(intKI64));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey71").equals(intKI71));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey81").equals(intKI81));
        assertTrue(basicModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91));

        assertTrue(basicModel.getKeyInformation().get("FloatKIKey01").equals(floatKI01));
        assertTrue(basicModel.getKeyInformation().get("FloatKIKey11").equals(floatKI11));
        assertTrue(basicModel.getKeyInformation().get("FloatKIKey21").equals(floatKI21));
        assertTrue(basicModel.getKeyInformation().get("FloatKIKey31").equals(floatKI31));
        assertTrue(basicModel.getKeyInformation().get("FloatKIKey41").equals(floatKI41));
        assertTrue(basicModel.getKeyInformation().get("FloatKIKey51").equals(floatKI51));
        assertTrue(basicModel.getKeyInformation().get("FloatKIKey61").equals(floatKI61));
        assertTrue(basicModel.getKeyInformation().get("FloatKIKey71").equals(floatKI71));
        assertTrue(basicModel.getKeyInformation().get("FloatKIKey83").equals(floatKI83));
        assertTrue(basicModel.getKeyInformation().get("FloatKIKey93").equals(floatKI93));

        // Ensure marshalling and unmarshalling is OK
        ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class);
        ApexModelFileWriter<AxModel> modelWriter = new ApexModelFileWriter<AxModel>(true);

        modelReader.setValidateFlag(false);
        modelWriter.setValidateFlag(false);

        File tempXmlFile = File.createTempFile("ApexModel", "xml");
        modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempXmlFile.getCanonicalPath());

        FileInputStream xmlFileInputStream = new FileInputStream(tempXmlFile);
        AxModel readXmlModel = modelReader.read(xmlFileInputStream);
        xmlFileInputStream.close();
        assertTrue(basicModel.equals(readXmlModel));
        assertTrue(readXmlModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91));
        assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey"));
        tempXmlFile.delete();
    }
}