Skip to content

Commit 71ed8d8

Browse files
authored
Merge pull request #37 from AutomateThePlanet/bellatrix-jira-zephyr-plugin
Bellatrix Jira Zephyr Plugin
2 parents b5b5c29 + dc7b881 commit 71ed8d8

23 files changed

+726
-7
lines changed

bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/Plugin.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,28 @@ public void postBeforeTest(TestResult testResult, Method memberInfo) {
3939
public void beforeTestFailed(Exception e) throws Exception {
4040
}
4141

42+
/**
43+
* Deprecated. <br>
44+
* Use {@link #preAfterTest(TestResult, TimeRecord, Method)} as it offers more information about the test.
45+
*/
46+
@Deprecated
4247
public void preAfterTest(TestResult testResult, Method memberInfo) throws IOException {
4348
}
4449

50+
public void preAfterTest(TestResult testResult, TimeRecord timeRecord, Method memberInfo) throws IOException {
51+
}
52+
53+
/**
54+
* Deprecated. <br>
55+
* Use {@link #postAfterTest(TestResult, TimeRecord, Method, Throwable)} as it offers more information about the test.
56+
*/
57+
@Deprecated
4558
public void postAfterTest(TestResult testResult, Method memberInfo, Throwable failedTestException) {
4659
}
4760

61+
public void postAfterTest(TestResult testResult, TimeRecord timeRecord, Method memberInfo, Throwable failedTestException) {
62+
}
63+
4864
public void afterTestFailed(Exception e) {
4965
}
5066

bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/PluginExecutionEngine.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,44 @@ public static void beforeTestFailed(Exception e) throws Exception {
7373
}
7474
}
7575

76+
/**
77+
* Deprecated. <br>
78+
* Use {@link #preAfterTest(TestResult, TimeRecord, Method)} as it offers more information about the test.
79+
*/
80+
@Deprecated
7681
public static void preAfterTest(TestResult result, Method memberInfo) throws Exception {
7782
for (var currentObserver : PLUGINS) {
7883
if (currentObserver != null)
7984
currentObserver.preAfterTest(result, memberInfo);
8085
}
8186
}
8287

88+
public static void preAfterTest(TestResult result, TimeRecord timeRecord, Method memberInfo) throws Exception {
89+
for (var currentObserver : PLUGINS) {
90+
if (currentObserver != null)
91+
currentObserver.preAfterTest(result, timeRecord, memberInfo);
92+
}
93+
}
94+
95+
/**
96+
* Deprecated. <br>
97+
* Use {@link #postAfterTest(TestResult, TimeRecord, Method, Throwable)} as it offers more information about the test.
98+
*/
99+
@Deprecated
83100
public static void postAfterTest(TestResult result, Method memberInfo, Throwable failedTestException) {
84101
for (var currentObserver : PLUGINS) {
85102
if (currentObserver != null)
86103
currentObserver.postAfterTest(result, memberInfo, failedTestException);
87104
}
88105
}
89106

107+
public static void postAfterTest(TestResult result, TimeRecord timeRecord, Method memberInfo, Throwable failedTestException) {
108+
for (var currentObserver : PLUGINS) {
109+
if (currentObserver != null)
110+
currentObserver.postAfterTest(result, timeRecord, memberInfo, failedTestException);
111+
}
112+
}
113+
90114
public static void afterTestFailed(Exception e) {
91115
for (var currentObserver : PLUGINS) {
92116
if (currentObserver != null)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2024 Automate The Planet Ltd.
3+
* Author: Miriam Kyoseva
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* You may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
14+
package solutions.bellatrix.core.plugins;
15+
16+
import lombok.Getter;
17+
import lombok.Setter;
18+
19+
@Getter @Setter
20+
public class TimeRecord {
21+
private long startTime;
22+
private long endTime;
23+
24+
public long getDuration() {
25+
return endTime - startTime;
26+
}
27+
}

bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/junit/BaseTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.junit.jupiter.api.extension.ExtendWith;
1818
import solutions.bellatrix.core.plugins.PluginExecutionEngine;
1919
import solutions.bellatrix.core.plugins.TestResult;
20+
import solutions.bellatrix.core.plugins.TimeRecord;
2021
import solutions.bellatrix.core.plugins.UsesPlugins;
2122

2223
import java.util.ArrayList;
@@ -26,8 +27,10 @@
2627

2728
@ExtendWith(TestResultWatcher.class)
2829
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
30+
@ExtendWith(TestDurationWatcher.class)
2931
public class BaseTest extends UsesPlugins {
3032
static final ThreadLocal<TestResult> CURRENT_TEST_RESULT = new ThreadLocal<>();
33+
static final ThreadLocal<TimeRecord> CURRENT_TEST_TIME_RECORD = ThreadLocal.withInitial(TimeRecord::new);
3134
private static final ThreadLocal<Boolean> CONFIGURATION_EXECUTED = new ThreadLocal<>();
3235
private static final List<String> ALREADY_EXECUTED_BEFORE_CLASSES = Collections.synchronizedList(new ArrayList<>());
3336
private TestInfo testInfo;
@@ -91,7 +94,8 @@ public void afterMethodCore(TestInfo testInfo) {
9194
var testClass = this.getClass();
9295
assert testInfo.getTestMethod().isPresent();
9396
var methodInfo = testClass.getMethod(testInfo.getTestMethod().get().getName(), testInfo.getTestMethod().get().getParameterTypes());
94-
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo);
97+
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo); // DEPRECATED, LEFT FOR COMPATIBILITY
98+
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), CURRENT_TEST_TIME_RECORD.get(), methodInfo);
9599
afterEach();
96100
// PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), methodInfo);
97101
} catch (Exception e) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2024 Automate The Planet Ltd.
3+
* Author: Miriam Kyoseva
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* You may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package solutions.bellatrix.core.plugins.junit;
14+
15+
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
16+
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
17+
import org.junit.jupiter.api.extension.ExtensionContext;
18+
19+
public class TestDurationWatcher implements BeforeTestExecutionCallback, AfterTestExecutionCallback {
20+
@Override
21+
public void beforeTestExecution(ExtensionContext context) {
22+
BaseTest.CURRENT_TEST_TIME_RECORD.get().setStartTime(System.currentTimeMillis());
23+
}
24+
25+
@Override
26+
public void afterTestExecution(ExtensionContext context) {
27+
BaseTest.CURRENT_TEST_TIME_RECORD.get().setEndTime(System.currentTimeMillis());
28+
}
29+
}

bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/junit/TestResultWatcher.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public void testAborted(ExtensionContext extensionContext, Throwable throwable)
2525
BaseTest.CURRENT_TEST_RESULT.set(TestResult.FAILURE);
2626

2727
try {
28-
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable);
28+
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable); // DEPRECATED, LEFT FOR COMPATIBILITY
29+
30+
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), throwable);
2931
} catch (Exception e) {
3032
PluginExecutionEngine.afterTestFailed(e);
3133
}
@@ -36,7 +38,9 @@ public void testDisabled(ExtensionContext extensionContext, Optional<String> opt
3638
BaseTest.CURRENT_TEST_RESULT.set(TestResult.SUCCESS);
3739

3840
try {
39-
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null);
41+
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null); // DEPRECATED, LEFT FOR COMPATIBILITY
42+
43+
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), null);
4044
} catch (Exception e) {
4145
PluginExecutionEngine.afterTestFailed(e);
4246
}
@@ -47,7 +51,9 @@ public void testFailed(ExtensionContext extensionContext, Throwable throwable) {
4751
BaseTest.CURRENT_TEST_RESULT.set(TestResult.FAILURE);
4852

4953
try {
50-
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable);
54+
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable); // DEPRECATED, LEFT FOR COMPATIBILITY
55+
56+
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), throwable);
5157
} catch (Exception e) {
5258
PluginExecutionEngine.afterTestFailed(e);
5359
}
@@ -58,7 +64,9 @@ public void testSuccessful(ExtensionContext extensionContext) {
5864
BaseTest.CURRENT_TEST_RESULT.set(TestResult.SUCCESS);
5965

6066
try {
61-
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null);
67+
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null); // DEPRECATED, LEFT FOR COMPATIBILITY
68+
69+
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), null);
6270
} catch (Exception e) {
6371
PluginExecutionEngine.afterTestFailed(e);
6472
}

bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/testng/BaseTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.testng.annotations.*;
1818
import solutions.bellatrix.core.plugins.PluginExecutionEngine;
1919
import solutions.bellatrix.core.plugins.TestResult;
20+
import solutions.bellatrix.core.plugins.TimeRecord;
2021
import solutions.bellatrix.core.plugins.UsesPlugins;
2122

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

@@ -82,9 +84,12 @@ public void afterMethodCore(ITestResult result) {
8284
try {
8385
var testClass = this.getClass();
8486
var methodInfo = testClass.getMethod(result.getMethod().getMethodName());
85-
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo);
87+
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo); // DEPRECATED, LEFT FOR COMPATIBILITY
88+
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), CURRENT_TEST_TIME_RECORD.get(), methodInfo);
8689
afterEach();
87-
PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), methodInfo, result.getThrowable());
90+
PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), methodInfo, result.getThrowable()); // DEPRECATED, LEFT FOR COMPATIBILITY
91+
PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), CURRENT_TEST_TIME_RECORD.get(), methodInfo, result.getThrowable());
92+
8893
} catch (Exception e) {
8994
PluginExecutionEngine.afterTestFailed(e);
9095
}

bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/testng/TestResultListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ public class TestResultListener implements ITestListener {
2020
@Override
2121
public void onTestSuccess(ITestResult result) {
2222
BaseTest.CURRENT_TEST_RESULT.set(TestResult.SUCCESS);
23+
BaseTest.CURRENT_TEST_TIME_RECORD.get().setStartTime(result.getStartMillis());
24+
BaseTest.CURRENT_TEST_TIME_RECORD.get().setEndTime(result.getEndMillis());
2325
}
2426

2527
@Override
2628
public void onTestFailure(ITestResult result) {
2729
BaseTest.CURRENT_TEST_RESULT.set(TestResult.FAILURE);
30+
BaseTest.CURRENT_TEST_TIME_RECORD.get().setStartTime(result.getStartMillis());
31+
BaseTest.CURRENT_TEST_TIME_RECORD.get().setEndTime(result.getEndMillis());
2832
}
2933
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<artifactId>bellatrix</artifactId>
7+
<groupId>solutions.bellatrix</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>bellatrix.plugins.jira.zephyr</artifactId>
12+
<version>1.0</version>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>solutions.bellatrix</groupId>
17+
<artifactId>bellatrix.core</artifactId>
18+
<version>1.0</version>
19+
</dependency>
20+
21+
</dependencies>
22+
23+
</project>

0 commit comments

Comments
 (0)