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