Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JTestDefinition.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.user.test.configurations;
2 
3 import com.google.common.collect.Lists;
4 import com.griddynamics.jagger.engine.e1.Provider;
5 import com.griddynamics.jagger.engine.e1.collector.ResponseValidatorProvider;
6 import com.griddynamics.jagger.engine.e1.collector.invocation.InvocationListener;
7 import com.griddynamics.jagger.invoker.Invoker;
8 import com.griddynamics.jagger.invoker.QueryPoolLoadBalancer;
9 import com.griddynamics.jagger.invoker.RandomLoadBalancer;
10 import com.griddynamics.jagger.invoker.RoundRobinLoadBalancer;
11 import com.griddynamics.jagger.invoker.RoundRobinPairSupplierFactory;
12 import com.griddynamics.jagger.invoker.v2.DefaultHttpInvoker;
13 import com.griddynamics.jagger.invoker.v2.DefaultInvokerProvider;
14 import com.griddynamics.jagger.user.test.configurations.auxiliary.Id;
15 
16 import java.util.List;
17 
36 public class JTestDefinition {
37 
38  private final String id;
39  private final Iterable endpoints;
40 
41  private final String comment;
42  private final Iterable queries;
43  private final Provider<Invoker> invoker;
44  private final List<ResponseValidatorProvider> validators;
45  private final List<Provider<InvocationListener>> listeners;
46  private final QueryPoolLoadBalancer loadBalancer;
47 
49  this.id = builder.id.value();
50  this.endpoints = builder.endpointsProvider;
51 
52  this.comment = (builder.comment == null) ? "" : builder.comment;
53  this.queries = builder.queries;
54  this.invoker = builder.invoker;
55  this.validators = builder.validators;
56  this.listeners = builder.listeners;
57  this.loadBalancer = builder.loadBalancer;
58  }
59 
69  public static Builder builder(Id id, Iterable endpointsProvider) {
70  return new Builder(id, endpointsProvider);
71  }
72 
73  public static class Builder {
74  private final Id id;
75  private final Iterable endpointsProvider;
76 
77  private String comment = "";
78  private Iterable queries;
79  private Provider<Invoker> invoker = DefaultInvokerProvider.of(DefaultHttpInvoker.class);
80  private List<ResponseValidatorProvider> validators = Lists.newArrayList();
81  private List<Provider<InvocationListener>> listeners = Lists.newArrayList();
82  private QueryPoolLoadBalancer loadBalancer;
83 
84  private Builder(Id id, Iterable endpointsProvider) {
85  this.id = id;
86  this.endpointsProvider = endpointsProvider;
87  this.loadBalancer = new RandomLoadBalancer() {{
88  setPairSupplierFactory(new RoundRobinPairSupplierFactory());
89  setRandomSeed(31);
90  }};
91  }
92 
98  public Builder withComment(String comment) {
99  this.comment = comment;
100  return this;
101  }
102 
109  public Builder withQueryProvider(Iterable queryProvider) {
110  this.queries = queryProvider;
111  return this;
112  }
113 
122  public Builder withLoadBalancer(QueryPoolLoadBalancer loadBalancer) {
123  this.loadBalancer = loadBalancer;
124  return this;
125  }
126 
136  public Builder withInvoker(Provider<Invoker> invoker) {
137  this.invoker = invoker;
138  return this;
139  }
140 
150  public Builder addValidators(List<ResponseValidatorProvider> validators) {
151  this.validators.addAll(validators);
152  return this;
153  }
154 
166  this.validators.add(validator);
167  return this;
168  }
169 
182  public Builder addListeners(List<Provider<InvocationListener>> listeners) {
183  this.listeners.addAll(listeners);
184  return this;
185  }
186 
199  public Builder addListener(Provider<InvocationListener> listener) {
200  this.listeners.add(listener);
201  return this;
202  }
203 
210  return new JTestDefinition(this);
211  }
212  }
213 
214  public String getId() {
215  return id;
216  }
217 
218  public String getDescription() {
219  return comment;
220  }
221 
222  public Iterable getEndpoints() {
223  return endpoints;
224  }
225 
226  public Iterable getQueries() {
227  return queries;
228  }
229 
230  public Provider<Invoker> getInvoker() {
231  return invoker;
232  }
233 
234  public String getComment() {
235  return comment;
236  }
237 
238  public List<ResponseValidatorProvider> getValidators() {
239  return validators;
240  }
241 
242  public List<Provider<InvocationListener>> getListeners() {
243  return listeners;
244  }
245 
246  public QueryPoolLoadBalancer getLoadBalancer() {
247  return loadBalancer;
248  }
249 }