81609cacf4f71a33141de2a15008f4f158ad3add
[policy/apex-pdp.git] / model / context-model / src / test / java / org / onap / policy / apex / model / contextmodel / handling / ContextComparisonTest.java
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.contextmodel.handling;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25
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;
34
35 /**
36  * Test context comparisons.
37  * 
38  * @author Liam Fallon (liam.fallon@ericsson.com)
39  */
40 public class ContextComparisonTest {
41     private AxContextModel emptyModel;
42     private AxContextModel fullModel;
43     private AxContextModel noGlobalContextModel;
44     private AxContextModel shellModel;
45     private AxContextModel singleEntryModel;
46
47     /**
48      * Set up tests.
49      */
50     @Before
51     public void getContext() {
52         final TestContextComparisonFactory factory = new TestContextComparisonFactory();
53         emptyModel = factory.getEmptyModel();
54         fullModel = factory.getFullModel();
55         noGlobalContextModel = factory.getNoGlobalContextModel();
56         shellModel = factory.getShellModel();
57         singleEntryModel = factory.getSingleEntryModel();
58     }
59
60     @Test
61     public void testEmptyEmpty() {
62         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
63                         .compare(emptyModel.getSchemas(), emptyModel.getSchemas());
64         assertNotNull(schemaResult);
65         assertTrue(emptyModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues()));
66
67         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
68                         .compare(emptyModel.getAlbums(), emptyModel.getAlbums());
69         assertNotNull(albumResult);
70         assertTrue(emptyModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues()));
71     }
72
73     @Test
74     public void testEmptyFull() {
75         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
76                         .compare(emptyModel.getSchemas(), fullModel.getSchemas());
77         assertNotNull(schemaResult);
78         assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly()));
79
80         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
81                         .compare(emptyModel.getAlbums(), fullModel.getAlbums());
82         assertNotNull(albumResult);
83         assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
84     }
85
86     @Test
87     public void testFullEmpty() {
88         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
89                         .compare(fullModel.getSchemas(), emptyModel.getSchemas());
90         assertNotNull(schemaResult);
91         assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly()));
92
93         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
94                         .compare(fullModel.getAlbums(), emptyModel.getAlbums());
95         assertNotNull(albumResult);
96         assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
97     }
98
99     @Test
100     public void testEmptyNoGlobalContext() {
101         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
102                         .compare(emptyModel.getSchemas(), noGlobalContextModel.getSchemas());
103         assertNotNull(schemaResult);
104         assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly()));
105
106         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
107                         .compare(emptyModel.getAlbums(), noGlobalContextModel.getAlbums());
108         assertNotNull(albumResult);
109         assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
110     }
111
112     @Test
113     public void testNoGlobalContextEmpty() {
114         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
115                         .compare(noGlobalContextModel.getSchemas(), emptyModel.getSchemas());
116         assertNotNull(schemaResult);
117         assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly()));
118
119         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
120                         .compare(noGlobalContextModel.getAlbums(), emptyModel.getAlbums());
121         assertNotNull(albumResult);
122         assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
123     }
124
125     @Test
126     public void testEmptyShell() {
127         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
128                         .compare(emptyModel.getSchemas(), shellModel.getSchemas());
129         assertNotNull(schemaResult);
130         assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly()));
131
132         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
133                         .compare(emptyModel.getAlbums(), shellModel.getAlbums());
134         assertNotNull(albumResult);
135         assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
136     }
137
138     @Test
139     public void testShellEmpty() {
140         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
141                         .compare(shellModel.getSchemas(), emptyModel.getSchemas());
142         assertNotNull(schemaResult);
143         assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly()));
144
145         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
146                         .compare(shellModel.getAlbums(), emptyModel.getAlbums());
147         assertNotNull(albumResult);
148         assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
149     }
150
151     @Test
152     public void testEmptySingleEntry() {
153         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
154                         .compare(emptyModel.getSchemas(), singleEntryModel.getSchemas());
155         assertNotNull(schemaResult);
156         assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly()));
157
158         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
159                         .compare(emptyModel.getAlbums(), singleEntryModel.getAlbums());
160         assertNotNull(albumResult);
161         assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
162     }
163
164     @Test
165     public void testSingleEntryEmpty() {
166         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
167                         .compare(singleEntryModel.getSchemas(), emptyModel.getSchemas());
168         assertNotNull(schemaResult);
169         assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly()));
170
171         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
172                         .compare(singleEntryModel.getAlbums(), emptyModel.getAlbums());
173         assertNotNull(albumResult);
174         assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
175     }
176
177     @Test
178     public void testFullFull() {
179         final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
180                         .compare(fullModel.getSchemas(), fullModel.getSchemas());
181         assertNotNull(schemaResult);
182         assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues()));
183
184         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
185                         .compare(fullModel.getAlbums(), fullModel.getAlbums());
186         assertNotNull(albumResult);
187         assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues()));
188     }
189 }