aboutsummaryrefslogtreecommitdiffstats
path: root/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/factory/TestContextAlbumFactory.java
blob: be4a379aa6778ba2b040f601433b0106810fcd99 (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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2019 Nordix Foundation.
 *  Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.testsuites.integration.context.factory;

import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.DATE_CONTEXT_ALBUM;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.EXTERNAL_CONTEXT_ALBUM;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.GLOBAL_CONTEXT_ALBUM;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.LONG_CONTEXT_ALBUM;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.MAP_CONTEXT_ALBUM;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.POLICY_CONTEXT_ALBUM;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.VERSION;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.onap.policy.apex.context.test.concepts.TestContextDateLocaleItem;
import org.onap.policy.apex.context.test.concepts.TestContextLongItem;
import org.onap.policy.apex.context.test.concepts.TestContextTreeMapItem;
import org.onap.policy.apex.context.test.concepts.TestExternalContextItem;
import org.onap.policy.apex.context.test.concepts.TestGlobalContextItem;
import org.onap.policy.apex.context.test.concepts.TestPolicyContextItem;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;

/**
 * The Class TestContextAlbumFactory creates test context albums.
 *
 * @author Liam Fallon (liam.fallon@ericsson.com)
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class TestContextAlbumFactory {
    // Recurring string constants.
    private static final String CONTEXT = "context";
    private static final String SCHEMAS2 = "Schemas";
    private static final String KEY_INFO_MAP_KEY = "KeyInfoMapKey";
    private static final String APPLICATION = "APPLICATION";
    private static final String JAVA_LONG = Long.class.getName();
    private static final String JAVA_FLAVOUR = "Java";

    /**
     * Creates the policy context model.
     *
     * @return the ax context model
     */
    public static AxContextModel createPolicyContextModel() {
        final AxContextSchema policySchema = new AxContextSchema(new AxArtifactKey("PolicySchema", VERSION),
                JAVA_FLAVOUR, TestPolicyContextItem.class.getName());
        final AxContextAlbum albumDefinition = new AxContextAlbum(new AxArtifactKey(POLICY_CONTEXT_ALBUM, VERSION),
                APPLICATION, true, policySchema.getKey());

        final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
        schemas.getSchemasMap().put(policySchema.getKey(), policySchema);
        final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
        albums.getAlbumsMap().put(albumDefinition.getKey(), albumDefinition);

        final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
        final AxContextModel contextModel =
                new AxContextModel(new AxArtifactKey("PolicyContextModel", VERSION), schemas, albums, keyInformation);
        contextModel.setKeyInformation(keyInformation);
        keyInformation.generateKeyInfo(contextModel);

        return contextModel;
    }

    /**
     * Creates the global context model.
     *
     * @return the ax context model
     */
    public static AxContextModel createGlobalContextModel() {
        final AxContextSchema globalSchema = new AxContextSchema(new AxArtifactKey("GlobalSchema", VERSION),
                JAVA_FLAVOUR, TestGlobalContextItem.class.getName());
        final AxContextAlbum albumDefinition = new AxContextAlbum(new AxArtifactKey(GLOBAL_CONTEXT_ALBUM, VERSION),
                "GLOBAL", true, globalSchema.getKey());

        final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
        schemas.getSchemasMap().put(globalSchema.getKey(), globalSchema);
        final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
        albums.getAlbumsMap().put(albumDefinition.getKey(), albumDefinition);

        final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
        final AxContextModel contextModel =
                new AxContextModel(new AxArtifactKey("GlobalContextModel", VERSION), schemas, albums, keyInformation);
        contextModel.setKeyInformation(keyInformation);
        keyInformation.generateKeyInfo(contextModel);

        return contextModel;
    }

    /**
     * Creates the external context model.
     *
     * @return the ax context model
     */
    public static AxContextModel createExternalContextModel() {
        final AxContextSchema externalSchema = new AxContextSchema(new AxArtifactKey("ExternalSchema", VERSION),
                JAVA_FLAVOUR, TestExternalContextItem.class.getName());
        final AxContextAlbum albumDefinition = new AxContextAlbum(new AxArtifactKey(EXTERNAL_CONTEXT_ALBUM, VERSION),
                "EXTERNAL", true, externalSchema.getKey());

        final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
        schemas.getSchemasMap().put(externalSchema.getKey(), externalSchema);
        final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
        albums.getAlbumsMap().put(albumDefinition.getKey(), albumDefinition);

        final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
        final AxContextModel contextModel =
                new AxContextModel(new AxArtifactKey("ExternalContextModel", VERSION), schemas, albums, keyInformation);
        contextModel.setKeyInformation(keyInformation);
        keyInformation.generateKeyInfo(contextModel);

        return contextModel;
    }

    /**
     * Creates the long context model.
     *
     * @return the ax context model
     */
    public static AxContextModel createLongContextModel() {
        final AxArtifactKey longSchemaKey = new AxArtifactKey("LongSchema", VERSION);
        final AxContextSchema longSchema = new AxContextSchema(longSchemaKey, JAVA_FLAVOUR, JAVA_LONG);

        final AxArtifactKey longContextAlbumKey = new AxArtifactKey("LongContextAlbum1", VERSION);
        final AxContextAlbum albumDefinition1 =
                new AxContextAlbum(longContextAlbumKey, APPLICATION, true, longSchema.getKey());

        final AxArtifactKey longContextAlbumKey2 = new AxArtifactKey("LongContextAlbum2", VERSION);
        final AxContextAlbum albumDefinition2 =
                new AxContextAlbum(longContextAlbumKey2, APPLICATION, true, longSchema.getKey());

        final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
        schemas.getSchemasMap().put(longSchema.getKey(), longSchema);
        final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
        albums.getAlbumsMap().put(albumDefinition1.getKey(), albumDefinition1);
        albums.getAlbumsMap().put(albumDefinition2.getKey(), albumDefinition2);

        final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
        final AxContextModel contextModel =
                new AxContextModel(new AxArtifactKey("LongContextModel", VERSION), schemas, albums, keyInformation);
        contextModel.setKeyInformation(keyInformation);
        keyInformation.generateKeyInfo(contextModel);

        return contextModel;
    }

    /**
     * Creates the multi albums context model.
     *
     * @return the ax context model
     */
    public static AxContextModel createMultiAlbumsContextModel() {
        final AxContextSchema longSchema =
                new AxContextSchema(new AxArtifactKey("LongSchema", VERSION), JAVA_FLAVOUR, JAVA_LONG);
        final AxContextSchema lTypeSchema = new AxContextSchema(new AxArtifactKey("LTypeSchema", VERSION), JAVA_FLAVOUR,
                TestContextLongItem.class.getName());
        final AxContextSchema dateSchema = new AxContextSchema(new AxArtifactKey("DateSchema", VERSION), JAVA_FLAVOUR,
                TestContextDateLocaleItem.class.getName());
        final AxContextSchema mapSchema = new AxContextSchema(new AxArtifactKey("MapSchema", VERSION), JAVA_FLAVOUR,
                TestContextTreeMapItem.class.getName());

        final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION));
        schemas.getSchemasMap().put(longSchema.getKey(), longSchema);
        schemas.getSchemasMap().put(lTypeSchema.getKey(), lTypeSchema);
        schemas.getSchemasMap().put(dateSchema.getKey(), dateSchema);
        schemas.getSchemasMap().put(mapSchema.getKey(), mapSchema);

        final AxContextAlbum longAlbumDefinition = new AxContextAlbum(new AxArtifactKey(LONG_CONTEXT_ALBUM, VERSION),
                APPLICATION, true, longSchema.getKey());
        final AxContextAlbum lTypeAlbumDefinition = new AxContextAlbum(new AxArtifactKey("LTypeContextAlbum", VERSION),
                APPLICATION, true, lTypeSchema.getKey());
        final AxContextAlbum dateAlbumDefinition = new AxContextAlbum(new AxArtifactKey(DATE_CONTEXT_ALBUM, VERSION),
                APPLICATION, true, dateSchema.getKey());
        final AxContextAlbum mapAlbumDefinition = new AxContextAlbum(new AxArtifactKey(MAP_CONTEXT_ALBUM, VERSION),
                APPLICATION, true, mapSchema.getKey());

        final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION));
        albums.getAlbumsMap().put(longAlbumDefinition.getKey(), longAlbumDefinition);
        albums.getAlbumsMap().put(lTypeAlbumDefinition.getKey(), lTypeAlbumDefinition);
        albums.getAlbumsMap().put(dateAlbumDefinition.getKey(), dateAlbumDefinition);
        albums.getAlbumsMap().put(mapAlbumDefinition.getKey(), mapAlbumDefinition);

        final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION));
        final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("MultiAlbumsContextModel", VERSION),
                schemas, albums, keyInformation);
        contextModel.setKeyInformation(keyInformation);
        keyInformation.generateKeyInfo(contextModel);

        return contextModel;
    }

}