Coverage Report - org.apache.commons.latka.validators.MaxRequestTimeValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
MaxRequestTimeValidator
0%
0/15
0%
0/2
1.2
 
 1  
 /*
 2  
  * Copyright 1999-2002,2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
   // --------------------------------------------------------------- Attributes
 30  
 
 31  0
   protected int _millis = 30000; // shouldn't this be long?
 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  
   // ------------------------------------------------------------- Constructors
 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  
   // ------------------------------------------------------------------ Methods
 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  
 }