|
13 | 13 |
|
14 | 14 | package org.omg.sysml.api; |
15 | 15 |
|
| 16 | +import org.omg.sysml.ApiClient; |
16 | 17 | import org.omg.sysml.ApiException; |
| 18 | +import org.omg.sysml.Configuration; |
17 | 19 | import org.omg.sysml.model.Error; |
18 | 20 | import org.omg.sysml.model.Project; |
| 21 | +import org.omg.sysml.model.Project.AtTypeEnum; |
| 22 | + |
19 | 23 | import java.util.UUID; |
20 | 24 | import org.junit.Test; |
| 25 | +import org.junit.BeforeClass; |
21 | 26 | import org.junit.Ignore; |
22 | 27 |
|
| 28 | +import static org.junit.Assert.assertEquals; |
| 29 | +import static org.junit.Assert.assertTrue; |
| 30 | +import static org.junit.Assert.fail; |
| 31 | + |
23 | 32 | import java.util.ArrayList; |
24 | 33 | import java.util.HashMap; |
25 | 34 | import java.util.List; |
26 | 35 | import java.util.Map; |
| 36 | +import java.util.Random; |
27 | 37 |
|
28 | 38 | /** |
29 | 39 | * API tests for ProjectApi |
30 | 40 | */ |
31 | | -@Ignore |
| 41 | + |
32 | 42 | public class ProjectApiTest { |
33 | 43 |
|
34 | | - private final ProjectApi api = new ProjectApi(); |
| 44 | + private final static ProjectApi api = new ProjectApi(); |
35 | 45 |
|
| 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 | + } |
36 | 52 |
|
37 | 53 | /** |
38 | | - * Get project by ID |
| 54 | + * Get projects |
39 | 55 | * |
40 | 56 | * |
41 | 57 | * |
42 | 58 | * @throws ApiException |
43 | 59 | * if the Api call fails |
44 | 60 | */ |
45 | 61 | @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 | + |
51 | 91 | } |
52 | 92 |
|
53 | 93 | /** |
54 | | - * Get projects |
| 94 | + * Get project by ID |
55 | 95 | * |
56 | 96 | * |
57 | 97 | * |
58 | 98 | * @throws ApiException |
59 | 99 | * if the Api call fails |
60 | 100 | */ |
61 | 101 | @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() { |
67 | 103 |
|
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 | + } |
69 | 117 | } |
70 | 118 |
|
71 | 119 | /** |
72 | | - * Create project |
| 120 | + * Get project by ID when when ID is null |
73 | 121 | * |
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) |
75 | 141 | * |
76 | 142 | * @throws ApiException |
77 | 143 | * if the Api call fails |
78 | 144 | */ |
79 | 145 | @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 | + } |
85 | 188 | } |
86 | 189 |
|
| 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 | + }*/ |
87 | 211 | } |
0 commit comments