2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.testsuites.integration.context.distribution;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.assertj.core.api.Assertions.assertThatThrownBy;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotNull;
30 import static org.junit.Assert.assertTrue;
31 import static org.onap.policy.apex.testsuites.integration.context.factory.TestContextAlbumFactory.createPolicyContextModel;
32 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.BYTE_VAL;
33 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.EXTERNAL_CONTEXT;
34 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.EXTERNAL_CONTEXT_ALBUM;
35 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.FLOAT_VAL;
36 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.GLOBAL_CONTEXT_ALBUM;
37 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.GLOBAL_CONTEXT_KEY;
38 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.INT_VAL;
39 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.INT_VAL_2;
40 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.INT_VAL_3;
41 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.LONG_VAL;
42 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.PI_VAL;
43 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.POLICY_CONTEXT_ALBUM;
44 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.STRING_EXT_VAL;
45 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.STRING_GLOBAL_VAL;
46 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.STRING_VAL;
47 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.TEST_POLICY_CONTEXT_ITEM;
48 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.TIME_ZONE;
49 import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.VERSION;
51 import java.util.Collection;
52 import java.util.Date;
53 import java.util.HashMap;
54 import java.util.LinkedHashMap;
55 import java.util.Locale;
57 import java.util.Map.Entry;
59 import java.util.TreeSet;
60 import org.onap.policy.apex.context.ContextAlbum;
61 import org.onap.policy.apex.context.ContextException;
62 import org.onap.policy.apex.context.ContextRuntimeException;
63 import org.onap.policy.apex.context.Distributor;
64 import org.onap.policy.apex.context.impl.distribution.DistributorFactory;
65 import org.onap.policy.apex.context.test.concepts.TestContextBooleanItem;
66 import org.onap.policy.apex.context.test.concepts.TestContextByteItem;
67 import org.onap.policy.apex.context.test.concepts.TestContextDateItem;
68 import org.onap.policy.apex.context.test.concepts.TestContextDateLocaleItem;
69 import org.onap.policy.apex.context.test.concepts.TestContextDateTzItem;
70 import org.onap.policy.apex.context.test.concepts.TestContextDoubleItem;
71 import org.onap.policy.apex.context.test.concepts.TestContextFloatItem;
72 import org.onap.policy.apex.context.test.concepts.TestContextIntItem;
73 import org.onap.policy.apex.context.test.concepts.TestContextLongItem;
74 import org.onap.policy.apex.context.test.concepts.TestContextLongObjectItem;
75 import org.onap.policy.apex.context.test.concepts.TestContextStringItem;
76 import org.onap.policy.apex.context.test.concepts.TestContextTreeMapItem;
77 import org.onap.policy.apex.context.test.concepts.TestContextTreeSetItem;
78 import org.onap.policy.apex.context.test.concepts.TestExternalContextItem;
79 import org.onap.policy.apex.context.test.concepts.TestGlobalContextItem;
80 import org.onap.policy.apex.context.test.concepts.TestPolicyContextItem;
81 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
82 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
83 import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
84 import org.onap.policy.apex.testsuites.integration.context.factory.TestContextAlbumFactory;
85 import org.onap.policy.apex.testsuites.integration.context.utils.Constants;
86 import org.slf4j.ext.XLogger;
87 import org.slf4j.ext.XLoggerFactory;
90 * The Class TestContextInstantiation is used to test Apex context insitiation
93 * @author Sergey Sachkov (sergey.sachkov@ericsson.com)
95 public class ContextInstantiation {
96 // Logger for this class
97 private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextInstantiation.class);
99 // Recurring string constants
100 private static final String TEST_POLICY_CONTEXT_ITEM000 = "TestPolicyContextItem000";
101 private static final String TEST_POLICY_CONTEXT_ITEM005 = "TestPolicyContextItem005";
102 private static final String TEST_POLICY_CONTEXT_ITEM004 = "TestPolicyContextItem004";
103 private static final String TEST_POLICY_CONTEXT_ITEM003 = "TestPolicyContextItem003";
104 private static final String TEST_POLICY_CONTEXT_ITEM002 = "TestPolicyContextItem002";
105 private static final String TEST_POLICY_CONTEXT_ITEM001 = "TestPolicyContextItem001";
106 private static final String NULL_ILLEGAL = "album \"ExternalContextAlbum:0.0.1\" null values are illegal on key ";
108 private static final TreeSet<String> TEST_TREE_SET = new TreeSet<>();
109 private static final Map<String, String> TEST_HASH_MAP = new HashMap<>();
112 TEST_TREE_SET.add("one hundred");
113 TEST_TREE_SET.add("one hundred and one");
114 TEST_TREE_SET.add("one hundred and two");
115 TEST_TREE_SET.add("one hundred and three");
116 TEST_TREE_SET.add("one hundred and four");
118 TEST_HASH_MAP.put("0", "zero");
119 TEST_HASH_MAP.put("1", "one");
120 TEST_HASH_MAP.put("2", "two");
121 TEST_HASH_MAP.put("3", "three");
122 TEST_HASH_MAP.put("4", "four");
127 * Test context instantiation.
129 * @throws ContextException the context exception
131 public void testContextInstantiation() throws ContextException {
132 LOGGER.debug("Running TestContextInstantiation test . . .");
134 final Distributor contextDistributor = getDistributor();
136 final ContextAlbum policyContextAlbum = contextDistributor
137 .createContextAlbum(new AxArtifactKey(POLICY_CONTEXT_ALBUM, VERSION));
139 assertNotNull(policyContextAlbum);
140 policyContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
142 final Date testDate = new Date();
144 final TestContextDateTzItem tci9 = getTestContextDateTzItem(testDate);
145 final TestContextDateLocaleItem tciA = getTestContextDateLocaleItem(testDate);
147 final TestPolicyContextItem policyContext = getTestPolicyContextItem(policyContextAlbum, testDate);
149 final Map<String, Object> valueMap0 = new HashMap<>();
150 valueMap0.put(TEST_POLICY_CONTEXT_ITEM, policyContext);
152 policyContextAlbum.putAll(valueMap0);
154 final TestPolicyContextItem contextItem = (TestPolicyContextItem) policyContextAlbum
155 .get(TEST_POLICY_CONTEXT_ITEM);
156 assertEquals(STRING_VAL, contextItem.getTestPolicyContextItem000().getStringValue());
158 assertEquals(LONG_VAL, contextItem.getTestPolicyContextItem001().getLongValue());
159 assertDouble(contextItem.getTestPolicyContextItem002().getDoubleValue(), PI_VAL);
160 assertTrue(contextItem.getTestPolicyContextItem003().isFlag());
161 assertEquals(contextItem.getTestPolicyContextItem004().getLongValue(), testDate.getTime());
162 assertEquals(TEST_HASH_MAP, contextItem.getTestPolicyContextItem005().getMapValue());
164 final TestGlobalContextItem globalContext = getTestGlobalContextItem(contextDistributor, testDate, tci9, tciA);
166 final Map<String, Object> valueMap1 = new HashMap<>();
167 valueMap1.put(GLOBAL_CONTEXT_KEY, globalContext);
169 final ContextAlbum globalContextAlbum = getContextAlbum(contextDistributor);
171 globalContextAlbum.putAll(valueMap1);
173 final TestGlobalContextItem globalContextItem = (TestGlobalContextItem) globalContextAlbum
174 .get(GLOBAL_CONTEXT_KEY);
176 assertFalse(globalContextItem.getTestGlobalContextItem000().isFlag());
178 assertEquals(BYTE_VAL, globalContextItem.getTestGlobalContextItem001().getByteValue());
180 assertEquals(INT_VAL, globalContextItem.getTestGlobalContextItem002().getIntValue());
181 assertEquals(LONG_VAL, globalContextItem.getTestGlobalContextItem003().getLongValue());
182 assertFloat(FLOAT_VAL, globalContextItem.getTestGlobalContextItem004().getFloatValue());
184 assertDouble(PI_VAL, globalContextItem.getTestGlobalContextItem005().getDoubleValue());
185 assertEquals(STRING_GLOBAL_VAL, globalContextItem.getTestGlobalContextItem006().getStringValue());
187 assertEquals((Long) testDate.getTime(), globalContextItem.getTestGlobalContextItem007().getLongValue());
188 assertEquals(testDate, globalContextItem.getTestGlobalContextItem008().getDateValue());
189 assertEquals(tci9.getDateValue().getTime(),
190 globalContextItem.getTestGlobalContextItem009().getDateValue().getTime());
192 assertEquals(tciA.getDateValue().getTime(),
193 globalContextItem.getTestGlobalContextItem00A().getDateValue().getTime());
195 assertEquals(TEST_TREE_SET, globalContextItem.getTestGlobalContextItem00B().getSetValue());
196 assertEquals(TEST_HASH_MAP, globalContextItem.getTestGlobalContextItem00C().getMapValue());
198 final AxContextModel externalContextModel = TestContextAlbumFactory.createExternalContextModel();
200 final TestContextDateTzItem tci9A = new TestContextDateTzItem(tci9);
201 final TestContextDateLocaleItem tciAa = new TestContextDateLocaleItem(tciA);
202 final TestExternalContextItem externalContext = getTestExternalContextItem(testDate, tci9A, tciAa);
204 final Map<String, Object> valueMap2 = new HashMap<>();
205 valueMap2.put(EXTERNAL_CONTEXT, externalContext);
207 contextDistributor.clear();
208 contextDistributor.init(new AxArtifactKey("ClearedandInittedDistributor", VERSION));
209 contextDistributor.registerModel(externalContextModel);
211 final AxArtifactKey axContextAlbumKey = new AxArtifactKey(EXTERNAL_CONTEXT_ALBUM, VERSION);
212 final ContextAlbum externalContextAlbum = contextDistributor.createContextAlbum(axContextAlbumKey);
213 assertNotNull(externalContextAlbum);
214 externalContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
216 externalContextAlbum.putAll(valueMap2);
217 externalContextAlbum.getAlbumDefinition().setWritable(false);
219 TestExternalContextItem externalContextItem = (TestExternalContextItem) externalContextAlbum
220 .get(EXTERNAL_CONTEXT);
222 assertFalse(externalContextItem.getTestExternalContextItem000().isFlag());
223 assertEquals(BYTE_VAL, externalContextItem.getTestExternalContextItem001().getByteValue());
224 assertEquals(INT_VAL, externalContextItem.getTestExternalContextItem002().getIntValue());
226 assertFloat(LONG_VAL, externalContextItem.getTestExternalContextItem003().getLongValue());
227 assertFloat(FLOAT_VAL, externalContextItem.getTestExternalContextItem004().getFloatValue());
229 assertDouble(PI_VAL, externalContextItem.getTestExternalContextItem005().getDoubleValue());
230 assertEquals(STRING_EXT_VAL, externalContextItem.getTestExternalContextItem006().getStringValue());
231 assertEquals((Long) testDate.getTime(), externalContextItem.getTestExternalContextItem007().getLongValue());
232 assertEquals(testDate, externalContextItem.getTestExternalContextItem008().getDateValue());
233 assertEquals(tci9A.getDateValue().getTime(),
234 externalContextItem.getTestExternalContextItem009().getDateValue().getTime());
236 assertEquals(tciAa.getDateValue().getTime(),
237 externalContextItem.getTestExternalContextItem00A().getDateValue().getTime());
238 assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue());
239 assertEquals(TEST_HASH_MAP, externalContextItem.getTestExternalContextItem00C().getMapValue());
241 final Collection<Object> mapValues = externalContextAlbum.values();
242 assertTrue(externalContextAlbum.values().containsAll(mapValues));
244 // Check that clearing does not work
245 assertThatThrownBy(() -> externalContextAlbum.clear()).isInstanceOf(ContextRuntimeException.class)
246 .hasMessageContaining("album \"ExternalContextAlbum:0.0.1\" clear() not allowed on read only albums");
247 assertEquals(1, externalContextAlbum.size());
249 assertContextAlbumContains(externalContext, externalContextAlbum);
251 final Set<Entry<String, Object>> entrySet = externalContextAlbum.entrySet();
252 assertEquals(1, entrySet.size());
254 assertThatThrownBy(() -> externalContextAlbum.get(null)).isInstanceOf(ContextRuntimeException.class)
255 .hasMessageContaining("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for get()");
256 final Object aObject = externalContextAlbum.get(EXTERNAL_CONTEXT);
257 assertEquals(aObject, externalContext);
259 // put null keys should fail, throws a runtime exception
260 assertThatThrownBy(() -> externalContextAlbum.put(null, null))
261 .hasMessageContaining("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for put()");
262 assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItem00A", null))
263 .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItem00A\" for put()");
264 assertEquals(tciAa, externalContextItem.getTestExternalContextItem00A());
266 // Should return the hash set
267 assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue());
269 assertTrue(externalContextAlbum.values().containsAll(mapValues));
271 // Set the write flag back as it should be
272 externalContextAlbum.getAlbumDefinition().setWritable(true);
274 // Put should return the previous contextItem
275 final TestExternalContextItem externalContextOther = new TestExternalContextItem();
276 externalContextOther.setTestExternalContextItem002(new TestContextIntItem());
277 externalContextOther.getTestExternalContextItem002().setIntValue(INT_VAL_2);
279 assertThat(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContextOther)).isEqualTo(externalContext);
280 externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT);
281 assertEquals(INT_VAL_2, externalContextItem.getTestExternalContextItem002().getIntValue());
282 assertThat(externalContextAlbum.put(EXTERNAL_CONTEXT, externalContext)).isEqualTo(externalContextOther);
283 externalContextItem = (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT);
284 assertEquals(INT_VAL_3, externalContextItem.getTestExternalContextItem002().getIntValue());
285 assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItem00A", null))
286 .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItem00A\" for put()");
288 assertThat(externalContextAlbum.get(EXTERNAL_CONTEXT)).isEqualTo(externalContext);
290 assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItemFFF", null))
291 .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItemFFF\" for put()");
292 assertEquals(1, externalContextAlbum.size());
294 assertThatThrownBy(() -> externalContextAlbum.put("TestExternalContextItemFFF", null))
295 .hasMessageContaining(NULL_ILLEGAL + "\"TestExternalContextItemFFF\" for put()");
296 assertEquals(1, externalContextAlbum.size());
298 // Should ignore remove
299 externalContextAlbum.remove("TestExternalContextItem017");
300 assertEquals(1, externalContextAlbum.size());
301 assertEquals(1, externalContextAlbum.values().size());
302 assertTrue(externalContextAlbum.values().containsAll(mapValues));
304 contextDistributor.clear();
307 private void assertContextAlbumContains(final TestExternalContextItem externalContext,
308 final ContextAlbum externalContextAlbum) {
309 assertThatThrownBy(() -> externalContextAlbum.containsKey(null))
310 .hasMessageContaining("null values are illegal on method parameter \"key\"");
311 assertTrue(externalContextAlbum.containsKey(EXTERNAL_CONTEXT));
312 assertTrue(!externalContextAlbum.containsKey(GLOBAL_CONTEXT_KEY));
314 assertThatThrownBy(() -> externalContextAlbum.containsValue(null))
315 .hasMessageContaining("null values are illegal on method parameter \"value\"");
316 assertTrue(externalContextAlbum.containsValue(externalContext));
317 assertFalse(externalContextAlbum.containsValue("Hello"));
320 private ContextAlbum getContextAlbum(final Distributor contextDistributor) throws ContextException {
321 final ContextAlbum globalContextAlbum = contextDistributor
322 .createContextAlbum(new AxArtifactKey(GLOBAL_CONTEXT_ALBUM, VERSION));
323 assertNotNull(globalContextAlbum);
324 globalContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray());
325 return globalContextAlbum;
328 private TestGlobalContextItem getTestGlobalContextItem(final Distributor contextDistributor, final Date testDate,
329 final TestContextDateTzItem tci9, final TestContextDateLocaleItem tciA) throws ContextException {
330 final AxContextModel globalContextModel = TestContextAlbumFactory.createGlobalContextModel();
331 final TestGlobalContextItem globalContext = getTestGlobalContextItem(testDate, tci9, tciA);
332 contextDistributor.registerModel(globalContextModel);
333 return globalContext;
336 private TestGlobalContextItem getTestGlobalContextItem(final Date testDate, final TestContextDateTzItem tci9,
337 final TestContextDateLocaleItem tciA) {
338 final TestGlobalContextItem globalContext = new TestGlobalContextItem();
340 final TestContextBooleanItem testGlobalContextItem000 = new TestContextBooleanItem(false);
341 final TestContextByteItem testGlobalContextItem001 = new TestContextByteItem(BYTE_VAL);
342 final TestContextIntItem testGlobalContextItem002 = new TestContextIntItem(INT_VAL);
343 final TestContextLongItem testGlobalContextItem003 = new TestContextLongItem(LONG_VAL);
344 final TestContextFloatItem testGlobalContextItem004 = new TestContextFloatItem(FLOAT_VAL);
345 final TestContextDoubleItem testGlobalContextItem005 = new TestContextDoubleItem(PI_VAL);
346 final TestContextStringItem testGlobalContextItem006 = new TestContextStringItem(STRING_GLOBAL_VAL);
347 final TestContextLongObjectItem testGlobalContextItem007 = new TestContextLongObjectItem(testDate.getTime());
349 final TestContextDateItem testGlobalContextItem008 = new TestContextDateItem(testDate);
350 final TestContextTreeSetItem testGlobalContextItem00B = new TestContextTreeSetItem(TEST_TREE_SET);
351 final TestContextTreeMapItem testGlobalContextItem00C = new TestContextTreeMapItem(TEST_HASH_MAP);
353 globalContext.setTestGlobalContextItem000(testGlobalContextItem000);
354 globalContext.setTestGlobalContextItem001(testGlobalContextItem001);
355 globalContext.setTestGlobalContextItem002(testGlobalContextItem002);
356 globalContext.setTestGlobalContextItem003(testGlobalContextItem003);
357 globalContext.setTestGlobalContextItem004(testGlobalContextItem004);
358 globalContext.setTestGlobalContextItem005(testGlobalContextItem005);
359 globalContext.setTestGlobalContextItem006(testGlobalContextItem006);
360 globalContext.setTestGlobalContextItem007(testGlobalContextItem007);
361 globalContext.setTestGlobalContextItem008(testGlobalContextItem008);
362 globalContext.setTestGlobalContextItem009(tci9);
363 globalContext.setTestGlobalContextItem00A(tciA);
364 globalContext.setTestGlobalContextItem00B(testGlobalContextItem00B);
365 globalContext.setTestGlobalContextItem00C(testGlobalContextItem00C);
366 return globalContext;
369 private TestPolicyContextItem getTestPolicyContextItem(final ContextAlbum policyContextAlbum, final Date testDate) {
370 final TestContextStringItem contextStringItem = new TestContextStringItem(STRING_VAL);
371 final TestContextLongItem contextLongItem = new TestContextLongItem(LONG_VAL);
372 final TestContextDoubleItem contextDoubleItem = new TestContextDoubleItem(PI_VAL);
373 final TestContextBooleanItem contextBooleanItem = new TestContextBooleanItem(true);
374 final TestContextLongItem contextLongItem2 = new TestContextLongItem(testDate.getTime());
375 final TestContextTreeMapItem contextTreeMapItem = new TestContextTreeMapItem(TEST_HASH_MAP);
377 final Map<String, Object> valueMapA = new LinkedHashMap<>();
378 valueMapA.put(TEST_POLICY_CONTEXT_ITEM001, contextLongItem);
379 valueMapA.put(TEST_POLICY_CONTEXT_ITEM002, contextDoubleItem);
380 valueMapA.put(TEST_POLICY_CONTEXT_ITEM003, contextBooleanItem);
381 valueMapA.put(TEST_POLICY_CONTEXT_ITEM004, contextLongItem2);
382 valueMapA.put(TEST_POLICY_CONTEXT_ITEM005, contextTreeMapItem);
383 valueMapA.put(TEST_POLICY_CONTEXT_ITEM000, contextStringItem);
385 assertPutMethods(policyContextAlbum, contextStringItem, valueMapA);
387 final TestPolicyContextItem policyContext = new TestPolicyContextItem();
389 LOGGER.debug(policyContextAlbum.toString());
391 policyContext.setTestPolicyContextItem000(contextStringItem);
392 policyContext.setTestPolicyContextItem001(contextLongItem);
393 policyContext.setTestPolicyContextItem002(contextDoubleItem);
394 policyContext.setTestPolicyContextItem003(contextBooleanItem);
395 policyContext.setTestPolicyContextItem004(contextLongItem2);
396 policyContext.setTestPolicyContextItem005(contextTreeMapItem);
397 return policyContext;
400 private void assertPutMethods(final ContextAlbum policyContextAlbum, final TestContextStringItem contextStringItem,
401 final Map<String, Object> valueMapA) {
402 assertThatThrownBy(() -> policyContextAlbum.put(TEST_POLICY_CONTEXT_ITEM000, contextStringItem))
403 .hasMessageContaining(getMessage(TEST_POLICY_CONTEXT_ITEM000, "TestContextItem006",
404 TestContextStringItem.class.getName(), "stringValue=" + STRING_VAL));
405 assertThatThrownBy(() -> policyContextAlbum.putAll(valueMapA))
406 .hasMessageContaining(getMessage(TEST_POLICY_CONTEXT_ITEM001, "TestContextItem003",
407 TestContextLongItem.class.getName(), "longValue=" + INT_VAL_3));
410 private AxContextModel getAxContextModel() {
411 final AxContextModel policyContextModel = createPolicyContextModel();
412 final AxValidationResult result = new AxValidationResult();
413 policyContextModel.validate(result);
414 LOGGER.debug(result.toString());
416 assertTrue(result.isValid());
417 return policyContextModel;
420 private TestContextDateLocaleItem getTestContextDateLocaleItem(final Date testDate) {
421 final TestContextDateLocaleItem tciA = new TestContextDateLocaleItem();
422 tciA.setDateValue(new TestContextDateItem(testDate));
423 tciA.setTzValue(TIME_ZONE.getDisplayName());
425 tciA.setUtcOffset(-600);
426 tciA.setLocale(Locale.ENGLISH);
430 private TestContextDateTzItem getTestContextDateTzItem(final Date testDate) {
431 final TestContextDateTzItem tci9 = new TestContextDateTzItem();
432 tci9.setDateValue(new TestContextDateItem(testDate));
433 tci9.setTzValue(TIME_ZONE.getDisplayName());
438 private TestExternalContextItem getTestExternalContextItem(final Date testDate, final TestContextDateTzItem tci9A,
439 final TestContextDateLocaleItem tciAa) {
440 final TestExternalContextItem externalContext = new TestExternalContextItem();
442 final TestContextBooleanItem testExternalContextItem000 = new TestContextBooleanItem(false);
443 final TestContextByteItem testExternalContextItem001 = new TestContextByteItem(BYTE_VAL);
444 final TestContextIntItem testExternalContextItem002 = new TestContextIntItem(INT_VAL);
445 final TestContextLongItem testExternalContextItem003 = new TestContextLongItem(LONG_VAL);
446 final TestContextFloatItem testExternalContextItem004 = new TestContextFloatItem(3.14159265359F);
447 final TestContextDoubleItem testExternalContextItem005 = new TestContextDoubleItem(PI_VAL);
448 final TestContextStringItem testExternalContextItem006 = new TestContextStringItem(STRING_EXT_VAL);
449 final TestContextLongObjectItem testExternalContextItem007 = new TestContextLongObjectItem(testDate.getTime());
450 final TestContextDateItem testExternalContextItem008 = new TestContextDateItem(testDate);
451 final TestContextTreeSetItem testExternalContextItem00B = new TestContextTreeSetItem(TEST_TREE_SET);
452 final TestContextTreeMapItem testExternalContextItem00C = new TestContextTreeMapItem(TEST_HASH_MAP);
454 externalContext.setTestExternalContextItem000(testExternalContextItem000);
455 externalContext.setTestExternalContextItem001(testExternalContextItem001);
456 externalContext.setTestExternalContextItem002(testExternalContextItem002);
457 externalContext.setTestExternalContextItem003(testExternalContextItem003);
458 externalContext.setTestExternalContextItem004(testExternalContextItem004);
459 externalContext.setTestExternalContextItem005(testExternalContextItem005);
460 externalContext.setTestExternalContextItem006(testExternalContextItem006);
461 externalContext.setTestExternalContextItem007(testExternalContextItem007);
462 externalContext.setTestExternalContextItem008(testExternalContextItem008);
463 externalContext.setTestExternalContextItem009(tci9A);
464 externalContext.setTestExternalContextItem00A(tciAa);
465 externalContext.setTestExternalContextItem00B(testExternalContextItem00B);
466 externalContext.setTestExternalContextItem00C(testExternalContextItem00C);
467 return externalContext;
470 private String getMessage(final String key, final String objName, final String clazzName, final String valString) {
471 return getMessage(key, objName, clazzName, valString, TestPolicyContextItem.class.getName());
474 private String getMessage(final String key, final String objName, final String clazzName, final String valString,
475 final String compatibleClazzName) {
476 return "Failed to set context value for key \"" + key + "\" in album \"PolicyContextAlbum:0.0.1\": "
477 + "PolicyContextAlbum:0.0.1: object \"" + objName + " [" + valString + "]\" " + "of class \"" + clazzName
478 + "\"" + " not compatible with class \"" + compatibleClazzName + "\"";
481 private void assertFloat(final float actual, final float expected) {
482 assertThat(actual).isEqualTo(expected);
485 private void assertDouble(final double actual, final double expected) {
486 assertThat(actual).isEqualTo(expected);
489 private Distributor getDistributor() throws ContextException {
490 final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributorInit", VERSION);
491 final Distributor distributor = new DistributorFactory().getDistributor(distributorKey);
492 final AxContextModel policyContextModel = getAxContextModel();
493 distributor.registerModel(policyContextModel);