Skip to content

Commit 7bbcabb

Browse files
committed
Fetch TestExecution statuses from Kiwi TCMS API, don't hard-code
1 parent 01f2a34 commit 7bbcabb

File tree

4 files changed

+89
-38
lines changed

4 files changed

+89
-38
lines changed

src/main/java/org/kiwitcms/java/api/RpcClient.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) 2018-2019 Aneta Petkova <[email protected]>
2-
// Copyright (c) 2019-2021 Alexander Todorov <[email protected]>
2+
// Copyright (c) 2019-2022 Alexander Todorov <[email protected]>
33

44
// Licensed under the GPLv3: https://www.gnu.org/licenses/gpl.html
55

@@ -199,7 +199,6 @@ public TestRun getRun(int runId) {
199199
}
200200

201201
public TestPlan createNewTP(int productId, String name, int versionId) {
202-
// TODO: remove call for plan type
203202
Map<String, Object> params = new HashMap<>();
204203
params.put("name", "Unit");
205204
JSONArray jsonArray = (JSONArray) executeViaPositionalParams("PlanType.filter", Arrays.asList((Object) params));
@@ -254,6 +253,7 @@ public TestExecution updateTestExecution(int tcRunId, int status) {
254253
Map<String, Object> params = new HashMap<>();
255254
params.put("execution_id", tcRunId);
256255
params.put("values", values);
256+
257257
JSONObject json = (JSONObject) executeViaNamedParams(TEST_EXECUTION_UPDATE, params);
258258
try {
259259
return new ObjectMapper().readValue(json.toJSONString(), TestExecution.class);
@@ -389,4 +389,26 @@ public Priority[] getPriority(Map<String, Object> filter) {
389389
public JSONArray getCategory(Map<String, Object> filter) {
390390
return (JSONArray) executeViaPositionalParams(CATEGORY_FILTER, Arrays.asList((Object) filter));
391391
}
392+
393+
public TestExecutionStatus getTestExecutionStatus(String name, String weightLookup) {
394+
Map<String, Object> filter = new HashMap<>();
395+
filter.put("name", name);
396+
JSONArray jsonArray = (JSONArray) executeViaPositionalParams("TestExecutionStatus.filter", Arrays.asList((Object) filter));
397+
398+
// name not found, search by weight
399+
if (jsonArray == null || jsonArray.isEmpty()) {
400+
filter.remove("name");
401+
// eq, gt or lt zero
402+
filter.put("weight" + weightLookup, 0);
403+
jsonArray = (JSONArray) executeViaPositionalParams("TestExecutionStatus.filter", Arrays.asList((Object) filter));
404+
}
405+
406+
try {
407+
TestExecutionStatus[] statuses = new ObjectMapper().readValue(jsonArray.toJSONString(), TestExecutionStatus[].class);
408+
return statuses[0];
409+
} catch (IOException e) {
410+
e.printStackTrace();
411+
return null;
412+
}
413+
}
392414
}

src/main/java/org/kiwitcms/java/junit/TestDataEmitter.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (c) 2018-2019 Aneta Petkova <[email protected]>
2+
// Copyright (c) 2022 Alexander Todorov <[email protected]>
23

34
// Licensed under the GPLv3: https://www.gnu.org/licenses/gpl.html
45

@@ -104,11 +105,31 @@ public void addTestResultsToRun(int runId, List<TestMethod> tests) {
104105

105106
TestExecution[] executions = client.addTestCaseToRunId(runId, testCase.getCaseId());
106107
for (TestExecution testExecution : executions) {
107-
client.updateTestExecution(testExecution.getTcRunId(), test.getTestExecutionStatus());
108+
client.updateTestExecution(testExecution.getTcRunId(), getTestExecutionStatusId(test.result));
108109
}
109110
}
110111
}
111112

113+
// TODO: this method is called for every execution.
114+
// Results can be cached
115+
private int getTestExecutionStatusId(String result) {
116+
TestExecutionStatus status = null;
117+
118+
switch (result) {
119+
case "PASS":
120+
status = client.getTestExecutionStatus("PASSED", "__gt");
121+
break;
122+
case "FAIL":
123+
status = client.getTestExecutionStatus("FAILED", "__lt");
124+
break;
125+
default:
126+
//IDLE
127+
status = client.getTestExecutionStatus(result, "");
128+
}
129+
130+
return status.getId();
131+
}
132+
112133
public int getBuild(int versionId) {
113134
String confBuild = config.getBuild();
114135
Map<String, Object> filter = new HashMap<>();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2022 Alexander Todorov <[email protected]>
2+
3+
// Licensed under the GPLv3: https://www.gnu.org/licenses/gpl.html
4+
5+
package org.kiwitcms.java.model;
6+
7+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
8+
import com.fasterxml.jackson.annotation.JsonSetter;
9+
10+
@JsonIgnoreProperties(ignoreUnknown = true)
11+
public class TestExecutionStatus {
12+
private int id;
13+
private int weight;
14+
private String name;
15+
16+
public int getId() {
17+
return id;
18+
}
19+
20+
@JsonSetter("id")
21+
public void setId(int id) {
22+
this.id = id;
23+
}
24+
25+
public int getWeight() {
26+
return weight;
27+
}
28+
29+
@JsonSetter("weight")
30+
public void setWeight(int weight) {
31+
this.weight = weight;
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
@JsonSetter("name")
39+
public void setName(String name) {
40+
this.name = name;
41+
}
42+
}
Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
// Copyright (c) 2018-2019 Aneta Petkova <[email protected]>
2+
// Copyright (c) 2022 Alexander Todorov <[email protected]>
23

34
// Licensed under the GPLv3: https://www.gnu.org/licenses/gpl.html
45

56
package org.kiwitcms.java.model;
67

7-
import com.fasterxml.jackson.core.JsonProcessingException;
8-
import com.fasterxml.jackson.databind.ObjectMapper;
9-
10-
import java.util.List;
118

129
public class TestMethod {
1310
public String name;
@@ -26,35 +23,4 @@ public TestMethod(String name, String containingClass, String result){
2623
public String getSummary() {
2724
return containingClass + "." + name;
2825
}
29-
30-
public int getTestExecutionStatus() {
31-
//todo: this must be coming from the database, not hard-coded
32-
switch (result) {
33-
case "PASS":
34-
return 4;
35-
case "FAIL":
36-
return 5;
37-
default:
38-
//IDLE
39-
return 1;
40-
}
41-
}
42-
43-
public String toJSONString() {
44-
ObjectMapper mapper = new ObjectMapper();
45-
try {
46-
return mapper.writeValueAsString(this);
47-
} catch (JsonProcessingException e) {
48-
return null;
49-
}
50-
}
51-
52-
public static String toJSONArrayString(List<TestMethod> list) {
53-
ObjectMapper mapper = new ObjectMapper();
54-
try {
55-
return mapper.writeValueAsString(list);
56-
} catch (JsonProcessingException e) {
57-
return null;
58-
}
59-
}
6026
}

0 commit comments

Comments
 (0)