forked from nmusaelian-rally/rally-java-rest-apps
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathaddTCtoTF.java
More file actions
100 lines (74 loc) · 4.14 KB
/
addTCtoTF.java
File metadata and controls
100 lines (74 loc) · 4.14 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
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.CreateRequest;
import com.rallydev.rest.request.GetRequest;
import com.rallydev.rest.response.CreateResponse;
import com.rallydev.rest.util.Ref;
public class addTCtoTF {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String username = "user@co.com";
String password = "secret";
String wsapiVersion = "v2.0";
String projectRef = "/project/12352608219";
String applicationName = "RestExample_createTFandTC";
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);
try {
for (int i=0; i<1; i++) {
System.out.println("Creating a test folder...");
JsonObject newTF = new JsonObject();
newTF.addProperty("Name", "tf via java");
newTF.addProperty("Project", projectRef);
CreateRequest createRequest = new CreateRequest("testfolder", newTF);
CreateResponse createResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
String folderRef = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading TestFolder %s...",folderRef));
System.out.println("Creating a child test folder...");
JsonObject newChildTF = new JsonObject();
newChildTF.addProperty("Name", "tf via java");
newChildTF.addProperty("Project", projectRef);
newChildTF.addProperty("Parent", folderRef);
CreateRequest createRequest2 = new CreateRequest("testfolder", newChildTF);
CreateResponse createResponse2 = restApi.create(createRequest2);
if (createResponse.wasSuccessful()) {
System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
String childFolderRef = Ref.getRelativeRef(createResponse2.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading Child TestFolder %s...",childFolderRef));
System.out.println("Creating a test case...");
JsonObject newTC = new JsonObject();
newTC.addProperty("Name", "tc via java");
newTC.addProperty("Project", projectRef);
newTC.addProperty("TestFolder", childFolderRef);
newTC.addProperty("Method", "Manual");
CreateRequest createRequest3 = new CreateRequest("testcase", newTC);
CreateResponse createResponse3 = restApi.create(createRequest3);
if (createResponse.wasSuccessful()) {
System.out.println(String.format("Created %s", createResponse3.getObject().get("_ref").getAsString()));
String testCaseRef = Ref.getRelativeRef(createResponse3.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading TestCase %s...",testCaseRef));
}
}
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error!");
for (int j=0; i<createErrors.length;j++) {
System.out.println(createErrors[j]);
}
}
}
} finally {
restApi.close();
}
}
}