9689acb3d9f80661a692e017760518b40d30d843
[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.context.test.factory;
22
23 import static org.onap.policy.apex.context.test.utils.Constants.DATE_CONTEXT_ALBUM;
24 import static org.onap.policy.apex.context.test.utils.Constants.EXTERNAL_CONTEXT_ALBUM;
25 import static org.onap.policy.apex.context.test.utils.Constants.GLOBAL_CONTEXT_ALBUM;
26 import static org.onap.policy.apex.context.test.utils.Constants.LONG_CONTEXT_ALBUM;
27 import static org.onap.policy.apex.context.test.utils.Constants.MAP_CONTEXT_ALBUM;
28 import static org.onap.policy.apex.context.test.utils.Constants.POLICY_CONTEXT_ALBUM;
29 import static org.onap.policy.apex.context.test.utils.Constants.VERSION;
30
31 import org.onap.policy.apex.context.test.concepts.TestContextDateLocaleItem;
32 import org.onap.policy.apex.context.test.concepts.TestContextLongItem;
33 import org.onap.policy.apex.context.test.concepts.TestContextTreeMapItem;
34 import org.onap.policy.apex.context.test.concepts.TestExternalContextItem;
35 import org.onap.policy.apex.context.test.concepts.TestGlobalContextItem;
36 import org.onap.policy.apex.context.test.concepts.TestPolicyContextItem;
37 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
38 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
39 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
40 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
41 import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
42 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
43 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
44
45 /**
46  * The Class TestContextAlbumFactory creates test context albums.
47  *
48  * @author Liam Fallon (liam.fallon@ericsson.com)
49  */
50 public final class TestContextAlbumFactory {
51     // Recurring string constants.
52     private static final String CONTEXT = "context";
53     private static final String SCHEMAS2 = "Schemas";
54     private static final String KEY_INFO_MAP_KEY = "KeyInfoMapKey";
55     private static final String APPLICATION = "APPLICATION";
56     private static final String JAVA_LONG = Long.class.getCanonicalName();
57     private static final String JAVA_FLAVOUR = "Java";
58
59     /**
60      * Default constructor to prevent sub-classing.
61      */
62     private TestContextAlbumFactory() {}
63
64     /**
65      * Creates the policy context model.
66      *
67      * @return the ax context model
68      */
69     public static AxContextModel createPolicyContextModel() {
70         final AxContextSchema policySchema = new AxContextSchema(new AxArtifactKey("PolicySchema", VERSION),
71                 JAVA_FLAVOUR, TestPolicyContextItem.class.getCanonicalName());
72         final AxContextAlbum albumDefinition = new AxContextAlbum(new AxArtifactKey(POLICY_CONTEXT_ALBUM, VERSION),
73                 APPLICATION, true, policySchema.getKey());
74
75         final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
76         schemas.getSchemasMap().put(policySchema.getKey(), policySchema);
77         final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
78         albums.getAlbumsMap().put(albumDefinition.getKey(), albumDefinition);
79
80         final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
81         final AxContextModel contextModel =
82                 new AxContextModel(new AxArtifactKey("PolicyContextModel", VERSION), schemas, albums, keyInformation);
83         contextModel.setKeyInformation(keyInformation);
84         keyInformation.generateKeyInfo(contextModel);
85
86         return contextModel;
87     }
88
89     /**
90      * Creates the global context model.
91      *
92      * @return the ax context model
93      */
94     public static AxContextModel createGlobalContextModel() {
95         final AxContextSchema globalSchema = new AxContextSchema(new AxArtifactKey("GlobalSchema", VERSION),
96                 JAVA_FLAVOUR, TestGlobalContextItem.class.getCanonicalName());
97         final AxContextAlbum albumDefinition = new AxContextAlbum(new AxArtifactKey(GLOBAL_CONTEXT_ALBUM, VERSION),
98                 "GLOBAL", true, globalSchema.getKey());
99
100         final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
101         schemas.getSchemasMap().put(globalSchema.getKey(), globalSchema);
102         final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
103         albums.getAlbumsMap().put(albumDefinition.getKey(), albumDefinition);
104
105         final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
106         final AxContextModel contextModel =
107                 new AxContextModel(new AxArtifactKey("GlobalContextModel", VERSION), schemas, albums, keyInformation);
108         contextModel.setKeyInformation(keyInformation);
109         keyInformation.generateKeyInfo(contextModel);
110
111         return contextModel;
112     }
113
114     /**
115      * Creates the external context model.
116      *
117      * @return the ax context model
118      */
119     public static AxContextModel createExternalContextModel() {
120         final AxContextSchema externalSchema = new AxContextSchema(new AxArtifactKey("ExternalSchema", VERSION),
121                 JAVA_FLAVOUR, TestExternalContextItem.class.getCanonicalName());
122         final AxContextAlbum albumDefinition = new AxContextAlbum(new AxArtifactKey(EXTERNAL_CONTEXT_ALBUM, VERSION),
123                 "EXTERNAL", true, externalSchema.getKey());
124
125         final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
126         schemas.getSchemasMap().put(externalSchema.getKey(), externalSchema);
127         final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
128         albums.getAlbumsMap().put(albumDefinition.getKey(), albumDefinition);
129
130         final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
131         final AxContextModel contextModel =
132                 new AxContextModel(new AxArtifactKey("ExternalContextModel", VERSION), schemas, albums, keyInformation);
133         contextModel.setKeyInformation(keyInformation);
134         keyInformation.generateKeyInfo(contextModel);
135
136         return contextModel;
137     }
138
139     /**
140      * Creates the long context model.
141      *
142      * @return the ax context model
143      */
144     public static AxContextModel createLongContextModel() {
145         final AxArtifactKey longSchemaKey = new AxArtifactKey("LongSchema", VERSION);
146         final AxContextSchema longSchema = new AxContextSchema(longSchemaKey, JAVA_FLAVOUR, JAVA_LONG);
147
148         final AxArtifactKey longContextAlbumKey = new AxArtifactKey("LongContextAlbum1", VERSION);
149         final AxContextAlbum albumDefinition1 =
150                 new AxContextAlbum(longContextAlbumKey, APPLICATION, true, longSchema.getKey());
151
152         final AxArtifactKey longContextAlbumKey2 = new AxArtifactKey("LongContextAlbum2", VERSION);
153         final AxContextAlbum albumDefinition2 =
154                 new AxContextAlbum(longContextAlbumKey2, APPLICATION, true, longSchema.getKey());
155
156         final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
157         schemas.getSchemasMap().put(longSchema.getKey(), longSchema);
158         final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
159         albums.getAlbumsMap().put(albumDefinition1.getKey(), albumDefinition1);
160         albums.getAlbumsMap().put(albumDefinition2.getKey(), albumDefinition2);
161
162         final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
163         final AxContextModel contextModel =
164                 new AxContextModel(new AxArtifactKey("LongContextModel", VERSION), schemas, albums, keyInformation);
165         contextModel.setKeyInformation(keyInformation);
166         keyInformation.generateKeyInfo(contextModel);
167
168         return contextModel;
169     }
170
171     /**
172      * Creates the multi albums context model.
173      *
174      * @return the ax context model
175      */
176     public static AxContextModel createMultiAlbumsContextModel() {
177         final AxContextSchema longSchema =
178                 new AxContextSchema(new AxArtifactKey("LongSchema", VERSION), JAVA_FLAVOUR, JAVA_LONG);
179         final AxContextSchema lTypeSchema = new AxContextSchema(new AxArtifactKey("LTypeSchema", VERSION), JAVA_FLAVOUR,
180                 TestContextLongItem.class.getCanonicalName());
181         final AxContextSchema dateSchema = new AxContextSchema(new AxArtifactKey("DateSchema", VERSION), JAVA_FLAVOUR,
182                 TestContextDateLocaleItem.class.getCanonicalName());
183         final AxContextSchema mapSchema = new AxContextSchema(new AxArtifactKey("MapSchema", VERSION), JAVA_FLAVOUR,
184                 TestContextTreeMapItem.class.getCanonicalName());
185
186         final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
187         schemas.getSchemasMap().put(longSchema.getKey(), longSchema);
188         schemas.getSchemasMap().put(lTypeSchema.getKey(), lTypeSchema);
189         schemas.getSchemasMap().put(dateSchema.getKey(), dateSchema);
190         schemas.getSchemasMap().put(mapSchema.getKey(), mapSchema);
191
192         final AxContextAlbum longAlbumDefinition = new AxContextAlbum(new AxArtifactKey(LONG_CONTEXT_ALBUM, VERSION),
193                 APPLICATION, true, longSchema.getKey());
194         final AxContextAlbum lTypeAlbumDefinition = new AxContextAlbum(new AxArtifactKey("LTypeContextAlbum", VERSION),
195                 APPLICATION, true, lTypeSchema.getKey());
196         final AxContextAlbum dateAlbumDefinition = new AxContextAlbum(new AxArtifactKey(DATE_CONTEXT_ALBUM, VERSION),
197                 APPLICATION, true, dateSchema.getKey());
198         final AxContextAlbum mapAlbumDefinition = new AxContextAlbum(new AxArtifactKey(MAP_CONTEXT_ALBUM, VERSION),
199                 APPLICATION, true, mapSchema.getKey());
200
201         final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
202         albums.getAlbumsMap().put(longAlbumDefinition.getKey(), longAlbumDefinition);
203         albums.getAlbumsMap().put(lTypeAlbumDefinition.getKey(), lTypeAlbumDefinition);
204         albums.getAlbumsMap().put(dateAlbumDefinition.getKey(), dateAlbumDefinition);
205         albums.getAlbumsMap().put(mapAlbumDefinition.getKey(), mapAlbumDefinition);
206
207         final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
208         final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("MultiAlbumsContextModel", VERSION),
209                 schemas, albums, keyInformation);
210         contextModel.setKeyInformation(keyInformation);
211         keyInformation.generateKeyInfo(contextModel);
212
213         return contextModel;
214     }
215
216 }