|
1 | 1 | package org.gitlab4j.api; |
2 | 2 |
|
| 3 | +import static org.junit.Assert.assertFalse; |
| 4 | +import static org.junit.Assert.assertNotNull; |
| 5 | +import static org.junit.Assert.fail; |
| 6 | + |
| 7 | +import java.util.Arrays; |
| 8 | + |
| 9 | +import org.gitlab4j.api.utils.AccessTokenUtils; |
3 | 10 | import org.junit.BeforeClass; |
4 | 11 | import org.junit.experimental.categories.Categories.IncludeCategory; |
5 | 12 | import org.junit.runner.RunWith; |
|
10 | 17 | @RunWith(WildcardPatternSuite.class) |
11 | 18 | @SuiteClasses({"**/Test*.class"}) |
12 | 19 | @IncludeCategory(IntegrationTest.class) |
13 | | -public class IntegrationTestSuite { |
| 20 | +public class IntegrationTestSuite implements PropertyConstants { |
| 21 | + |
| 22 | + private static final String TEST_LOGIN_USERNAME = HelperUtils.getProperty(LOGIN_USERNAME_KEY); |
| 23 | + private static final String TEST_LOGIN_PASSWORD = HelperUtils.getProperty(LOGIN_PASSWORD_KEY); |
| 24 | + private static final String TEST_HOST_URL = HelperUtils.getProperty(HOST_URL_KEY); |
| 25 | + |
| 26 | + protected static final String TEST_PROJECT_NAME = HelperUtils.getProperty(PROJECT_NAME_KEY); |
| 27 | + protected static final String TEST_NAMESPACE = HelperUtils.getProperty(NAMESPACE_KEY); |
| 28 | + |
| 29 | + protected static String TEST_PRIVATE_TOKEN; |
| 30 | + protected static String TEST_ACCESS_TOKEN; |
| 31 | + private static String problems = ""; |
14 | 32 |
|
15 | 33 | @BeforeClass |
16 | | - public static void suiteSetup() { |
| 34 | + public static void suiteSetup() throws GitLabApiException { |
| 35 | + |
17 | 36 | System.out.println("********************************************************"); |
18 | | - System.out.println(" Test Suite Setup"); |
| 37 | + System.out.println("* Test Suite Setup *"); |
19 | 38 | System.out.println("********************************************************"); |
20 | 39 |
|
21 | | - // TODO Create default test resources if not present |
| 40 | + if (TEST_LOGIN_USERNAME == null || TEST_LOGIN_USERNAME.trim().isEmpty()) { |
| 41 | + problems += "TEST_LOGIN_USERNAME cannot be empty\n"; |
| 42 | + } |
| 43 | + |
| 44 | + if (TEST_LOGIN_PASSWORD == null || TEST_LOGIN_PASSWORD.trim().isEmpty()) { |
| 45 | + problems += "TEST_LOGIN_PASSWORD cannot be empty\n"; |
| 46 | + } |
| 47 | + |
| 48 | + if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { |
| 49 | + problems += "TEST_HOST_URL cannot be empty\n"; |
| 50 | + } |
| 51 | + |
| 52 | + if (!problems.isEmpty()) { |
| 53 | + fail(problems); |
| 54 | + } |
| 55 | + |
| 56 | + // Create a new personal access token for both the private and access tokens |
| 57 | + TEST_PRIVATE_TOKEN = AccessTokenUtils.createPersonalAccessToken( |
| 58 | + TEST_HOST_URL, TEST_LOGIN_USERNAME, TEST_LOGIN_PASSWORD, |
| 59 | + "GitLab4J Test Private Token", Arrays.asList("api", "sudo")); |
| 60 | + System.out.println("Created private token: " + TEST_PRIVATE_TOKEN); |
| 61 | + assertNotNull(TEST_PRIVATE_TOKEN); |
| 62 | + assertFalse(TEST_PRIVATE_TOKEN.trim().isEmpty()); |
| 63 | + HelperUtils.setProperty(PRIVATE_TOKEN_KEY, TEST_PRIVATE_TOKEN); |
| 64 | + |
| 65 | + TEST_ACCESS_TOKEN = AccessTokenUtils.createPersonalAccessToken( |
| 66 | + TEST_HOST_URL, TEST_LOGIN_USERNAME, TEST_LOGIN_PASSWORD, |
| 67 | + "GitLab4J Test Access Token", Arrays.asList("api", "sudo")); |
| 68 | + System.out.println("Created private token: " + TEST_ACCESS_TOKEN); |
| 69 | + assertNotNull(TEST_ACCESS_TOKEN); |
| 70 | + assertFalse(TEST_ACCESS_TOKEN.trim().isEmpty()); |
| 71 | + HelperUtils.setProperty(ACCESS_TOKEN_KEY, TEST_ACCESS_TOKEN); |
22 | 72 | } |
23 | 73 | } |
0 commit comments