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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.context.test.distribution;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.onap.policy.apex.context.test.utils.Constants.APEX_DISTRIBUTOR;
26 import static org.onap.policy.apex.context.test.utils.Constants.VERSION;
28 import org.onap.policy.apex.context.ContextAlbum;
29 import org.onap.policy.apex.context.Distributor;
30 import org.onap.policy.apex.context.impl.distribution.DistributorFactory;
31 import org.onap.policy.apex.context.test.factory.TestContextAlbumFactory;
32 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
34 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
35 import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
36 import org.onap.policy.apex.model.utilities.comparison.KeyedMapComparer;
37 import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference;
38 import org.slf4j.ext.XLogger;
39 import org.slf4j.ext.XLoggerFactory;
42 * The Class ContextAlbumUpdate is used to test Context Album updates.
44 public class ContextAlbumUpdate {
45 private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextAlbumUpdate.class);
48 * Test context album update.
50 * @throws ApexException the apex exception
52 public void testContextAlbumUpdate() throws ApexException {
53 LOGGER.debug("Running TestContextAlbumUpdate test . . .");
55 final AxArtifactKey distributorKey = new AxArtifactKey(APEX_DISTRIBUTOR, VERSION);
56 final Distributor contextDistributor = new DistributorFactory().getDistributor(distributorKey);
58 final AxContextModel longModel = TestContextAlbumFactory.createLongContextModel();
59 contextDistributor.registerModel(longModel);
61 final AxContextAlbum longAlbum1Def = longModel.getAlbums().get(new AxArtifactKey("LongContextAlbum1", VERSION));
62 final ContextAlbum longAlbum1 = contextDistributor.createContextAlbum(longAlbum1Def.getKey());
64 assertNotNull(longAlbum1);
66 final AxContextAlbum longAlbum2Def = longModel.getAlbums().get(new AxArtifactKey("LongContextAlbum2", VERSION));
67 final ContextAlbum longAlbum2 = contextDistributor.createContextAlbum(longAlbum2Def.getKey());
69 assertNotNull(longAlbum2);
71 longAlbum1.put("0", (long) 0);
72 longAlbum1.put("1", (long) 1);
73 longAlbum1.put("2", (long) 2);
74 longAlbum1.put("3", (long) 3);
76 final KeyedMapDifference<String, Object> result0 =
77 new KeyedMapComparer<String, Object>().compareMaps(longAlbum1, longAlbum2);
79 assertEquals(0, result0.getDifferentValues().size());
80 assertEquals(0, result0.getIdenticalValues().size());
81 assertEquals(0, result0.getRightOnly().size());
82 assertEquals(4, result0.getLeftOnly().size());
84 longAlbum2.putAll(longAlbum1);
86 final KeyedMapDifference<String, Object> result1 =
87 new KeyedMapComparer<String, Object>().compareMaps(longAlbum1, longAlbum2);
90 assertEquals(0, result1.getDifferentValues().size());
91 assertEquals(4, result1.getIdenticalValues().size());
92 assertEquals(0, result1.getRightOnly().size());
93 assertEquals(0, result1.getLeftOnly().size());
95 longAlbum1.put("4", (long) 4);
96 longAlbum2.put("5", (long) 5);
97 longAlbum1.put("67", (long) 6);
98 longAlbum2.put("67", (long) 7);
100 final KeyedMapDifference<String, Object> result2 =
101 new KeyedMapComparer<String, Object>().compareMaps(longAlbum1, longAlbum2);
103 assertEquals(1, result2.getDifferentValues().size());
104 assertEquals(4, result2.getIdenticalValues().size());
105 assertEquals(1, result2.getRightOnly().size());
106 assertEquals(1, result2.getLeftOnly().size());
108 longAlbum1.remove("0");
109 longAlbum2.remove("3");
111 final KeyedMapDifference<String, Object> result3 =
112 new KeyedMapComparer<String, Object>().compareMaps(longAlbum1, longAlbum2);
114 assertEquals(1, result3.getDifferentValues().size());
115 assertEquals(2, result3.getIdenticalValues().size());
116 assertEquals(2, result3.getRightOnly().size());
117 assertEquals(2, result3.getLeftOnly().size());
118 contextDistributor.clear();