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