794cfa9f7229556fac026dad2f83840032d569d1
[policy/apex-pdp.git] /
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  * @author Liam Fallon (liam.fallon@ericsson.com)
37  */
38 public class TestContextComparison {
39     private AxContextModel emptyModel;
40     private AxContextModel fullModel;
41     private AxContextModel noGlobalContextModel;
42     private AxContextModel shellModel;
43     private AxContextModel singleEntryModel;
44
45     @Before
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();
53     }
54     
55     @Test
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()));
60
61         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), emptyModel.getAlbums());
62         assertNotNull(albumResult);
63         assertTrue(emptyModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues()));
64     }
65     
66     @Test
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()));
71
72         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), fullModel.getAlbums());
73         assertNotNull(albumResult);
74         assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
75     }
76     
77     @Test
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()));
82
83         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(fullModel.getAlbums(), emptyModel.getAlbums());
84         assertNotNull(albumResult);
85         assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
86     }
87     
88     @Test
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()));
93
94         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), noGlobalContextModel.getAlbums());
95         assertNotNull(albumResult);
96         assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
97     }
98     
99     @Test
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()));
104
105         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(noGlobalContextModel.getAlbums(), emptyModel.getAlbums());
106         assertNotNull(albumResult);
107         assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
108     }
109     
110     @Test
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()));
115
116         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), shellModel.getAlbums());
117         assertNotNull(albumResult);
118         assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
119     }
120     
121     @Test
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()));
126
127         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(shellModel.getAlbums(), emptyModel.getAlbums());
128         assertNotNull(albumResult);
129         assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
130     }
131     
132     @Test
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()));
137
138         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(emptyModel.getAlbums(), singleEntryModel.getAlbums());
139         assertNotNull(albumResult);
140         assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly()));
141     }
142     
143     @Test
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()));
148
149         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(singleEntryModel.getAlbums(), emptyModel.getAlbums());
150         assertNotNull(albumResult);
151         assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly()));
152     }
153     
154     @Test
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()));
159
160         final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer().compare(fullModel.getAlbums(), fullModel.getAlbums());
161         assertNotNull(albumResult);
162         assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues()));
163     }
164 }