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.model.contextmodel.handling;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
29 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
30 import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
31 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
32 import org.onap.policy.apex.model.contextmodel.handling.ContextComparer;
33 import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference;
36 * @author Liam Fallon (liam.fallon@ericsson.com)
38 public class TestContextComparison {
39 private AxContextModel emptyModel;
40 private AxContextModel fullModel;
41 private AxContextModel noGlobalContextModel;
42 private AxContextModel shellModel;
43 private AxContextModel singleEntryModel;
46 public void getContext() {
47 final TestContextComparisonFactory factory = new TestContextComparisonFactory();
48 emptyModel = factory.getEmptyModel();
49 fullModel = factory.getFullModel();
50 noGlobalContextModel = factory.getNoGlobalContextModel();
51 shellModel = factory.getShellModel();
52 singleEntryModel = factory.getSingleEntryModel();
56 public void testEmptyEmpty() {
57 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(emptyModel.getSchemas(), emptyModel.getSchemas());
58 assertNotNull(schemaResult);
59 assertTrue(emptyModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues()));
61 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), emptyModel.getAlbums());
62 assertNotNull(albumResult);
63 assertTrue(emptyModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues()));
67 public void testEmptyFull() {
68 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(emptyModel.getSchemas(), fullModel.getSchemas());
69 assertNotNull(schemaResult);
70 assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly()));
72 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), fullModel.getAlbums());
73 assertNotNull(albumResult);
74 assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
78 public void testFullEmpty() {
79 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(fullModel.getSchemas(), emptyModel.getSchemas());
80 assertNotNull(schemaResult);
81 assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly()));
83 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(fullModel.getAlbums(), emptyModel.getAlbums());
84 assertNotNull(albumResult);
85 assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
89 public void testEmptyNoGlobalContext() {
90 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(emptyModel.getSchemas(), noGlobalContextModel.getSchemas());
91 assertNotNull(schemaResult);
92 assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly()));
94 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), noGlobalContextModel.getAlbums());
95 assertNotNull(albumResult);
96 assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
100 public void testNoGlobalContextEmpty() {
101 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(noGlobalContextModel.getSchemas(), emptyModel.getSchemas());
102 assertNotNull(schemaResult);
103 assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly()));
105 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(noGlobalContextModel.getAlbums(), emptyModel.getAlbums());
106 assertNotNull(albumResult);
107 assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
111 public void testEmptyShell() {
112 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(emptyModel.getSchemas(), shellModel.getSchemas());
113 assertNotNull(schemaResult);
114 assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly()));
116 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), shellModel.getAlbums());
117 assertNotNull(albumResult);
118 assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
122 public void testShellEmpty() {
123 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(shellModel.getSchemas(), emptyModel.getSchemas());
124 assertNotNull(schemaResult);
125 assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly()));
127 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(shellModel.getAlbums(), emptyModel.getAlbums());
128 assertNotNull(albumResult);
129 assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
133 public void testEmptySingleEntry() {
134 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(emptyModel.getSchemas(), singleEntryModel.getSchemas());
135 assertNotNull(schemaResult);
136 assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly()));
138 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), singleEntryModel.getAlbums());
139 assertNotNull(albumResult);
140 assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
144 public void testSingleEntryEmpty() {
145 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(singleEntryModel.getSchemas(), emptyModel.getSchemas());
146 assertNotNull(schemaResult);
147 assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly()));
149 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(singleEntryModel.getAlbums(), emptyModel.getAlbums());
150 assertNotNull(albumResult);
151 assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
155 public void testFullFull() {
156 final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer().compare(fullModel.getSchemas(), fullModel.getSchemas());
157 assertNotNull(schemaResult);
158 assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues()));
160 final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(fullModel.getAlbums(), fullModel.getAlbums());
161 assertNotNull(albumResult);
162 assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues()));