Skip to content

Commit 3bc7c35

Browse files
committed
updated
1 parent b43f0dd commit 3bc7c35

File tree

4 files changed

+259
-46
lines changed

4 files changed

+259
-46
lines changed

src/test/java/org/omg/sysml/api/CommitApiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ else if ((commitId = commit.getId()) == null)
152152
* @throws ApiException
153153
* if the Api call fails
154154
*/
155-
@Test
155+
156156
public void postCommitByProjectTest() {
157157
if (projectId == null)
158158
fail("Failed - no project is available.");

src/test/java/org/omg/sysml/api/ElementApiTest.java

Lines changed: 137 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@
1313

1414
package org.omg.sysml.api;
1515

16+
import org.omg.sysml.ApiClient;
1617
import org.omg.sysml.ApiException;
18+
import org.omg.sysml.Configuration;
19+
import org.omg.sysml.model.Commit;
1720
import org.omg.sysml.model.Element;
1821
import org.omg.sysml.model.Error;
22+
import org.omg.sysml.model.Project;
23+
1924
import java.util.UUID;
2025
import org.junit.Test;
26+
import org.junit.BeforeClass;
2127
import org.junit.Ignore;
2228

29+
import static org.junit.Assert.assertTrue;
30+
import static org.junit.Assert.fail;
31+
2332
import java.util.ArrayList;
2433
import java.util.HashMap;
2534
import java.util.List;
@@ -28,31 +37,93 @@
2837
/**
2938
* API tests for ElementApi
3039
*/
31-
@Ignore
40+
3241
public class ElementApiTest {
3342

34-
private final ElementApi api = new ElementApi();
43+
private final static ProjectApi project_api = new ProjectApi();
44+
private final static CommitApi commit_api = new CommitApi();
45+
private final static ElementApi api = new ElementApi();
46+
47+
private static UUID projectId;
48+
private static UUID commitId;
49+
private static UUID elementId;
3550

51+
@BeforeClass
52+
public static void setUp() {
53+
ApiClient apiClient = Configuration.getDefaultApiClient();
54+
apiClient.setBasePath("http://sysml2-sst.intercax.com:9000");
55+
api.setApiClient(apiClient);
56+
project_api.setApiClient(apiClient);
57+
commit_api.setApiClient(apiClient);
58+
List<Project> project_response;
59+
try {
60+
project_response = project_api.getProjects(null, null, null);
61+
assertTrue(project_response.size() >= 0); //no project then size = 0?
62+
System.out.println(project_response);
63+
projectId = project_response.get(0).getId();
64+
65+
List<Commit> commit_response = null;
66+
try {
67+
commit_response = commit_api.getCommitsByProject(projectId, null, null, null);
68+
System.out.println("=== getCommitsByProjectTest() ===\n" + commit_response);
69+
assertTrue(commit_response.size() > 0);
70+
Commit commit = commit_response.get(0);
71+
commitId = commit.getId();
72+
} catch (ApiException e) {
73+
e.printStackTrace();
74+
fail("Failed - no commitId.");
75+
}
76+
} catch (ApiException e) {
77+
e.printStackTrace();
78+
fail("Failed - no project available.");
79+
}
3680

81+
}
3782
/**
38-
* Get element by project, commit and ID
83+
* WIP - response size = 0
84+
* WIP Element does not have getId method
85+
* Get root elements by project and commit
3986
*
4087
*
4188
*
4289
* @throws ApiException
4390
* if the Api call fails
4491
*/
4592
@Test
46-
public void getElementByProjectCommitIdTest() throws ApiException {
47-
UUID projectId = null;
48-
UUID commitId = null;
49-
UUID elementId = null;
50-
Element response = api.getElementByProjectCommitId(projectId, commitId, elementId);
51-
52-
// TODO: test validations
93+
public void getRootsByProjectCommitTest() throws ApiException {
94+
95+
if (projectId == null) {
96+
fail("Failed - no project is available.");
97+
return;
98+
}
99+
if (commitId == null) {
100+
fail("Failed - no commit is available.");
101+
return;
102+
}
103+
104+
String pageAfter = null;
105+
String pageBefore = null;
106+
Integer pageSize = null;
107+
108+
try {
109+
List<Element> response = api.getRootsByProjectCommit(projectId, commitId, pageAfter, pageBefore, pageSize);
110+
System.out.println("=== getRootsByProjectCommitTest() ===\n" + response.size());
111+
assertTrue(response.size() > 0);
112+
Element element = response.get(0);
113+
System.out.println(element);
114+
assertTrue(element.getIdentifier() != null);
115+
//elementId = element.getId();
116+
//System.out.println("elementId: " + elementId);
117+
118+
} catch (ApiException e) {
119+
e.printStackTrace();
120+
fail("Failed - getRootsByProjectCommitTest - no element");
121+
}
53122
}
123+
54124

55125
/**
126+
* WIP - response size = 0
56127
* Get elements by project and commit
57128
*
58129
*
@@ -62,34 +133,76 @@ public void getElementByProjectCommitIdTest() throws ApiException {
62133
*/
63134
@Test
64135
public void getElementsByProjectCommitTest() throws ApiException {
65-
UUID projectId = null;
66-
UUID commitId = null;
136+
137+
if (projectId == null) {
138+
fail("Failed - no project is available.");
139+
return;
140+
}
141+
if (commitId == null) {
142+
fail("Failed - no commit is available.");
143+
return;
144+
}
67145
String pageAfter = null;
68146
String pageBefore = null;
69147
Integer pageSize = null;
70-
List<Element> response = api.getElementsByProjectCommit(projectId, commitId, pageAfter, pageBefore, pageSize);
71-
72-
// TODO: test validations
148+
try {
149+
List<Element> response = api.getElementsByProjectCommit(projectId, commitId, pageAfter, pageBefore, pageSize);
150+
System.out.println("=== getElementsByProjectCommitTest() ===\n" + response.size());
151+
assertTrue(response.size() > 0);
152+
Element element = response.get(0);
153+
System.out.println(element);
154+
assertTrue(element.getIdentifier() != null);
155+
//elementId = element.getId();
156+
//System.out.println("elementId: " + elementId);
157+
} catch (ApiException e) {
158+
e.printStackTrace();
159+
fail("Failed - getElementsByProjectCommitTest. no element.");
160+
}
73161
}
74162

163+
75164
/**
76-
* Get root elements by project and commit
165+
* WIP - no elementId available from previous test
166+
* Get element by project, commit and ID
77167
*
78168
*
79169
*
80170
* @throws ApiException
81171
* if the Api call fails
82172
*/
83173
@Test
84-
public void getRootsByProjectCommitTest() throws ApiException {
85-
UUID projectId = null;
86-
UUID commitId = null;
87-
String pageAfter = null;
88-
String pageBefore = null;
89-
Integer pageSize = null;
90-
List<Element> response = api.getRootsByProjectCommit(projectId, commitId, pageAfter, pageBefore, pageSize);
91-
174+
public void getElementByProjectCommitIdTest() {
175+
if (projectId == null) {
176+
fail("Failed - no project available.");
177+
return;
178+
}
179+
if (commitId == null) {
180+
fail("Failed - no commit available.");
181+
return;
182+
}
183+
if (elementId == null) {
184+
fail("Failed - no element available.");
185+
return;
186+
}
187+
188+
189+
try {
190+
Element response = api.getElementByProjectCommitId(projectId, commitId, elementId);
191+
assertTrue(response != null);
192+
System.out.println("=== getElementByProjectCommitIdTest() ===\n" + response);
193+
194+
} catch (ApiException e) {
195+
e.printStackTrace();
196+
fail("Failed - no element for elementId \'"+ elementId + "\' returned.");
197+
}
198+
199+
200+
201+
92202
// TODO: test validations
93203
}
204+
205+
206+
94207

95208
}

src/test/java/org/omg/sysml/api/ProjectApiTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public void postProjectTest() {
175175
assertEquals(name, response.getName());
176176
assertEquals(AtTypeEnum.PROJECT, response.getAtType());
177177
} catch (ApiException e) {
178+
e.printStackTrace();
178179
fail("getProjectByIdTest_404 failed: not expecting ApiException");
179180
}
180181
}

0 commit comments

Comments
 (0)