|
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.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 | + |
19 | 26 | import java.util.UUID; |
20 | 27 | 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; |
22 | 34 |
|
23 | | -import java.util.ArrayList; |
24 | | -import java.util.HashMap; |
25 | 35 | import java.util.List; |
26 | | -import java.util.Map; |
27 | 36 |
|
28 | 37 | /** |
29 | 38 | * API tests for CommitApi |
30 | 39 | */ |
31 | | -@Ignore |
| 40 | +@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
32 | 41 | public class CommitApiTest { |
33 | 42 |
|
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 | + } |
36 | 66 |
|
37 | 67 | /** |
38 | | - * Get commit by project and ID |
39 | | - * |
40 | | - * |
| 68 | + * Get head commit by project |
41 | 69 | * |
42 | 70 | * @throws ApiException |
43 | 71 | * if the Api call fails |
44 | 72 | */ |
45 | 73 | @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 | + } |
52 | 87 | } |
53 | 88 |
|
| 89 | + |
54 | 90 | /** |
55 | 91 | * Get commits by project |
56 | 92 | * |
57 | | - * |
58 | | - * |
| 93 | + * Using the setup to projectId |
59 | 94 | * @throws ApiException |
60 | 95 | * if the Api call fails |
61 | 96 | */ |
62 | 97 | @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 | + |
71 | 115 | } |
72 | 116 |
|
| 117 | + |
| 118 | + |
73 | 119 | /** |
74 | | - * Get head commit by project |
| 120 | + * Get commit by project and ID |
75 | 121 | * |
76 | | - * |
| 122 | + * Using the previously run test get2CommitsByProjectTest to get commitId |
77 | 123 | * |
78 | 124 | * @throws ApiException |
79 | 125 | * if the Api call fails |
80 | 126 | */ |
81 | 127 | @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 | + } |
87 | 144 | } |
88 | 145 |
|
| 146 | + |
89 | 147 | /** |
90 | 148 | * Create commit by project |
91 | | - * |
| 149 | + * Using the previously run test get2CommitsByProjectTest to get commitId |
92 | 150 | * |
93 | 151 | * |
94 | 152 | * @throws ApiException |
95 | 153 | * if the Api call fails |
96 | 154 | */ |
97 | 155 | @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 | + } |
104 | 201 | } |
105 | 202 |
|
106 | 203 | } |
0 commit comments