Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JHttpResponseStatusValidator.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.engine.e1.collector;
2 
3 import com.griddynamics.jagger.coordinator.NodeContext;
4 import com.griddynamics.jagger.invoker.v2.JHttpEndpoint;
5 import com.griddynamics.jagger.invoker.v2.JHttpQuery;
6 import com.griddynamics.jagger.invoker.v2.JHttpResponse;
7 
8 import java.util.Set;
9 import java.util.regex.Pattern;
10 
11 import static com.google.common.collect.Sets.newHashSet;
12 
20 public class JHttpResponseStatusValidator extends ResponseValidator<JHttpQuery, JHttpEndpoint, JHttpResponse> {
21 
22  private Set<Integer> validStatusCodes = newHashSet();
23 
24  private Pattern validStatusCodesRegexp;
25 
26  public JHttpResponseStatusValidator(String taskId, String sessionId, NodeContext kernelContext) {
27  super(taskId, sessionId, kernelContext);
28  }
29 
30  @Override
31  public String getName() {
32  return "Default Http Response Status Validator";
33  }
34 
46  @Override
47  public boolean validate(JHttpQuery query, JHttpEndpoint endpoint, JHttpResponse result, long duration) {
48  if (validStatusCodesRegexp != null) {
49  return validStatusCodesRegexp.matcher(result.getStatus().toString()).matches();
50  }
51  return validStatusCodes.contains(result.getStatus().value());
52  }
53 
54  public Set<Integer> getValidStatusCodes() {
55  return validStatusCodes;
56  }
57 
58  public void setValidStatusCodes(Set<Integer> validStatusCodes) {
59  this.validStatusCodes = validStatusCodes;
60  }
61 
62  public Pattern getValidStatusCodesRegexp() {
63  return validStatusCodesRegexp;
64  }
65 
66  public void setValidStatusCodesRegexp(Pattern validStatusCodesRegexp) {
67  this.validStatusCodesRegexp = validStatusCodesRegexp;
68  }
69 }