-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMainDefinitions.java
More file actions
513 lines (436 loc) · 25.8 KB
/
Copy pathMainDefinitions.java
File metadata and controls
513 lines (436 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
package cucumber.functional_tests;
import cucumber.TestConstants;
import fr.insee.bpm.exceptions.MetadataParserException;
import fr.insee.bpm.metadata.model.VariablesMap;
import fr.insee.bpm.metadata.reader.ddi.DDIReader;
import fr.insee.genesis.configuration.Config;
import fr.insee.genesis.controller.adapter.LunaticXmlAdapter;
import fr.insee.genesis.controller.dto.SurveyUnitQualityToolDto;
import fr.insee.genesis.controller.dto.VariableQualityToolDto;
import fr.insee.genesis.controller.dto.VariableStateDto;
import fr.insee.genesis.controller.rest.responses.ApiError;
import fr.insee.genesis.controller.rest.responses.ResponseController;
import fr.insee.genesis.controller.services.MetadataService;
import fr.insee.genesis.controller.sources.xml.LunaticXmlCampaign;
import fr.insee.genesis.controller.sources.xml.LunaticXmlDataParser;
import fr.insee.genesis.controller.sources.xml.LunaticXmlSurveyUnit;
import fr.insee.genesis.controller.utils.AuthUtils;
import fr.insee.genesis.controller.utils.ControllerUtils;
import fr.insee.genesis.domain.model.surveyunit.DataState;
import fr.insee.genesis.domain.model.surveyunit.Mode;
import fr.insee.genesis.domain.model.surveyunit.SurveyUnitModel;
import fr.insee.genesis.domain.model.surveyunit.VariableModel;
import fr.insee.genesis.domain.ports.api.DataProcessingContextApiPort;
import fr.insee.genesis.domain.service.context.DataProcessingContextService;
import fr.insee.genesis.domain.service.surveyunit.SurveyUnitQualityService;
import fr.insee.genesis.domain.service.surveyunit.SurveyUnitService;
import fr.insee.genesis.exceptions.GenesisException;
import fr.insee.genesis.infrastructure.document.context.DataProcessingContextDocument;
import fr.insee.genesis.infrastructure.utils.FileUtils;
import fr.insee.genesis.stubs.ConfigStub;
import fr.insee.genesis.stubs.DataProcessingContextPersistancePortStub;
import fr.insee.genesis.stubs.SurveyUnitPersistencePortStub;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.assertj.core.api.Assertions;
import org.springframework.http.ResponseEntity;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
public class MainDefinitions {
private final PrintStream standardOut = System.out;
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
String directory;
Path inDirectory = Paths.get(TestConstants.FUNCTIONAL_TESTS_WEB_DIRECTORY);
final Path ddiDirectory = Paths.get(TestConstants.FUNCTIONAL_TESTS_DDI_DIRECTORY);
SurveyUnitQualityService surveyUnitQualityService = new SurveyUnitQualityService();
SurveyUnitPersistencePortStub surveyUnitPersistence = new SurveyUnitPersistencePortStub();
DataProcessingContextPersistancePortStub dataProcessingContextPersistancePortStub =
new DataProcessingContextPersistancePortStub();
DataProcessingContextApiPort dataProcessingContextApiPort = new DataProcessingContextService(
dataProcessingContextPersistancePortStub,
surveyUnitPersistence
);
Config config = new ConfigStub();
ResponseEntity<List<SurveyUnitModel>> surveyUnitModelResponse;
ResponseEntity<Object> surveyUnitLatestStatesResponse;
ResponseController responseController = new ResponseController(
new SurveyUnitService(surveyUnitPersistence, new MetadataService(), new FileUtils(config)),
surveyUnitQualityService,
new FileUtils(config),
new ControllerUtils(new FileUtils(config)),
new AuthUtils(config),
new MetadataService(),
dataProcessingContextApiPort
);
List<SurveyUnitModel> surveyUnitModels;
//BEFOREs
@Before
public void init() {
this.surveyUnitPersistence.getMongoStub().clear();
}
@Before("@NeedsLogPrepare")
public void prepare_log_check(){
System.setOut(new PrintStream(outputStreamCaptor));
}
//GIVENs
@Given("We have data in directory {string}")
public void init_folder(String directory) throws IOException {
this.directory = directory;
inDirectory = inDirectory.resolve(directory);
Files.createDirectories(inDirectory);
}
@Given("We copy data file {string} to that directory")
public void copy_data_file(String dataFile) throws IOException {
Path dataFilePath = Paths.get(TestConstants.TEST_RESOURCES_DIRECTORY).resolve(dataFile);
Files.copy(dataFilePath, this.inDirectory.resolve(dataFilePath.getFileName().toString()),
StandardCopyOption.REPLACE_EXISTING);
}
@Given("We have a context in database for that data with review {string}")
public void create_context(String withReviewString) {
dataProcessingContextPersistancePortStub.getMongoStub().add(
new DataProcessingContextDocument(
directory,
new ArrayList<>(),
Boolean.parseBoolean(withReviewString)
)
);
}
@Given("We have a context in database for partitionId {string} with review {string}")
public void create_context(String partitionId, String withReviewString) {
dataProcessingContextPersistancePortStub.getMongoStub().add(
new DataProcessingContextDocument(
partitionId,
new ArrayList<>(),
Boolean.parseBoolean(withReviewString)
)
);
}
@Given("We have a survey unit with campaignId {string} and interrogationId {string}")
public void create_light_surveyUnit(String campaignId, String interrogationId) {
surveyUnitPersistence.getMongoStub().add(SurveyUnitModel.builder()
.campaignId(campaignId)
.interrogationId(interrogationId)
.build());
}
//WHENs
@When("We create survey unit models from file {string} with DDI {string}")
public void get_models(String fileName, String ddiName) throws IOException, ParserConfigurationException,
SAXException, GenesisException, MetadataParserException {
Path filePath = inDirectory.resolve(fileName);
Path ddiFilePath = ddiDirectory.resolve(directory).resolve(ddiName);
if(fileName.endsWith(".xml")){
LunaticXmlDataParser parser = new LunaticXmlDataParser();
LunaticXmlCampaign campaign;
campaign = parser.parseDataFile(filePath);
VariablesMap variablesMap = DDIReader.getMetadataFromDDI(
ddiFilePath.toFile().toURI().toURL().toString(),
new FileInputStream(ddiFilePath.toFile())
).getVariables();
List<SurveyUnitModel> surveyUnitModels1 = new ArrayList<>();
for (LunaticXmlSurveyUnit su : campaign.getSurveyUnits()) {
surveyUnitModels1.addAll(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), Mode.WEB));
}
surveyUnitQualityService.verifySurveyUnits(surveyUnitModels1,variablesMap);
surveyUnitModels = surveyUnitModels1;
}
}
@When("We save data from that directory")
public void get_su_models_from_folder() throws Exception {
responseController.saveResponsesFromXmlCampaignFolder(this.inDirectory.getFileName().toString(), null);
}
@When("We allow review for that partition")
public void set_review_to_true() {
String partitionId = this.inDirectory.getFileName().toString();
dataProcessingContextPersistancePortStub.getMongoStub().stream().filter(
dataProcessingContextDocument -> dataProcessingContextDocument.getPartitionId().equals(partitionId)
).toList().forEach(
dataProcessingContextDocument -> dataProcessingContextDocument.setWithReview(true)
);
}
@When("We delete that directory")
public void delete_directory() throws IOException {
org.springframework.util.FileSystemUtils.deleteRecursively(inDirectory);
}
@When("We extract survey unit data with questionnaireId {string} and interrogationId {string}")
public void extract_survey_data(String questionnaireId, String interrogationId) {
this.surveyUnitModelResponse = responseController.getLatestByInterrogation(interrogationId, questionnaireId);
}
@When("We extract survey unit latest states with questionnaireId {string} and interrogationId {string}")
public void extract_survey_unit_latest_states(String questionnaireId, String interrogationId){
try {
this.surveyUnitLatestStatesResponse =
responseController.findResponsesByInterrogationAndQuestionnaireLatestStates(interrogationId,
questionnaireId);
} catch (GenesisException e) {
this.surveyUnitLatestStatesResponse = ResponseEntity.status(e.getStatus()).body(new ApiError(e.getMessage()));
}
}
//THENs
@Then("There should be {int} {string} SurveyUnit in database")
public void check_surveyunits_by_state(int expectedCount, String expectedStatus) {
Assertions.assertThat(this.surveyUnitPersistence.getMongoStub().stream().filter(
surveyUnitModel -> surveyUnitModel.getState().name().equals(expectedStatus)
).toList()).hasSize(expectedCount);
}
@Then("For SurveyUnit {string} there should be at least one {string} SurveyUnit Model")
public void check_expected_datastate_model(String interrogationId, String expectedDataState) {
Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitModel ->
surveyUnitModel.getState().toString().equals(expectedDataState)
&& surveyUnitModel.getInterrogationId().equals(interrogationId)
).isNotEmpty();
}
@Then("For SurveyUnit {string} there shouldn't be a {string} SurveyUnit Model")
public void check_unexpected_datastate_model(String interrogationId, String unexpectedDataState) {
Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitModel ->
surveyUnitModel.getState().toString().equals(unexpectedDataState)
&& surveyUnitModel.getInterrogationId().equals(interrogationId)
).isEmpty();
}
@Then("We should have a {string} Survey Unit model for survey unit {string} with {string} filled with {string} for iteration " +
"{int}")
public void check_survey_unit_model_content(String dataState, String interrogationId, String variableName,
String expectedValue, int iteration) {
//Get model
List<SurveyUnitModel> concernedSurveyUnitModels = this.surveyUnitModels.stream().filter(surveyUnitModel ->
surveyUnitModel.getState().toString().equals(dataState)
&& surveyUnitModel.getInterrogationId().equals(interrogationId)
).toList();
Assertions.assertThat(concernedSurveyUnitModels).isNotEmpty();
SurveyUnitModel concernedSurveyUnitModel = concernedSurveyUnitModels.getFirst();
//Get Variable
List<VariableModel> concernedCollectedVariables =
concernedSurveyUnitModel.getCollectedVariables().stream().filter(variable ->
variable.varId().equals(variableName)
&& variable.iteration().equals(iteration)
).toList();
Assertions.assertThat(concernedCollectedVariables).isNotEmpty().hasSize(1);
VariableModel concernedCollectedVariable = concernedCollectedVariables.getFirst();
//Value assertion
Assertions.assertThat(concernedCollectedVariable.value()).isEqualTo(expectedValue);
}
@Then("For collected variable {string} in survey unit {string} we should have {string} and scope {string} for " +
"iteration {int}")
public void check_collected_variable_content_in_mongo(
String collectedVariableName,
String interrogationId,
String expectedValue,
String expectedScope,
Integer iteration
) {
//Get SurveyUnitModel
List<SurveyUnitModel> concernedSurveyUnitModels = surveyUnitPersistence.getMongoStub().stream().filter(surveyUnitModel ->
surveyUnitModel.getState().equals(DataState.COLLECTED)
&& surveyUnitModel.getInterrogationId().equals(interrogationId)
).toList();
Assertions.assertThat(concernedSurveyUnitModels).hasSize(1);
SurveyUnitModel surveyUnitModel = concernedSurveyUnitModels.getFirst();
//Get Variable
List<VariableModel> concernedCollectedVariables =
surveyUnitModel.getCollectedVariables().stream().filter(variableModel ->
variableModel.varId().equals(collectedVariableName)
&& Objects.equals(variableModel.scope(), expectedScope)
&& variableModel.iteration().equals(iteration)
).toList();
Assertions.assertThat(concernedCollectedVariables).hasSize(1);
VariableModel variableModel = concernedCollectedVariables.getFirst();
//Value content assertion
Assertions.assertThat(variableModel.value()).isEqualTo(expectedValue);
}
@Then("For external variable {string} in survey unit {string} we should have {string} and scope {string} for " +
"iteration {int}")
public void check_external_variable_content_in_mongo(
String externalVariableName,
String interrogationId,
String expectedValue,
String expectedScope,
Integer iteration
) {
//Get SurveyUnitModel
List<SurveyUnitModel> concernedSurveyUnitModels = surveyUnitPersistence.getMongoStub().stream().filter(surveyUnitModel ->
surveyUnitModel.getState().equals(DataState.COLLECTED)
&& surveyUnitModel.getInterrogationId().equals(interrogationId)
).toList();
Assertions.assertThat(concernedSurveyUnitModels).hasSize(1);
SurveyUnitModel surveyUnitModel = concernedSurveyUnitModels.getFirst();
//Get Variable
List<VariableModel> concernedExternalVariables =
surveyUnitModel.getExternalVariables().stream().filter(variableModel ->
variableModel.varId().equals(externalVariableName)
&& Objects.equals(variableModel.scope(), expectedScope)
&& variableModel.iteration().equals(iteration)
).toList();
Assertions.assertThat(concernedExternalVariables).hasSize(1);
VariableModel variableModel = concernedExternalVariables.getFirst();
//Value content assertion
Assertions.assertThat(variableModel.value()).isEqualTo(expectedValue);
}
@Then("If we get latest states for {string} in collected variable {string}, survey unit {string} we should have {string} for iteration {int}")
public void check_latest_state_collected(String questionnaireId, String variableName, String interrogationId, String expectedValue, int iteration) throws GenesisException {
ResponseEntity<Object> response =
responseController.findResponsesByInterrogationAndQuestionnaireLatestStates(interrogationId, questionnaireId);
Assertions.assertThat(response.getStatusCode().value()).isEqualTo(200);
SurveyUnitQualityToolDto surveyUnitQualityToolDto = (SurveyUnitQualityToolDto) response.getBody();
List<VariableQualityToolDto> variableQualityToolDtos = surveyUnitQualityToolDto.getCollectedVariables().stream().filter(
variableQualityToolDto -> variableQualityToolDto.getVariableName().equals(variableName)
&& variableQualityToolDto.getIteration().equals(iteration)
).toList();
Assertions.assertThat(variableQualityToolDtos).hasSize(1);
List<VariableStateDto> variableStateDtoList =
variableQualityToolDtos.getFirst().getVariableStateDtoList().stream().filter(
variableStateDto -> variableStateDto.getState().equals(DataState.COLLECTED)
).toList();
Assertions.assertThat(variableStateDtoList).hasSize(1);
Assertions.assertThat(variableStateDtoList.getFirst().getValue()).isEqualTo(expectedValue);
}
@Then("If we get latest states for {string} in external variable {string}, survey unit {string} we should have {string} for iteration {int}")
public void check_latest_state_external(String questionnaireId, String variableName, String interrogationId, String expectedValue, int iteration) throws GenesisException {
ResponseEntity<Object> response =
responseController.findResponsesByInterrogationAndQuestionnaireLatestStates(interrogationId, questionnaireId);
Assertions.assertThat(response.getStatusCode().value()).isEqualTo(200);
SurveyUnitQualityToolDto surveyUnitQualityToolDto = (SurveyUnitQualityToolDto) response.getBody();
List<VariableQualityToolDto> variableQualityToolDtos = surveyUnitQualityToolDto.getExternalVariables().stream().filter(
variableQualityToolDto -> variableQualityToolDto.getVariableName().equals(variableName)
&& variableQualityToolDto.getIteration().equals(iteration)
).toList();
Assertions.assertThat(variableQualityToolDtos).hasSize(1);
List<VariableStateDto> variableStateDtoList =
variableQualityToolDtos.getFirst().getVariableStateDtoList().stream().filter(
variableStateDto -> variableStateDto.getState().equals(DataState.COLLECTED)
).toList();
Assertions.assertThat(variableStateDtoList).hasSize(1);
Assertions.assertThat(variableStateDtoList.getFirst().getValue()).isEqualTo(expectedValue);
}
@Then("The extracted survey unit data response should have a survey unit model with interrogationId {string}")
public void check_su_model_interrogationId(String interrogationId) {
Assertions.assertThat(surveyUnitModelResponse).isNotNull();
Assertions.assertThat(surveyUnitModelResponse.getBody()).isNotNull().hasSize(1);
Assertions.assertThat(surveyUnitModelResponse.getBody().getFirst().getInterrogationId()).isEqualTo(interrogationId);
}
@Then("The extracted survey unit data response should have a survey unit model for interrogationId {string} with " +
"{int} collected variables")
public void check_su_model_collected_variables_volumetry(
String interrogationId,
int expectedVolumetry
){
Assertions.assertThat(surveyUnitModelResponse).isNotNull();
Assertions.assertThat(surveyUnitModelResponse.getBody()).isNotNull();
List<SurveyUnitModel> filteredList = surveyUnitModelResponse.getBody().stream().filter(
surveyUnitModel -> surveyUnitModel.getInterrogationId().equals(interrogationId)
).toList();
Assertions.assertThat(filteredList)
.isNotNull().hasSize(1);
Assertions.assertThat(filteredList.getFirst().getCollectedVariables()).hasSize(expectedVolumetry);
}
@Then("The extracted survey unit data response should have a survey unit model for interrogationId {string} with " +
"{int} external variables")
public void check_su_model_external_variables_volumetry(
String interrogationId,
int expectedVolumetry
){
Assertions.assertThat(surveyUnitModelResponse).isNotNull();
Assertions.assertThat(surveyUnitModelResponse.getBody()).isNotNull();
List<SurveyUnitModel> filteredList = surveyUnitModelResponse.getBody().stream().filter(
surveyUnitModel -> surveyUnitModel.getInterrogationId().equals(interrogationId)
).toList();
Assertions.assertThat(filteredList)
.isNotNull().hasSize(1);
Assertions.assertThat(filteredList.getFirst().getExternalVariables()).hasSize(expectedVolumetry);
}
@Then("The extracted survey unit latest states response should have a survey unit DTO has interrogationId " +
"{string}" +
" with {int} collected variables")
public void check_su_latest_states_collected_variables_volumetry(String interrogationId, int expectedVolumetry) {
SurveyUnitQualityToolDto response = (SurveyUnitQualityToolDto) surveyUnitLatestStatesResponse.getBody();
Assertions.assertThat(response).isNotNull();
Assertions.assertThat(surveyUnitLatestStatesResponse.getStatusCode().value()).isEqualTo(200);
Assertions.assertThat(response.getInterrogationId()).isEqualTo(interrogationId);
Assertions.assertThat(response.getCollectedVariables()).hasSize(expectedVolumetry);
}
@Then("The extracted survey unit latest states response should have a survey unit DTO has interrogationId " +
"{string}" +
" with {int} external variables")
public void check_su_latest_states_external_variables_volumetry(String interrogationId, int expectedVolumetry) {
Assertions.assertThat(surveyUnitLatestStatesResponse).isNotNull();
Assertions.assertThat(surveyUnitLatestStatesResponse.getBody()).isNotNull();
SurveyUnitQualityToolDto surveyUnitQualityToolDto = (SurveyUnitQualityToolDto) surveyUnitLatestStatesResponse.getBody();
Assertions.assertThat(surveyUnitQualityToolDto.getInterrogationId()).isEqualTo(interrogationId);
Assertions.assertThat(surveyUnitQualityToolDto.getExternalVariables()).hasSize(expectedVolumetry);
}
@Then("We shouldn't have any response for campaign {string}")
public void check_response_not_present(String campaignId) {
List<SurveyUnitModel> concernedSurveyUnitModels = surveyUnitPersistence.getMongoStub().stream().filter(surveyUnitModel ->
surveyUnitModel.getState().equals(DataState.COLLECTED)
&& surveyUnitModel.getCampaignId().equals(campaignId)
).toList();
Assertions.assertThat(concernedSurveyUnitModels).isEmpty();
}
@Then("We should have {string} in the logs")
public void check_log(String expectedLogContent) {
Assertions.assertThat(outputStreamCaptor.toString()).contains(expectedLogContent);
}
@Then("The response of get latest states should have {int} status code")
public void check_latest_status_status_code(int expectedStatusCode) {
Assertions.assertThat(surveyUnitLatestStatesResponse.getStatusCode().value()).isEqualTo(expectedStatusCode);
}
@Then("The extracted survey unit data latest states response dto should have a {string} collected variable named {string} with {string} as value for iteration {int}")
public void check_latest_states_variable_type(String variableType, String expectedVariableName, String expectedValue, int iteration){
Assertions.assertThat(surveyUnitLatestStatesResponse).isNotNull();
Assertions.assertThat(surveyUnitLatestStatesResponse.getBody()).isNotNull();
Assertions.assertThat(surveyUnitLatestStatesResponse.getStatusCode().value()).isEqualTo(200);
SurveyUnitQualityToolDto surveyUnitQualityToolDto = (SurveyUnitQualityToolDto) surveyUnitLatestStatesResponse.getBody();
List<VariableQualityToolDto> variableQualityToolDtos = surveyUnitQualityToolDto.getCollectedVariables().stream().filter(variable ->
variable.getVariableName().equals(expectedVariableName)
&& variable.getIteration().equals(iteration)).toList();
Assertions.assertThat(variableQualityToolDtos).hasSize(1);
switch (variableType.toLowerCase()){
case "integer" -> Assertions.assertThat(variableQualityToolDtos.getFirst().getVariableStateDtoList().getFirst().getValue()).isInstanceOf(Integer.class).isEqualTo(Integer.parseInt(expectedValue));
case "float" -> Assertions.assertThat(variableQualityToolDtos.getFirst().getVariableStateDtoList().getFirst().getValue()).isInstanceOf(Float.class).isEqualTo(Float.parseFloat(expectedValue));
case "boolean" -> Assertions.assertThat(variableQualityToolDtos.getFirst().getVariableStateDtoList().getFirst().getValue()).isInstanceOf(Boolean.class).isEqualTo(Boolean.parseBoolean(expectedValue));
case "string" -> Assertions.assertThat(variableQualityToolDtos.getFirst().getVariableStateDtoList().getFirst().getValue()).isInstanceOf(String.class).isEqualTo(expectedValue);
default -> Assertions.fail("incorrect variable type %s".formatted(variableType));
}
}
//AFTERs
@After
public void clean() throws IOException {
System.setOut(standardOut);
//Move from DONE to IN
Path doneDirectory = Path.of(TestConstants.TEST_RESOURCES_DIRECTORY, "DONE");
if (doneDirectory
.resolve(inDirectory.getParent().getFileName())
.resolve(inDirectory.getFileName()).toFile().exists()
){
try (Stream<Path> stream = Files.list(doneDirectory
.resolve(inDirectory.getParent().getFileName())
.resolve(inDirectory.getFileName())
)){
for (Path filePath : stream.filter(path -> !path.toFile().isDirectory()).toList()) {
Files.copy(filePath, inDirectory.resolve(filePath.getFileName()),
StandardCopyOption.REPLACE_EXISTING);
}
}
}
//Clean DONE test folder
org.springframework.util.FileSystemUtils.deleteRecursively(doneDirectory);
}
@After("@NeedsLogPrepare")
public void print_log(){
System.setOut(standardOut);
System.out.println(outputStreamCaptor);
}
}