Skip to content

Commit f3588a6

Browse files
committed
wip - failing postCommitByProjectTest()
1 parent 99f753f commit f3588a6

File tree

1 file changed

+138
-41
lines changed

1 file changed

+138
-41
lines changed

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

Lines changed: 138 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,94 +13,191 @@
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;
1719
import org.omg.sysml.model.Commit;
18-
import org.omg.sysml.model.Error;
20+
import org.omg.sysml.model.CommitContainingProject;
21+
import org.omg.sysml.model.Element;
22+
import org.omg.sysml.model.ElementVersion;
23+
import org.omg.sysml.model.Project;
24+
import org.omg.sysml.model.Record;
25+
1926
import java.util.UUID;
2027
import org.junit.Test;
21-
import org.junit.Ignore;
28+
import org.junit.BeforeClass;
29+
import org.junit.FixMethodOrder;
30+
import org.junit.runners.MethodSorters;
31+
32+
import static org.junit.Assert.assertTrue;
33+
import static org.junit.Assert.fail;
2234

23-
import java.util.ArrayList;
24-
import java.util.HashMap;
2535
import java.util.List;
26-
import java.util.Map;
2736

2837
/**
2938
* API tests for CommitApi
3039
*/
31-
@Ignore
40+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
3241
public class CommitApiTest {
3342

34-
private final CommitApi api = new CommitApi();
35-
43+
private final static CommitApi api = new CommitApi();
44+
private final static ProjectApi projectApi = new ProjectApi();
45+
private static UUID projectId;
46+
//private static UUID commitId;
47+
private static Commit commit;
48+
49+
@BeforeClass
50+
public static void setUp() {
51+
ApiClient apiClient = Configuration.getDefaultApiClient();
52+
apiClient.setBasePath("http://sysml2-sst.intercax.com:9000");
53+
api.setApiClient(apiClient);
54+
projectApi.setApiClient(apiClient);
55+
56+
List<Project> result = null;
57+
try {
58+
result = projectApi.getProjects(null, null, null);
59+
projectId = result.get(0).getId();
60+
} catch (ApiException e) {
61+
e.printStackTrace();
62+
fail("Failed to check GET /projects/{projectId}/commits - no project is available.");
63+
}
64+
65+
}
3666

3767
/**
38-
* Get commit by project and ID
39-
*
40-
*
68+
* Get head commit by project
4169
*
4270
* @throws ApiException
4371
* if the Api call fails
4472
*/
4573
@Test
46-
public void getCommitByProjectAndIdTest() throws ApiException {
47-
UUID projectId = null;
48-
UUID commitId = null;
49-
Commit response = api.getCommitByProjectAndId(projectId, commitId);
50-
51-
// TODO: test validations
74+
public void get1HeadCommitByProjectTest() {
75+
if (projectId == null)
76+
fail("Failed - no project is available.");
77+
else {
78+
try {
79+
Commit response = api.getHeadCommitByProject(projectId);
80+
System.out.println("=== getHeadCommitByProjectTest() ===\n" + response);
81+
assertTrue(response != null);
82+
} catch (ApiException e) {
83+
e.printStackTrace();
84+
fail("Failed - response(Commit) is null");
85+
}
86+
}
5287
}
5388

89+
5490
/**
5591
* Get commits by project
5692
*
57-
*
58-
*
93+
* Using the setup to projectId
5994
* @throws ApiException
6095
* if the Api call fails
6196
*/
6297
@Test
63-
public void getCommitsByProjectTest() throws ApiException {
64-
UUID projectId = null;
65-
String pageAfter = null;
66-
String pageBefore = null;
67-
Integer pageSize = null;
68-
List<Commit> response = api.getCommitsByProject(projectId, pageAfter, pageBefore, pageSize);
69-
70-
// TODO: test validations
98+
public void get2CommitsByProjectTest() {
99+
100+
if (projectId == null)
101+
fail("Failed - no project is available.");
102+
else {
103+
List<Commit> response = null;
104+
try {
105+
response = api.getCommitsByProject(projectId, null, null, null);
106+
System.out.println("=== getCommitsByProjectTest() ===\n" + response);
107+
assertTrue(response.size() > 0);
108+
commit = response.get(0);
109+
} catch (ApiException e) {
110+
e.printStackTrace();
111+
fail("Failed - no project available to query commit.");
112+
}
113+
}
114+
71115
}
72116

117+
118+
73119
/**
74-
* Get head commit by project
120+
* Get commit by project and ID
75121
*
76-
*
122+
* Using the previously run test get2CommitsByProjectTest to get commitId
77123
*
78124
* @throws ApiException
79125
* if the Api call fails
80126
*/
81127
@Test
82-
public void getHeadCommitByProjectTest() throws ApiException {
83-
UUID projectId = null;
84-
Commit response = api.getHeadCommitByProject(projectId);
85-
86-
// TODO: test validations
128+
public void get3CommitByProjectAndIdTest() {
129+
UUID commitId;
130+
if (projectId == null)
131+
fail("Failed - no project is available.");
132+
else if ((commitId = commit.getId()) == null)
133+
fail("Failed - no commit is available.");
134+
else {
135+
try {
136+
Commit response = api.getCommitByProjectAndId(projectId, commitId);
137+
System.out.println("=== getCommitByProjectAndIdTest() ===\n" + response);
138+
assertTrue(response != null);
139+
} catch (ApiException e) {
140+
e.printStackTrace();
141+
fail("Failed - response(Commit) is null");
142+
}
143+
}
87144
}
88145

146+
89147
/**
90148
* Create commit by project
91-
*
149+
* Using the previously run test get2CommitsByProjectTest to get commitId
92150
*
93151
*
94152
* @throws ApiException
95153
* if the Api call fails
96154
*/
97155
@Test
98-
public void postCommitByProjectTest() throws ApiException {
99-
UUID projectId = null;
100-
Commit body = null;
101-
Commit response = api.postCommitByProject(projectId, body);
102-
103-
// TODO: test validations
156+
public void postCommitByProjectTest() {
157+
if (projectId == null)
158+
fail("Failed - no project is available.");
159+
else {
160+
Commit body = new Commit();
161+
body.setAtType(org.omg.sysml.model.Commit.AtTypeEnum.COMMIT);
162+
163+
Element element = new Element();
164+
element.setAtType("Package");
165+
element.setAtId(UUID.randomUUID());
166+
167+
//element.setIdentifier();
168+
169+
ElementVersion elementVersion = new ElementVersion();
170+
elementVersion.setAtType(org.omg.sysml.model.ElementVersion.AtTypeEnum.ELEMENTVERSION);
171+
elementVersion.setData(element);
172+
elementVersion.setId(UUID.randomUUID());
173+
//elementVersion.setIdentity(identity);
174+
175+
CommitContainingProject containingProject = new CommitContainingProject();
176+
containingProject.setId(UUID.randomUUID());
177+
178+
body.addChangeItem(elementVersion);
179+
body.setContainingProject(containingProject);
180+
body.setId(UUID.randomUUID());
181+
//body.setPreviousCommit(null);
182+
Record previousCommit = new Record();
183+
previousCommit.setId(commit.getId());
184+
body.setPreviousCommit(previousCommit);
185+
186+
Commit response;
187+
try {
188+
response = api.postCommitByProject(projectId, body);
189+
System.out.println("=== postCommitByProjectTest() ===\n" + response);
190+
assertTrue(response != null);
191+
} catch (ApiException e) {
192+
System.out.println("=== ApiException: postCommitByProjectTest() ===\n");
193+
System.out.println(e.getCode());
194+
System.out.println(e.getMessage());
195+
e.printStackTrace();
196+
fail("Failed - response(Commit) is null");
197+
198+
}
199+
200+
}
104201
}
105202

106203
}

0 commit comments

Comments
 (0)