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.basicmodel.handling.ApexModelException;
35 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
36 import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
37 import org.onap.policy.apex.model.utilities.comparison.KeyedMapComparer;
38 import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference;
39 import org.slf4j.ext.XLogger;
40 import org.slf4j.ext.XLoggerFactory;
43 * The Class ContextAlbumUpdate is used to test Context Album updates.
45 public class ContextAlbumUpdate {
46 private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextAlbumUpdate.class);
49 * Test context album update.
51 * @throws ApexModelException the apex model exception
52 * @throws ApexException the apex exception
54 public void testContextAlbumUpdate() throws ApexException {
55 LOGGER.debug("Running TestContextAlbumUpdate test . . .");
57 final AxArtifactKey distributorKey = new AxArtifactKey(APEX_DISTRIBUTOR, VERSION);
58 final Distributor contextDistributor = new DistributorFactory().getDistributor(distributorKey);
60 final AxContextModel longModel = TestContextAlbumFactory.createLongContextModel();
61 contextDistributor.registerModel(longModel);
63 final AxContextAlbum longAlbum1Def = longModel.getAlbums().get(new AxArtifactKey("LongContextAlbum1", VERSION));
64 final ContextAlbum longAlbum1 = contextDistributor.createContextAlbum(longAlbum1Def.getKey());
66 assertNotNull(longAlbum1);
68 final AxContextAlbum longAlbum2Def = longModel.getAlbums().get(new AxArtifactKey("LongContextAlbum2", VERSION));
69 final ContextAlbum longAlbum2 = contextDistributor.createContextAlbum(longAlbum2Def.getKey());
71 assertNotNull(longAlbum2);
73 longAlbum1.put("0", (long) 0);
74 longAlbum1.put("1", (long) 1);
75 longAlbum1.put("2", (long) 2);
76 longAlbum1.put("3", (long) 3);
78 final KeyedMapDifference<String, Object> result0 =
79 new KeyedMapComparer<String, Object>().compareMaps(longAlbum1, longAlbum2);
81 assertEquals(0, result0.getDifferentValues().size());
82 assertEquals(0, result0.getIdenticalValues().size());
83 assertEquals(0, result0.getRightOnly().size());
84 assertEquals(4, result0.getLeftOnly().size());
86 longAlbum2.putAll(longAlbum1);
88 final KeyedMapDifference<String, Object> result1 =
89 new KeyedMapComparer<String, Object>().compareMaps(longAlbum1, longAlbum2);
92 assertEquals(0, result1.getDifferentValues().size());
93 assertEquals(4, result1.getIdenticalValues().size());
94 assertEquals(0, result1.getRightOnly().size());
95 assertEquals(0, result1.getLeftOnly().size());
97 longAlbum1.put("4", (long) 4);
98 longAlbum2.put("5", (long) 5);
99 longAlbum1.put("67", (long) 6);
100 longAlbum2.put("67", (long) 7);
102 final KeyedMapDifference<String, Object> result2 =
103 new KeyedMapComparer<String, Object>().compareMaps(longAlbum1, longAlbum2);
105 assertEquals(1, result2.getDifferentValues().size());
106 assertEquals(4, result2.getIdenticalValues().size());
107 assertEquals(1, result2.getRightOnly().size());
108 assertEquals(1, result2.getLeftOnly().size());
110 longAlbum1.remove("0");
111 longAlbum2.remove("3");
113 final KeyedMapDifference<String, Object> result3 =
114 new KeyedMapComparer<String, Object>().compareMaps(longAlbum1, longAlbum2);
116 assertEquals(1, result3.getDifferentValues().size());
117 assertEquals(2, result3.getIdenticalValues().size());
118 assertEquals(2, result3.getRightOnly().size());
119 assertEquals(2, result3.getLeftOnly().size());
120 contextDistributor.clear();