]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
04f8f55c5f895aac3c7ed533740020203ebbecca
[tmp/jakarta-migration.git] /
1 /**\r
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
5  *\r
6  * http://www.collectionspace.org\r
7  * http://wiki.collectionspace.org\r
8  *\r
9  * Copyright (c) 2009 Regents of the University of California\r
10  *\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
13  *\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
16  *\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
22  */\r
23 \r
24 package org.collectionspace.services.IntegrationTests.xmlreplay;\r
25 \r
26 import java.util.ArrayList;\r
27 import java.util.List;\r
28 \r
29 /**\r
30  * User: laramie\r
31  * $LastChangedRevision:  $\r
32  * $LastChangedDate:  $\r
33  */\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
52             return false;\r
53         } else if (400<=code) {\r
54             return false;\r
55         }\r
56         return true;\r
57     }\r
58     public boolean gotExpectedResult(){\r
59         for (Integer oneExpected : expectedCodes){\r
60             if (responseCode == oneExpected){\r
61                 return true;\r
62             }\r
63         }\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
67                     return false;\r
68                 }\r
69             }\r
70         }\r
71         return codeInSuccessRange(responseCode);\r
72     }\r
73     //public static final String[] DUMP_OPTIONS = {"minimal", "detailed", "full"};\r
74     public static enum DUMP_OPTIONS {minimal, detailed, full};\r
75 \r
76     public String toString(){\r
77         return detail(true);\r
78 \r
79     }\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
85                 +"; "+method\r
86                 +"; "+responseCode\r
87                 + ( Tools.notEmpty(responseMessage) ? "; msg:"+responseMessage : "" )\r
88                 +"; URL:"+fullURL\r
89                 +"; auth: "+auth\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
96                 +"}";\r
97     }\r
98     public String minimal(){\r
99         return "{"\r
100                 + ( gotExpectedResult() ? "SUCCESS" : "FAILURE"  )\r
101 \r
102                 + ( Tools.notEmpty(testID) ? "; "+testID : "" )\r
103                 +"; "+method\r
104                 +"; "+responseCode\r
105                 + (expectedCodes.size()>0 ? "; expected:"+expectedCodes : "")\r
106                 + ( Tools.notEmpty(responseMessage) ? "; msg:"+responseMessage : "" )\r
107                 +"; URL:"+fullURL\r
108                 +"; auth: "+auth\r
109                 + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" )\r
110                 +"}";\r
111     }\r
112     public String dump(ServiceResult.DUMP_OPTIONS opt){\r
113         switch (opt){\r
114             case minimal:\r
115                 return minimal();\r
116             case detailed:\r
117                 return detail(false);\r
118             case full:\r
119                 return detail(true);\r
120             default:\r
121                 return toString();\r
122         }\r
123     }\r
124 }\r