Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#8] Fixed usage of ExecutionResult in result printers #10

Merged
merged 2 commits into from
Nov 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.griddynamics.qa</groupId>
<artifactId>sprimber-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>

<name>Sprimber</name>
<description>Spring BDD engine for popular frameworks</description>
Expand Down
2 changes: 1 addition & 1 deletion sprimber-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sprimber-parent</artifactId>
<groupId>com.griddynamics.qa</groupId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void illuminateTestCaseStart(TestCaseStartedEvent startEvent) {
@EventListener
public void illuminateTestCaseFinish(TestCaseFinishedEvent finishEvent) {
LOGGER.debug("Test case finished: '{}' with status {}",
finishEvent.getTestCase().getName(), finishEvent.getExecutionResult());
finishEvent.getTestCase().getName(), finishEvent.getExecutionResult().getStatus());
}

@EventListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

package com.griddynamics.qa.sprimber.lifecycle;

import com.griddynamics.qa.sprimber.engine.model.ExecutionResult;
import com.griddynamics.qa.sprimber.lifecycle.model.executor.testcase.TestCaseFinishedEvent;
import com.griddynamics.qa.sprimber.lifecycle.model.executor.testcase.TestCaseStartedEvent;
import com.griddynamics.qa.sprimber.lifecycle.model.executor.testhook.TestHookFinishedEvent;
Expand All @@ -34,9 +35,10 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import org.springframework.core.NamedThreadLocal;

import java.util.Arrays;
import java.util.Optional;

/**
* This is a helper class that able to print shor summary after each scenario to info log level
* This is a helper class that able to print short summary after each scenario to info log level
* By default this bean not configured automatically,
* use property {@code sprimber.configuration.summary.printer.enable} to enable it
*
Expand All @@ -46,13 +48,14 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
public class TestCaseSummaryPrinter {

private static final Logger LOGGER = LoggerFactory.getLogger(TestCaseSummaryPrinter.class);
private static final String EMPTY_STRING = "";
private ThreadLocal<StringBuilder> reportBuilder = new NamedThreadLocal<>("Testcase report builder");

@EventListener
public void illuminateTestCaseStart(TestCaseStartedEvent startEvent) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("\n\n");
stringBuilder.append(String.format("Test Case Started: %s", startEvent.getTestCase().getName()));
stringBuilder.append(String.format("Test Case Completed: %s", startEvent.getTestCase().getName()));
reportBuilder.set(stringBuilder);
}

Expand All @@ -71,14 +74,24 @@ public void illuminateTestStepFinish(TestStepFinishedEvent finishEvent) {
stringBuilder.append(String.format(" %s", finishEvent.getTestStep().getStepAction().getActionType()));
stringBuilder.append(String.format(" %s", finishEvent.getTestStep().getActualText()));
stringBuilder.append(String.format(" %s", Arrays.toString(finishEvent.getTestStep().getStepArguments())));
stringBuilder.append(String.format(" (%s) ", finishEvent.getExecutionResult()));
stringBuilder.append(String.format(" (%s) ", finishEvent.getExecutionResult().getStatus()));
stringBuilder.append(String.format(" (%s) ", getExceptionMessageIfAny(finishEvent.getExecutionResult())));
}

@EventListener
public void illuminateTestHookFinish(TestHookFinishedEvent finishEvent) {
StringBuilder stringBuilder = reportBuilder.get();
stringBuilder.append("\n");
stringBuilder.append(String.format(" %s from:", finishEvent.getHookDefinition().getActionType()));
stringBuilder.append(String.format(" %s of scope", finishEvent.getHookDefinition().getActionType()));
stringBuilder.append(String.format(" %s from:", finishEvent.getHookDefinition().getActionScope()));
stringBuilder.append(String.format(" %s", finishEvent.getHookDefinition().getMethod()));
}

private String getExceptionMessageIfAny(ExecutionResult executionResult) {
return executionResult.getOptionalError().map(this::buildExceptionMessage).orElse(EMPTY_STRING);
}

private String buildExceptionMessage(Throwable throwable) {
return Optional.ofNullable(throwable.getMessage()).orElse(throwable.getClass().getName());
}
}
4 changes: 2 additions & 2 deletions sprimber-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sprimber-parent</artifactId>
<groupId>com.griddynamics.qa</groupId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>com.griddynamics.qa</groupId>
<artifactId>sprimber-engine</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
<optional>true</optional>
</dependency>

Expand Down
6 changes: 3 additions & 3 deletions sprimber-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sprimber-parent</artifactId>
<groupId>com.griddynamics.qa</groupId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>com.griddynamics.qa</groupId>
<artifactId>sprimber-spring-boot-autoconfigure</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
</dependency>

<dependency>
Expand All @@ -27,7 +27,7 @@
<dependency>
<groupId>com.griddynamics.qa</groupId>
<artifactId>sprimber-engine</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions sprimber-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sprimber-parent</artifactId>
<groupId>com.griddynamics.qa</groupId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>com.griddynamics.qa</groupId>
<artifactId>sprimber-spring-boot-starter</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down