2 * This document is a part of the source code and related artifacts
\r
3 * for CollectionSpace, an open source collections management system
\r
4 * for museums and related institutions:
\r
6 * http://www.collectionspace.org
\r
7 * http://wiki.collectionspace.org
\r
9 * Copyright (c) 2009 Regents of the University of California
\r
11 * Licensed under the Educational Community License (ECL), Version 2.0.
\r
12 * You may not use this file except in compliance with this License.
\r
14 * You may obtain a copy of the ECL 2.0 License at
\r
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
\r
17 * Unless required by applicable law or agreed to in writing, software
\r
18 * distributed under the License is distributed on an "AS IS" BASIS,
\r
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
20 * See the License for the specific language governing permissions and
\r
21 * limitations under the License.
\r
24 package org.collectionspace.services.IntegrationTests.xmlreplay;
\r
26 import org.apache.commons.httpclient.Header;
\r
27 import org.collectionspace.services.common.Tools;
\r
29 import java.util.ArrayList;
\r
30 import java.util.HashMap;
\r
31 import java.util.List;
\r
32 import java.util.Map;
\r
36 * $LastChangedRevision: $
\r
37 * $LastChangedDate: $
\r
39 public class ServiceResult {
\r
40 public String testID = "";
\r
41 public String testGroupID = "";
\r
42 public String fullURL = "";
\r
43 public String deleteURL = "";
\r
44 public String location = "";
\r
45 public String CSID = "";
\r
46 public String subresourceCSID = "";
\r
47 public String requestPayload = "";
\r
48 public String result = "";
\r
49 public int responseCode = 0;
\r
50 public String responseMessage = "";
\r
51 public String method = "";
\r
52 public String error = "";
\r
53 public String fromTestID = "";
\r
54 public String auth = "";
\r
55 public String boundary = "";
\r
56 public String payloadStrictness = "";
\r
57 public long contentLength = 0;
\r
58 public String failureReason = "";
\r
59 public Header[] responseHeaders = new Header[0];
\r
60 public List<Integer> expectedCodes = new ArrayList<Integer>();
\r
61 private Map<String, TreeWalkResults> partSummaries = new HashMap<String, TreeWalkResults>();
\r
62 public void addPartSummary(String label, TreeWalkResults list){
\r
63 partSummaries.put(label, list);
\r
65 public String partsSummary(boolean detailed){
\r
66 StringBuffer buf = new StringBuffer();
\r
67 if (!isDomWalkOK()){
\r
68 if (detailed) buf.append("\r\nDOM CHECK FAILED:\r\n");
\r
69 else buf.append("; DOM CHECK FAILED:");
\r
71 for (Map.Entry<String,TreeWalkResults> entry : partSummaries.entrySet()) {
\r
72 String key = entry.getKey();
\r
73 TreeWalkResults value = entry.getValue();
\r
74 buf.append(" label:"+key+": ");
\r
77 buf.append(value.fullSummary());
\r
79 buf.append(value.miniSummary());
\r
83 return buf.toString();
\r
85 public boolean codeInSuccessRange(int code){
\r
86 if (0<=code && code<200){
\r
88 } else if (400<=code) {
\r
94 public boolean isDomWalkOK(){
\r
95 if (Tools.isEmpty(payloadStrictness)){
\r
98 PAYLOAD_STRICTNESS strictness = PAYLOAD_STRICTNESS.valueOf(payloadStrictness);
\r
99 for (Map.Entry<String,TreeWalkResults> entry : partSummaries.entrySet()) {
\r
100 String key = entry.getKey();
\r
101 TreeWalkResults value = entry.getValue();
\r
102 if (value.hasDocErrors()){
\r
103 failureReason = " : DOM DOC_ERROR; ";
\r
106 switch (strictness){
\r
108 if (!value.isStrictMatch()) {
\r
109 failureReason = " : DOM NOT STRICT; ";
\r
114 if (value.countFor(TreeWalkResults.TreeWalkEntry.STATUS.TEXT_DIFFERENT)>0) {
\r
115 failureReason = " : DOM TEXT_DIFFERENT; ";
\r
118 if (value.countFor(TreeWalkResults.TreeWalkEntry.STATUS.R_MISSING)>0){
\r
119 failureReason = " : DOM R_MISSING; ";
\r
124 if (!value.treesMatch()) {
\r
125 failureReason = " : DOM TREE MISMATCH; ";
\r
128 if (value.countFor(TreeWalkResults.TreeWalkEntry.STATUS.TEXT_DIFFERENT)>0) {
\r
129 failureReason = " : DOM TEXT_DIFFERENT; ";
\r
134 if (!value.treesMatch()) {
\r
135 failureReason = " : DOM TREE MISMATCH; ";
\r
146 public boolean gotExpectedResult(){
\r
147 if (Tools.notEmpty(failureReason)){
\r
150 for (Integer oneExpected : expectedCodes){
\r
151 if (responseCode == oneExpected){
\r
152 return isDomWalkOK();
\r
155 if ( expectedCodes.size()>0 && codeInSuccessRange(responseCode)){ //none found, but result expected.
\r
156 for (Integer oneExpected : expectedCodes){
\r
157 if ( ! codeInSuccessRange(oneExpected)){
\r
158 return isDomWalkOK();
\r
162 boolean ok = codeInSuccessRange(responseCode);
\r
164 return isDomWalkOK();
\r
166 failureReason = " : STATUS CODE UNEXPECTED; ";
\r
170 //public static final String[] DUMP_OPTIONS = {"minimal", "detailed", "full"};
\r
171 public static enum DUMP_OPTIONS {minimal, detailed, full};
\r
173 public static enum PAYLOAD_STRICTNESS {ZERO, ADDOK, TREE, TEXT, STRICT};
\r
175 public String toString(){
\r
176 return detail(true);
\r
179 public String detail(boolean includePayloads){
\r
181 + ( gotExpectedResult() ? "SUCCESS" : "FAILURE" )
\r
185 + ( (expectedCodes.size()>0) ? "; expectedCodes:"+expectedCodes : "" )
\r
186 + ( Tools.notEmpty(testID) ? "; testID:"+testID : "" )
\r
187 + ( Tools.notEmpty(testGroupID) ? "; testGroupID:"+testGroupID : "" )
\r
188 + ( Tools.notEmpty(fromTestID) ? "; fromTestID:"+fromTestID : "" )
\r
189 + ( Tools.notEmpty(responseMessage) ? "; msg:"+responseMessage : "" )
\r
192 + ( Tools.notEmpty(deleteURL) ? "; deleteURL:"+deleteURL : "" )
\r
193 + ( Tools.notEmpty(location) ? "; location.CSID:"+location : "" )
\r
194 + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" )
\r
195 + "; gotExpected:"+gotExpectedResult()
\r
196 + ( includePayloads && Tools.notEmpty(requestPayload) ? "; requestPayload:\r\n"+requestPayload+"\r\n" : "" )
\r
197 + ( includePayloads && Tools.notEmpty(result) ? "; result:"+result : "" )
\r
198 + ( partsSummary(true))
\r
202 public String minimal(){
\r
204 + ( gotExpectedResult() ? "SUCCESS" : "FAILURE" )
\r
206 + ( Tools.notEmpty(testID) ? "; "+testID : "" )
\r
209 + (expectedCodes.size()>0 ? "; expected:"+expectedCodes : "")
\r
210 + ( Tools.notEmpty(responseMessage) ? "; msg:"+responseMessage : "" )
\r
213 + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" )
\r
214 + ( partsSummary(false))
\r
217 public String dump(ServiceResult.DUMP_OPTIONS opt){
\r
222 return detail(false);
\r
224 return detail(true);
\r