forked from kinow/testlink-java-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildService.java
More file actions
185 lines (159 loc) · 7.22 KB
/
BuildService.java
File metadata and controls
185 lines (159 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* The MIT License
*
* Copyright (c) 2010 Bruno P. Kinoshita http://www.kinoshita.eti.br
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package br.eti.kinoshita.testlinkjavaapi;
import java.util.HashMap;
import java.util.Map;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import br.eti.kinoshita.testlinkjavaapi.constants.TestLinkMethods;
import br.eti.kinoshita.testlinkjavaapi.constants.TestLinkParams;
import br.eti.kinoshita.testlinkjavaapi.constants.TestLinkResponseParams;
import br.eti.kinoshita.testlinkjavaapi.model.Build;
import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException;
import br.eti.kinoshita.testlinkjavaapi.util.Util;
/**
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 1.9.0-1
*/
class BuildService extends BaseService {
/**
* @param xmlRpcClient XML RPC Client.
* @param devKey TestLink User DevKey.
*/
public BuildService(XmlRpcClient xmlRpcClient, String devKey) {
super(xmlRpcClient, devKey);
}
@SuppressWarnings("unchecked")
protected Build createBuild(Integer testPlanId, String buildName, String buildNotes) throws TestLinkAPIException {
Build build = null;
Integer id = 0;
build = new Build(id, testPlanId, buildName, buildNotes);
try {
Map<String, Object> executionData = Util.getBuildMap(build);
Object response = this.executeXmlRpcCall(TestLinkMethods.CREATE_BUILD.toString(), executionData);
Object[] responseArray = Util.castToArray(response);
Map<String, Object> responseMap = (Map<String, Object>) responseArray[0];
id = Util.getInteger(responseMap, TestLinkResponseParams.ID.toString());
build.setId(id);
} catch (XmlRpcException xmlrpcex) {
throw new TestLinkAPIException("Error creating build: " + xmlrpcex.getMessage(), xmlrpcex);
}
return build;
}
/**
* @param testPlanId
* @return
*/
@SuppressWarnings("unchecked")
protected Build[] getBuildsForTestPlan(Integer testPlanId) throws TestLinkAPIException {
Build[] builds = null;
try {
Map<String, Object> executionData = new HashMap<String, Object>();
executionData.put(TestLinkParams.TEST_PLAN_ID.toString(), testPlanId);
Object response = this.executeXmlRpcCall(TestLinkMethods.GET_BUILDS_FOR_TEST_PLAN.toString(),
executionData);
if (response instanceof Object[]) {
Object[] responseArray = Util.castToArray(response);
builds = new Build[responseArray.length];
for (int i = 0; i < responseArray.length; i++) {
Map<String, Object> responseMap = (Map<String, Object>) responseArray[i];
builds[i] = Util.getBuild(responseMap);
}
}
} catch (XmlRpcException xmlrpcex) {
throw new TestLinkAPIException("Error retrieving test plan's builds: " + xmlrpcex.getMessage(), xmlrpcex);
}
return builds;
}
/**
* @param testPlanId
* @return
* @throws TestLinkAPIException
*/
@SuppressWarnings("unchecked")
protected Build getLatestBuildForTestPlan(Integer testPlanId) throws TestLinkAPIException {
Build build = null;
try {
Map<String, Object> executionData = new HashMap<String, Object>();
executionData.put(TestLinkParams.TEST_PLAN_ID.toString(), testPlanId);
Object response = this.executeXmlRpcCall(TestLinkMethods.GET_LATEST_BUILD_FOR_TEST_PLAN.toString(),
executionData);
if (response instanceof Map<?, ?>) {
Map<String, Object> responseMap = (Map<String, Object>) response;
build = Util.getBuild(responseMap);
}
} catch (XmlRpcException xmlrpcex) {
throw new TestLinkAPIException("Error retrieving latest build for test plan: " + xmlrpcex.getMessage(),
xmlrpcex);
}
return build;
}
/**
* @param testPlanId
* @return
*/
@SuppressWarnings("unchecked")
protected Map<String, Object> getExecCountersByBuild(Integer testPlanId) {
Map<String, Object> responseMap = null;
try {
Map<String, Object> executionData = new HashMap<String, Object>();
executionData.put(TestLinkParams.TEST_PLAN_ID.toString(), testPlanId);
Object response = this.executeXmlRpcCall(TestLinkMethods.GET_EXEC_COUNTERS_BY_BUILD.toString(),
executionData);
if (response instanceof Map<?, ?>) {
responseMap = (Map<String, Object>) response;
}
} catch (XmlRpcException xmlrpcex) {
throw new TestLinkAPIException("Error getting exec counters by build: " + xmlrpcex.getMessage(), xmlrpcex);
}
return responseMap;
}
/**
*
* @param buildId
* @param testProjectId
* @param customFields
*/
protected Map<String, Object> updateBuildCustomFields(Integer buildId, Integer testProjectId, Integer testPlanId, Map<String, String> customFields) {
Map<String, Object> responseMap =null;
try {
Map<String, Object> executionData = new HashMap<String, Object>();
executionData.put(TestLinkParams.BUILD_ID.toString(), buildId);
executionData.put(TestLinkParams.TEST_PROJECT_ID.toString(), testProjectId);
executionData.put(TestLinkParams.TEST_PLAN_ID.toString(), testPlanId);
executionData.put(TestLinkParams.CUSTOM_FIELDS.toString(), customFields);
Object response = this.executeXmlRpcCall(TestLinkMethods.UPDATE_BUILD_CUSTOM_FIELDS.toString(),
executionData);
if (response instanceof Map<?, ?>) {
responseMap = Util.castToMap(response);
} else if (! (response instanceof String) ) {
responseMap = Util.castToMap(((Object[]) response)[0]);
}
} catch (XmlRpcException xmlrpcex) {
throw new TestLinkAPIException("Error updating Build custom fields. " + xmlrpcex.getMessage(),
xmlrpcex);
}
return responseMap;
}
}