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

Not run/Skipped test reporting #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ public interface TestResultFactory {
* @return an appropriate TestResult object.
*/
TestResult error(String testName, Throwable throwable, Instant startTime, Instant endTime);

/**
* @param testName - the name of the test that did not run.
* @return an appropriate TestResult object.
*/
TestResult notExecuted(String testName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

public enum TestStatus {
PASS(0), FAIL(1), ERROR(2);
PASS(0), FAIL(1), ERROR(2), NOT_EXECUTED(3);

private int returnCode;
TestStatus(int returnCode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.codice.itest;

import org.codice.itest.api.TestResult;
import org.codice.itest.api.TestResultFactory;
import org.codice.itest.reporter.RemainingTestsReporter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.*;
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved
import java.util.function.Consumer;

import static org.codice.itest.api.TestStatus.NOT_EXECUTED;

@Component("SkipAwareExecutorService")
public class SkipAwareExecutorService extends ThreadPoolExecutor {
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved

@Value("${itest.tests:#{null}}")
private String tests;
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved

private List<Consumer<TestResult>> testResultListenerList;

private List<String> testNameList = Arrays.asList(tests.split(","));

private RemainingTestsReporter remainingTestsReporter;

private TestResultFactory testResultFactory;

public SkipAwareExecutorService(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit,
BlockingQueue<Runnable> workQueue, List<Consumer<TestResult>> testResultListenerList, RemainingTestsReporter remainingTestsReporter, TestResultFactory testResultFactory) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
this.testResultListenerList = testResultListenerList;
this.remainingTestsReporter = remainingTestsReporter;
this.testResultFactory = testResultFactory;
}

@Override
public List<Runnable> shutdownNow() {
remainingTestsReporter.getRemainingList().forEach(testName -> {
TestResult testResult = testResultFactory.notExecuted(testName);
testResultListenerList.forEach(listener -> listener.accept(testResult));
});

return super.shutdownNow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void accept(TestResult testResult) {
case FAIL: logger.warn(formattedResult);
break;
case ERROR: logger.error(formattedResult);
case NOT_EXECUTED: logger.error(formattedResult);
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.codice.itest.reporter;

import org.codice.itest.api.TestResult;

import java.util.List;
import java.util.function.Consumer;

public class RemainingTestsReporter implements Consumer<TestResult> {
private List<String> testNames;
public RemainingTestsReporter(List<String> testNames){
this.testNames = testNames;
}

@Override
public void accept(TestResult testResult) {
if(testNames.contains(testResult.getTestName())){
testNames.remove(testResult.getTestName());
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved
}
}

public List<String> getRemainingList(){return testNames;}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
import org.codice.itest.config.ITestConfigurationProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

@Configuration
Expand All @@ -34,6 +37,11 @@ public ExitCodeReporter exitCodeReporter(){
return new ExitCodeReporter();
}

@Value("${itest.tests:#{null}}")
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved
private String tests;

private List<String> testNameList = Arrays.asList(tests.split(","));

@Bean("testReporter")
@ConditionalOnProperty(prefix="codice.itest", name="loggerName")
public Consumer<TestResult> loggingDiagnosticTestReporter() {
Expand All @@ -52,4 +60,9 @@ public Consumer<TestResult> defaultLoggingDiagnosticTestReporter() {
public Consumer<TestResult> exitCodeReporterConsumer(ExitCodeReporter exitCodeReporter) {
return (tr) -> exitCodeReporter.register(tr.getTestStatus());
}

@Bean("remainingTestsConsumer")
public Consumer<TestResult> remainingTestsReporterConsumer() {
return new RemainingTestsReporter(testNameList);
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright (c) Codice Foundation

* This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the License, or any later version.

* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details. A copy of the GNU Lesser General Public License is distributed along with this program and can be found at
* http://www.gnu.org/licenses/lgpl.html.
*/
package org.codice.itest.result;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.time.Instant;
import java.util.UUID;

import static org.codice.itest.api.TestStatus.NOT_EXECUTED;

final class NotExecutedTestResultImpl extends BaseTestResult{

NotExecutedTestResultImpl(UUID runId, String testName) {
super(runId, testName, NOT_EXECUTED, Instant.now(), Instant.now());
}

@Override
public String toString() {
return toStringCreator.append(super.getRunId())
.append(super.getTestStatus())
.append(super.getTestName())
.append(NOT_EXECUTED)
.toString();
}

@Override
public boolean equals(Object other) {
if (other == null) {
return false;
}

if (other == this) {
return true;
}

if (!(other instanceof NotExecutedTestResultImpl)) {
return false;
}

NotExecutedTestResultImpl testResult = (NotExecutedTestResultImpl) other;
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved

return new EqualsBuilder().append(super.getRunId(), testResult.getRunId())
.append(super.getTestName(), testResult.getTestName())
.append(super.getTestStatus(), testResult.getTestStatus())
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(1313, 4137).append(super.getRunId())
.append(super.getTestName())
.append(super.getTestStatus())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class TestResultFactoryImpl implements TestResultFactory {
private static final String START_TIME = "startTime";
private static final String END_TIME = "endTime";
private static final String EXCEPTION_MESSAGE = "exceptionMessage";
//private static final String NOT_EXECUTED_MESSAGE = "";
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved
private static final String STACK_TRACE = "stackTrace";
private static final String TEST_STATUS = "testStatus";
private final UUID runId;
Expand Down Expand Up @@ -65,6 +66,13 @@ public TestResult error(String testName, Throwable throwable, Instant startTime,
return new ErrorTestResultImpl(runId, testName, throwable, startTime, endTime);
}

@Override
public TestResult notExecuted(String testName) {
MDC.put(STACK_TRACE, "Not Executed");
knekylen-smith marked this conversation as resolved.
Show resolved Hide resolved
MDC.put(TEST_STATUS, TestStatus.NOT_EXECUTED.name());
return new NotExecutedTestResultImpl(runId, testName);
}

private void logTestResultCommonFields(String testName, Instant startTime, Instant endTime) {
MDC.clear();
MDC.put(TEST_NAME, testName);
Expand Down