Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JParallelTestsGroup.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.testgroup.TestGroupDecisionMakerListener;
6 import com.griddynamics.jagger.engine.e1.collector.testgroup.TestGroupListener;
7 import com.griddynamics.jagger.user.test.configurations.auxiliary.Id;
8 
9 import java.util.ArrayList;
10 import java.util.Collections;
11 import java.util.List;
12 import java.util.stream.Collectors;
13 
28 public class JParallelTestsGroup {
29  private final String id;
30  private final List<JLoadTest> tests;
31  private final List<Provider<TestGroupListener>> listeners;
32  private final List<Provider<TestGroupDecisionMakerListener>> decisionMakerListeners;
33 
42  public static Builder builder(Id id, List<JLoadTest> tests) {
43  return new Builder(id, tests);
44  }
45 
55  public static Builder builder(Id id, JLoadTest test, JLoadTest... tests) {
56 
57  List<JLoadTest> testList = new ArrayList<>();
58  testList.add(test);
59  Collections.addAll(testList, tests);
60 
61  return new Builder(id, testList);
62  }
63 
64  private JParallelTestsGroup(Builder builder) {
65  this.id = builder.id.value();
66  this.tests = builder.tests;
67  this.listeners = builder.listeners;
68  this.decisionMakerListeners = builder.decisionMakerListeners;
69  }
70 
71  public static class Builder {
72 
73  private final Id id;
74  private final List<JLoadTest> tests;
75  private List<Provider<TestGroupListener>> listeners = Lists.newArrayList();
76  private List<Provider<TestGroupDecisionMakerListener>> decisionMakerListeners = Lists.newArrayList();
77 
78  public Builder(Id id, List<JLoadTest> tests) {
79  this.id = id;
80  this.tests = tests;
81  }
82 
92  public Builder addListener(Provider<TestGroupListener> listener) {
93  this.listeners.add(listener);
94  return this;
95  }
96 
106  public Builder addListeners(List<Provider<TestGroupListener>> listeners) {
107  this.listeners.addAll(listeners);
108  return this;
109  }
110 
121  public Builder addDecisionMakerListener(Provider<TestGroupDecisionMakerListener> listener) {
122  this.decisionMakerListeners.add(listener);
123  return this;
124  }
125 
136  public Builder addDecisionMakerListeners(List<Provider<TestGroupDecisionMakerListener>> listeners) {
137  this.decisionMakerListeners.addAll(listeners);
138  return this;
139  }
140 
147 
148  if (tests.stream().map(JLoadTest::getId).collect(Collectors.toSet()).size() < tests.size()) {
149  throw new IllegalStateException("JLoadTest ids inside one JParallelTestsGroup are not all unique");
150  }
151 
152  return new JParallelTestsGroup(this);
153  }
154 
155  }
156 
157  public List<JLoadTest> getTests() {
158  return tests;
159  }
160 
161  public String getId() {
162  return id;
163  }
164 
165  public List<Provider<TestGroupListener>> getListeners() {
166  return listeners;
167  }
168 
169  public List<Provider<TestGroupDecisionMakerListener>> getDecisionMakerListeners() {
170  return decisionMakerListeners;
171  }
172 }