Mentions légales du service

Skip to content
Snippets Groups Projects

feature(test): unregister application

Merged Jamalac Orange requested to merge feature/tests_e2e_unregister_application into develop
Files
2
@@ -6,16 +6,18 @@ import io.cucumber.java.en.When;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.api.AssertionsForClassTypes;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
@Slf4j
@AllArgsConstructor
@@ -23,19 +25,7 @@ public class RobertBatchSteps {
private final ApplicationProperties applicationProperties;
private final List<String> processErrorLogs;
private final List<String> processLogs;
private void getLogsListFromProcessInputStream(final InputStream processStdOutput, List<String> lineList) {
lineList.clear();
new BufferedReader(new InputStreamReader(processStdOutput))
.lines()
.forEach(line -> {
lineList.add(line);
log.debug(line);
});
}
private final List<String> processLogs = new ArrayList<>();
@When("robert batch as not been executed yet")
public void batchDoesNotExecute() {
@@ -50,27 +40,43 @@ public class RobertBatchSteps {
final var process = builder.start();
final var background = Executors.newFixedThreadPool(2);
getLogsListFromProcessInputStream(process.getInputStream(), processLogs);
getLogsListFromProcessInputStream(process.getErrorStream(), processErrorLogs);
background.submit(new StreamGobbler(process.getInputStream(), processLogs));
background.submit(new StreamGobbler(process.getErrorStream(), processLogs));
boolean hasExited = process.waitFor(60, SECONDS);
background.shutdownNow();
assertThat(hasExited)
AssertionsForClassTypes.assertThat(hasExited)
.as("Robert batch execution timed out after 60 seconds")
.isTrue();
assertThat(process.exitValue())
AssertionsForClassTypes.assertThat(process.exitValue())
.as("Robert batch process exit code")
.isEqualTo(0);
}
@Then("robert batch has discarded the hello messages")
public void checkDiscardedErrorInBatch() {
var nbDiscardedHello = processLogs
.stream()
.filter(line -> line.contains("Could not find keys for id, discarding the hello message"))
.count();
assertThat(nbDiscardedHello)
.as("Robert batch process number of discarded hello message")
.isGreaterThan(0);
@Then("robert batch logs contains: {string}")
public void checkDiscardedErrorInBatch(String message) {
assertThat(processLogs).anyMatch(line -> line.contains(message));
}
private static class StreamGobbler implements Runnable {
private final InputStream inputStream;
List<String> processLogs;
public StreamGobbler(final InputStream inputStream, List<String> processLogs) {
this.inputStream = inputStream;
this.processLogs = processLogs;
}
@Override
public void run() {
new BufferedReader(new InputStreamReader(inputStream))
.lines()
.forEach(line -> {
processLogs.add(line);
log.debug(line);
});
}
}
}
Loading