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.RoundRobinPairSupplierFactory;
11 import com.griddynamics.jagger.invoker.v2.DefaultHttpInvoker;
12 import com.griddynamics.jagger.invoker.v2.DefaultInvokerProvider;
13 import com.griddynamics.jagger.user.test.configurations.auxiliary.Id;
14 import com.griddynamics.jagger.user.test.configurations.loadbalancer.JLoadBalancer;
15 
16 import java.util.List;
17 
18 import static com.griddynamics.jagger.user.test.configurations.loadbalancer.JLoadBalancer.DefaultLoadBalancer.ROUND_ROBIN;
19 
38 public class JTestDefinition {
39 
40  private final String id;
41  private final Iterable endpoints;
42 
43  private final String comment;
44  private final Iterable queries;
45  private final Provider<Invoker> invoker;
46  private final List<ResponseValidatorProvider> validators;
47  private final List<Provider<InvocationListener>> listeners;
48  private final QueryPoolLoadBalancer loadBalancer;
49 
51  this.id = builder.id.value();
52  this.endpoints = builder.endpointsProvider;
53 
54  this.comment = (builder.comment == null) ? "" : builder.comment;
55  this.queries = builder.queries;
56  this.invoker = builder.invoker;
57  this.validators = builder.validators;
58  this.listeners = builder.listeners;
59  this.loadBalancer = builder.loadBalancer;
60  }
61 
71  public static Builder builder(Id id, Iterable endpointsProvider) {
72  return new Builder(id, endpointsProvider);
73  }
74 
75  public static class Builder {
76  private final Id id;
77  private final Iterable endpointsProvider;
78 
79  private String comment = "";
80  private Iterable queries;
81  private Provider<Invoker> invoker = DefaultInvokerProvider.of(DefaultHttpInvoker.class);
82  private List<ResponseValidatorProvider> validators = Lists.newArrayList();
83  private List<Provider<InvocationListener>> listeners = Lists.newArrayList();
84  private QueryPoolLoadBalancer loadBalancer;
85 
86  private Builder(Id id, Iterable endpointsProvider) {
87  this.id = id;
88  this.endpointsProvider = endpointsProvider;
89  this.loadBalancer = JLoadBalancer.builder(ROUND_ROBIN).withRandomSeed(31).build();
90  }
91 
97  public Builder withComment(String comment) {
98  this.comment = comment;
99  return this;
100  }
101 
108  public Builder withQueryProvider(Iterable queryProvider) {
109  this.queries = queryProvider;
110  return this;
111  }
112 
121  public Builder withLoadBalancer(QueryPoolLoadBalancer loadBalancer) {
122  this.loadBalancer = loadBalancer;
123  return this;
124  }
125 
135  public Builder withInvoker(Provider<Invoker> invoker) {
136  this.invoker = invoker;
137  return this;
138  }
139 
149  public Builder addValidators(List<ResponseValidatorProvider> validators) {
150  this.validators.addAll(validators);
151  return this;
152  }
153 
165  this.validators.add(validator);
166  return this;
167  }
168 
181  public Builder addListeners(List<Provider<InvocationListener>> listeners) {
182  this.listeners.addAll(listeners);
183  return this;
184  }
185 
198  public Builder addListener(Provider<InvocationListener> listener) {
199  this.listeners.add(listener);
200  return this;
201  }
202 
209  return new JTestDefinition(this);
210  }
211  }
212 
213  public String getId() {
214  return id;
215  }
216 
217  public String getDescription() {
218  return comment;
219  }
220 
221  public Iterable getEndpoints() {
222  return endpoints;
223  }
224 
225  public Iterable getQueries() {
226  return queries;
227  }
228 
229  public Provider<Invoker> getInvoker() {
230  return invoker;
231  }
232 
233  public String getComment() {
234  return comment;
235  }
236 
237  public List<ResponseValidatorProvider> getValidators() {
238  return validators;
239  }
240 
241  public List<Provider<InvocationListener>> getListeners() {
242  return listeners;
243  }
244 
245  public QueryPoolLoadBalancer getLoadBalancer() {
246  return loadBalancer;
247  }
248 }