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  * Test context comparisons.
 
  38  * @author Liam Fallon (liam.fallon@ericsson.com)
 
  40 public class ContextComparisonTest {
 
  41     private AxContextModel emptyModel;
 
  42     private AxContextModel fullModel;
 
  43     private AxContextModel noGlobalContextModel;
 
  44     private AxContextModel shellModel;
 
  45     private AxContextModel singleEntryModel;
 
  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();
 
  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()));
 
  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()));
 
  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()));
 
  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()));
 
  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()));
 
  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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));
 
 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()));