Skip to content

Commit 4b27d13

Browse files
committed
Removed ZephyrTestCycleResponse and moved id and key fields to ZephyrTestCycle
1 parent 8857da7 commit 4b27d13

File tree

5 files changed

+24
-45
lines changed

5 files changed

+24
-45
lines changed

bellatrix.plugins.jira.zephyr/src/main/java/plugins/jira/zephyr/ZephyrPlugin.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import plugins.jira.zephyr.annotations.ZephyrProjectId;
1919
import plugins.jira.zephyr.annotations.ZephyrTestCase;
2020
import plugins.jira.zephyr.data.ZephyrTestCycle;
21-
import plugins.jira.zephyr.data.ZephyrTestCycleResponse;
2221
import plugins.jira.zephyr.config.ZephyrSettings;
2322
import plugins.jira.zephyr.data.ZephyrTestCycleStatus;
2423
import plugins.jira.zephyr.data.ZephyrTestExecutionStatus;
@@ -33,14 +32,14 @@
3332
import solutions.bellatrix.core.plugins.TimeRecord;
3433

3534
import java.lang.reflect.Method;
35+
import java.util.Map;
3636

3737
public class ZephyrPlugin extends Plugin {
3838
public static final EventListener<ZephyrCyclePluginEventArgs> ZEPHYR_CYCLE_CREATED = new EventListener<>();
3939
public static final EventListener<ZephyrExecutionPluginEventArgs> ZEPHYR_TEST_CASE_EXECUTION_FAILED = new EventListener<>();
4040
public static final EventListener<ZephyrExecutionPluginEventArgs> ZEPHYR_TEST_CASE_EXECUTED = new EventListener<>();
4141
public static final EventListener<ZephyrCyclePluginEventArgs> ZEPHYR_CYCLE_STATUS_UPDATE_FAILED = new EventListener<>();
4242

43-
private ZephyrTestCycleResponse testCycleResponse;
4443
private ZephyrTestCycle testCycle;
4544

4645
public ZephyrPlugin() {
@@ -62,7 +61,7 @@ private boolean isEnabled() {
6261
}
6362

6463
private String getCycleId(Method memberInfo) {
65-
if (!settings().isExistingCycle()) return testCycleResponse.getKey();
64+
if (!settings().isExistingCycle()) return testCycle.getKey();
6665

6766
if (memberInfo.isAnnotationPresent(ZephyrTestCase.class) && !memberInfo.getAnnotation(ZephyrTestCase.class).cycleId().isBlank()) {
6867
return memberInfo.getAnnotation(ZephyrTestCase.class).cycleId();
@@ -115,9 +114,9 @@ public void postBeforeClass(Class type) {
115114
testCycle = new ZephyrTestCycle(settings().getDefaultProjectKey(), testCycleName, ZephyrTestCycleStatus.IN_PROGRESS.getValue());
116115
testCycle.setPlannedStartDate(DateTimeUtilities.getUtcNow());
117116

118-
testCycleResponse = ZephyrApiService.createTestCycle(testCycle);
117+
ZephyrApiService.createTestCycle(testCycle);
119118

120-
ZEPHYR_CYCLE_CREATED.broadcast(new ZephyrCyclePluginEventArgs(testCycleResponse));
119+
ZEPHYR_CYCLE_CREATED.broadcast(new ZephyrCyclePluginEventArgs(testCycle));
121120
}
122121

123122
@Override
@@ -133,6 +132,8 @@ public void postAfterTest(TestResult testResult, TimeRecord timeRecord, Method m
133132

134133
var response = ZephyrApiService.executeTestCase(testCase);
135134

135+
var responseBody = response.body().prettyPrint();
136+
136137
if (response.statusCode() >= 400) {
137138
ZEPHYR_TEST_CASE_EXECUTION_FAILED.broadcast(new ZephyrExecutionPluginEventArgs(testCase));
138139
}
@@ -146,7 +147,7 @@ public void preAfterClass(Class type) {
146147

147148
testCycle.setPlannedEndDate(DateTimeUtilities.getUtcNow());
148149

149-
var response = ZephyrApiService.changeTestCycleStatus(testCycle, testCycleResponse);
150+
var response = ZephyrApiService.changeTestCycleStatus(testCycle);
150151

151152
if (response.statusCode() >= 400) {
152153
ZEPHYR_CYCLE_STATUS_UPDATE_FAILED.broadcast(new ZephyrCyclePluginEventArgs());

bellatrix.plugins.jira.zephyr/src/main/java/plugins/jira/zephyr/data/ZephyrTestCycle.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public ZephyrTestCycle(String projectKey, String name, String statusName) {
2323
this.statusName = statusName;
2424
}
2525

26+
private String id;
27+
private String key;
2628
private String projectKey;
2729
private String name;
2830
private String statusName;

bellatrix.plugins.jira.zephyr/src/main/java/plugins/jira/zephyr/data/ZephyrTestCycleResponse.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

bellatrix.plugins.jira.zephyr/src/main/java/plugins/jira/zephyr/events/ZephyrCyclePluginEventArgs.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
package plugins.jira.zephyr.events;
1414

1515
import lombok.Getter;
16-
import plugins.jira.zephyr.data.ZephyrTestCycleResponse;
16+
import plugins.jira.zephyr.data.ZephyrTestCycle;
1717

1818
public class ZephyrCyclePluginEventArgs {
19-
@Getter private ZephyrTestCycleResponse testCycle;
19+
@Getter private ZephyrTestCycle testCycle;
2020

21-
public ZephyrCyclePluginEventArgs(ZephyrTestCycleResponse testCycle) {
21+
public ZephyrCyclePluginEventArgs(ZephyrTestCycle testCycle) {
2222
this.testCycle = testCycle;
2323
}
2424

bellatrix.plugins.jira.zephyr/src/main/java/plugins/jira/zephyr/services/ZephyrApiService.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
import io.restassured.path.json.JsonPath;
1717
import io.restassured.response.Response;
1818
import lombok.experimental.UtilityClass;
19-
import net.minidev.json.JSONObject;
2019
import org.apache.commons.text.StringEscapeUtils;
2120
import plugins.jira.zephyr.config.ZephyrSettings;
2221
import plugins.jira.zephyr.data.ZephyrTestCycle;
23-
import plugins.jira.zephyr.data.ZephyrTestCycleResponse;
2422
import plugins.jira.zephyr.data.ZephyrTestCycleStatus;
2523
import solutions.bellatrix.core.configuration.ConfigurationService;
26-
import solutions.bellatrix.core.utilities.DebugInformation;
2724

28-
import java.net.URLEncoder;
29-
import java.nio.charset.StandardCharsets;
30-
import java.util.ArrayList;
3125
import java.util.Arrays;
3226
import java.util.List;
3327
import java.util.Map;
@@ -40,19 +34,24 @@ private ZephyrSettings settings() {
4034
return ConfigurationService.get(ZephyrSettings.class);
4135
}
4236

43-
public ZephyrTestCycleResponse createTestCycle(ZephyrTestCycle testCycle) {
37+
public Response createTestCycle(ZephyrTestCycle testCycle) {
4438
var body = Map.of(
4539
"projectKey", testCycle.getProjectKey(),
4640
"name", testCycle.getName(),
4741
"statusName", testCycle.getStatusName()
4842
);
4943

50-
return given()
44+
var extractableResponse = given()
5145
.body(body, ObjectMapperType.GSON)
5246
.when()
5347
.post("/testcycles")
5448
.then()
55-
.extract().response().body().as(ZephyrTestCycleResponse.class, ObjectMapperType.GSON);
49+
.extract();
50+
51+
testCycle.setId(extractableResponse.jsonPath().getString("id"));
52+
testCycle.setKey(extractableResponse.jsonPath().getString("key"));
53+
54+
return extractableResponse.response();
5655
}
5756

5857
public Response executeTestCase(plugins.jira.zephyr.data.ZephyrTestCase testCase) {
@@ -76,14 +75,14 @@ public Response executeTestCase(plugins.jira.zephyr.data.ZephyrTestCase testCase
7675
.extract().response();
7776
}
7877

79-
public Response changeTestCycleStatus(ZephyrTestCycle cycleData, ZephyrTestCycleResponse cycleCreationResponse) {
78+
public Response changeTestCycleStatus(ZephyrTestCycle cycleData) {
8079
var isDefaultValueAvailableInConfig = settings().getCycleFinalStatus() != null && !settings().getCycleFinalStatus().isBlank();
8180

8281
var body = Map.of(
83-
"id", cycleCreationResponse.getId(),
84-
"key", cycleCreationResponse.getKey(),
82+
"id", cycleData.getId(),
83+
"key", cycleData.getKey(),
8584
"name", cycleData.getName(),
86-
"project", Map.of("id", ZephyrApiService.getProjectId(cycleCreationResponse.getKey())),
85+
"project", Map.of("id", ZephyrApiService.getProjectId(cycleData.getKey())),
8786
"status", Map.of("id", ZephyrApiService.getStatusId(isDefaultValueAvailableInConfig ?
8887
settings().getCycleFinalStatus() : ZephyrTestCycleStatus.DONE.getValue(), cycleData.getProjectKey())),
8988
"plannedEndDate", cycleData.getPlannedEndDate()
@@ -136,5 +135,4 @@ private static String formatError(Throwable error) {
136135

137136
return errorInfo.replace("\n", "<br>");
138137
}
139-
140138
}

0 commit comments

Comments
 (0)