]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
c5142354df10b451a18e2f2062a8878af50bfa9a
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23  
24 package org.collectionspace.services.client.test;
25
26 import java.util.Arrays;
27 import javax.ws.rs.core.Response;
28
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * ServiceRequestType, identifies types of service requests
34  * and the valid HTTP status codes that can be returned from
35  * each type of request.  Used by client tests of services.
36  * 
37  * $LastChangedRevision: 566 $
38  * $LastChangedDate$
39  */
40 public enum ServiceRequestType {
41
42   // Define each of the service request types and their valid HTTP status codes.
43   
44   CREATE {
45     @Override
46     public int[] validStatusCodes() { 
47       final int[] STATUS_CODES = {
48         Response.Status.CREATED.getStatusCode(),
49         Response.Status.BAD_REQUEST.getStatusCode(),
50         Response.Status.FORBIDDEN.getStatusCode(),
51         Response.Status.CONFLICT.getStatusCode(),
52         Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
53       };
54       Arrays.sort(STATUS_CODES);
55       return STATUS_CODES;
56     }
57     @Override
58     public boolean isValidStatusCode(int statusCode) {
59       if (Arrays.binarySearch(CREATE.validStatusCodes(), statusCode) >= 0) {
60         return true;
61       } else {
62         return false;
63       }
64     }
65     @Override
66     public String validStatusCodesAsString() {
67       return Arrays.toString(CREATE.validStatusCodes());
68     }
69   },
70   
71   
72   READ {
73     @Override
74     public int[] validStatusCodes() { 
75       final int[] STATUS_CODES = {
76         Response.Status.OK.getStatusCode(),
77         Response.Status.FORBIDDEN.getStatusCode(),
78         Response.Status.NOT_FOUND.getStatusCode(),
79         Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
80       };
81       Arrays.sort(STATUS_CODES);
82       return STATUS_CODES;
83     }
84     @Override
85     public boolean isValidStatusCode(int statusCode) {
86       if (Arrays.binarySearch(READ.validStatusCodes(), statusCode) >= 0) {
87         return true;
88       } else {
89         return false;
90       }
91     }
92     @Override
93     public String validStatusCodesAsString() {
94       return Arrays.toString(READ.validStatusCodes());
95     }
96   },
97   
98   
99   READ_MULTIPLE {
100     @Override
101     public int[] validStatusCodes() { 
102       final int[] STATUS_CODES = {
103         Response.Status.OK.getStatusCode(),
104         Response.Status.BAD_REQUEST.getStatusCode(),
105         Response.Status.FORBIDDEN.getStatusCode(),
106         Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
107       };
108       Arrays.sort(STATUS_CODES);
109       return STATUS_CODES;
110     }
111     @Override
112     public boolean isValidStatusCode(int statusCode) {
113       if (Arrays.binarySearch(READ_MULTIPLE.validStatusCodes(), statusCode) >= 0) {
114         return true;
115       } else {
116         return false;
117       }
118     }
119     @Override
120     public String validStatusCodesAsString() {
121       return Arrays.toString(READ_MULTIPLE.validStatusCodes());
122     }
123   },
124   
125   
126   UPDATE {
127     @Override
128     public int[] validStatusCodes() { 
129       final int[] STATUS_CODES = {
130         Response.Status.OK.getStatusCode(),
131         Response.Status.BAD_REQUEST.getStatusCode(),
132         Response.Status.FORBIDDEN.getStatusCode(),
133         Response.Status.NOT_FOUND.getStatusCode(),
134         Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
135       };
136       Arrays.sort(STATUS_CODES);
137       return STATUS_CODES;
138     }
139     @Override
140     public boolean isValidStatusCode(int statusCode) {
141       if (Arrays.binarySearch(UPDATE.validStatusCodes(), statusCode) >= 0) {
142         return true;
143       } else {
144         return false;
145       }
146     }
147     @Override
148     public String validStatusCodesAsString() {
149       return Arrays.toString(UPDATE.validStatusCodes());
150     }
151   },
152   
153   
154   DELETE {
155     @Override
156     public int[] validStatusCodes() { 
157       final int[] STATUS_CODES = {
158         Response.Status.OK.getStatusCode(),
159         Response.Status.FORBIDDEN.getStatusCode(),
160         Response.Status.NOT_FOUND.getStatusCode(),
161         Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
162       };
163       Arrays.sort(STATUS_CODES);
164       return STATUS_CODES;
165     }
166     @Override
167     public boolean isValidStatusCode(int statusCode) {
168       if (Arrays.binarySearch(DELETE.validStatusCodes(), statusCode) >= 0) {
169         return true;
170       } else {
171         return false;
172       }
173     }
174     @Override
175     public String validStatusCodesAsString() {
176       return Arrays.toString(DELETE.validStatusCodes());
177     }
178   };
179   
180   // Template methods to be implemented by each ServiceRequestType.
181   
182   public abstract int[] validStatusCodes();
183   
184   public abstract boolean isValidStatusCode(int i);
185
186   public abstract String validStatusCodesAsString();
187
188 }