1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.latka.validators; |
18 | |
|
19 | |
import org.apache.commons.latka.Validator; |
20 | |
import org.apache.commons.latka.ValidationException; |
21 | |
|
22 | |
import org.apache.commons.latka.http.Request; |
23 | |
import org.apache.commons.latka.http.Response; |
24 | |
|
25 | |
import java.text.MessageFormat; |
26 | |
|
27 | |
public class MaxRequestTimeValidator extends BaseValidator implements Validator { |
28 | |
|
29 | |
|
30 | |
|
31 | 0 | protected int _millis = 30000; |
32 | |
|
33 | 0 | protected static final MessageFormat MESSAGE = new MessageFormat("Expected maximum response time of \"{0,number,integer}\" millis, but took at least \"{1,number,integer}\" millis."); |
34 | |
|
35 | |
|
36 | |
|
37 | |
public MaxRequestTimeValidator() { |
38 | 0 | this(null,30000); |
39 | 0 | } |
40 | |
|
41 | |
public MaxRequestTimeValidator(String label) { |
42 | 0 | this(label,30000); |
43 | 0 | } |
44 | |
|
45 | |
public MaxRequestTimeValidator(String label, int millis) { |
46 | 0 | super(label); |
47 | 0 | _millis = millis; |
48 | 0 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
public void setMaxMillis(int millis) { |
53 | 0 | _millis = millis; |
54 | 0 | } |
55 | |
|
56 | |
public void validate(Response response) throws ValidationException { |
57 | 0 | Request request = response.getRequest(); |
58 | |
|
59 | 0 | if (request.getRequestTiming() > _millis) { |
60 | 0 | fail(MESSAGE.format(new Object[] { new Integer(_millis), new Integer(request.getRequestTiming()) }).toString()); |
61 | |
} |
62 | 0 | } |
63 | |
|
64 | |
} |