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

Bellatrix Jira Zephyr Plugin #37

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,32 @@ public void preBeforeTest(TestResult testResult, Method memberInfo) throws Excep
public void postBeforeTest(TestResult testResult, Method memberInfo) {
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line

public void beforeTestFailed(Exception e) throws Exception {
}

/**
* Deprecated. <br>
* Use {@link #preAfterTest(TestResult, TimeRecord, Method)} as it offers more information about the test.
*/
@Deprecated
public void preAfterTest(TestResult testResult, Method memberInfo) throws IOException {
}

public void preAfterTest(TestResult testResult, TimeRecord timeRecord, Method memberInfo) throws IOException {
}

/**
* Deprecated. <br>
* Use {@link #postAfterTest(TestResult, TimeRecord, Method, Throwable)} as it offers more information about the test.
*/
@Deprecated
public void postAfterTest(TestResult testResult, Method memberInfo, Throwable failedTestException) {
}

public void postAfterTest(TestResult testResult, TimeRecord timeRecord, Method memberInfo, Throwable failedTestException) {
}

public void afterTestFailed(Exception e) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package solutions.bellatrix.core.plugins;

import org.apache.http.annotation.Obsolete;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -68,27 +70,52 @@ public static void postBeforeTest(TestResult result, Method memberInfo) {
}
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line here as well

public static void beforeTestFailed(Exception e) throws Exception {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
currentObserver.beforeTestFailed(e);
}
}

/**
* Deprecated. <br>
* Use {@link #preAfterTest(TestResult, TimeRecord, Method)} as it offers more information about the test.
*/
@Deprecated
public static void preAfterTest(TestResult result, Method memberInfo) throws Exception {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
currentObserver.preAfterTest(result, memberInfo);
}
}

public static void preAfterTest(TestResult result, TimeRecord timeRecord, Method memberInfo) throws Exception {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
currentObserver.preAfterTest(result, timeRecord, memberInfo);
}
}

/**
* Deprecated. <br>
* Use {@link #postAfterTest(TestResult, TimeRecord, Method, Throwable)} as it offers more information about the test.
*/
@Deprecated
public static void postAfterTest(TestResult result, Method memberInfo, Throwable failedTestException) {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
currentObserver.postAfterTest(result, memberInfo, failedTestException);
}
}

public static void postAfterTest(TestResult result, TimeRecord timeRecord, Method memberInfo, Throwable failedTestException) {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
currentObserver.postAfterTest(result, timeRecord, memberInfo, failedTestException);
}
}

public static void afterTestFailed(Exception e) {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Automate The Planet Ltd.
* Author: Miriam Kyoseva
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package solutions.bellatrix.core.plugins;

import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class TimeRecord {
private long startTime;
private long endTime;

public long getDuration() {
return endTime - startTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import solutions.bellatrix.core.plugins.PluginExecutionEngine;
import solutions.bellatrix.core.plugins.TestResult;
import solutions.bellatrix.core.plugins.TimeRecord;
import solutions.bellatrix.core.plugins.UsesPlugins;

import java.util.ArrayList;
Expand All @@ -28,8 +29,10 @@
import java.util.List;

@ExtendWith(TestResultWatcher.class)
@ExtendWith(TestDurationWatcher.class)
public class BaseTest extends UsesPlugins {
static final ThreadLocal<TestResult> CURRENT_TEST_RESULT = new ThreadLocal<>();
static final ThreadLocal<TimeRecord> CURRENT_TEST_TIME_RECORD = ThreadLocal.withInitial(TimeRecord::new);
private static final ThreadLocal<Boolean> CONFIGURATION_EXECUTED = new ThreadLocal<>();
private static final List<String> ALREADY_EXECUTED_BEFORE_CLASSES = Collections.synchronizedList(new ArrayList<>());
private TestInfo testInfo;
Expand Down Expand Up @@ -93,7 +96,8 @@ public void afterMethodCore(TestInfo testInfo) {
var testClass = this.getClass();
assert testInfo.getTestMethod().isPresent();
var methodInfo = testClass.getMethod(testInfo.getTestMethod().get().getName());
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo);
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo); // DEPRECATED, LEFT FOR COMPATIBILITY
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), CURRENT_TEST_TIME_RECORD.get(), methodInfo);
afterEach();
// PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), methodInfo);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 Automate The Planet Ltd.
* Author: Miriam Kyoseva
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package solutions.bellatrix.core.plugins.junit;

import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

public class TestDurationWatcher implements BeforeTestExecutionCallback, AfterTestExecutionCallback {
@Override
public void beforeTestExecution(ExtensionContext context) {
BaseTest.CURRENT_TEST_TIME_RECORD.get().setStartTime(System.currentTimeMillis());
}

@Override
public void afterTestExecution(ExtensionContext context) {
BaseTest.CURRENT_TEST_TIME_RECORD.get().setEndTime(System.currentTimeMillis());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public void testAborted(ExtensionContext extensionContext, Throwable throwable)
BaseTest.CURRENT_TEST_RESULT.set(TestResult.FAILURE);

try {
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable);
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable); // DEPRECATED, LEFT FOR COMPATIBILITY

PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), throwable);
} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand All @@ -36,7 +38,9 @@ public void testDisabled(ExtensionContext extensionContext, Optional<String> opt
BaseTest.CURRENT_TEST_RESULT.set(TestResult.SUCCESS);

try {
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null);
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null); // DEPRECATED, LEFT FOR COMPATIBILITY

PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), null);
} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand All @@ -47,7 +51,9 @@ public void testFailed(ExtensionContext extensionContext, Throwable throwable) {
BaseTest.CURRENT_TEST_RESULT.set(TestResult.FAILURE);

try {
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable);
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable); // DEPRECATED, LEFT FOR COMPATIBILITY

PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), throwable);
} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand All @@ -58,7 +64,9 @@ public void testSuccessful(ExtensionContext extensionContext) {
BaseTest.CURRENT_TEST_RESULT.set(TestResult.SUCCESS);

try {
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null);
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null); // DEPRECATED, LEFT FOR COMPATIBILITY

PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), null);
} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.testng.annotations.*;
import solutions.bellatrix.core.plugins.PluginExecutionEngine;
import solutions.bellatrix.core.plugins.TestResult;
import solutions.bellatrix.core.plugins.TimeRecord;
import solutions.bellatrix.core.plugins.UsesPlugins;

import java.util.ArrayList;
Expand All @@ -26,6 +27,7 @@
@Listeners(TestResultListener.class)
public class BaseTest extends UsesPlugins {
static final ThreadLocal<TestResult> CURRENT_TEST_RESULT = new ThreadLocal<>();
static final ThreadLocal<TimeRecord> CURRENT_TEST_TIME_RECORD = ThreadLocal.withInitial(TimeRecord::new);
private static final ThreadLocal<Boolean> CONFIGURATION_EXECUTED = new ThreadLocal<>();
private static final List<String> ALREADY_EXECUTED_BEFORE_CLASSES = Collections.synchronizedList(new ArrayList<>());

Expand Down Expand Up @@ -82,9 +84,12 @@ public void afterMethodCore(ITestResult result) {
try {
var testClass = this.getClass();
var methodInfo = testClass.getMethod(result.getMethod().getMethodName());
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo);
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo); // DEPRECATED, LEFT FOR COMPATIBILITY
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), CURRENT_TEST_TIME_RECORD.get(), methodInfo);
afterEach();
PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), methodInfo, result.getThrowable());
PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), methodInfo, result.getThrowable()); // DEPRECATED, LEFT FOR COMPATIBILITY
PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), CURRENT_TEST_TIME_RECORD.get(), methodInfo, result.getThrowable());

} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public class TestResultListener implements ITestListener {
@Override
public void onTestSuccess(ITestResult result) {
BaseTest.CURRENT_TEST_RESULT.set(TestResult.SUCCESS);
BaseTest.CURRENT_TEST_TIME_RECORD.get().setStartTime(result.getStartMillis());
BaseTest.CURRENT_TEST_TIME_RECORD.get().setEndTime(result.getEndMillis());
}

@Override
public void onTestFailure(ITestResult result) {
BaseTest.CURRENT_TEST_RESULT.set(TestResult.FAILURE);
BaseTest.CURRENT_TEST_TIME_RECORD.get().setStartTime(result.getStartMillis());
BaseTest.CURRENT_TEST_TIME_RECORD.get().setEndTime(result.getEndMillis());
}
}
29 changes: 29 additions & 0 deletions bellatrix.plugins.jira.zephyr/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>bellatrix</artifactId>
<groupId>solutions.bellatrix</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>bellatrix.plugins.jira.zephyr</artifactId>
<version>1.0</version>

<dependencies>
<dependency>
<groupId>solutions.bellatrix</groupId>
<artifactId>bellatrix.core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.4.0</version>
<scope>compile</scope>
</dependency>

</dependencies>

</project>
Loading
Loading