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.policymodel.handling;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
27 import java.io.IOException;
28 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.apex.model.policymodel.handling.PolicyComparer;
35 import org.onap.policy.apex.model.policymodel.handling.PolicyModelComparer;
36 import org.onap.policy.apex.model.utilities.TextFileUtils;
38 public class PolicyModelComparerTest {
41 public void testPolicyComparer() throws IOException {
42 final AxPolicyModel leftApexModel = new ApexPolicyModelCreatorTest().getModel();
43 final AxPolicyModel rightApexModel = new AxPolicyModel(leftApexModel);
45 PolicyModelComparer policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
47 String resultString = policyModelComparer.asString(false, false);
48 String checkString = TextFileUtils
49 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt");
50 assertEquals(resultString.trim().replaceAll("[\\r?\\n]+", " "),
51 checkString.trim().replaceAll("[\\r?\\n]+", " "));
53 resultString = policyModelComparer.asString(false, true);
54 checkString = TextFileUtils
55 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt");
56 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
57 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
59 resultString = policyModelComparer.asString(true, false);
60 checkString = TextFileUtils
61 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
62 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
63 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
65 resultString = policyModelComparer.asString(true, true);
66 checkString = TextFileUtils
67 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
68 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
69 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
71 final AxKeyInfo leftOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("LeftOnlyKeyInfo", "0.0.1"),
72 UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f000"), "Left only key info");
73 final AxKeyInfo rightOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("RightOnlyKeyInfo", "0.0.1"),
74 UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f001"), "Right only key info");
76 leftApexModel.getKeyInformation().getKeyInfoMap().put(leftOnlyKeyInfo.getKey(), leftOnlyKeyInfo);
77 rightApexModel.getKeyInformation().getKeyInfoMap().put(rightOnlyKeyInfo.getKey(), rightOnlyKeyInfo);
79 leftApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
80 .setDescription("Left InEvent Description");
81 rightApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
82 .setDescription("Right InEvent Description");
84 policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
86 resultString = policyModelComparer.asString(false, false);
87 checkString = TextFileUtils
88 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt");
89 assertEquals(resultString.trim().replaceAll("[\\r?\\n]+", " "),
90 checkString.trim().replaceAll("[\\r?\\n]+", " "));
92 resultString = policyModelComparer.asString(false, true);
93 checkString = TextFileUtils
94 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt");
95 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
96 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
98 resultString = policyModelComparer.asString(true, false);
99 checkString = TextFileUtils
100 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt");
101 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
102 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
104 resultString = policyModelComparer.asString(true, true);
105 checkString = TextFileUtils
106 .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt");
107 assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
108 .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
110 assertNotNull(policyModelComparer.getContextAlbumComparisonResult());
111 assertNotNull(policyModelComparer.getContextAlbumKeyDifference());
112 assertNotNull(policyModelComparer.getContextSchemaComparisonResult());
113 assertNotNull(policyModelComparer.getContextSchemaKeyDifference());
114 assertNotNull(policyModelComparer.getEventComparisonResult());
115 assertNotNull(policyModelComparer.getEventKeyDifference());
116 assertNotNull(policyModelComparer.getKeyInfoComparisonResult());
117 assertNotNull(policyModelComparer.getKeyInformationKeyDifference());
118 assertNotNull(policyModelComparer.getPolicyComparisonResult());
119 assertNotNull(policyModelComparer.getPolicykeyDifference());
120 assertNotNull(policyModelComparer.getPolicyModelsKeyDifference());
121 assertNotNull(policyModelComparer.getTaskComparisonResult());
122 assertNotNull(policyModelComparer.getTaskKeyDifference());
124 assertNotNull(new PolicyComparer().compare(leftApexModel.getPolicies(), rightApexModel.getPolicies()));
126 assertEquals("****** policy map differences ******\n*** context s",
127 policyModelComparer.toString().substring(0, 50));