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;
27 import java.io.IOException;
28 import java.util.UUID;
29 import org.junit.Test;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
32 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
33 import org.onap.policy.common.utils.resources.TextFileUtils;
35 public class PolicyModelComparerTest {
38 public void testPolicyComparer() throws IOException {
39 final AxPolicyModel leftApexModel = new SupportApexPolicyModelCreator().getModel();
40 final AxPolicyModel rightApexModel = new AxPolicyModel(leftApexModel);
42 PolicyModelComparer policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
44 String resultString = policyModelComparer.asString(false, false);
45 String checkString = TextFileUtils
46 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt");
47 assertEquals(resultString.trim().replaceAll("\\s+", ""),
48 checkString.trim().replaceAll("\\s+", ""));
50 resultString = policyModelComparer.asString(false, true);
51 checkString = TextFileUtils
52 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt");
53 assertEquals(checkString.trim().replaceAll("\\s+", ""),
54 resultString.trim().replaceAll("\\s+", ""));
56 resultString = policyModelComparer.asString(true, false);
57 checkString = TextFileUtils
58 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
59 assertEquals(checkString.trim().replaceAll("\\s+", ""),
60 resultString.trim().replaceAll("\\s+", ""));
62 resultString = policyModelComparer.asString(true, true);
63 checkString = TextFileUtils
64 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
65 assertEquals(checkString.trim().replaceAll("\\s+", ""),
66 resultString.trim().replaceAll("\\s+", ""));
68 final AxKeyInfo leftOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("LeftOnlyKeyInfo", "0.0.1"),
69 UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f000"), "Left only key info");
70 final AxKeyInfo rightOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("RightOnlyKeyInfo", "0.0.1"),
71 UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f001"), "Right only key info");
73 leftApexModel.getKeyInformation().getKeyInfoMap().put(leftOnlyKeyInfo.getKey(), leftOnlyKeyInfo);
74 rightApexModel.getKeyInformation().getKeyInfoMap().put(rightOnlyKeyInfo.getKey(), rightOnlyKeyInfo);
76 leftApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
77 .setDescription("Left InEvent Description");
78 rightApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
79 .setDescription("Right InEvent Description");
81 policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
83 resultString = policyModelComparer.asString(false, false);
84 checkString = TextFileUtils
85 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt");
86 assertEquals(resultString.trim().replaceAll("\\s+", ""),
87 checkString.trim().replaceAll("\\s+", ""));
89 resultString = policyModelComparer.asString(false, true);
90 checkString = TextFileUtils
91 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt");
92 assertEquals(checkString.trim().replaceAll("\\s+", ""),
93 resultString.trim().replaceAll("\\s+", ""));
95 resultString = policyModelComparer.asString(true, false);
96 checkString = TextFileUtils
97 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt");
98 assertEquals(checkString.trim().replaceAll("\\s+", ""),
99 resultString.trim().replaceAll("\\s+", ""));
101 resultString = policyModelComparer.asString(true, true);
102 checkString = TextFileUtils
103 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt");
104 assertEquals(checkString.trim().replaceAll("\\s+", ""),
105 resultString.trim().replaceAll("\\s+", ""));
107 assertNotNull(policyModelComparer.getContextAlbumComparisonResult());
108 assertNotNull(policyModelComparer.getContextAlbumKeyDifference());
109 assertNotNull(policyModelComparer.getContextSchemaComparisonResult());
110 assertNotNull(policyModelComparer.getContextSchemaKeyDifference());
111 assertNotNull(policyModelComparer.getEventComparisonResult());
112 assertNotNull(policyModelComparer.getEventKeyDifference());
113 assertNotNull(policyModelComparer.getKeyInfoComparisonResult());
114 assertNotNull(policyModelComparer.getKeyInformationKeyDifference());
115 assertNotNull(policyModelComparer.getPolicyComparisonResult());
116 assertNotNull(policyModelComparer.getPolicykeyDifference());
117 assertNotNull(policyModelComparer.getPolicyModelsKeyDifference());
118 assertNotNull(policyModelComparer.getTaskComparisonResult());
119 assertNotNull(policyModelComparer.getTaskKeyDifference());
121 assertNotNull(new PolicyComparer().compare(leftApexModel.getPolicies(), rightApexModel.getPolicies()));
123 assertEquals("****** policy map differences ******\n*** context s",
124 policyModelComparer.toString().substring(0, 50));