2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.pdp.test.conformance;
23 import com.att.research.xacml.api.Result;
24 import com.att.research.xacml.std.StdStatusCode;
25 import com.att.research.xacml.util.ListUtil;
28 * ResultMatchResult provides information about how well a {@link com.att.research.xacml.api.Result} object matches
29 * another <code>Result</code> object.
31 * @version $Revision: 1.1 $
33 public class ResultMatchResult {
34 private boolean bAssociatedAdviceMatches = true;
35 private boolean bAttributesMatch = true;
36 private boolean bDecisionsMatch = true;
37 private boolean bObligationsMatch = true;
38 private boolean bPolicyIdentifiersMatch = true;
39 private boolean bPolicySetIdentifiersMatch = true;
40 private boolean bStatusCodesMatch = true;
41 private boolean bUnknownFunction = false;
43 protected void setAssociatedAdviceMatches(boolean b) {
44 this.bAssociatedAdviceMatches = b;
46 protected void setAttributesMatch(boolean b) {
47 this.bAttributesMatch = b;
49 protected void setDecisionsMatch(boolean b) {
50 this.bDecisionsMatch = b;
52 protected void setObligationsMatch(boolean b) {
53 this.bObligationsMatch = b;
55 protected void setPolicyIdentifiersMatch(boolean b) {
56 this.bPolicyIdentifiersMatch = b;
58 protected void setPolicySetIdentifiersMatch(boolean b) {
59 this.bPolicySetIdentifiersMatch = b;
61 protected void setStatusCodesMatch(boolean b) {
62 this.bStatusCodesMatch = b;
64 protected void setUnknownFunction(boolean b) {
65 this.bUnknownFunction = b;
68 public ResultMatchResult() {
71 public static ResultMatchResult newInstance(Result result1, Result result2) {
72 ResultMatchResult resultMatchResult = new ResultMatchResult();
73 if (result2 != null && result2.getStatus() != null &&
74 result2.getStatus().getStatusCode().equals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR) &&
75 result2.getStatus().getStatusMessage() != null &&
76 result2.getStatus().getStatusMessage().contains("Unknown Function")
78 resultMatchResult.setUnknownFunction(true);
80 if (result1 == null || result2 == null) {
81 resultMatchResult.setAssociatedAdviceMatches(false);
82 resultMatchResult.setAttributesMatch(false);
83 resultMatchResult.setDecisionsMatch(false);
84 resultMatchResult.setObligationsMatch(false);
85 resultMatchResult.setPolicyIdentifiersMatch(false);
86 resultMatchResult.setPolicySetIdentifiersMatch(false);
87 resultMatchResult.setStatusCodesMatch(false);
89 resultMatchResult.setAssociatedAdviceMatches(ListUtil.equalsAllowNulls(result1.getAssociatedAdvice(), result2.getAssociatedAdvice()));
90 resultMatchResult.setAttributesMatch(ListUtil.equalsAllowNulls(result1.getAttributes(), result2.getAttributes()));
91 resultMatchResult.setDecisionsMatch(result1.getDecision() == result2.getDecision());
92 resultMatchResult.setObligationsMatch(ListUtil.equalsAllowNulls(result1.getObligations(), result2.getObligations()));
93 resultMatchResult.setPolicyIdentifiersMatch(ListUtil.equalsAllowNulls(result1.getPolicyIdentifiers(), result2.getPolicyIdentifiers()));
94 resultMatchResult.setPolicySetIdentifiersMatch(ListUtil.equalsAllowNulls(result1.getPolicySetIdentifiers(), result2.getPolicySetIdentifiers()));
95 if (result1.getStatus() == null || result1.getStatus().getStatusCode() == null || result2.getStatus() == null || result2.getStatus().getStatusCode() == null) {
96 resultMatchResult.setStatusCodesMatch(false);
98 resultMatchResult.setStatusCodesMatch(result1.getStatus().getStatusCode().equals(result2.getStatus().getStatusCode()));
101 return resultMatchResult;
104 public boolean associatedAdviceMatches() {
105 return this.bAssociatedAdviceMatches;
108 public boolean attributesMatch() {
109 return this.bAttributesMatch;
112 public boolean decisionsMatch() {
113 return this.bDecisionsMatch;
116 public boolean obligationsMatch() {
117 return this.bObligationsMatch;
120 public boolean policyIdentifiersMatch() {
121 return this.bPolicyIdentifiersMatch;
124 public boolean policySetIdentifiersMatch() {
125 return this.bPolicySetIdentifiersMatch;
128 public boolean statusCodesMatch() {
129 return this.bStatusCodesMatch;
132 public boolean unknownFunction() {
133 return this.bUnknownFunction;