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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.policymodel.handling;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
28 import java.io.IOException;
29 import java.util.UUID;
31 import org.junit.Test;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
34 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
35 import org.onap.policy.common.utils.resources.TextFileUtils;
37 public class PolicyModelComparerTest {
40 public void testPolicyComparer() throws IOException {
41 final AxPolicyModel leftApexModel = new SupportApexPolicyModelCreator().getModel();
42 final AxPolicyModel rightApexModel = new AxPolicyModel(leftApexModel);
44 PolicyModelComparer policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
46 String resultString = policyModelComparer.asString(false, false);
47 String checkString = TextFileUtils
48 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt");
49 assertEquals(resultString.trim().replaceAll("[\\r?\\n]+", " "),
50 checkString.trim().replaceAll("[\\r?\\n]+", " "));
52 resultString = policyModelComparer.asString(false, true);
53 checkString = TextFileUtils
54 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt");
55 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
56 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
58 resultString = policyModelComparer.asString(true, false);
59 checkString = TextFileUtils
60 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
61 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
62 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
64 resultString = policyModelComparer.asString(true, true);
65 checkString = TextFileUtils
66 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
67 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
68 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
70 final AxKeyInfo leftOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("LeftOnlyKeyInfo", "0.0.1"),
71 UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f000"), "Left only key info");
72 final AxKeyInfo rightOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("RightOnlyKeyInfo", "0.0.1"),
73 UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f001"), "Right only key info");
75 leftApexModel.getKeyInformation().getKeyInfoMap().put(leftOnlyKeyInfo.getKey(), leftOnlyKeyInfo);
76 rightApexModel.getKeyInformation().getKeyInfoMap().put(rightOnlyKeyInfo.getKey(), rightOnlyKeyInfo);
78 leftApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
79 .setDescription("Left InEvent Description");
80 rightApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
81 .setDescription("Right InEvent Description");
83 policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
85 resultString = policyModelComparer.asString(false, false);
86 checkString = TextFileUtils
87 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt");
88 assertEquals(resultString.trim().replaceAll("[\\r?\\n]+", " "),
89 checkString.trim().replaceAll("[\\r?\\n]+", " "));
91 resultString = policyModelComparer.asString(false, true);
92 checkString = TextFileUtils
93 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt");
94 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
95 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
97 resultString = policyModelComparer.asString(true, false);
98 checkString = TextFileUtils
99 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt");
100 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
101 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
103 resultString = policyModelComparer.asString(true, true);
104 checkString = TextFileUtils
105 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt");
106 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
107 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
109 assertNotNull(policyModelComparer.getContextAlbumComparisonResult());
110 assertNotNull(policyModelComparer.getContextAlbumKeyDifference());
111 assertNotNull(policyModelComparer.getContextSchemaComparisonResult());
112 assertNotNull(policyModelComparer.getContextSchemaKeyDifference());
113 assertNotNull(policyModelComparer.getEventComparisonResult());
114 assertNotNull(policyModelComparer.getEventKeyDifference());
115 assertNotNull(policyModelComparer.getKeyInfoComparisonResult());
116 assertNotNull(policyModelComparer.getKeyInformationKeyDifference());
117 assertNotNull(policyModelComparer.getPolicyComparisonResult());
118 assertNotNull(policyModelComparer.getPolicykeyDifference());
119 assertNotNull(policyModelComparer.getPolicyModelsKeyDifference());
120 assertNotNull(policyModelComparer.getTaskComparisonResult());
121 assertNotNull(policyModelComparer.getTaskKeyDifference());
123 assertNotNull(new PolicyComparer().compare(leftApexModel.getPolicies(), rightApexModel.getPolicies()));
125 assertEquals("****** policy map differences ******\n*** context s",
126 policyModelComparer.toString().substring(0, 50));