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;
30 import org.junit.Test;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
33 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
34 import org.onap.policy.common.utils.resources.TextFileUtils;
36 public class PolicyModelComparerTest {
39 public void testPolicyComparer() throws IOException {
40 final AxPolicyModel leftApexModel = new SupportApexPolicyModelCreator().getModel();
41 final AxPolicyModel rightApexModel = new AxPolicyModel(leftApexModel);
43 PolicyModelComparer policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
45 String resultString = policyModelComparer.asString(false, false);
46 String checkString = TextFileUtils
47 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt");
48 assertEquals(resultString.trim().replaceAll("[\\r?\\n]+", " "),
49 checkString.trim().replaceAll("[\\r?\\n]+", " "));
51 resultString = policyModelComparer.asString(false, true);
52 checkString = TextFileUtils
53 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt");
54 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
55 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
57 resultString = policyModelComparer.asString(true, false);
58 checkString = TextFileUtils
59 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
60 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
61 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
63 resultString = policyModelComparer.asString(true, true);
64 checkString = TextFileUtils
65 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
66 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
67 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
69 final AxKeyInfo leftOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("LeftOnlyKeyInfo", "0.0.1"),
70 UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f000"), "Left only key info");
71 final AxKeyInfo rightOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("RightOnlyKeyInfo", "0.0.1"),
72 UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f001"), "Right only key info");
74 leftApexModel.getKeyInformation().getKeyInfoMap().put(leftOnlyKeyInfo.getKey(), leftOnlyKeyInfo);
75 rightApexModel.getKeyInformation().getKeyInfoMap().put(rightOnlyKeyInfo.getKey(), rightOnlyKeyInfo);
77 leftApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
78 .setDescription("Left InEvent Description");
79 rightApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
80 .setDescription("Right InEvent Description");
82 policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
84 resultString = policyModelComparer.asString(false, false);
85 checkString = TextFileUtils
86 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt");
87 assertEquals(resultString.trim().replaceAll("[\\r?\\n]+", " "),
88 checkString.trim().replaceAll("[\\r?\\n]+", " "));
90 resultString = policyModelComparer.asString(false, true);
91 checkString = TextFileUtils
92 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt");
93 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
94 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
96 resultString = policyModelComparer.asString(true, false);
97 checkString = TextFileUtils
98 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt");
99 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
100 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
102 resultString = policyModelComparer.asString(true, true);
103 checkString = TextFileUtils
104 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt");
105 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
106 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
108 assertNotNull(policyModelComparer.getContextAlbumComparisonResult());
109 assertNotNull(policyModelComparer.getContextAlbumKeyDifference());
110 assertNotNull(policyModelComparer.getContextSchemaComparisonResult());
111 assertNotNull(policyModelComparer.getContextSchemaKeyDifference());
112 assertNotNull(policyModelComparer.getEventComparisonResult());
113 assertNotNull(policyModelComparer.getEventKeyDifference());
114 assertNotNull(policyModelComparer.getKeyInfoComparisonResult());
115 assertNotNull(policyModelComparer.getKeyInformationKeyDifference());
116 assertNotNull(policyModelComparer.getPolicyComparisonResult());
117 assertNotNull(policyModelComparer.getPolicykeyDifference());
118 assertNotNull(policyModelComparer.getPolicyModelsKeyDifference());
119 assertNotNull(policyModelComparer.getTaskComparisonResult());
120 assertNotNull(policyModelComparer.getTaskKeyDifference());
122 assertNotNull(new PolicyComparer().compare(leftApexModel.getPolicies(), rightApexModel.getPolicies()));
124 assertEquals("****** policy map differences ******\n*** context s",
125 policyModelComparer.toString().substring(0, 50));