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.griddynamics.jagger.engine.e1.Provider;
4 import com.griddynamics.jagger.engine.e1.collector.ResponseValidatorProvider;
5 import com.griddynamics.jagger.engine.e1.collector.invocation.InvocationListener;
6 import com.griddynamics.jagger.invoker.Invoker;
7 import com.griddynamics.jagger.invoker.v2.DefaultHttpInvoker;
8 import com.griddynamics.jagger.user.test.configurations.auxiliary.Id;
9 
10 import com.google.common.collect.Lists;
11 
12 import java.util.List;
13 
31 public class JTestDefinition {
32 
33  private final String id;
34  private final Iterable endpoints;
35 
36  private final String comment;
37  private final Iterable queries;
38  private final Class<? extends Invoker> invoker;
39  private final List<ResponseValidatorProvider> validators;
40  private final List<Provider<InvocationListener>> listeners;
41 
43  this.id = builder.id.value();
44  this.endpoints = builder.endpointsProvider;
45 
46  this.comment = (builder.comment == null) ? "" : builder.comment;
47  this.queries = builder.queries;
48  this.invoker = builder.invoker;
49  this.validators = builder.validators;
50  this.listeners = builder.listeners;
51  }
52 
62  public static Builder builder(Id id, Iterable endpointsProvider) {
63  return new Builder(id, endpointsProvider);
64  }
65 
66  public static class Builder {
67  private final Id id;
68  private final Iterable endpointsProvider;
69 
70  private String comment = "";
71  private Iterable queries;
72  private Class<? extends Invoker> invoker = DefaultHttpInvoker.class;
73  private List<ResponseValidatorProvider> validators = Lists.newArrayList();
74  private List<Provider<InvocationListener>> listeners = Lists.newArrayList();
75 
76  private Builder(Id id, Iterable endpointsProvider) {
77  this.id = id;
78  this.endpointsProvider = endpointsProvider;
79  }
80 
86  public Builder withComment(String comment) {
87  this.comment = comment;
88  return this;
89  }
90 
97  public Builder withQueryProvider(Iterable queryProvider) {
98  this.queries = queryProvider;
99  return this;
100  }
101 
111  public Builder withInvoker(Class<? extends Invoker> invoker) {
112  this.invoker = invoker;
113  return this;
114  }
115 
125  public Builder addValidators(List<ResponseValidatorProvider> validators) {
126  this.validators.addAll(validators);
127  return this;
128  }
129 
141  this.validators.add(validator);
142  return this;
143  }
144 
157  public Builder addListeners(List<Provider<InvocationListener>> listeners) {
158  this.listeners.addAll(listeners);
159  return this;
160  }
161 
174  public Builder addListener(Provider<InvocationListener> listener) {
175  this.listeners.add(listener);
176  return this;
177  }
178 
185  return new JTestDefinition(this);
186  }
187  }
188 
189  public String getId() {
190  return id;
191  }
192 
193  public String getDescription() {
194  return comment;
195  }
196 
197  public Iterable getEndpoints() {
198  return endpoints;
199  }
200 
201  public Iterable getQueries() {
202  return queries;
203  }
204 
205  public Class<? extends Invoker> getInvoker() {
206  return invoker;
207  }
208 
209  public String getComment() {
210  return comment;
211  }
212 
213  public List<ResponseValidatorProvider> getValidators() {
214  return validators;
215  }
216 
217  public List<Provider<InvocationListener>> getListeners() {
218  return listeners;
219  }
220 }