aboutsummaryrefslogtreecommitdiffstats
path: root/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ResponseMatchResult.java
blob: 31e6da4151179bbd55d30479abc1e01af276a998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*-
 * ============LICENSE_START=======================================================
 * ECOMP-TEST
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.policy.pdp.test.conformance;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import com.att.research.xacml.api.Response;
import com.att.research.xacml.api.Result;

/**
 * ResponseMatchResult provides information about how a {@link com.att.research.xacml.api.Response} object matches
 * another <code>Response</code> object.
 * 
 * @version $Revision: 1.1 $
 */
public class ResponseMatchResult {
	private List<ResultMatchResult>	resultMatchResults	= new ArrayList<ResultMatchResult>();
	
	private boolean bAssociatedAdviceMatches			= true;
	private boolean bAttributesMatch					= true;
	private boolean bDecisionsMatch						= true;
	private boolean bStatusCodesMatch					= true;
	private boolean bObligationsMatch					= true;
	private boolean bPolicyIdentifiersMatch				= true;
	private boolean bPolicySetIdentifiersMatch			= true;
	private boolean bNumResultsMatch					= true;
	private boolean bUnknownFunction;
	
	protected void addResultMatchResult(ResultMatchResult resultMatchResult) {
		this.resultMatchResults.add(resultMatchResult);
		this.bAssociatedAdviceMatches	= resultMatchResult.associatedAdviceMatches() && this.bAssociatedAdviceMatches;
		this.bAttributesMatch			= resultMatchResult.attributesMatch() && this.bAttributesMatch;
		this.bDecisionsMatch			= resultMatchResult.decisionsMatch() && this.bDecisionsMatch;
		this.bStatusCodesMatch			= resultMatchResult.statusCodesMatch() && this.bStatusCodesMatch;
		this.bObligationsMatch			= resultMatchResult.obligationsMatch() && this.bObligationsMatch;
		this.bPolicyIdentifiersMatch	= resultMatchResult.policyIdentifiersMatch() && this.bPolicyIdentifiersMatch;
		this.bPolicySetIdentifiersMatch	= resultMatchResult.policySetIdentifiersMatch() && this.bPolicySetIdentifiersMatch;
		this.bUnknownFunction			= resultMatchResult.unknownFunction() || this.bUnknownFunction;
	}
	
	protected void setNumResultsMatch(boolean b) {
		this.bNumResultsMatch	= b;
	}
	
	public ResponseMatchResult() {
	}
	
	public static ResponseMatchResult newInstance(Response response1, Response response2) {
		ResponseMatchResult responseMatchResult	= new ResponseMatchResult();

		Collection<Result> listResultsResponse1	= response1.getResults();
		Collection<Result> listResultsResponse2	= response2.getResults();
		if (listResultsResponse1.size() == 1 && listResultsResponse2.size() == 1) {
			/*
			 * Just add a single ResultMatchResult comparing the results in the two responses
			 */
			responseMatchResult.addResultMatchResult(ResultMatchResult.newInstance(listResultsResponse1.iterator().next(), listResultsResponse2.iterator().next()));
		} else {
			/*
			 * Iterate over all of the results in the two responses and match them
			 */
			Iterator<Result> iterResponse1Results	= listResultsResponse1.iterator();
			Iterator<Result> iterResponse2Results	= listResultsResponse2.iterator();
			while ((iterResponse1Results != null && iterResponse1Results.hasNext()) || (iterResponse2Results != null && iterResponse2Results.hasNext())) {
				Result result1	= (iterResponse1Results != null && iterResponse1Results.hasNext() ? iterResponse1Results.next() : null);
				Result result2	= (iterResponse2Results != null && iterResponse2Results.hasNext() ? iterResponse2Results.next() : null);
				if ((result1 == null || result2 == null) && responseMatchResult.numResultsMatch()) {
					responseMatchResult.setNumResultsMatch(false);
				}
				responseMatchResult.addResultMatchResult(ResultMatchResult.newInstance(result1, result2));
			}
		}
		return responseMatchResult;
	}

	public Iterator<ResultMatchResult> getResultMatchResults() {
		return this.resultMatchResults.iterator();
	}
	
	public boolean numResultsMatch() {
		return this.bNumResultsMatch;
	}
	
	public boolean associatedAdviceMatches() {
		return this.bAssociatedAdviceMatches;
	}
	
	public boolean attributesMatch() {
		return this.bAttributesMatch;
	}
	
	public boolean decisionsMatch() {
		return this.bDecisionsMatch;
	}
	
	public boolean obligationsMatch() {
		return this.bObligationsMatch;
	}
	
	public boolean policyIdentifiersMatch() {
		return this.bPolicyIdentifiersMatch;
	}
	
	public boolean policySetIdentifiersMatch() {
		return this.bPolicySetIdentifiersMatch;
	}
	
	public boolean statusCodesMatch() {
		return this.bStatusCodesMatch;
	}
	
	public boolean unknownFunction() {
		return this.bUnknownFunction;
	}

}