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