1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package dev.aherscu.qa.jgiven.commons.steps;
17
18 import static dev.aherscu.qa.testing.utils.FileUtilsExtensions.*;
19 import static dev.aherscu.qa.testing.utils.ThreadUtils.*;
20 import static org.apache.commons.lang3.StringUtils.*;
21
22 import java.io.*;
23 import java.time.*;
24 import java.util.function.*;
25
26 import javax.annotation.concurrent.*;
27
28 import org.apache.commons.io.filefilter.*;
29
30 import com.tngtech.jgiven.annotation.*;
31 import com.tngtech.jgiven.base.*;
32
33 import dev.aherscu.qa.jgiven.commons.formatters.*;
34 import dev.aherscu.qa.jgiven.commons.model.*;
35 import dev.aherscu.qa.jgiven.commons.utils.*;
36 import lombok.*;
37 import lombok.extern.slf4j.*;
38
39
40
41
42
43
44
45
46
47
48 @ThreadSafe
49 @Slf4j
50 public class GenericActions<T extends AnyScenarioType, SELF extends GenericActions<T, SELF>>
51 extends StageEx<SELF>
52 implements ScenarioType<T> {
53
54
55
56
57 public GenericActions() {
58 log.trace("when stage {} constructed", this);
59 }
60
61
62
63
64
65
66
67
68
69
70 @Override
71 @Deprecated
72 public SELF comment(final String comment) {
73 return self();
74 }
75
76
77
78
79
80
81
82
83
84
85
86
87
88 @SneakyThrows(IOException.class)
89 public SELF concatenate_$_files_from_$_into(
90 final IOFileFilter fileFilter,
91 final File sourceDirectory,
92 final File targetFile) {
93
94 for (val sourceFile : listFiles(
95 sourceDirectory, fileFilter, FileFilterUtils.trueFileFilter())) {
96 log.debug("concatenating {} into {}", sourceFile, targetFile);
97 append(sourceFile, targetFile);
98 }
99
100 return self();
101 }
102
103
104
105
106
107
108
109
110 @SneakyThrows(IOException.class)
111 public SELF deleting_directory(final File directory) {
112 log.debug("deleting directory {}", directory.toString());
113 deleteDirectory(directory);
114 return self();
115 }
116
117
118
119
120
121
122 public SELF doing_nothing() {
123 return doing_nothing(0);
124 }
125
126
127
128
129
130
131
132
133 @SuppressWarnings("boxing")
134 public SELF doing_nothing(
135 @UnitFormatter.Annotation("ms") final long millis) {
136 log.debug("sleeping {} millis", millis);
137 sleep(millis);
138 return self();
139 }
140
141
142
143
144
145
146
147
148 @NestedSteps
149 public SELF doing_nothing(final Duration duration) {
150 return doing_nothing(duration.toMillis());
151 }
152
153
154
155
156
157
158
159
160 @SneakyThrows
161 public SELF failing_on_purpose_with(final Throwable throwable) {
162 log.debug("about to throw {}", throwable.toString());
163 throw throwable;
164 }
165
166
167
168
169
170
171
172
173
174 public final SELF retrying(final Function<SELF, SELF> step) {
175 return retrying(new StepWithDescription<>(EMPTY, step));
176 }
177
178
179
180
181
182
183
184
185
186 public final SELF retrying(final StepWithDescription<SELF> step) {
187 return retry(() -> step.apply(self()));
188 }
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203 @Hidden
204 public final SELF safely(final Function<SELF, SELF> step) {
205 return safely(new StepWithDescription<>(EMPTY, step));
206 }
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 @Hidden
222 public final SELF safely(final StepWithDescription<SELF> step) {
223 return safely(() -> step.apply(self()));
224 }
225 }