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 java.util.ArrayList;
\r
27 import java.util.List;
\r
31 * $LastChangedRevision: $
\r
32 * $LastChangedDate: $
\r
34 public class ServiceResult {
\r
35 public String testID = "";
\r
36 public String testGroupID = "";
\r
37 public String fullURL = "";
\r
38 public String deleteURL = "";
\r
39 public String location = "";
\r
40 public String CSID = "";
\r
41 public String subresourceCSID = "";
\r
42 public String result = "";
\r
43 public int responseCode = 0;
\r
44 public String responseMessage = "";
\r
45 public String method = "";
\r
46 public String error = "";
\r
47 public String fromTestID = "";
\r
48 public String auth = "";
\r
49 public List<Integer> expectedCodes = new ArrayList<Integer>();
\r
50 public boolean codeInSuccessRange(int code){
\r
51 if (0<=code && code<200){
\r
53 } else if (400<=code) {
\r
58 public boolean gotExpectedResult(){
\r
59 for (Integer oneExpected : expectedCodes){
\r
60 if (responseCode == oneExpected){
\r
64 if (expectedCodes.size()>0 && codeInSuccessRange(responseCode)){ //none found, but result expected.
\r
65 for (Integer oneExpected : expectedCodes){
\r
66 if ( ! codeInSuccessRange(oneExpected)){
\r
71 return codeInSuccessRange(responseCode);
\r
73 //public static final String[] DUMP_OPTIONS = {"minimal", "detailed", "full"};
\r
74 public static enum DUMP_OPTIONS {minimal, detailed, full};
\r
76 public String toString(){
\r
77 return detail(true);
\r
80 public String detail(boolean includePayloads){
\r
81 return "{ServiceResult: "
\r
82 + ( Tools.notEmpty(testID) ? " testID:"+testID : "" )
\r
83 + ( Tools.notEmpty(testGroupID) ? "; testGroupID:"+testGroupID : "" )
\r
84 + ( Tools.notEmpty(fromTestID) ? "; fromTestID:"+fromTestID : "" )
\r
87 + ( Tools.notEmpty(responseMessage) ? "; msg:"+responseMessage : "" )
\r
90 + ( Tools.notEmpty(deleteURL) ? "; deleteURL:"+deleteURL : "" )
\r
91 + ( Tools.notEmpty(location) ? "; location.CSID:"+location : "" )
\r
92 + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" )
\r
93 + ( (expectedCodes.size()>0) ? "; expectedCodes:"+expectedCodes : "" )
\r
94 + "; gotExpected:"+gotExpectedResult()
\r
95 + ( includePayloads && Tools.notEmpty(result) ? "; result:"+result : "" )
\r
98 public String minimal(){
\r
100 + ( gotExpectedResult() ? "SUCCESS" : "FAILURE" )
\r
102 + ( Tools.notEmpty(testID) ? "; "+testID : "" )
\r
105 + (expectedCodes.size()>0 ? "; expected:"+expectedCodes : "")
\r
106 + ( Tools.notEmpty(responseMessage) ? "; msg:"+responseMessage : "" )
\r
109 + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" )
\r
112 public String dump(ServiceResult.DUMP_OPTIONS opt){
\r
117 return detail(false);
\r
119 return detail(true);
\r