2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.testsuites.integration.context.distribution;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29 import static org.onap.policy.apex.testsuites.integration.context.factory.TestContextAlbumFactory.createPolicyContextModel;
30 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.BYTE_VAL;
31 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.EXTERNAL_CONTEXT;
32 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.EXTERNAL_CONTEXT_ALBUM;
33 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.FLOAT_VAL;
34 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.GLOBAL_CONTEXT_ALBUM;
35 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.GLOBAL_CONTEXT_KEY;
36 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.INT_VAL;
37 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.INT_VAL_2;
38 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.INT_VAL_3;
39 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.LONG_VAL;
40 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.PI_VAL;
41 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.POLICY_CONTEXT_ALBUM;
42 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.STRING_EXT_VAL;
43 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.STRING_GLOBAL_VAL;
44 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.STRING_VAL;
45 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.TEST_POLICY_CONTEXT_ITEM;
46 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.TIME_ZONE;
47 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.VERSION;
49 import java.util.Collection;
50 import java.util.Date;
51 import java.util.HashMap;
52 import java.util.LinkedHashMap;
53 import java.util.Locale;
55 import java.util.Map.Entry;
57 import java.util.TreeSet;
58 import org.onap.policy.apex.context.ContextAlbum;
59 import org.onap.policy.apex.context.ContextException;
60 import org.onap.policy.apex.context.ContextRuntimeException;
61 import org.onap.policy.apex.context.Distributor;
62 import org.onap.policy.apex.context.impl.distribution.DistributorFactory;
63 import org.onap.policy.apex.context.test.concepts.TestContextBooleanItem;
64 import org.onap.policy.apex.context.test.concepts.TestContextByteItem;
65 import org.onap.policy.apex.context.test.concepts.TestContextDateItem;
66 import org.onap.policy.apex.context.test.concepts.TestContextDateLocaleItem;
67 import org.onap.policy.apex.context.test.concepts.TestContextDateTzItem;
68 import org.onap.policy.apex.context.test.concepts.TestContextDoubleItem;
69 import org.onap.policy.apex.context.test.concepts.TestContextFloatItem;
70 import org.onap.policy.apex.context.test.concepts.TestContextIntItem;
71 import org.onap.policy.apex.context.test.concepts.TestContextLongItem;
72 import org.onap.policy.apex.context.test.concepts.TestContextLongObjectItem;
73 import org.onap.policy.apex.context.test.concepts.TestContextStringItem;
74 import org.onap.policy.apex.context.test.concepts.TestContextTreeMapItem;
75 import org.onap.policy.apex.context.test.concepts.TestContextTreeSetItem;
76 import org.onap.policy.apex.context.test.concepts.TestExternalContextItem;
77 import org.onap.policy.apex.context.test.concepts.TestGlobalContextItem;
78 import org.onap.policy.apex.context.test.concepts.TestPolicyContextItem;
79 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
80 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
81 import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
82 import org.onap.policy.apex.testsuites.integration.context.factory.TestContextAlbumFactory;
83 import org.onap.policy.apex.testsuites.integration.context.utils.Constants;
84 import org.slf4j.ext.XLogger;
85 import org.slf4j.ext.XLoggerFactory;
88 * The Class TestContextInstantiation is used to test Apex context insitiation
91 * @author Sergey Sachkov (sergey.sachkov@ericsson.com)
93 public class ContextInstantiation {
94 // Logger for this class
95 private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextInstantiation.class);
97 // Recurring string constants
98 private static final String TEST_POLICY_CONTEXT_ITEM000 = "TestPolicyContextItem000";
99 private static final String TEST_POLICY_CONTEXT_ITEM005 = "TestPolicyContextItem005";
100 private static final String TEST_POLICY_CONTEXT_ITEM004 = "TestPolicyContextItem004";
101 private static final String TEST_POLICY_CONTEXT_ITEM003 = "TestPolicyContextItem003";
102 private static final String TEST_POLICY_CONTEXT_ITEM002 = "TestPolicyContextItem002";
103 private static final String TEST_POLICY_CONTEXT_ITEM001 = "TestPolicyContextItem001";
104 private static final String NULL_ILLEGAL = "album \"ExternalContextAlbum:0.0.1\" null values are illegal on key ";
106 private static final TreeSet<String> TEST_TREE_SET = new TreeSet<>();
107 private static final Map<String, String> TEST_HASH_MAP = new HashMap<>();
110 TEST_TREE_SET.add("one hundred");
111 TEST_TREE_SET.add("one hundred and one");
112 TEST_TREE_SET.add("one hundred and two");
113 TEST_TREE_SET.add("one hundred and three");
114 TEST_TREE_SET.add("one hundred and four");
116 TEST_HASH_MAP.put("0", "zero");
117 TEST_HASH_MAP.put("1", "one");
118 TEST_HASH_MAP.put("2", "two");
119 TEST_HASH_MAP.put("3", "three");
120 TEST_HASH_MAP.put("4", "four");
125 * Test context instantiation.
127 * @throws ContextException the context exception
129 public void testContextInstantiation() throws ContextException {
130 LOGGER.debug("Running TestContextInstantiation test . . .");
132 final Distributor contextDistributor = getDistributor();
134 final ContextAlbum policyContextAlbum = contextDistributor
135 .createContextAlbum(new AxArtifactKey(POLICY_CONTEXT_ALBUM, VERSION));
137 assertNotNull(policyContextAlbum);
138 policyContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
140 final Date testDate = new Date();
142 final TestContextDateTzItem tci9 = getTestContextDateTzItem(testDate);
143 final TestContextDateLocaleItem tciA = getTestContextDateLocaleItem(testDate);
145 final TestPolicyContextItem policyContext = getTestPolicyContextItem(policyContextAlbum, testDate);
147 final Map<String, Object> valueMap0 = new HashMap<>();
148 valueMap0.put(TEST_POLICY_CONTEXT_ITEM, policyContext);
150 policyContextAlbum.putAll(valueMap0);
152 final TestPolicyContextItem contextItem = (TestPolicyContextItem) policyContextAlbum
153 .get(TEST_POLICY_CONTEXT_ITEM);
154 assertEquals(STRING_VAL, contextItem.getTestPolicyContextItem000().getStringValue());
156 assertEquals(LONG_VAL, contextItem.getTestPolicyContextItem001().getLongValue());
157 assertDouble(contextItem.getTestPolicyContextItem002().getDoubleValue(), PI_VAL);
158 assertTrue(contextItem.getTestPolicyContextItem003().isFlag());
159 assertEquals(contextItem.getTestPolicyContextItem004().getLongValue(), testDate.getTime());
160 assertEquals(TEST_HASH_MAP, contextItem.getTestPolicyContextItem005().getMapValue());
162 final TestGlobalContextItem globalContext = getTestGlobalContextItem(contextDistributor, testDate, tci9, tciA);
164 final Map<String, Object> valueMap1 = new HashMap<>();
165 valueMap1.put(GLOBAL_CONTEXT_KEY, globalContext);
167 final ContextAlbum globalContextAlbum = getContextAlbum(contextDistributor);
169 globalContextAlbum.putAll(valueMap1);
171 final TestGlobalContextItem globalContextItem = (TestGlobalContextItem) globalContextAlbum
172 .get(GLOBAL_CONTEXT_KEY);
174 assertFalse(globalContextItem.getTestGlobalContextItem000().isFlag());
176 assertEquals(BYTE_VAL, globalContextItem.getTestGlobalContextItem001().getByteValue());
178 assertEquals(INT_VAL, globalContextItem.getTestGlobalContextItem002().getIntValue());
179 assertEquals(LONG_VAL, globalContextItem.getTestGlobalContextItem003().getLongValue());
180 assertFloat(FLOAT_VAL, globalContextItem.getTestGlobalContextItem004().getFloatValue());
182 assertDouble(PI_VAL, globalContextItem.getTestGlobalContextItem005().getDoubleValue());
183 assertEquals(STRING_GLOBAL_VAL, globalContextItem.getTestGlobalContextItem006().getStringValue());
185 assertEquals((Long) testDate.getTime(), globalContextItem.getTestGlobalContextItem007().getLongValue());
186 assertEquals(testDate, globalContextItem.getTestGlobalContextItem008().getDateValue());
187 assertEquals(tci9.getDateValue().getTime(),
188 globalContextItem.getTestGlobalContextItem009().getDateValue().getTime());
190 assertEquals(tciA.getDateValue().getTime(),
191 globalContextItem.getTestGlobalContextItem00A().getDateValue().getTime());
193 assertEquals(TEST_TREE_SET, globalContextItem.getTestGlobalContextItem00B().getSetValue());
194 assertEquals(TEST_HASH_MAP, globalContextItem.getTestGlobalContextItem00C().getMapValue());
196 final AxContextModel externalContextModel = TestContextAlbumFactory.createExternalContextModel();
198 final TestContextDateTzItem tci9A = new TestContextDateTzItem(tci9);
199 final TestContextDateLocaleItem tciAa = new TestContextDateLocaleItem(tciA);
200 final TestExternalContextItem externalContext = getTestExternalContextItem(testDate, tci9A, tciAa);
202 final Map<String, Object> valueMap2 = new HashMap<>();
203 valueMap2.put(EXTERNAL_CONTEXT, externalContext);
205 contextDistributor.clear();
206 contextDistributor.init(new AxArtifactKey("ClearedandInittedDistributor", VERSION));
207 contextDistributor.registerModel(externalContextModel);
209 final AxArtifactKey axContextAlbumKey = new AxArtifactKey(EXTERNAL_CONTEXT_ALBUM, VERSION);
210 final ContextAlbum externalContextAlbum = contextDistributor.createContextAlbum(axContextAlbumKey);
211 assertNotNull(externalContextAlbum);
212 externalContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
214 externalContextAlbum.putAll(valueMap2);
215 externalContextAlbum.getAlbumDefinition().setWritable(false);
217 TestExternalContextItem externalContextItem = (TestExternalContextItem) externalContextAlbum
218 .get(EXTERNAL_CONTEXT);
220 assertFalse(externalContextItem.getTestExternalContextItem000().isFlag());
221 assertEquals(BYTE_VAL, externalContextItem.getTestExternalContextItem001().getByteValue());
222 assertEquals(INT_VAL, externalContextItem.getTestExternalContextItem002().getIntValue());
224 assertFloat(LONG_VAL, externalContextItem.getTestExternalContextItem003().getLongValue());
225 assertFloat(FLOAT_VAL, externalContextItem.getTestExternalContextItem004().getFloatValue());
227 assertDouble(PI_VAL, externalContextItem.getTestExternalContextItem005().getDoubleValue());
228 assertEquals(STRING_EXT_VAL, externalContextItem.getTestExternalContextItem006().getStringValue());
229 assertEquals((Long) testDate.getTime(), externalContextItem.getTestExternalContextItem007().getLongValue());
230 assertEquals(testDate, externalContextItem.getTestExternalContextItem008().getDateValue());
231 assertEquals(tci9A.getDateValue().getTime(),
232 externalContextItem.getTestExternalContextItem009().getDateValue().getTime());
234 assertEquals(tciAa.getDateValue().getTime(),
235 externalContextItem.getTestExternalContextItem00A().getDateValue().getTime());
236 assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue());
237 assertEquals(TEST_HASH_MAP, externalContextItem.getTestExternalContextItem00C().getMapValue());
239 final Collection<Object> mapValues = externalContextAlbum.values();
240 assertTrue(externalContextAlbum.values().containsAll(mapValues));
242 // Check that clearing does not work
243 assertThatThrownBy(() -> externalContextAlbum.clear()).isInstanceOf(ContextRuntimeException.class)
244 .hasMessageContaining("album \"ExternalContextAlbum:0.0.1\" clear() not allowed on read only albums");
245 assertEquals(1, externalContextAlbum.size());
247 assertContextAlbumContains(externalContext, externalContextAlbum);
249 final Set<Entry<String, Object>> entrySet = externalContextAlbum.entrySet();
250 assertEquals(1, entrySet.size());
252 assertThatThrownBy(() -> externalContextAlbum.get(null)).isInstanceOf(ContextRuntimeException.class)
253 .hasMessageContaining("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for get()");
254 final Object aObject = externalContextAlbum.get(EXTERNAL_CONTEXT);
255 assertEquals(aObject, externalContext);
257 // put null keys should fail, throws a runtime exception
258 assertThatThrownBy(() -> externalContextAlbum.put(null, null))
259 .hasMessageContaining("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for put()");
260 assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItem00A", null))
261 .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItem00A\" for put()");
262 assertEquals(tciAa, externalContextItem.getTestExternalContextItem00A());
264 // Should return the hash set
265 assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue());
267 assertTrue(externalContextAlbum.values().containsAll(mapValues));
269 // Set the write flag back as it should be
270 externalContextAlbum.getAlbumDefinition().setWritable(true);
272 // Put should return the previous contextItem
273 final TestExternalContextItem externalContextOther = new TestExternalContextItem();
274 externalContextOther.setTestExternalContextItem002(new TestContextIntItem());
275 externalContextOther.getTestExternalContextItem002().setIntValue(INT_VAL_2);
277 assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContextOther).equals(externalContext));
278 externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT);
279 assertEquals(INT_VAL_2, externalContextItem.getTestExternalContextItem002().getIntValue());
280 assertTrue(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContext).equals(externalContextOther));
281 externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT);
282 assertEquals(INT_VAL_3, externalContextItem.getTestExternalContextItem002().getIntValue());
283 assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItem00A", null))
284 .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItem00A\" for put()");
286 assertTrue(externalContextAlbum.get(EXTERNAL_CONTEXT).equals(externalContext));
288 assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItemFFF", null))
289 .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItemFFF\" for put()");
290 assertEquals(1, externalContextAlbum.size());
292 assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItemFFF", null))
293 .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItemFFF\" for put()");
294 assertEquals(1, externalContextAlbum.size());
296 // Should ignore remove
297 externalContextAlbum.remove("TestExternalContextItem017");
298 assertEquals(1, externalContextAlbum.size());
299 assertEquals(1, externalContextAlbum.values().size());
300 assertTrue(externalContextAlbum.values().containsAll(mapValues));
302 contextDistributor.clear();
305 private void assertContextAlbumContains(final TestExternalContextItem externalContext,
306 final ContextAlbum externalContextAlbum) {
307 assertThatThrownBy(() -> externalContextAlbum.containsKey(null))
308 .hasMessageContaining("null values are illegal on method parameter \"key\"");
309 assertTrue(externalContextAlbum.containsKey(EXTERNAL_CONTEXT));
310 assertTrue(!externalContextAlbum.containsKey(GLOBAL_CONTEXT_KEY));
312 assertThatThrownBy(() -> externalContextAlbum.containsValue(null))
313 .hasMessageContaining("null values are illegal on method parameter \"value\"");
314 assertTrue(externalContextAlbum.containsValue(externalContext));
315 assertFalse(externalContextAlbum.containsValue("Hello"));
318 private ContextAlbum getContextAlbum(final Distributor contextDistributor) throws ContextException {
319 final ContextAlbum globalContextAlbum = contextDistributor
320 .createContextAlbum(new AxArtifactKey(GLOBAL_CONTEXT_ALBUM, VERSION));
321 assertNotNull(globalContextAlbum);
322 globalContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
323 return globalContextAlbum;
326 private TestGlobalContextItem getTestGlobalContextItem(final Distributor contextDistributor, final Date testDate,
327 final TestContextDateTzItem tci9, final TestContextDateLocaleItem tciA) throws ContextException {
328 final AxContextModel globalContextModel = TestContextAlbumFactory.createGlobalContextModel();
329 final TestGlobalContextItem globalContext = getTestGlobalContextItem(testDate, tci9, tciA);
330 contextDistributor.registerModel(globalContextModel);
331 return globalContext;
334 private TestGlobalContextItem getTestGlobalContextItem(final Date testDate, final TestContextDateTzItem tci9,
335 final TestContextDateLocaleItem tciA) {
336 final TestGlobalContextItem globalContext = new TestGlobalContextItem();
338 final TestContextBooleanItem testGlobalContextItem000 = new TestContextBooleanItem(false);
339 final TestContextByteItem testGlobalContextItem001 = new TestContextByteItem(BYTE_VAL);
340 final TestContextIntItem testGlobalContextItem002 = new TestContextIntItem(INT_VAL);
341 final TestContextLongItem testGlobalContextItem003 = new TestContextLongItem(LONG_VAL);
342 final TestContextFloatItem testGlobalContextItem004 = new TestContextFloatItem(FLOAT_VAL);
343 final TestContextDoubleItem testGlobalContextItem005 = new TestContextDoubleItem(PI_VAL);
344 final TestContextStringItem testGlobalContextItem006 = new TestContextStringItem(STRING_GLOBAL_VAL);
345 final TestContextLongObjectItem testGlobalContextItem007 = new TestContextLongObjectItem(testDate.getTime());
347 final TestContextDateItem testGlobalContextItem008 = new TestContextDateItem(testDate);
348 final TestContextTreeSetItem testGlobalContextItem00B = new TestContextTreeSetItem(TEST_TREE_SET);
349 final TestContextTreeMapItem testGlobalContextItem00C = new TestContextTreeMapItem(TEST_HASH_MAP);
351 globalContext.setTestGlobalContextItem000(testGlobalContextItem000);
352 globalContext.setTestGlobalContextItem001(testGlobalContextItem001);
353 globalContext.setTestGlobalContextItem002(testGlobalContextItem002);
354 globalContext.setTestGlobalContextItem003(testGlobalContextItem003);
355 globalContext.setTestGlobalContextItem004(testGlobalContextItem004);
356 globalContext.setTestGlobalContextItem005(testGlobalContextItem005);
357 globalContext.setTestGlobalContextItem006(testGlobalContextItem006);
358 globalContext.setTestGlobalContextItem007(testGlobalContextItem007);
359 globalContext.setTestGlobalContextItem008(testGlobalContextItem008);
360 globalContext.setTestGlobalContextItem009(tci9);
361 globalContext.setTestGlobalContextItem00A(tciA);
362 globalContext.setTestGlobalContextItem00B(testGlobalContextItem00B);
363 globalContext.setTestGlobalContextItem00C(testGlobalContextItem00C);
364 return globalContext;
367 private TestPolicyContextItem getTestPolicyContextItem(final ContextAlbum policyContextAlbum, final Date testDate) {
368 final TestContextStringItem contextStringItem = new TestContextStringItem(STRING_VAL);
369 final TestContextLongItem contextLongItem = new TestContextLongItem(LONG_VAL);
370 final TestContextDoubleItem contextDoubleItem = new TestContextDoubleItem(PI_VAL);
371 final TestContextBooleanItem contextBooleanItem = new TestContextBooleanItem(true);
372 final TestContextLongItem contextLongItem2 = new TestContextLongItem(testDate.getTime());
373 final TestContextTreeMapItem contextTreeMapItem = new TestContextTreeMapItem(TEST_HASH_MAP);
375 final Map<String, Object> valueMapA = new LinkedHashMap<>();
376 valueMapA.put(TEST_POLICY_CONTEXT_ITEM001, contextLongItem);
377 valueMapA.put(TEST_POLICY_CONTEXT_ITEM002, contextDoubleItem);
378 valueMapA.put(TEST_POLICY_CONTEXT_ITEM003, contextBooleanItem);
379 valueMapA.put(TEST_POLICY_CONTEXT_ITEM004, contextLongItem2);
380 valueMapA.put(TEST_POLICY_CONTEXT_ITEM005, contextTreeMapItem);
381 valueMapA.put(TEST_POLICY_CONTEXT_ITEM000, contextStringItem);
383 assertPutMethods(policyContextAlbum, contextStringItem, valueMapA);
385 final TestPolicyContextItem policyContext = new TestPolicyContextItem();
387 LOGGER.debug(policyContextAlbum.toString());
389 policyContext.setTestPolicyContextItem000(contextStringItem);
390 policyContext.setTestPolicyContextItem001(contextLongItem);
391 policyContext.setTestPolicyContextItem002(contextDoubleItem);
392 policyContext.setTestPolicyContextItem003(contextBooleanItem);
393 policyContext.setTestPolicyContextItem004(contextLongItem2);
394 policyContext.setTestPolicyContextItem005(contextTreeMapItem);
395 return policyContext;
398 private void assertPutMethods(final ContextAlbum policyContextAlbum, final TestContextStringItem contextStringItem,
399 final Map<String, Object> valueMapA) {
400 assertThatThrownBy(() -> policyContextAlbum.put(TEST_POLICY_CONTEXT_ITEM000, contextStringItem))
401 .hasMessageContaining(getMessage(TEST_POLICY_CONTEXT_ITEM000, "TestContextItem006",
402 TestContextStringItem.class.getName(), "stringValue=" + STRING_VAL));
403 assertThatThrownBy(() -> policyContextAlbum.putAll(valueMapA))
404 .hasMessageContaining(getMessage(TEST_POLICY_CONTEXT_ITEM001, "TestContextItem003",
405 TestContextLongItem.class.getName(), "longValue=" + INT_VAL_3));
408 private AxContextModel getAxContextModel() {
409 final AxContextModel policyContextModel = createPolicyContextModel();
410 final AxValidationResult result = new AxValidationResult();
411 policyContextModel.validate(result);
412 LOGGER.debug(result.toString());
414 assertTrue(result.isValid());
415 return policyContextModel;
418 private TestContextDateLocaleItem getTestContextDateLocaleItem(final Date testDate) {
419 final TestContextDateLocaleItem tciA = new TestContextDateLocaleItem();
420 tciA.setDateValue(new TestContextDateItem(testDate));
421 tciA.setTzValue(TIME_ZONE.getDisplayName());
423 tciA.setUtcOffset(-600);
424 tciA.setLocale(Locale.ENGLISH);
428 private TestContextDateTzItem getTestContextDateTzItem(final Date testDate) {
429 final TestContextDateTzItem tci9 = new TestContextDateTzItem();
430 tci9.setDateValue(new TestContextDateItem(testDate));
431 tci9.setTzValue(TIME_ZONE.getDisplayName());
436 private TestExternalContextItem getTestExternalContextItem(final Date testDate, final TestContextDateTzItem tci9A,
437 final TestContextDateLocaleItem tciAa) {
438 final TestExternalContextItem externalContext = new TestExternalContextItem();
440 final TestContextBooleanItem testExternalContextItem000 = new TestContextBooleanItem(false);
441 final TestContextByteItem testExternalContextItem001 = new TestContextByteItem(BYTE_VAL);
442 final TestContextIntItem testExternalContextItem002 = new TestContextIntItem(INT_VAL);
443 final TestContextLongItem testExternalContextItem003 = new TestContextLongItem(LONG_VAL);
444 final TestContextFloatItem testExternalContextItem004 = new TestContextFloatItem(3.14159265359F);
445 final TestContextDoubleItem testExternalContextItem005 = new TestContextDoubleItem(PI_VAL);
446 final TestContextStringItem testExternalContextItem006 = new TestContextStringItem(STRING_EXT_VAL);
447 final TestContextLongObjectItem testExternalContextItem007 = new TestContextLongObjectItem(testDate.getTime());
448 final TestContextDateItem testExternalContextItem008 = new TestContextDateItem(testDate);
449 final TestContextTreeSetItem testExternalContextItem00B = new TestContextTreeSetItem(TEST_TREE_SET);
450 final TestContextTreeMapItem testExternalContextItem00C = new TestContextTreeMapItem(TEST_HASH_MAP);
452 externalContext.setTestExternalContextItem000(testExternalContextItem000);
453 externalContext.setTestExternalContextItem001(testExternalContextItem001);
454 externalContext.setTestExternalContextItem002(testExternalContextItem002);
455 externalContext.setTestExternalContextItem003(testExternalContextItem003);
456 externalContext.setTestExternalContextItem004(testExternalContextItem004);
457 externalContext.setTestExternalContextItem005(testExternalContextItem005);
458 externalContext.setTestExternalContextItem006(testExternalContextItem006);
459 externalContext.setTestExternalContextItem007(testExternalContextItem007);
460 externalContext.setTestExternalContextItem008(testExternalContextItem008);
461 externalContext.setTestExternalContextItem009(tci9A);
462 externalContext.setTestExternalContextItem00A(tciAa);
463 externalContext.setTestExternalContextItem00B(testExternalContextItem00B);
464 externalContext.setTestExternalContextItem00C(testExternalContextItem00C);
465 return externalContext;
468 private String getMessage(final String key, final String objName, final String clazzName, final String valString) {
469 return getMessage(key, objName, clazzName, valString, TestPolicyContextItem.class.getName());
472 private String getMessage(final String key, final String objName, final String clazzName, final String valString,
473 final String compatibleClazzName) {
474 return "Failed to set context value for key \"" + key + "\" in album \"PolicyContextAlbum:0.0.1\": "
475 + "PolicyContextAlbum:0.0.1: object \"" + objName + " [" + valString + "]\" " + "of class \"" + clazzName
476 + "\"" + " not compatible with class \"" + compatibleClazzName + "\"";
479 private void assertFloat(final float actual, final float expected) {
480 assertTrue(Float.compare(actual, expected) == 0);
483 private void assertDouble(final double actual, final double expected) {
484 assertTrue(Double.compare(actual, expected) == 0);
487 private Distributor getDistributor() throws ContextException {
488 final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributorInit", VERSION);
489 final Distributor distributor = new DistributorFactory().getDistributor(distributorKey);
490 final AxContextModel policyContextModel = getAxContextModel();
491 distributor.registerModel(policyContextModel);