Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-TEST / src / test / java / org / openecomp / policy / pdp / test / conformance / ResultMatchResult.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-TEST
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.policy.pdp.test.conformance;
22
23 import com.att.research.xacml.api.Result;
24 import com.att.research.xacml.std.StdStatusCode;
25 import com.att.research.xacml.util.ListUtil;
26
27 /**
28  * ResultMatchResult provides information about how well a {@link com.att.research.xacml.api.Result} object matches
29  * another <code>Result</code> object.
30  * 
31  * @version $Revision: 1.1 $
32  */
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;
42         
43         protected void setAssociatedAdviceMatches(boolean b) {
44                 this.bAssociatedAdviceMatches   = b;
45         }
46         protected void setAttributesMatch(boolean b) {
47                 this.bAttributesMatch   = b;
48         }
49         protected void setDecisionsMatch(boolean b) {
50                 this.bDecisionsMatch    = b;
51         }
52         protected void setObligationsMatch(boolean b) {
53                 this.bObligationsMatch  = b;
54         }
55         protected void setPolicyIdentifiersMatch(boolean b) {
56                 this.bPolicyIdentifiersMatch    = b;
57         }
58         protected void setPolicySetIdentifiersMatch(boolean b) {
59                 this.bPolicySetIdentifiersMatch = b;
60         }
61         protected void setStatusCodesMatch(boolean b) {
62                 this.bStatusCodesMatch  = b;
63         }
64         protected void setUnknownFunction(boolean b) {
65                 this.bUnknownFunction   = b;
66         }
67         
68         public ResultMatchResult() {
69         }
70         
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")
77                         ) {
78                         resultMatchResult.setUnknownFunction(true);
79                 }
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);
88                 } else {
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);
97                         } else {
98                                 resultMatchResult.setStatusCodesMatch(result1.getStatus().getStatusCode().equals(result2.getStatus().getStatusCode()));
99                         }
100                 }
101                 return resultMatchResult;
102         }
103         
104         public boolean associatedAdviceMatches() {
105                 return this.bAssociatedAdviceMatches;
106         }
107         
108         public boolean attributesMatch() {
109                 return this.bAttributesMatch;
110         }
111         
112         public boolean decisionsMatch() {
113                 return this.bDecisionsMatch;
114         }
115         
116         public boolean obligationsMatch() {
117                 return this.bObligationsMatch;
118         }
119         
120         public boolean policyIdentifiersMatch() {
121                 return this.bPolicyIdentifiersMatch;
122         }
123         
124         public boolean policySetIdentifiersMatch() {
125                 return this.bPolicySetIdentifiersMatch;
126         }
127         
128         public boolean statusCodesMatch() {
129                 return this.bStatusCodesMatch;
130         }
131         
132         public boolean unknownFunction() {
133                 return this.bUnknownFunction;
134         }
135
136 }