Skip to content

Commit

Permalink
Merge pull request #25 from telekom/refactoring/model-improvements
Browse files Browse the repository at this point in the history
Refactoring/model improvements
  • Loading branch information
Mike Reiche authored Apr 19, 2021
2 parents 22915eb + 1ce3b6f commit 9f05ac6
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 201 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {

// <ExceptionUtils>
// Comes already implicit from reflections
implementation 'org.javassist:javassist:3.20.0-GA'
// implementation 'org.javassist:javassist:3.20.0-GA'
// </ExceptionUtils>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package eu.tsystems.mms.tic.testframework.events;

import eu.tsystems.mms.tic.testframework.report.TesterraListener;
import eu.tsystems.mms.tic.testframework.report.model.context.MethodContext;
import java.lang.reflect.Method;
import org.testng.IInvokedMethod;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public void onMethodEnd(MethodEndEvent event) {
if (testResult.isSuccess()) {
if (methodContext.getStatus().equals(TestStatusController.Status.PASSED_RETRY)) {
methodContext.readDependsOnMethodContexts()
.filter(dependsOnMethodContexts -> dependsOnMethodContexts.isSame(methodContext) && dependsOnMethodContexts.isRetry())
.forEach(dependsOnMethodContexts -> {
testResult.getTestContext().getFailedTests().removeResult(dependsOnMethodContexts.testResult);
testResult.getTestContext().getSkippedTests().removeResult(dependsOnMethodContexts.testResult);
.filter(dependsOnMethodContext -> dependsOnMethodContext.isSame(methodContext) && dependsOnMethodContext.isRetry())
.forEach(dependsOnMethodContext -> {
dependsOnMethodContext.getTestNgResult().ifPresent(dependsOnTestResult -> {
testResult.getTestContext().getFailedTests().removeResult(dependsOnTestResult);
testResult.getTestContext().getSkippedTests().removeResult(dependsOnTestResult);
});
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import java.util.LinkedHashMap;
import java.util.Map;

/**
* TODO: Move this class to legacy report module
*/
public class ReportInfo {

private static final Logger LOGGER = LoggerFactory.getLogger(ReportInfo.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ public static void setMethodStatus(MethodContext methodContext, Status status, M
/*
set status
*/
if (methodContext.testResult != null) {
Throwable throwable = methodContext.testResult.getThrowable();
if (methodContext.getTestNgResult().isPresent()) {
ITestResult testResult = methodContext.getTestNgResult().get();
Throwable throwable = testResult.getThrowable();

if (methodContext.testResult.getStatus() == ITestResult.CREATED && status == Status.FAILED) {
if (testResult.getStatus() == ITestResult.CREATED && status == Status.FAILED) {
LOGGER.warn("TestNG bug - result status is CREATED, which is wrong. Method status is " + Status.FAILED +
", which is also wrong. Assuming SKIPPED.");
status = Status.SKIPPED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import eu.tsystems.mms.tic.testframework.exceptions.SystemException;
import eu.tsystems.mms.tic.testframework.execution.testng.ListenerUtils;
import eu.tsystems.mms.tic.testframework.execution.testng.worker.finish.HandleCollectedAssertsWorker;
import eu.tsystems.mms.tic.testframework.execution.testng.worker.finish.MethodAnnotationCheckerWorker;
import eu.tsystems.mms.tic.testframework.execution.testng.worker.finish.MethodContextUpdateWorker;
import eu.tsystems.mms.tic.testframework.execution.testng.worker.finish.MethodEndWorker;
import eu.tsystems.mms.tic.testframework.execution.testng.worker.finish.RemoveTestMethodIfRetryPassedWorker;
Expand Down Expand Up @@ -130,7 +129,6 @@ public class TesterraListener implements
eventBus.register(new MethodStartWorker());
eventBus.register(new MethodParametersWorker());
eventBus.register(new HandleCollectedAssertsWorker());// !! must be invoked before MethodAnnotationCheckerWorker
eventBus.register(new MethodAnnotationCheckerWorker()); // !! must be invoked before Container Update
eventBus.register(new MethodContextUpdateWorker());
eventBus.register(new RemoveTestMethodIfRetryPassedWorker());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,19 @@ private MethodContext getMethodContext(

if (testResult != null) {
found = methodContexts.stream()
.filter(mc -> testResult == mc.getTestNgResult())
.filter(methodContext -> methodContext.getTestNgResult().isPresent())
.filter(methodContext -> testResult == methodContext.getTestNgResult().get())
.findFirst();
methodContextName = TesterraListener.getContextGenerator().getMethodContextName(testResult);
} else {
// TODO: (!!!!) this is not eindeutig
found = methodContexts.stream()
.filter(mc -> testContext == mc.getTestNgContext())
.filter(mc -> testNGMethod == mc.getTestNgMethod())
.filter(mc -> mc.getParameterValues().containsAll(parametersList))
.filter(methodContext -> methodContext.getTestNgResult().isPresent())
.filter(methodContext -> {
ITestResult iTestResult = methodContext.getTestNgResult().get();
return testContext == iTestResult.getTestContext() && testNGMethod == iTestResult.getMethod();
})
.filter(methodContext -> methodContext.getParameterValues().containsAll(parametersList))
.findFirst();

methodContextName = TesterraListener.getContextGenerator().getMethodContextName(testContext, testNGMethod, parameters);
Expand All @@ -170,8 +174,6 @@ private MethodContext getMethodContext(
//fillBasicContextValues(methodContext, this, name);

methodContext.setTestNgResult(testResult);
methodContext.setTestNgContext(testContext);
methodContext.setTestNgMethod(testNGMethod);
methodContext.setParameterValues(testResult.getParameters());
//
// if (parameters.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
import eu.tsystems.mms.tic.testframework.report.model.steps.TestStepAction;
import eu.tsystems.mms.tic.testframework.report.model.steps.TestStepController;
import eu.tsystems.mms.tic.testframework.utils.StringUtils;
import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import java.util.ArrayList;
import org.testng.ITestResult;

import java.lang.annotation.Annotation;
Expand All @@ -59,19 +58,7 @@ public enum Type {
CONFIGURATION_METHOD
}

/**
* @deprecated
*/
public ITestResult testResult;
/**
* @deprecated
*/
public ITestContext iTestContext;
/**
* @deprecated
*/
public ITestNGMethod iTestNgMethod;

private ITestResult testResult;
private TestStatusController.Status status = TestStatusController.Status.NO_RUN;
private final Type methodType;
private List<Object> parameterValues;
Expand All @@ -82,15 +69,16 @@ public enum Type {
private Class failureCorridorClass = FailureCorridor.High.class;
private int hashCodeOfTestResult = 0;
public final List<String> infos = new LinkedList<>();
private List<SessionContext> sessionContexts = new LinkedList<>();
private final List<SessionContext> sessionContexts = new LinkedList<>();
public String priorityMessage = null;
private final TestStepController testStepController = new TestStepController();
private List<MethodContext> relatedMethodContexts = new LinkedList<>();
private List<MethodContext> dependsOnMethodContexts = new LinkedList<>();
private final List<MethodContext> dependsOnMethodContexts = new LinkedList<>();
private List<CustomContext> customContexts;
private ErrorContext errorContext;
private int numAssertions = 0;
private int numOptionalAssertions = 0;
private final List<Annotation> annotationList = new ArrayList<>();

/**
* Public constructor. Creates a new <code>MethodContext</code> object.
Expand Down Expand Up @@ -506,7 +494,7 @@ public Stream<Video> readVideos() {
* Proper parameter names are available by setting {https://stackoverflow.com/questions/6759880/getting-the-name-of-a-method-parameter}
*/
public Parameter[] getParameters() {
return iTestNgMethod.getConstructorOrMethod().getMethod().getParameters();
return getTestNgResult().map(testResult -> testResult.getMethod().getConstructorOrMethod().getMethod().getParameters()).orElse(new Parameter[]{});
}

public MethodContext setParameterValues(Object[] parameters) {
Expand All @@ -523,37 +511,29 @@ public List<Object> getParameterValues() {
}
}

public ITestResult getTestNgResult() {
return testResult;
public Optional<ITestResult> getTestNgResult() {
return Optional.ofNullable(this.testResult);
}

public MethodContext setTestNgResult(ITestResult testResult) {
this.testResult = testResult;
return this;
}

public ITestContext getTestNgContext() {
return iTestContext;
}

public MethodContext setTestNgContext(ITestContext iTestContext) {
this.iTestContext = iTestContext;
return this;
}

public ITestNGMethod getTestNgMethod() {
return iTestNgMethod;
public Stream<Annotation> readAnnotations() {
return Stream.concat(
this.annotationList.stream(),
getTestNgResult()
.map(testResult -> Stream.of(testResult.getMethod().getConstructorOrMethod().getMethod().getAnnotations()))
.orElse(Stream.empty())
);
}

public MethodContext setTestNgMethod(ITestNGMethod iTestNgMethod) {
this.iTestNgMethod = iTestNgMethod;
public MethodContext addAnnotation(Annotation annotation) {
this.annotationList.add(annotation);
return this;
}

public Stream<Annotation> readAnnotations() {
return Stream.of(this.iTestNgMethod.getConstructorOrMethod().getMethod().getAnnotations());
}

/**
* @deprecated Used in methodTags.vm, methodBodyDashboard.vm, methodsDashboard.vm
*/
Expand Down
Loading

0 comments on commit 9f05ac6

Please sign in to comment.