483bc366169ecf8bd9e2b451cd1055ae61fe7149
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.contextmodel.handling;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
30 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
31 import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
32 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
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         assertEquals(emptyModel.getSchemas().getSchemasMap(), schemaResult.getIdenticalValues());
66
67         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
68                         .compare(emptyModel.getAlbums(), emptyModel.getAlbums());
69         assertNotNull(albumResult);
70         assertEquals(emptyModel.getAlbums().getAlbumsMap(), 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         assertEquals(fullModel.getSchemas().getSchemasMap(), schemaResult.getRightOnly());
79
80         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
81                         .compare(emptyModel.getAlbums(), fullModel.getAlbums());
82         assertNotNull(albumResult);
83         assertEquals(fullModel.getAlbums().getAlbumsMap(), 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         assertEquals(fullModel.getSchemas().getSchemasMap(), schemaResult.getLeftOnly());
92
93         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
94                         .compare(fullModel.getAlbums(), emptyModel.getAlbums());
95         assertNotNull(albumResult);
96         assertEquals(fullModel.getAlbums().getAlbumsMap(), 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         assertEquals(noGlobalContextModel.getSchemas().getSchemasMap(), schemaResult.getRightOnly());
105
106         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
107                         .compare(emptyModel.getAlbums(), noGlobalContextModel.getAlbums());
108         assertNotNull(albumResult);
109         assertEquals(noGlobalContextModel.getAlbums().getAlbumsMap(), 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         assertEquals(noGlobalContextModel.getSchemas().getSchemasMap(), schemaResult.getLeftOnly());
118
119         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
120                         .compare(noGlobalContextModel.getAlbums(), emptyModel.getAlbums());
121         assertNotNull(albumResult);
122         assertEquals(noGlobalContextModel.getAlbums().getAlbumsMap(), 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         assertEquals(shellModel.getSchemas().getSchemasMap(), schemaResult.getRightOnly());
131
132         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
133                         .compare(emptyModel.getAlbums(), shellModel.getAlbums());
134         assertNotNull(albumResult);
135         assertEquals(shellModel.getAlbums().getAlbumsMap(), 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         assertEquals(shellModel.getSchemas().getSchemasMap(), schemaResult.getLeftOnly());
144
145         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
146                         .compare(shellModel.getAlbums(), emptyModel.getAlbums());
147         assertNotNull(albumResult);
148         assertEquals(shellModel.getAlbums().getAlbumsMap(), 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         assertEquals(singleEntryModel.getSchemas().getSchemasMap(), schemaResult.getRightOnly());
157
158         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
159                         .compare(emptyModel.getAlbums(), singleEntryModel.getAlbums());
160         assertNotNull(albumResult);
161         assertEquals(singleEntryModel.getAlbums().getAlbumsMap(), 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         assertEquals(singleEntryModel.getSchemas().getSchemasMap(), schemaResult.getLeftOnly());
170
171         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
172                         .compare(singleEntryModel.getAlbums(), emptyModel.getAlbums());
173         assertNotNull(albumResult);
174         assertEquals(singleEntryModel.getAlbums().getAlbumsMap(), 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         assertEquals(fullModel.getSchemas().getSchemasMap(), schemaResult.getIdenticalValues());
183
184         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
185                         .compare(fullModel.getAlbums(), fullModel.getAlbums());
186         assertNotNull(albumResult);
187         assertEquals(fullModel.getAlbums().getAlbumsMap(), albumResult.getIdenticalValues());
188     }
189 }