|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2017 Greg Messner <[email protected]> |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 7 | + * this software and associated documentation files (the "Software"), to deal in |
| 8 | + * the Software without restriction, including without limitation the rights to |
| 9 | + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 10 | + * the Software, and to permit persons to whom the Software is furnished to do so, |
| 11 | + * subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 18 | + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 19 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 20 | + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | + */ |
| 23 | + |
| 24 | +package org.gitlab4j.api; |
| 25 | + |
| 26 | +import static org.junit.Assert.assertNotNull; |
| 27 | +import static org.junit.Assume.assumeTrue; |
| 28 | + |
| 29 | +import java.util.List; |
| 30 | + |
| 31 | +import org.gitlab4j.api.models.Job; |
| 32 | +import org.gitlab4j.api.models.Project; |
| 33 | +import org.junit.AfterClass; |
| 34 | +import org.junit.Before; |
| 35 | +import org.junit.BeforeClass; |
| 36 | +import org.junit.Test; |
| 37 | + |
| 38 | +/** |
| 39 | + * In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties |
| 40 | + * <p> |
| 41 | + * TEST_NAMESPACE |
| 42 | + * TEST_PROJECT_NAME |
| 43 | + * TEST_HOST_URL |
| 44 | + * TEST_PRIVATE_TOKEN |
| 45 | + * <p> |
| 46 | + * If any of the above are NULL, all tests in this class will be skipped. |
| 47 | + */ |
| 48 | +public class TestJobApi { |
| 49 | + |
| 50 | + // The following needs to be set to your test repository |
| 51 | + private static final String TEST_NAMESPACE; |
| 52 | + private static final String TEST_PROJECT_NAME; |
| 53 | + private static final String TEST_HOST_URL; |
| 54 | + private static final String TEST_PRIVATE_TOKEN; |
| 55 | + private static GitLabApi gitLabApi; |
| 56 | + private static Integer testProjectId; |
| 57 | + |
| 58 | + static { |
| 59 | + TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); |
| 60 | + TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); |
| 61 | + TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); |
| 62 | + TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); |
| 63 | + } |
| 64 | + |
| 65 | + public TestJobApi() { |
| 66 | + super(); |
| 67 | + } |
| 68 | + |
| 69 | + @BeforeClass |
| 70 | + public static void setup() { |
| 71 | + |
| 72 | + String problems = ""; |
| 73 | + if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { |
| 74 | + problems += "TEST_NAMESPACE cannot be empty\n"; |
| 75 | + } |
| 76 | + |
| 77 | + if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { |
| 78 | + problems += "TEST_HOST_URL cannot be empty\n"; |
| 79 | + } |
| 80 | + |
| 81 | + if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { |
| 82 | + problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; |
| 83 | + } |
| 84 | + |
| 85 | + if (problems.isEmpty()) { |
| 86 | + gitLabApi = new GitLabApi(TEST_HOST_URL, TEST_PRIVATE_TOKEN); |
| 87 | + } else { |
| 88 | + System.err.print(problems); |
| 89 | + } |
| 90 | + |
| 91 | + if (gitLabApi != null) { |
| 92 | + try { |
| 93 | + Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); |
| 94 | + testProjectId = project.getId(); |
| 95 | + } catch (Exception e) { |
| 96 | + System.err.print(e.getMessage()); |
| 97 | + gitLabApi = null; |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + @AfterClass |
| 103 | + public static void teardown() throws GitLabApiException { |
| 104 | + } |
| 105 | + |
| 106 | + @Before |
| 107 | + public void beforeMethod() { |
| 108 | + assumeTrue(gitLabApi != null); |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + public void testGetJobs() throws GitLabApiException { |
| 113 | + List<Job> jobs = gitLabApi.getJobApi().getJobs(testProjectId.intValue()); |
| 114 | + assertNotNull(jobs); |
| 115 | + } |
| 116 | +} |
0 commit comments