Skip to content

Commit 99f753f

Browse files
committed
add some test for Projects
1 parent b8f057c commit 99f753f

File tree

1 file changed

+146
-22
lines changed

1 file changed

+146
-22
lines changed

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

Lines changed: 146 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,75 +13,199 @@
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.Error;
1820
import org.omg.sysml.model.Project;
21+
import org.omg.sysml.model.Project.AtTypeEnum;
22+
1923
import java.util.UUID;
2024
import org.junit.Test;
25+
import org.junit.BeforeClass;
2126
import org.junit.Ignore;
2227

28+
import static org.junit.Assert.assertEquals;
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;
2635
import java.util.Map;
36+
import java.util.Random;
2737

2838
/**
2939
* API tests for ProjectApi
3040
*/
31-
@Ignore
41+
3242
public class ProjectApiTest {
3343

34-
private final ProjectApi api = new ProjectApi();
44+
private final static ProjectApi api = new ProjectApi();
3545

46+
@BeforeClass
47+
public static void setUp() {
48+
ApiClient apiClient = Configuration.getDefaultApiClient();
49+
apiClient.setBasePath("http://sysml2-sst.intercax.com:9000");
50+
api.setApiClient(apiClient);
51+
}
3652

3753
/**
38-
* Get project by ID
54+
* Get projects
3955
*
4056
*
4157
*
4258
* @throws ApiException
4359
* if the Api call fails
4460
*/
4561
@Test
46-
public void getProjectByIdTest() throws ApiException {
47-
UUID projectId = null;
48-
Project response = api.getProjectById(projectId);
49-
50-
// TODO: test validations
62+
public void getProjectsTest() {
63+
64+
List<Project> response;
65+
try {
66+
response = api.getProjects(null, null, null);
67+
assertTrue(response.size() >= 0); //no project then size = 0?
68+
} catch (ApiException e) {
69+
fail("getProjectsTest failed: not expecting ApiException");
70+
}
71+
}
72+
73+
@Test
74+
public void getProjectsTest_0() {
75+
76+
ApiClient apiClient = Configuration.getDefaultApiClient();
77+
apiClient.setBasePath("http://sysml2-sst.intercaxxxxxxx.com:9000");
78+
ProjectApi api = new ProjectApi();
79+
api.setApiClient(apiClient);
80+
81+
try {
82+
List<Project> response = api.getProjects(null, null, null);
83+
fail("getProjectsTest_0 failed: expecting ApiException");
84+
System.out.println(response);
85+
}
86+
catch( ApiException e) {
87+
assertEquals("0", Integer.toString(e.getCode()));
88+
assertEquals("java.net.UnknownHostException: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server (sysml2-sst.intercaxxxxxxx.com)", e.getMessage());
89+
}
90+
5191
}
5292

5393
/**
54-
* Get projects
94+
* Get project by ID
5595
*
5696
*
5797
*
5898
* @throws ApiException
5999
* if the Api call fails
60100
*/
61101
@Test
62-
public void getProjectsTest() throws ApiException {
63-
String pageAfter = null;
64-
String pageBefore = null;
65-
Integer pageSize = null;
66-
List<Project> response = api.getProjects(pageAfter, pageBefore, pageSize);
102+
public void getProjectByIdTest() {
67103

68-
// TODO: test validations
104+
try {
105+
List<Project> result = api.getProjects(null, null, null);
106+
if ( result.size() > 0) {
107+
UUID projectId = result.get(0).getId();
108+
Project response = api.getProjectById(projectId);
109+
assertEquals(projectId, response.getId());
110+
assertEquals(projectId.toString(), response.getId().toString());
111+
}
112+
else
113+
fail("getProjectByIdTest failed: No project available to test");
114+
} catch (ApiException e) {
115+
fail("getProjectByIdTest failed: not expecting ApiException");
116+
}
69117
}
70118

71119
/**
72-
* Create project
120+
* Get project by ID when when ID is null
73121
*
74-
*
122+
* @throws ApiException
123+
* if the Api call fails
124+
*/
125+
126+
@Test
127+
public void getProjectByIdTest_0() throws ApiException {
128+
129+
try {
130+
UUID projectId = null;
131+
api.getProjectById(projectId);
132+
fail("getProjectByIdTest_0 failed: expecting ApiException"); //did not throw an ApiException
133+
134+
} catch (ApiException e) {
135+
assertEquals("0", Integer.toString(e.getCode()));
136+
assertEquals("Missing the required parameter 'projectId' when calling getProjectById(Async)", e.getMessage());
137+
}
138+
}
139+
/**
140+
* Get project by ID when randomly created ID (ID Not Found)
75141
*
76142
* @throws ApiException
77143
* if the Api call fails
78144
*/
79145
@Test
80-
public void postProjectTest() throws ApiException {
81-
Project body = null;
82-
Project response = api.postProject(body);
83-
84-
// TODO: test validations
146+
public void getProjectByIdTest_404() throws ApiException {
147+
148+
try {
149+
//create uuid not likely existing in the server
150+
UUID projectId = UUID.fromString("11345678-9012-3456-7890-123456789012");
151+
api.getProjectById(projectId);
152+
fail("getProjectByIdTest_404 failed: expecting ApiException"); //did not throw an ApiException
153+
154+
} catch (ApiException e) {
155+
assertEquals("404", Integer.toString(e.getCode()));
156+
assertEquals("Not Found", e.getMessage());
157+
}
158+
}
159+
160+
/**
161+
* Create project using ramdom uuid
162+
*
163+
* @throws ApiException
164+
* if the Api call fails
165+
*/
166+
@Test
167+
public void postProjectTest() {
168+
169+
UUID id = UUID.randomUUID();
170+
String description = "desc"+ Math.random();
171+
String name = "name" + Math.random();
172+
173+
Project body = new Project();
174+
body.setId(id);
175+
body.setDescription(description);
176+
body.setName(name);
177+
Project response;
178+
try {
179+
response = api.postProject(body);
180+
System.out.println(response);
181+
assertEquals(id.toString(), response.getId().toString());
182+
assertEquals(description, response.getDescription());
183+
assertEquals(name, response.getName());
184+
assertEquals(AtTypeEnum.PROJECT, response.getAtType());
185+
} catch (ApiException e) {
186+
fail("getProjectByIdTest_404 failed: not expecting ApiException");
187+
}
85188
}
86189

190+
//? if the UUID exist in post, the response is the same as new creation.
191+
// and able to change its attribute ... Is this supposed to be like that? I thought return 415.
192+
/*@Test
193+
public void postProjectTest_415() throws ApiException {
194+
195+
UUID id = UUID.fromString("90ac8d42-90bf-481d-a484-67491285a3d3");
196+
String description = "postProjectTestDescription";
197+
String name = "postProjectTestName!!!!!!!";
198+
199+
Project body = new Project();
200+
body.setId(id);
201+
body.setDescription(description);
202+
body.setName(name);
203+
Project response = api.postProject(body);
204+
System.out.println(response);
205+
assertEquals(id.toString(), response.getId().toString());
206+
assertEquals(description, response.getDescription());
207+
assertEquals(name, response.getName());
208+
assertEquals(AtTypeEnum.PROJECT, response.getAtType());
209+
210+
}*/
87211
}

0 commit comments

Comments
 (0)