Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JHttpResponseStatusValidatorProvider.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 
5 import java.util.Arrays;
6 import java.util.Collection;
7 import java.util.List;
8 import java.util.Set;
9 import java.util.regex.Pattern;
10 import java.util.regex.PatternSyntaxException;
11 import java.util.stream.IntStream;
12 
13 import static com.google.common.collect.Sets.newHashSet;
14 import static java.util.stream.Collectors.toSet;
15 
22 
23  private Set<Integer> validStatusCodes = newHashSet();
24  private Pattern validStatusCodesRegexp;
25 
26  private JHttpResponseStatusValidatorProvider(Collection<Integer> validStatusCodes) {
27  this.validStatusCodes.addAll(validStatusCodes);
28  }
29 
30  private JHttpResponseStatusValidatorProvider(Pattern validStatusCodesRegexp) {
31  this.validStatusCodesRegexp = validStatusCodesRegexp;
32  }
33 
34  @Override
35  public ResponseValidator<?, ?, ?> provide(String sessionId, String taskId, NodeContext kernelContext) {
36  JHttpResponseStatusValidator jHttpResponseStatusValidator = new JHttpResponseStatusValidator(taskId, sessionId, kernelContext);
37  jHttpResponseStatusValidator.setValidStatusCodes(validStatusCodes);
38  jHttpResponseStatusValidator.setValidStatusCodesRegexp(validStatusCodesRegexp);
39  return jHttpResponseStatusValidator;
40  }
41 
51  public static JHttpResponseStatusValidatorProvider of(Integer... codes) {
52  return new JHttpResponseStatusValidatorProvider(Arrays.asList(codes));
53  }
54 
64  public static JHttpResponseStatusValidatorProvider of(List<Integer> codes) {
65  return new JHttpResponseStatusValidatorProvider(codes);
66  }
67 
79  public static JHttpResponseStatusValidatorProvider of(IntStream range) {
80  return new JHttpResponseStatusValidatorProvider(range.boxed().collect(toSet()));
81  }
82 
94  public static JHttpResponseStatusValidatorProvider of(String stringRegExp) {
95  return new JHttpResponseStatusValidatorProvider(Pattern.compile(stringRegExp));
96  }
97 }