From 798c1ef27a69f6367fdbfd70ff4d963cc399f7fa Mon Sep 17 00:00:00 2001 From: Greg Messner Date: Thu, 25 Apr 2019 23:30:44 -0700 Subject: [PATCH] Mods to support split unit and integration tests (#311). --- pom.xml | 76 ++++++++++- .../gitlab4j/api/AbstractIntegrationTest.java | 81 ++++++++++-- .../org/gitlab4j/api/IntegrationTest.java | 22 ++++ .../gitlab4j/api/IntegrationTestSuite.java | 23 ++++ .../org/gitlab4j/api/TestAccessToken.java | 58 ++++----- .../org/gitlab4j/api/TestAvatarUpload.java | 61 ++------- .../java/org/gitlab4j/api/TestCommitsApi.java | 85 ++++-------- .../org/gitlab4j/api/TestDeployKeysApi.java | 32 +---- .../java/org/gitlab4j/api/TestEventsApi.java | 49 +------ .../java/org/gitlab4j/api/TestFileUpload.java | 41 +----- .../java/org/gitlab4j/api/TestGitLabApi.java | 28 +--- .../gitlab4j/api/TestGitLabApiException.java | 42 +----- .../org/gitlab4j/api/TestGitLabLogin.java | 26 +--- .../java/org/gitlab4j/api/TestGroupApi.java | 43 +++--- .../org/gitlab4j/api/TestHealthCheckApi.java | 2 + .../api/TestIgnoreCertificateErrors.java | 2 + .../java/org/gitlab4j/api/TestIssuesApi.java | 49 ++----- .../java/org/gitlab4j/api/TestJobApi.java | 56 ++------ .../org/gitlab4j/api/TestNamespaceApi.java | 41 +----- .../java/org/gitlab4j/api/TestNotesApi.java | 54 ++------ .../api/TestNotificationSettingsApi.java | 49 ++----- src/test/java/org/gitlab4j/api/TestPager.java | 47 +------ .../org/gitlab4j/api/TestPipelineApi.java | 52 ++------ .../java/org/gitlab4j/api/TestProjectApi.java | 123 ++++++++---------- .../gitlab4j/api/TestProjectApiSnippets.java | 79 ++++------- .../api/TestProtectedBranchesApi.java | 45 +------ .../org/gitlab4j/api/TestRepositoryApi.java | 46 ++----- .../gitlab4j/api/TestRepositoryFileApi.java | 45 ++----- .../api/TestRequestResponseLogging.java | 2 + .../java/org/gitlab4j/api/TestRunnersApi.java | 36 +---- .../org/gitlab4j/api/TestServicesApi.java | 56 ++------ .../org/gitlab4j/api/TestSnippetsApi.java | 36 ++--- .../org/gitlab4j/api/TestSystemHooksApi.java | 38 ++---- .../java/org/gitlab4j/api/TestTagsApi.java | 15 ++- .../java/org/gitlab4j/api/TestUserApi.java | 60 +++++---- src/test/java/org/gitlab4j/api/TestUtils.java | 14 ++ .../java/org/gitlab4j/api/TestWikisApi.java | 87 ++++--------- 37 files changed, 583 insertions(+), 1118 deletions(-) create mode 100644 src/test/java/org/gitlab4j/api/IntegrationTest.java create mode 100644 src/test/java/org/gitlab4j/api/IntegrationTestSuite.java diff --git a/pom.xml b/pom.xml index 0130e9a0..ab45b1e2 100644 --- a/pom.xml +++ b/pom.xml @@ -38,17 +38,22 @@ - 1.8 - 1.8 + 8 + 1.8 + 1.8 + 2.28 2.9.8 + 4.0.1 + 4.12 2.19.0 1.3 1.18.0 UTF-8 UTF-8 + 1.59 @@ -62,6 +67,7 @@ package + org.apache.maven.plugins maven-release-plugin @@ -191,14 +197,35 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.0 + 3.0.0-M3 + org.gitlab4j.api.IntegrationTest target/jacoco.exec + + org.apache.maven.plugins + maven-failsafe-plugin + 3.0.0-M3 + + org.gitlab4j.api.IntegrationTest + + **/IntegrationTestSuite.java + + + + + + integration-test + verify + + + + + org.apache.maven.plugins maven-enforcer-plugin @@ -206,7 +233,7 @@ - 1.8 + 1.8 module-info @@ -230,10 +257,31 @@ + + org.codehaus.mojo + animal-sniffer-maven-plugin + 1.17 + + + + check + + check + + + + + org.codehaus.mojo.signature + java1${java.level} + + + + + se.bjurr.gitchangelog git-changelog-maven-plugin @@ -252,7 +300,6 @@ - @@ -319,7 +366,24 @@ ${systemRules.version} test - + + com.googlecode.junit-toolbox + junit-toolbox + 2.4 + test + + + + + + org.codehaus.mojo.signature + java18 + 1.0 + signature + + + + diff --git a/src/test/java/org/gitlab4j/api/AbstractIntegrationTest.java b/src/test/java/org/gitlab4j/api/AbstractIntegrationTest.java index 6fa8856a..8f7a4215 100644 --- a/src/test/java/org/gitlab4j/api/AbstractIntegrationTest.java +++ b/src/test/java/org/gitlab4j/api/AbstractIntegrationTest.java @@ -1,20 +1,24 @@ package org.gitlab4j.api; +import java.util.Collections; +import java.util.Map; +import java.util.WeakHashMap; + import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Project; /** - * In order for these tests to run you must set the following properties in - * test-gitlab4j.properties + * In order for the integration tests to run you must set the following properties in test-gitlab4j.properties + * and the resources pointed to must exist. * * TEST_NAMESPACE * TEST_PROJECT_NAME * TEST_HOST_URL * TEST_PRIVATE_TOKEN */ -public class AbstractBaseTest { +public class AbstractIntegrationTest { - // The following needs to be set to your test repository + // Get the values of the minimum required test properties. protected static final String TEST_PROJECT_NAME; protected static final String TEST_NAMESPACE; protected static final String TEST_HOST_URL; @@ -26,14 +30,38 @@ public class AbstractBaseTest { TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); } - protected static Project testProject; - protected static GitLabApi gitLabApi; + protected static class BaseTestResources { + protected GitLabApi gitLabApi; + protected Project testProject; + + protected BaseTestResources(GitLabApi gitLabApi) { + this.gitLabApi = gitLabApi; + } + } + + // Used to keep track of GitLabApi and Project instances for each test class + private static final Map baseTestResourcesMap = + Collections.synchronizedMap(new WeakHashMap()); - public AbstractBaseTest() { + public AbstractIntegrationTest() { super(); } - protected static void testSetup() { + /** + * Verifies that the required test properties are present and returns an instance of GitLabApi + * set up to use the TEST_PRIVATE_TOKEN property to authenticate. + * + * @return an instance of GitLabApi set up to use the TEST_PRIVATE_TOKEN property to authenticate + */ + protected static GitLabApi baseTestSetup() { + + Throwable t = new Throwable(); + StackTraceElement directCaller = t.getStackTrace()[1]; + String callingClassName = directCaller.getClassName(); + BaseTestResources baseResources = baseTestResourcesMap.get(callingClassName); + if (baseResources != null && baseResources.gitLabApi != null) { + return (baseResources.gitLabApi); + } String problems = ""; if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { @@ -54,15 +82,44 @@ public class AbstractBaseTest { if (problems.isEmpty()) { try { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); + GitLabApi gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); + baseResources = new BaseTestResources(gitLabApi); + baseTestResourcesMap.put(callingClassName, baseResources); + return (gitLabApi); } catch (Exception e) { problems += e.getMessage() + "\n"; } } - if (!problems.isEmpty()) { - System.err.print(problems); + System.err.print(problems); + return (null); + } + + /** + * Get the test Project instance for the calling test class. + * + * @return the test Project instance for the calling test class + */ + protected static Project getTestProject() { + + Throwable t = new Throwable(); + StackTraceElement directCaller = t.getStackTrace()[1]; + String callingClassName = directCaller.getClassName(); + BaseTestResources baseResources = baseTestResourcesMap.get(callingClassName); + if (baseResources == null || baseResources.gitLabApi == null) { + System.err.println("Problems fetching test Project instance: GitLabApi instance is null"); + return (null); + } else if (baseResources.testProject != null) { + return (baseResources.testProject); + } + + try { + Project testProject = (baseResources.gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME)); + baseResources.testProject = testProject; + return (testProject); + } catch (Exception e) { + System.err.println("Problems fetching test Project instance: " + e.getMessage()); + return (null); } } } diff --git a/src/test/java/org/gitlab4j/api/IntegrationTest.java b/src/test/java/org/gitlab4j/api/IntegrationTest.java new file mode 100644 index 00000000..19fc3dc4 --- /dev/null +++ b/src/test/java/org/gitlab4j/api/IntegrationTest.java @@ -0,0 +1,22 @@ +package org.gitlab4j.api; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This interface is used as a category for JUnit allowing integration tests to be skipped + * while running unit tests. + *

To mark a test class as an integration test add the following lines before the class declaration:

+ * + *

+ * import org.junit.experimental.categories.Category;
+ *
+ * @Category(org.gitlab4j.api.IntegrationTest.class)
+ * 
+ */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface IntegrationTest { +} diff --git a/src/test/java/org/gitlab4j/api/IntegrationTestSuite.java b/src/test/java/org/gitlab4j/api/IntegrationTestSuite.java new file mode 100644 index 00000000..2c6f194b --- /dev/null +++ b/src/test/java/org/gitlab4j/api/IntegrationTestSuite.java @@ -0,0 +1,23 @@ +package org.gitlab4j.api; + +import org.junit.BeforeClass; +import org.junit.experimental.categories.Categories.IncludeCategory; +import org.junit.runner.RunWith; + +import com.googlecode.junittoolbox.SuiteClasses; +import com.googlecode.junittoolbox.WildcardPatternSuite; + +@RunWith(WildcardPatternSuite.class) +@SuiteClasses({"**/Test*.class"}) +@IncludeCategory(IntegrationTest.class) +public class IntegrationTestSuite { + + @BeforeClass + public static void suiteSetup() { + System.out.println("********************************************************"); + System.out.println(" Test Suite Setup"); + System.out.println("********************************************************"); + + // TODO Create default test resources if not present + } +} diff --git a/src/test/java/org/gitlab4j/api/TestAccessToken.java b/src/test/java/org/gitlab4j/api/TestAccessToken.java index 7bb55a85..646c6037 100644 --- a/src/test/java/org/gitlab4j/api/TestAccessToken.java +++ b/src/test/java/org/gitlab4j/api/TestAccessToken.java @@ -1,7 +1,7 @@ package org.gitlab4j.api; import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import org.gitlab4j.api.Constants.TokenType; import org.gitlab4j.api.GitLabApi.ApiVersion; @@ -9,6 +9,7 @@ import org.gitlab4j.api.models.Version; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -20,61 +21,52 @@ import org.junit.Test; * If any of the above are NULL, all tests in this class will be skipped. * */ -public class TestAccessToken { +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestAccessToken extends AbstractIntegrationTest { - // The following needs to be set to your test repository - private static final String TEST_HOST_URL; - private static final String TEST_ACCESS_TOKEN; - private static final String TEST_PRIVATE_TOKEN; - static { - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_ACCESS_TOKEN = TestUtils.getProperty("TEST_ACCESS_TOKEN"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } - - private static boolean setupOk; + // TEST_ACCESS_TOKEN must be defined to run this test + private static final String TEST_ACCESS_TOKEN = TestUtils.getProperty("TEST_ACCESS_TOKEN"); + private static GitLabApi gitLabApi; public TestAccessToken() { super(); } @BeforeClass - public static void setup() { + public static void testSetup() { - String problems = ""; - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); if (TEST_ACCESS_TOKEN == null || TEST_ACCESS_TOKEN.trim().isEmpty()) { - problems += "TEST_ACCESS_TOKEN cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - setupOk = true; - } else { - setupOk = false; - System.err.print(problems); + System.err.println("TEST_ACCESS_TOKEN cannot be empty"); } } @Before public void beforeMethod() { - assumeTrue(setupOk); + assumeNotNull(gitLabApi); } @Test - public void testAccessToken() throws GitLabApiException { + public void testPrivateToken() throws GitLabApiException { - GitLabApi gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TokenType.PRIVATE, TEST_PRIVATE_TOKEN); + // This test uses the GitLabApi instance created in setup() Version version = gitLabApi.getVersion(); assertNotNull(version); System.out.format("tokenType: %s, version=%s, revision=%s%n", TokenType.PRIVATE, gitLabApi.getIgnoreCertificateErrors(), version.getVersion(), version.getRevision()); assertNotNull(version.getVersion()); assertNotNull(version.getRevision()); } + + @Test + public void testAccessToken() throws GitLabApiException { + assumeNotNull(TEST_ACCESS_TOKEN); + GitLabApi gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TokenType.ACCESS, TEST_ACCESS_TOKEN); + Version version = gitLabApi.getVersion(); + assertNotNull(version); + System.out.format("tokenType: %s, version=%s, revision=%s%n", TokenType.ACCESS, gitLabApi.getIgnoreCertificateErrors(), version.getVersion(), version.getRevision()); + assertNotNull(version.getVersion()); + assertNotNull(version.getRevision()); + } } diff --git a/src/test/java/org/gitlab4j/api/TestAvatarUpload.java b/src/test/java/org/gitlab4j/api/TestAvatarUpload.java index 27625838..d8e90f4a 100644 --- a/src/test/java/org/gitlab4j/api/TestAvatarUpload.java +++ b/src/test/java/org/gitlab4j/api/TestAvatarUpload.java @@ -2,18 +2,18 @@ package org.gitlab4j.api; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeNotNull; import static org.junit.Assume.assumeTrue; import java.io.File; import java.util.Map; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.User; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -26,31 +26,24 @@ import org.junit.runners.MethodSorters; * * If any of the above are NULL, all tests in this class will be skipped. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestAvatarUpload { +public class TestAvatarUpload extends AbstractIntegrationTest { // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; private static final String TEST_PROXY_URI; private static final String TEST_PROXY_USERNAME; private static final String TEST_PROXY_PASSWORD; static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); TEST_PROXY_URI = TestUtils.getProperty("TEST_PROXY_URI"); TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME"); TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD"); } - private static final String AVATAR_FILENAME = "avatar.png"; private static GitLabApi gitLabApi; + private static Project testProject; public TestAvatarUpload() { super(); @@ -58,44 +51,18 @@ public class TestAvatarUpload { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } - } - - @Before - public void beforeMethod() { - assumeTrue(gitLabApi != null); + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); } @Test public void testSetProjectAvatar() throws GitLabApiException { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - assertNotNull(project); + assumeNotNull(testProject); File avatarFile = new File("src/test/resources/org/gitlab4j/api", AVATAR_FILENAME); - Project updatedProject = gitLabApi.getProjectApi().setProjectAvatar(project.getId(), avatarFile); + Project updatedProject = gitLabApi.getProjectApi().setProjectAvatar(testProject.getId(), avatarFile); assertNotNull(updatedProject); assertTrue(updatedProject.getAvatarUrl().endsWith(AVATAR_FILENAME)); } @@ -103,6 +70,7 @@ public class TestAvatarUpload { @Test public void testSetProjectAvatarWithProxy() throws GitLabApiException { + assumeNotNull(testProject); assumeTrue(TEST_PROXY_URI != null && TEST_PROXY_USERNAME != null && TEST_PROXY_PASSWORD != null); assumeTrue(TEST_PROXY_URI.length() > 0 && TEST_PROXY_USERNAME.length() > 0 && TEST_PROXY_PASSWORD.length() > 0); @@ -110,11 +78,8 @@ public class TestAvatarUpload { Map clientConfig = ProxyClientConfig.createProxyClientConfig(TEST_PROXY_URI, TEST_PROXY_USERNAME, TEST_PROXY_PASSWORD); GitLabApi gitLabApi = new GitLabApi(TEST_HOST_URL, TEST_PRIVATE_TOKEN, null, clientConfig); - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - assertNotNull(project); - File avatarFile = new File("src/test/resources/org/gitlab4j/api", AVATAR_FILENAME); - Project updatedProject = gitLabApi.getProjectApi().setProjectAvatar(project.getId(), avatarFile); + Project updatedProject = gitLabApi.getProjectApi().setProjectAvatar(testProject.getId(), avatarFile); assertNotNull(updatedProject); assertTrue(updatedProject.getAvatarUrl().endsWith(AVATAR_FILENAME)); } @@ -122,6 +87,8 @@ public class TestAvatarUpload { @Test public void testSetUserAvatar() throws GitLabApiException { + assumeNotNull(gitLabApi); + User user = gitLabApi.getUserApi().getCurrentUser(); assertNotNull(user); diff --git a/src/test/java/org/gitlab4j/api/TestCommitsApi.java b/src/test/java/org/gitlab4j/api/TestCommitsApi.java index 36b9c49c..ea3f337c 100644 --- a/src/test/java/org/gitlab4j/api/TestCommitsApi.java +++ b/src/test/java/org/gitlab4j/api/TestCommitsApi.java @@ -1,6 +1,16 @@ package org.gitlab4j.api; -import org.gitlab4j.api.GitLabApi.ApiVersion; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +import java.text.ParseException; +import java.util.Date; +import java.util.List; + +import javax.ws.rs.core.Response; + import org.gitlab4j.api.models.Comment; import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.CommitRef; @@ -11,19 +21,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; -import javax.ws.rs.core.Response; - -import java.text.ParseException; -import java.util.Date; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; - /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties * @@ -34,21 +34,11 @@ import static org.junit.Assume.assumeTrue; * * If any of the above are NULL, all tests in this class will be skipped. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestCommitsApi { +public class TestCommitsApi extends AbstractIntegrationTest { - // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; private static final String TEST_PROJECT_SUBDIRECTORY_PATH = "src/main/docs/test-project.txt"; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } private static GitLabApi gitLabApi; private static Project testProject; @@ -59,37 +49,9 @@ public class TestCommitsApi { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - - try { - testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - } catch (GitLabApiException gle) { - System.err.print(gle.getMessage()); - } - - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); } @Before @@ -191,20 +153,20 @@ public class TestCommitsApi { assertNotNull(testProject); CommitsApi commitsApi = gitLabApi.getCommitsApi(); - List commits = commitsApi.getCommits(testProject.getId(), "master", null); + List commits = commitsApi.getCommits(testProject, "master", null); assertNotNull(commits); assertTrue(commits.size() > 0); - commits = commitsApi.getCommits(testProject.getId(), "master", "README"); + commits = commitsApi.getCommits(testProject, "master", "README"); assertNotNull(commits); assertTrue(commits.size() > 0); commitsApi = gitLabApi.getCommitsApi(); - commits = commitsApi.getCommits(testProject.getId(), "master", "README.md"); + commits = commitsApi.getCommits(testProject, "master", "README.md"); assertNotNull(commits); assertTrue(commits.size() > 0); - commits = commitsApi.getCommits(testProject.getId(), "master", TEST_PROJECT_SUBDIRECTORY_PATH); + commits = commitsApi.getCommits(testProject, "master", TEST_PROJECT_SUBDIRECTORY_PATH); assertNotNull(commits); assertTrue(commits.size() > 0); } @@ -212,10 +174,9 @@ public class TestCommitsApi { @Test public void testCommitsByPathNotFound() throws GitLabApiException { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - try { - List commits = gitLabApi.getCommitsApi().getCommits(project.getId(), "master", "this-file-does-not-exist.an-extension"); + List commits = gitLabApi.getCommitsApi().getCommits( + testProject, "master", "this-file-does-not-exist.an-extension"); assertTrue(commits == null || commits.isEmpty()); } catch (GitLabApiException gle) { assertEquals(Response.Status.NOT_FOUND, gle.getHttpStatus()); diff --git a/src/test/java/org/gitlab4j/api/TestDeployKeysApi.java b/src/test/java/org/gitlab4j/api/TestDeployKeysApi.java index 395e4777..fa1f4416 100644 --- a/src/test/java/org/gitlab4j/api/TestDeployKeysApi.java +++ b/src/test/java/org/gitlab4j/api/TestDeployKeysApi.java @@ -2,9 +2,9 @@ package org.gitlab4j.api; import static org.junit.Assume.assumeTrue; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -16,17 +16,11 @@ import org.junit.BeforeClass; * If any of the above are NULL, all tests in this class will be skipped. * */ -public class TestDeployKeysApi { +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestDeployKeysApi extends AbstractIntegrationTest { // The following needs to be set to your test repository - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - private static final String TEST_USERNAME; - static { - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME"); - } + private static final String TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME"); private static GitLabApi gitLabApi; @@ -37,23 +31,11 @@ public class TestDeployKeysApi { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); if (TEST_USERNAME == null || TEST_USERNAME.trim().isEmpty()) { - problems += "TEST_USER_NAME cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); + System.err.println("TEST_USER_NAME cannot be empty"); } } diff --git a/src/test/java/org/gitlab4j/api/TestEventsApi.java b/src/test/java/org/gitlab4j/api/TestEventsApi.java index 3d1c7fd4..10879138 100644 --- a/src/test/java/org/gitlab4j/api/TestEventsApi.java +++ b/src/test/java/org/gitlab4j/api/TestEventsApi.java @@ -8,7 +8,6 @@ import java.text.ParseException; import java.util.Date; import java.util.List; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Event; import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.User; @@ -16,6 +15,7 @@ import org.gitlab4j.api.utils.ISO8601; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -27,19 +27,8 @@ import org.junit.Test; * * If any of the above are NULL, all tests in this class will be skipped. */ -public class TestEventsApi { - - // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestEventsApi extends AbstractIntegrationTest { private static GitLabApi gitLabApi; private static Project testProject; @@ -52,40 +41,16 @@ public class TestEventsApi { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - - try { - testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - } catch (GitLabApiException gle) { - System.err.print(gle.getMessage()); - } + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); + if (gitLabApi != null) { try { testUser = gitLabApi.getUserApi().getCurrentUser(); } catch (GitLabApiException gle) { System.err.print(gle.getMessage()); } - - } else { - System.err.print(problems); } } diff --git a/src/test/java/org/gitlab4j/api/TestFileUpload.java b/src/test/java/org/gitlab4j/api/TestFileUpload.java index a12bd0d5..78c63259 100644 --- a/src/test/java/org/gitlab4j/api/TestFileUpload.java +++ b/src/test/java/org/gitlab4j/api/TestFileUpload.java @@ -1,18 +1,19 @@ package org.gitlab4j.api; import static org.junit.Assert.assertNotNull; +import static org.junit.Assume.assumeNotNull; import static org.junit.Assume.assumeTrue; import java.io.File; import java.util.Map; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.FileUpload; import org.gitlab4j.api.models.Project; import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -25,22 +26,15 @@ import org.junit.runners.MethodSorters; * * If any of the above are NULL, all tests in this class will be skipped. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestFileUpload { +public class TestFileUpload extends AbstractIntegrationTest { // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; private static final String TEST_PROXY_URI; private static final String TEST_PROXY_USERNAME; private static final String TEST_PROXY_PASSWORD; static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); TEST_PROXY_URI = TestUtils.getProperty("TEST_PROXY_URI"); TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME"); TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD"); @@ -54,34 +48,13 @@ public class TestFileUpload { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestGitLabApi.java b/src/test/java/org/gitlab4j/api/TestGitLabApi.java index da1a1252..addc607a 100644 --- a/src/test/java/org/gitlab4j/api/TestGitLabApi.java +++ b/src/test/java/org/gitlab4j/api/TestGitLabApi.java @@ -1,6 +1,7 @@ package org.gitlab4j.api; import static org.junit.Assert.assertNotNull; +import static org.junit.Assume.assumeNotNull; import static org.junit.Assume.assumeTrue; import java.util.Map; @@ -9,6 +10,7 @@ import org.gitlab4j.api.models.Version; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -19,17 +21,14 @@ import org.junit.Test; * If any of the above are NULL, all tests in this class will be skipped. * */ -public class TestGitLabApi { +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestGitLabApi extends AbstractIntegrationTest { // The following needs to be set to your test repository - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; private static final String TEST_PROXY_URI; private static final String TEST_PROXY_USERNAME; private static final String TEST_PROXY_PASSWORD; static { - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); TEST_PROXY_URI = TestUtils.getProperty("TEST_PROXY_URI"); TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME"); TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD"); @@ -43,26 +42,13 @@ public class TestGitLabApi { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestGitLabApiException.java b/src/test/java/org/gitlab4j/api/TestGitLabApiException.java index 69d2d93a..b570979f 100644 --- a/src/test/java/org/gitlab4j/api/TestGitLabApiException.java +++ b/src/test/java/org/gitlab4j/api/TestGitLabApiException.java @@ -5,19 +5,19 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.Arrays; import java.util.List; import java.util.Map; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Visibility; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties @@ -28,19 +28,8 @@ import org.junit.Test; * * If any of the above are NULL, all tests in this class will be skipped. */ -public class TestGitLabApiException { - - // The following needs to be set to your test repository - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - - - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestGitLabApiException extends AbstractIntegrationTest { private static final String TEST_PROJECT_NAME_DUPLICATE = "test-gitlab4j-create-project-duplicate"; private static GitLabApi gitLabApi; @@ -51,25 +40,8 @@ public class TestGitLabApiException { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); deleteAllTestProjects(); } @@ -90,7 +62,7 @@ public class TestGitLabApiException { @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestGitLabLogin.java b/src/test/java/org/gitlab4j/api/TestGitLabLogin.java index 5d3e1807..452de24b 100644 --- a/src/test/java/org/gitlab4j/api/TestGitLabLogin.java +++ b/src/test/java/org/gitlab4j/api/TestGitLabLogin.java @@ -1,6 +1,5 @@ package org.gitlab4j.api; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; @@ -11,6 +10,7 @@ import org.gitlab4j.api.utils.SecretString; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -22,6 +22,7 @@ import org.junit.Test; * * If any of the above are NULL, all tests in this class will be skipped. */ +@Category(org.gitlab4j.api.IntegrationTest.class) public class TestGitLabLogin { // The following needs to be set to your test repository @@ -89,28 +90,6 @@ public class TestGitLabLogin { assumeTrue(problems != null && problems.isEmpty()); } - @SuppressWarnings("deprecation") - @Test - public void testSession() throws GitLabApiException { - - assumeTrue(hasSession); - GitLabApi gitLabApi = GitLabApi.login(ApiVersion.V4, TEST_HOST_URL, TEST_LOGIN_USERNAME, TEST_LOGIN_PASSWORD); - assertNotNull(gitLabApi); - assertNotNull(gitLabApi.getSession()); - assertEquals(TEST_PRIVATE_TOKEN, gitLabApi.getSession().getPrivateToken()); - } - - @SuppressWarnings("deprecation") - @Test - public void testSessionV3() throws GitLabApiException { - - assumeTrue(hasSession); - GitLabApi gitLabApi = GitLabApi.login(ApiVersion.V3, TEST_HOST_URL, TEST_LOGIN_USERNAME, TEST_LOGIN_PASSWORD); - assertNotNull(gitLabApi); - assertNotNull(gitLabApi.getSession()); - assertEquals(TEST_PRIVATE_TOKEN, gitLabApi.getSession().getPrivateToken()); - } - @Test public void testSessionFallover() throws GitLabApiException { assumeFalse(hasSession); @@ -126,6 +105,7 @@ public class TestGitLabLogin { GitLabApi gitLabApi = GitLabApi.oauth2Login(TEST_HOST_URL, TEST_LOGIN_USERNAME, TEST_LOGIN_PASSWORD, null, null, true); assertNotNull(gitLabApi); Version version = gitLabApi.getVersion(); + System.out.println("ACCESS_TOKEN: " + gitLabApi.getAuthToken()); assertNotNull(version); } diff --git a/src/test/java/org/gitlab4j/api/TestGroupApi.java b/src/test/java/org/gitlab4j/api/TestGroupApi.java index 9763352b..f8695596 100644 --- a/src/test/java/org/gitlab4j/api/TestGroupApi.java +++ b/src/test/java/org/gitlab4j/api/TestGroupApi.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; import java.util.Optional; @@ -20,6 +20,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -33,17 +34,14 @@ import org.junit.Test; * If any of the above are NULL, all tests in this class will be skipped. * */ -public class TestGroupApi { +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestGroupApi extends AbstractIntegrationTest { // The following needs to be set to your test repository - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; private static final String TEST_USERNAME; private static final String TEST_GROUP; private static final String TEST_GROUP_MEMBER_USERNAME; static { - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME"); TEST_GROUP = TestUtils.getProperty("TEST_GROUP"); TEST_GROUP_MEMBER_USERNAME = TestUtils.getProperty("TEST_GROUP_MEMBER_USERNAME"); @@ -60,20 +58,15 @@ public class TestGroupApi { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); + String problems = ""; if (TEST_USERNAME == null || TEST_USERNAME.trim().isEmpty()) { problems += "TEST_USER_NAME cannot be empty\n"; } - if (problems.isEmpty()) { + if (gitLabApi != null && problems.isEmpty()) { gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); try { @@ -92,9 +85,7 @@ public class TestGroupApi { } } - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { + if (!problems.isEmpty()) { System.err.print(problems); } @@ -108,21 +99,19 @@ public class TestGroupApi { private static void removeGroupMember() { - if (gitLabApi != null) { - - if (testGroup != null && testUser != null) { - try { - gitLabApi.getGroupApi().removeMember(testGroup.getId(), testUser.getId()); - } catch (GitLabApiException ignore) { - } + if (gitLabApi != null && testGroup != null && testUser != null) { + try { + gitLabApi.getGroupApi().removeMember(testGroup.getId(), testUser.getId()); + } catch (GitLabApiException ignore) { } } } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); - assumeTrue(testGroup != null && testUser != null); + assumeNotNull(gitLabApi); + assumeNotNull(testGroup); + assumeNotNull(testUser); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestHealthCheckApi.java b/src/test/java/org/gitlab4j/api/TestHealthCheckApi.java index 2d3b313e..1ce08ac4 100644 --- a/src/test/java/org/gitlab4j/api/TestHealthCheckApi.java +++ b/src/test/java/org/gitlab4j/api/TestHealthCheckApi.java @@ -7,6 +7,7 @@ import org.gitlab4j.api.models.HealthCheckInfo; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -17,6 +18,7 @@ import org.junit.Test; * If any of the above are NULL, all tests in this class will be skipped. * */ +@Category(org.gitlab4j.api.IntegrationTest.class) public class TestHealthCheckApi { // The following needs to be set to your test repository diff --git a/src/test/java/org/gitlab4j/api/TestIgnoreCertificateErrors.java b/src/test/java/org/gitlab4j/api/TestIgnoreCertificateErrors.java index 828f816c..61f3dd88 100644 --- a/src/test/java/org/gitlab4j/api/TestIgnoreCertificateErrors.java +++ b/src/test/java/org/gitlab4j/api/TestIgnoreCertificateErrors.java @@ -10,6 +10,7 @@ import org.gitlab4j.api.models.Version; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -20,6 +21,7 @@ import org.junit.Test; * If any of the above are NULL, all tests in this class will be skipped. * */ +@Category(org.gitlab4j.api.IntegrationTest.class) public class TestIgnoreCertificateErrors { // The following needs to be set to your test repository diff --git a/src/test/java/org/gitlab4j/api/TestIssuesApi.java b/src/test/java/org/gitlab4j/api/TestIssuesApi.java index f30935a9..c7c57a33 100644 --- a/src/test/java/org/gitlab4j/api/TestIssuesApi.java +++ b/src/test/java/org/gitlab4j/api/TestIssuesApi.java @@ -27,7 +27,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.Arrays; import java.util.Date; @@ -37,7 +37,6 @@ import java.util.Random; import javax.ws.rs.core.Response; import org.gitlab4j.api.Constants.IssueState; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Duration; import org.gitlab4j.api.models.Issue; import org.gitlab4j.api.models.IssueFilter; @@ -47,6 +46,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties @@ -58,20 +58,8 @@ import org.junit.Test; * * If any of the above are NULL, all tests in this class will be skipped. */ -public class TestIssuesApi { - - // The following needs to be set to your test repository - private static final String TEST_NAMESPACE; - private static final String TEST_PROJECT_NAME; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestIssuesApi extends AbstractIntegrationTest { private static GitLabApi gitLabApi; private static Project testProject; @@ -87,37 +75,16 @@ public class TestIssuesApi { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - - try { - testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - } catch (GitLabApiException gle) { - } - - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); deleteAllTestIssues(); } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @AfterClass diff --git a/src/test/java/org/gitlab4j/api/TestJobApi.java b/src/test/java/org/gitlab4j/api/TestJobApi.java index dd7eb356..68e1339e 100644 --- a/src/test/java/org/gitlab4j/api/TestJobApi.java +++ b/src/test/java/org/gitlab4j/api/TestJobApi.java @@ -24,7 +24,7 @@ package org.gitlab4j.api; import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; @@ -34,6 +34,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties @@ -45,22 +46,11 @@ import org.junit.Test; *

* If any of the above are NULL, all tests in this class will be skipped. */ -public class TestJobApi { +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestJobApi extends AbstractIntegrationTest { - // The following needs to be set to your test repository - private static final String TEST_NAMESPACE; - private static final String TEST_PROJECT_NAME; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; private static GitLabApi gitLabApi; - private static Integer testProjectId; - - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } + private static Project testProject; public TestJobApi() { super(); @@ -68,35 +58,9 @@ public class TestJobApi { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } - - if (gitLabApi != null) { - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - testProjectId = project.getId(); - } catch (Exception e) { - System.err.print(e.getMessage()); - gitLabApi = null; - } - } + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); } @AfterClass @@ -105,12 +69,12 @@ public class TestJobApi { @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(testProject); } @Test public void testGetJobs() throws GitLabApiException { - List jobs = gitLabApi.getJobApi().getJobs(testProjectId.intValue()); + List jobs = gitLabApi.getJobApi().getJobs(testProject); assertNotNull(jobs); } } diff --git a/src/test/java/org/gitlab4j/api/TestNamespaceApi.java b/src/test/java/org/gitlab4j/api/TestNamespaceApi.java index fdca5ee9..946c0c09 100644 --- a/src/test/java/org/gitlab4j/api/TestNamespaceApi.java +++ b/src/test/java/org/gitlab4j/api/TestNamespaceApi.java @@ -3,15 +3,15 @@ package org.gitlab4j.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Namespace; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -23,18 +23,8 @@ import org.junit.Test; * If any of the above are NULL, all tests in this class will be skipped. * */ -public class TestNamespaceApi { - - // The following needs to be set to your test repository - - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestNamespaceApi extends AbstractIntegrationTest { private static GitLabApi gitLabApi; @@ -44,30 +34,13 @@ public class TestNamespaceApi { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestNotesApi.java b/src/test/java/org/gitlab4j/api/TestNotesApi.java index e8a62209..7c538e47 100644 --- a/src/test/java/org/gitlab4j/api/TestNotesApi.java +++ b/src/test/java/org/gitlab4j/api/TestNotesApi.java @@ -1,7 +1,11 @@ package org.gitlab4j.api; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assume.assumeNotNull; + +import java.util.List; + import org.gitlab4j.api.Constants.SortOrder; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Issue; import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.Note; @@ -10,13 +14,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; -import java.util.List; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeTrue; - /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties * @@ -27,20 +27,9 @@ import static org.junit.Assume.assumeTrue; * * If any of the above are NULL, all tests in this class will be skipped. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestNotesApi { - - // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +public class TestNotesApi extends AbstractIntegrationTest { private static GitLabApi gitLabApi; @@ -50,34 +39,13 @@ public class TestNotesApi { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestNotificationSettingsApi.java b/src/test/java/org/gitlab4j/api/TestNotificationSettingsApi.java index 4cc44e9c..2984f30b 100644 --- a/src/test/java/org/gitlab4j/api/TestNotificationSettingsApi.java +++ b/src/test/java/org/gitlab4j/api/TestNotificationSettingsApi.java @@ -3,11 +3,11 @@ package org.gitlab4j.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeNotNull; import java.util.List; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Group; import org.gitlab4j.api.models.NotificationSettings; import org.gitlab4j.api.models.Project; @@ -15,6 +15,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -28,22 +29,12 @@ import org.junit.runners.MethodSorters; * * If any of the above are NULL, all tests in this class will be skipped. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestNotificationSettingsApi { +public class TestNotificationSettingsApi extends AbstractIntegrationTest { // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_GROUP; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_GROUP = TestUtils.getProperty("TEST_GROUP"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } + private static final String TEST_GROUP = TestUtils.getProperty("TEST_GROUP"); private static GitLabApi gitLabApi; @@ -53,34 +44,13 @@ public class TestNotificationSettingsApi { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test @@ -100,6 +70,7 @@ public class TestNotificationSettingsApi { @Test public void testGroupNotificationSettings() throws GitLabApiException { + assumeFalse(TEST_GROUP == null || TEST_GROUP.trim().isEmpty()); List groups = gitLabApi.getGroupApi().getGroups(TEST_GROUP); assertNotNull(groups); assertFalse(groups.isEmpty()); diff --git a/src/test/java/org/gitlab4j/api/TestPager.java b/src/test/java/org/gitlab4j/api/TestPager.java index 52efbf5f..2ad50a90 100644 --- a/src/test/java/org/gitlab4j/api/TestPager.java +++ b/src/test/java/org/gitlab4j/api/TestPager.java @@ -3,11 +3,10 @@ package org.gitlab4j.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Branch; import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.Member; @@ -16,6 +15,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -30,21 +30,9 @@ import org.junit.runners.MethodSorters; * * NOTE: &FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that the tests are in the correct order */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestPager { - - // The following needs to be set to your test repository - - private static final String TEST_NAMESPACE; - private static final String TEST_PROJECT_NAME; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +public class TestPager extends AbstractIntegrationTest { private static GitLabApi gitLabApi; @@ -54,34 +42,13 @@ public class TestPager { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestPipelineApi.java b/src/test/java/org/gitlab4j/api/TestPipelineApi.java index 21244596..8ef1ab02 100644 --- a/src/test/java/org/gitlab4j/api/TestPipelineApi.java +++ b/src/test/java/org/gitlab4j/api/TestPipelineApi.java @@ -4,31 +4,20 @@ import static java.util.stream.Collectors.toList; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.PipelineSchedule; import org.gitlab4j.api.models.Project; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; -public class TestPipelineApi { - // The following needs to be set to your test repository - private static final String TEST_NAMESPACE; - private static final String TEST_PROJECT_NAME; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestPipelineApi extends AbstractIntegrationTest { private static final String SCHEDULE_DESCRIPTION = "Test pipeline schedule - DELETE AFTER TEST"; @@ -64,33 +53,9 @@ public class TestPipelineApi { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - - try { - testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - } catch (GitLabApiException gle) { - } - - deleteTestSchedules(); - - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); } @AfterClass @@ -98,10 +63,9 @@ public class TestPipelineApi { deleteTestSchedules(); } - @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestProjectApi.java b/src/test/java/org/gitlab4j/api/TestProjectApi.java index 3a80cd8f..14910604 100644 --- a/src/test/java/org/gitlab4j/api/TestProjectApi.java +++ b/src/test/java/org/gitlab4j/api/TestProjectApi.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeNotNull; import static org.junit.Assume.assumeTrue; import java.util.Arrays; @@ -38,7 +39,6 @@ import java.util.stream.Stream; import javax.ws.rs.core.Response; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.AccessLevel; import org.gitlab4j.api.models.Group; import org.gitlab4j.api.models.Project; @@ -49,6 +49,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -64,23 +65,15 @@ import org.junit.runners.MethodSorters; * * NOTE: &FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that the tests are in the correct order */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestProjectApi { +public class TestProjectApi extends AbstractIntegrationTest { // The following needs to be set to your test repository - private static final String TEST_NAMESPACE; - private static final String TEST_PROJECT_NAME; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; private static final String TEST_GROUP; private static final String TEST_GROUP_PROJECT; private static final String TEST_XFER_NAMESPACE; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); TEST_GROUP = TestUtils.getProperty("TEST_GROUP"); TEST_GROUP_PROJECT = TestUtils.getProperty("TEST_GROUP_PROJECT"); TEST_XFER_NAMESPACE = TestUtils.getProperty("TEST_XFER_NAMESPACE"); @@ -100,24 +93,8 @@ public class TestProjectApi { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); deleteAllTestProjects(); } @@ -128,65 +105,67 @@ public class TestProjectApi { } private static void deleteAllTestProjects() { - if (gitLabApi != null) { - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_1); - gitLabApi.getProjectApi().deleteProject(project); - } catch (GitLabApiException ignore) {} + if (gitLabApi == null) { + return; + } - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_2); - gitLabApi.getProjectApi().deleteProject(project); - } catch (GitLabApiException ignore) {} + try { + Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_1); + gitLabApi.getProjectApi().deleteProject(project); + } catch (GitLabApiException ignore) {} - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_UPDATE); - gitLabApi.getProjectApi().deleteProject(project); - } catch (GitLabApiException ignore) {} - - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_XFER_PROJECT_NAME); - gitLabApi.getProjectApi().deleteProject(project); - } catch (GitLabApiException ignore) {} + try { + Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_2); + gitLabApi.getProjectApi().deleteProject(project); + } catch (GitLabApiException ignore) {} + + try { + Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_UPDATE); + gitLabApi.getProjectApi().deleteProject(project); + } catch (GitLabApiException ignore) {} - if (TEST_GROUP != null && TEST_PROJECT_NAME != null) { - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - List groups = gitLabApi.getGroupApi().getGroups(TEST_GROUP); - gitLabApi.getProjectApi().unshareProject(project.getId(), groups.get(0).getId()); + try { + Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_XFER_PROJECT_NAME); + gitLabApi.getProjectApi().deleteProject(project); + } catch (GitLabApiException ignore) {} - List variables = gitLabApi.getProjectApi().getVariables(project); - if (variables != null) { + if (TEST_GROUP != null && TEST_PROJECT_NAME != null) { + try { + Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); + List groups = gitLabApi.getGroupApi().getGroups(TEST_GROUP); + gitLabApi.getProjectApi().unshareProject(project.getId(), groups.get(0).getId()); - for (Variable variable : variables) { - if (variable.getKey().startsWith(TEST_VARIABLE_KEY_PREFIX)) { - gitLabApi.getProjectApi().deleteVariable(project, variable.getKey()); - } + List variables = gitLabApi.getProjectApi().getVariables(project); + if (variables != null) { + + for (Variable variable : variables) { + if (variable.getKey().startsWith(TEST_VARIABLE_KEY_PREFIX)) { + gitLabApi.getProjectApi().deleteVariable(project, variable.getKey()); } } - } catch (GitLabApiException ignore) { } + } catch (GitLabApiException ignore) { } + } - if (TEST_GROUP != null && TEST_GROUP_PROJECT != null) { - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_GROUP_PROJECT); - gitLabApi.getProjectApi().deleteProject(project); - } catch (GitLabApiException ignore) {} - } + if (TEST_GROUP != null && TEST_GROUP_PROJECT != null) { + try { + Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_GROUP_PROJECT); + gitLabApi.getProjectApi().deleteProject(project); + } catch (GitLabApiException ignore) {} + } - if (TEST_XFER_NAMESPACE != null) { - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_XFER_NAMESPACE, TEST_XFER_PROJECT_NAME); - gitLabApi.getProjectApi().deleteProject(project); - } catch (GitLabApiException ignore) {} - } + if (TEST_XFER_NAMESPACE != null) { + try { + Project project = gitLabApi.getProjectApi().getProject(TEST_XFER_NAMESPACE, TEST_XFER_PROJECT_NAME); + gitLabApi.getProjectApi().deleteProject(project); + } catch (GitLabApiException ignore) {} } } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestProjectApiSnippets.java b/src/test/java/org/gitlab4j/api/TestProjectApiSnippets.java index e7ba5ac0..11fa6cd9 100644 --- a/src/test/java/org/gitlab4j/api/TestProjectApiSnippets.java +++ b/src/test/java/org/gitlab4j/api/TestProjectApiSnippets.java @@ -26,11 +26,10 @@ package org.gitlab4j.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Snippet; import org.gitlab4j.api.models.Visibility; @@ -38,6 +37,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties @@ -49,24 +49,12 @@ import org.junit.Test; * * If any of the above are NULL, all tests in this class will be skipped. */ -public class TestProjectApiSnippets { - - // The following needs to be set to your test repository - private static final String TEST_NAMESPACE; - private static final String TEST_PROJECT_NAME; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestProjectApiSnippets extends AbstractIntegrationTest { private static final String TEST_SNIPPET_TITLE_PREFIX = "Test Snippet: "; private static GitLabApi gitLabApi; - private static Integer testProjectId; + private static Project testProject; public TestProjectApiSnippets() { super(); @@ -75,34 +63,9 @@ public class TestProjectApiSnippets { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } - - if (gitLabApi != null) { - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - testProjectId = project.getId(); - } catch (Exception e) { - System.err.print(e.getMessage()); - gitLabApi = null; - } - } + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); deleteAllTestSnippets(); } @@ -115,11 +78,11 @@ public class TestProjectApiSnippets { private static void deleteAllTestSnippets() { if (gitLabApi != null) { try { - List snippets = gitLabApi.getProjectApi().getSnippets(testProjectId); + List snippets = gitLabApi.getProjectApi().getSnippets(testProject); if (snippets != null) { for (Snippet snippet : snippets) { if (snippet.getTitle().startsWith(TEST_SNIPPET_TITLE_PREFIX)) { - gitLabApi.getProjectApi().deleteSnippet(testProjectId, snippet.getId()); + gitLabApi.getProjectApi().deleteSnippet(testProject, snippet.getId()); } } } @@ -130,12 +93,12 @@ public class TestProjectApiSnippets { @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } private Snippet createSnippet(String title, String filename, String description, String code, Visibility visibility) throws GitLabApiException { - return (gitLabApi.getProjectApi().createSnippet(testProjectId, title, filename, description, code, visibility)); + return (gitLabApi.getProjectApi().createSnippet(testProject, title, filename, description, code, visibility)); } @Test @@ -155,6 +118,8 @@ public class TestProjectApiSnippets { @Test public void testUpdate() throws GitLabApiException { + assumeNotNull(testProject); + String title = TEST_SNIPPET_TITLE_PREFIX + "Test createSnippet()"; String filename = "test-update-snippet.js"; String description = null; @@ -164,7 +129,7 @@ public class TestProjectApiSnippets { assertNotNull(snippet); title = TEST_SNIPPET_TITLE_PREFIX + "Test updateSnippet()"; - snippet = gitLabApi.getProjectApi().updateSnippet(testProjectId, snippet.getId(), title, null, null, null, null); + snippet = gitLabApi.getProjectApi().updateSnippet(testProject, snippet.getId(), title, null, null, null, null); assertEquals(title, snippet.getTitle()); assertEquals(filename, snippet.getFileName()); } @@ -172,6 +137,8 @@ public class TestProjectApiSnippets { @Test public void testListSnippets() throws GitLabApiException { + assumeNotNull(testProject); + String title = TEST_SNIPPET_TITLE_PREFIX + "Test listSnippets()"; String filename = "test-list-snippets.js"; String description = null; @@ -181,7 +148,7 @@ public class TestProjectApiSnippets { assertNotNull(newSnippet); int snippetId = newSnippet.getId(); - List snippets = gitLabApi.getProjectApi().getSnippets(testProjectId); + List snippets = gitLabApi.getProjectApi().getSnippets(testProject); assertNotNull(snippets); for (Snippet snippet : snippets) { if (snippet.getId() == snippetId) { @@ -195,6 +162,8 @@ public class TestProjectApiSnippets { @Test public void testDeleteSnippet() throws GitLabApiException { + assumeNotNull(testProject); + String title = TEST_SNIPPET_TITLE_PREFIX + "Test listSnippets()"; String filename = "test-delete-snippet.js"; String description = null; @@ -204,8 +173,8 @@ public class TestProjectApiSnippets { assertNotNull(createdSnippet); int snippetId = createdSnippet.getId(); - gitLabApi.getProjectApi().deleteSnippet(testProjectId, snippetId); - List snippets = gitLabApi.getProjectApi().getSnippets(testProjectId); + gitLabApi.getProjectApi().deleteSnippet(testProject, snippetId); + List snippets = gitLabApi.getProjectApi().getSnippets(testProject); if (snippets != null) { for (Snippet snippet : snippets) { if (snippet.getId() == snippetId) { @@ -218,6 +187,8 @@ public class TestProjectApiSnippets { @Test public void testSnippetContent() throws GitLabApiException { + assumeNotNull(testProject); + String title = TEST_SNIPPET_TITLE_PREFIX + "Test getRawSnippetContent()"; String filename = "test-raw-snippet.js"; String description = null; @@ -226,7 +197,7 @@ public class TestProjectApiSnippets { Snippet createdSnippet = createSnippet(title, filename, description, code, visibility); assertNotNull(createdSnippet); - String rawContent = gitLabApi.getProjectApi().getRawSnippetContent(testProjectId, createdSnippet.getId()); + String rawContent = gitLabApi.getProjectApi().getRawSnippetContent(testProject.getId(), createdSnippet.getId()); assertEquals(code, rawContent); } } diff --git a/src/test/java/org/gitlab4j/api/TestProtectedBranchesApi.java b/src/test/java/org/gitlab4j/api/TestProtectedBranchesApi.java index 963f46e3..f376f613 100644 --- a/src/test/java/org/gitlab4j/api/TestProtectedBranchesApi.java +++ b/src/test/java/org/gitlab4j/api/TestProtectedBranchesApi.java @@ -3,7 +3,7 @@ package org.gitlab4j.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; @@ -15,6 +15,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -29,20 +30,9 @@ import org.junit.runners.MethodSorters; * * NOTE: &FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that testCreate() is executed first. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestProtectedBranchesApi { - // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +public class TestProtectedBranchesApi extends AbstractIntegrationTest { private static GitLabApi gitLabApi; @@ -52,29 +42,8 @@ public class TestProtectedBranchesApi { @BeforeClass public static void setup() { - - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(GitLabApi.ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); } @AfterClass @@ -102,7 +71,7 @@ public class TestProtectedBranchesApi { @Before public void beforeMethod() throws GitLabApiException { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); Branch protectedBranch; try { diff --git a/src/test/java/org/gitlab4j/api/TestRepositoryApi.java b/src/test/java/org/gitlab4j/api/TestRepositoryApi.java index 965e7759..bc9c4fff 100644 --- a/src/test/java/org/gitlab4j/api/TestRepositoryApi.java +++ b/src/test/java/org/gitlab4j/api/TestRepositoryApi.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.io.File; import java.io.IOException; @@ -24,6 +24,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -38,21 +39,9 @@ import org.junit.runners.MethodSorters; * * NOTE: &FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that testCreate() is executed first. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestRepositoryApi { - - // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +public class TestRepositoryApi extends AbstractIntegrationTest { private static final String TEST_BRANCH_NAME = "feature/test_branch"; private static final String TEST_BRANCH1 = "feature/test_branch1"; @@ -67,29 +56,10 @@ public class TestRepositoryApi { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(TEST_HOST_URL, TEST_PRIVATE_TOKEN); - teardown(); - } else { - System.err.print(problems); - } + teardown(); } @AfterClass @@ -123,7 +93,7 @@ public class TestRepositoryApi { @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestRepositoryFileApi.java b/src/test/java/org/gitlab4j/api/TestRepositoryFileApi.java index cbd9f4ae..21cd9e06 100644 --- a/src/test/java/org/gitlab4j/api/TestRepositoryFileApi.java +++ b/src/test/java/org/gitlab4j/api/TestRepositoryFileApi.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.io.File; import java.io.IOException; @@ -22,6 +22,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -36,20 +37,9 @@ import org.junit.runners.MethodSorters; * * NOTE: &FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that testCreate() is executed first. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestRepositoryFileApi { - - // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +public class TestRepositoryFileApi extends AbstractIntegrationTest { private static final String TEST_CONTENT = "This is some content to test file content 1234567890 !@#$%^&()."; private static final String TEST_ADDITIONAL_CONTENT = "\n\nThis is an additional line"; @@ -65,29 +55,10 @@ public class TestRepositoryFileApi { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(TEST_HOST_URL, TEST_PRIVATE_TOKEN); - teardown(); - } else { - System.err.print(problems); - } + teardown(); } @AfterClass @@ -114,7 +85,7 @@ public class TestRepositoryFileApi { @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestRequestResponseLogging.java b/src/test/java/org/gitlab4j/api/TestRequestResponseLogging.java index 8e56b6f0..c29e6f2b 100644 --- a/src/test/java/org/gitlab4j/api/TestRequestResponseLogging.java +++ b/src/test/java/org/gitlab4j/api/TestRequestResponseLogging.java @@ -44,6 +44,7 @@ import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.contrib.java.lang.system.SystemErrRule; +import org.junit.experimental.categories.Category; import org.junit.rules.TemporaryFolder; /** @@ -54,6 +55,7 @@ import org.junit.rules.TemporaryFolder; *

* If any of the above are NULL, all tests in this class will be skipped. */ +@Category(org.gitlab4j.api.IntegrationTest.class) public class TestRequestResponseLogging { @ClassRule diff --git a/src/test/java/org/gitlab4j/api/TestRunnersApi.java b/src/test/java/org/gitlab4j/api/TestRunnersApi.java index 42daf14f..81ee693f 100644 --- a/src/test/java/org/gitlab4j/api/TestRunnersApi.java +++ b/src/test/java/org/gitlab4j/api/TestRunnersApi.java @@ -30,7 +30,6 @@ import static org.junit.Assume.assumeTrue; import java.util.Arrays; import java.util.List; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Runner; import org.gitlab4j.api.models.RunnerDetail; @@ -38,6 +37,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -51,19 +51,9 @@ import org.junit.runners.MethodSorters; *

* NOTE: &FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that the tests are in the correct order */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.JVM) -public class TestRunnersApi { - - // The following needs to be set to your test repository - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +public class TestRunnersApi extends AbstractIntegrationTest { private static GitLabApi gitLabApi; @@ -74,24 +64,8 @@ public class TestRunnersApi { @BeforeClass public static void setup() throws GitLabApiException { - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); List allRunners = gitLabApi.getRunnersApi().getAllRunners(); diff --git a/src/test/java/org/gitlab4j/api/TestServicesApi.java b/src/test/java/org/gitlab4j/api/TestServicesApi.java index 050ef131..55788ebb 100644 --- a/src/test/java/org/gitlab4j/api/TestServicesApi.java +++ b/src/test/java/org/gitlab4j/api/TestServicesApi.java @@ -4,9 +4,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Project; import org.gitlab4j.api.services.ExternalWikiService; import org.gitlab4j.api.services.JiraService; @@ -15,6 +14,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -27,20 +27,9 @@ import org.junit.runners.MethodSorters; * * If any of the above are NULL, all tests in this class will be skipped. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestServicesApi { - - // The following needs to be set to your test repository - private static final String TEST_PROJECT_NAME; - private static final String TEST_NAMESPACE; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +public class TestServicesApi extends AbstractIntegrationTest { private static GitLabApi gitLabApi; private static Project testProject; @@ -52,42 +41,19 @@ public class TestServicesApi { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) { - problems += "TEST_PROJECT_NAME cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); - try { - testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - try { gitLabApi.getServicesApi().deleteJiraService(testProject); } catch (Exception ignore) {} - try { gitLabApi.getServicesApi().deleteSlackService(testProject); } catch (Exception ignore) {} - } catch (GitLabApiException gle) { - System.err.print(gle.getMessage()); - } - - } else { - System.err.print(problems); + if (testProject != null) { + try { gitLabApi.getServicesApi().deleteJiraService(testProject); } catch (Exception ignore) {} + try { gitLabApi.getServicesApi().deleteSlackService(testProject); } catch (Exception ignore) {} } } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null && testProject != null); + assumeNotNull(testProject); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestSnippetsApi.java b/src/test/java/org/gitlab4j/api/TestSnippetsApi.java index 9298c20d..e91e14b4 100644 --- a/src/test/java/org/gitlab4j/api/TestSnippetsApi.java +++ b/src/test/java/org/gitlab4j/api/TestSnippetsApi.java @@ -4,24 +4,19 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Snippet; import org.gitlab4j.api.models.Visibility; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; -public class TestSnippetsApi { - - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; - - static { - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestSnippetsApi extends AbstractIntegrationTest { private static GitLabApi gitLabApi; private static final String TEST_SNIPPET_TITLE_1 = "test-snippet-title-1"; @@ -32,22 +27,13 @@ public class TestSnippetsApi { @BeforeClass public static void setup() { + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); + } - String problems = ""; - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } + @Before + public void beforeMethod() { + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestSystemHooksApi.java b/src/test/java/org/gitlab4j/api/TestSystemHooksApi.java index acf0a457..f257c2c6 100644 --- a/src/test/java/org/gitlab4j/api/TestSystemHooksApi.java +++ b/src/test/java/org/gitlab4j/api/TestSystemHooksApi.java @@ -4,16 +4,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNotNull; import java.util.List; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.SystemHook; import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; /** @@ -24,19 +24,13 @@ import org.junit.runners.MethodSorters; * * If any of the above are NULL, all tests in this class will be skipped. */ +@Category(org.gitlab4j.api.IntegrationTest.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestSystemHooksApi { +public class TestSystemHooksApi extends AbstractIntegrationTest { // The following needs to be set to your test repository - private static final String TEST_HOST_URL; - private static final String TEST_HOOK_URL; - private static final String TEST_PRIVATE_TOKEN; - static { - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_HOOK_URL = "http://hook.example.com/hook/callback"; - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } - + private static final String TEST_HOOK_URL = "http://hook.example.com/hook/callback"; + private static final String TEST_SECRET_TOKEN = "123456abcd"; private static GitLabApi gitLabApi; @@ -48,29 +42,17 @@ public class TestSystemHooksApi { @BeforeClass public static void setup() { - String problems = ""; if (TEST_HOOK_URL == null || TEST_HOOK_URL.trim().isEmpty()) { - problems += "TEST_HOOK_URL cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); + System.err.println("TEST_HOOK_URL cannot be empty"); } else { - System.err.print(problems); + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); } } @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestTagsApi.java b/src/test/java/org/gitlab4j/api/TestTagsApi.java index 8ba15828..f2b33596 100644 --- a/src/test/java/org/gitlab4j/api/TestTagsApi.java +++ b/src/test/java/org/gitlab4j/api/TestTagsApi.java @@ -9,27 +9,34 @@ import static org.junit.Assume.assumeTrue; import java.util.List; import java.util.Optional; +import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Release; import org.gitlab4j.api.models.Tag; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; -public class TestTagsApi extends AbstractBaseTest { +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestTagsApi extends AbstractIntegrationTest { private static final String TEST_TAG_NAME_1 = "test-tag-1"; private static final String TEST_TAG_NAME_0 = "test-tag-0"; + private static GitLabApi gitLabApi; + private static Project testProject; + public TestTagsApi() { super(); } @BeforeClass - public static void setup() { + public static void testSetup() { - // Must setup the connection to the GitLab test server - AbstractBaseTest.testSetup(); + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); if (testProject != null) { try { diff --git a/src/test/java/org/gitlab4j/api/TestUserApi.java b/src/test/java/org/gitlab4j/api/TestUserApi.java index 04785030..0228e0b3 100644 --- a/src/test/java/org/gitlab4j/api/TestUserApi.java +++ b/src/test/java/org/gitlab4j/api/TestUserApi.java @@ -16,7 +16,6 @@ import java.util.Optional; import javax.ws.rs.core.Response; -import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.ImpersonationToken; import org.gitlab4j.api.models.ImpersonationToken.Scope; import org.gitlab4j.api.models.SshKey; @@ -26,6 +25,7 @@ import org.gitlab4j.api.utils.ISO8601; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in test-gitlab4j.properties @@ -45,18 +45,15 @@ import org.junit.Test; * If this is null the SSH key tests will be skipped. * */ -public class TestUserApi { +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestUserApi extends AbstractIntegrationTest { // The following needs to be set to your test repository - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; private static final String TEST_USERNAME; private static final String TEST_BLOCK_USERNAME; private static final String TEST_SUDO_AS_USERNAME; private static final String TEST_SSH_KEY; static { - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME"); TEST_BLOCK_USERNAME = TestUtils.getProperty("TEST_BLOCK_USERNAME"); TEST_SUDO_AS_USERNAME = TestUtils.getProperty("TEST_SUDO_AS_USERNAME"); @@ -80,10 +77,6 @@ public class TestUserApi { public static void setup() { String problems = ""; - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; } @@ -93,28 +86,33 @@ public class TestUserApi { } if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - - if (TEST_BLOCK_USERNAME != null) { - try { - blockUser = gitLabApi.getUserApi().getUser(TEST_BLOCK_USERNAME); - if (blockUser != null) { - gitLabApi.getUserApi().unblockUser(blockUser.getId()); - } - } catch (Exception ignore) {} - } - if (TEST_SSH_KEY != null) { - try { - List sshKeys = gitLabApi.getUserApi().getSshKeys(); - if (sshKeys != null) { - for (SshKey key : sshKeys) { - if (TEST_SSH_KEY.equals(key.getKey())) { - gitLabApi.getUserApi().deleteSshKey(key.getId()); + // Must setup the connection to the GitLab test server + gitLabApi = baseTestSetup(); + + if (gitLabApi != null) { + + if (TEST_BLOCK_USERNAME != null) { + try { + blockUser = gitLabApi.getUserApi().getUser(TEST_BLOCK_USERNAME); + if (blockUser != null) { + gitLabApi.getUserApi().unblockUser(blockUser.getId()); + } + } catch (Exception ignore) {} + } + + if (TEST_SSH_KEY != null) { + try { + List sshKeys = gitLabApi.getUserApi().getSshKeys(); + if (sshKeys != null) { + for (SshKey key : sshKeys) { + if (TEST_SSH_KEY.equals(key.getKey())) { + gitLabApi.getUserApi().deleteSshKey(key.getId()); + } } } - } - } catch (Exception ignore) {} + } catch (Exception ignore) {} + } } } else { @@ -124,7 +122,7 @@ public class TestUserApi { @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(gitLabApi); } @Test @@ -175,7 +173,7 @@ public class TestUserApi { optional = gitLabApi.getUserApi().getOptionalUser("this-username-does-not-exist"); assertNotNull(optional); assertFalse(optional.isPresent()); - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), GitLabApi.getOptionalException(optional).getHttpStatus()); + assertNull(GitLabApi.getOptionalException(optional)); } @Test diff --git a/src/test/java/org/gitlab4j/api/TestUtils.java b/src/test/java/org/gitlab4j/api/TestUtils.java index 0a05973c..a76bf76d 100644 --- a/src/test/java/org/gitlab4j/api/TestUtils.java +++ b/src/test/java/org/gitlab4j/api/TestUtils.java @@ -63,6 +63,20 @@ public class TestUtils { return (testProperties.getProperty(key)); } + /** + * Set a named property, this will amend and overwrite properties read from the test-gitlab4j.properties file. + * + * @param key the key of the property to get + * @return the named property from the test-gitlab4j.properties file + */ + public static final void setProperty(String key, String value) { + if (value == null) { + testProperties.remove(key); + } else { + testProperties.setProperty(key, value); + } + } + /** * Get a random integer between 1 and the specified value (inclusive). * diff --git a/src/test/java/org/gitlab4j/api/TestWikisApi.java b/src/test/java/org/gitlab4j/api/TestWikisApi.java index b9146e6c..e505591a 100644 --- a/src/test/java/org/gitlab4j/api/TestWikisApi.java +++ b/src/test/java/org/gitlab4j/api/TestWikisApi.java @@ -23,7 +23,14 @@ package org.gitlab4j.api; -import org.gitlab4j.api.GitLabApi.ApiVersion; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeNotNull; + +import java.io.File; +import java.util.List; + import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.WikiAttachment; import org.gitlab4j.api.models.WikiPage; @@ -31,12 +38,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; - -import java.io.File; -import java.util.List; - -import static org.junit.Assert.*; -import static org.junit.Assume.assumeTrue; +import org.junit.experimental.categories.Category; /** * In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties @@ -48,25 +50,14 @@ import static org.junit.Assume.assumeTrue; *

* If any of the above are NULL, all tests in this class will be skipped. */ -public class TestWikisApi { +@Category(org.gitlab4j.api.IntegrationTest.class) +public class TestWikisApi extends AbstractIntegrationTest { - // The following needs to be set to your test repository - private static final String TEST_NAMESPACE; - private static final String TEST_PROJECT_NAME; - private static final String TEST_HOST_URL; - private static final String TEST_PRIVATE_TOKEN; private static final String TEST_WIKI_TITLE_PREFIX = "Test Wiki: "; private static GitLabApi gitLabApi; - private static Integer testProjectId; + private static Project testProject; private static String testContent; - static { - TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); - TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); - TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); - TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); - } - public TestWikisApi() { super(); } @@ -74,37 +65,11 @@ public class TestWikisApi { @BeforeClass public static void setup() { - String problems = ""; - if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { - problems += "TEST_NAMESPACE cannot be empty\n"; - } - - if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { - problems += "TEST_HOST_URL cannot be empty\n"; - } - - if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { - problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; - } - - if (problems.isEmpty()) { - gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); - } else { - System.err.print(problems); - } - - if (gitLabApi != null) { - try { - Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); - testProjectId = project.getId(); - } catch (Exception e) { - System.err.print(e.getMessage()); - gitLabApi = null; - } - } + // Must setup the connection to the GitLab test server and get the test Project instance + gitLabApi = baseTestSetup(); + testProject = getTestProject(); testContent = "This is a test content and must be deleted after testing."; - deleteAllTestWikiPages(); } @@ -114,12 +79,12 @@ public class TestWikisApi { } private static void deleteAllTestWikiPages() { - if (gitLabApi != null) { + if (testProject != null) { try { - List wikiPages = gitLabApi.getWikisApi().getPages(testProjectId); + List wikiPages = gitLabApi.getWikisApi().getPages(testProject); wikiPages.stream().filter(wp -> wp.getTitle().startsWith(TEST_WIKI_TITLE_PREFIX)).map(WikiPage::getSlug).forEach(slug -> { try { - gitLabApi.getWikisApi().deletePage(testProjectId, slug); + gitLabApi.getWikisApi().deletePage(testProject, slug); } catch (GitLabApiException ignored) { } }); @@ -131,11 +96,11 @@ public class TestWikisApi { @Before public void beforeMethod() { - assumeTrue(gitLabApi != null); + assumeNotNull(testProject); } private WikiPage createWikiPage(String title, String content) throws GitLabApiException { - return (gitLabApi.getWikisApi().createPage(testProjectId, title, content)); + return (gitLabApi.getWikisApi().createPage(testProject.getId(), title, content)); } @Test @@ -154,7 +119,7 @@ public class TestWikisApi { assertNotNull(wikiPage); title = TEST_WIKI_TITLE_PREFIX + "Test updateWikiPage()"; - wikiPage = gitLabApi.getWikisApi().updatePage(testProjectId, wikiPage.getSlug(), title, "some content"); + wikiPage = gitLabApi.getWikisApi().updatePage(testProject, wikiPage.getSlug(), title, "some content"); assertEquals(title, wikiPage.getTitle()); assertEquals("some content", wikiPage.getContent()); } @@ -166,7 +131,7 @@ public class TestWikisApi { assertNotNull(newWikiPage); String wikiPageSlug = newWikiPage.getSlug(); - List wikiPages = gitLabApi.getWikisApi().getPages(testProjectId); + List wikiPages = gitLabApi.getWikisApi().getPages(testProject); assertNotNull(wikiPages); wikiPages.stream().filter(wp -> wp.getSlug().equals(wikiPageSlug)).forEach(wp -> { @@ -182,8 +147,8 @@ public class TestWikisApi { assertNotNull(createdWikiPage); String wikiPageSlug = createdWikiPage.getSlug(); - gitLabApi.getWikisApi().deletePage(testProjectId, wikiPageSlug); - List wikiPages = gitLabApi.getWikisApi().getPages(testProjectId); + gitLabApi.getWikisApi().deletePage(testProject, wikiPageSlug); + List wikiPages = gitLabApi.getWikisApi().getPages(testProject); if (wikiPages.stream().anyMatch(wp -> wp.getSlug().equals(wikiPageSlug))) { fail("WikiPage was not deleted."); } @@ -196,7 +161,7 @@ public class TestWikisApi { assertNotNull(wikiPage); File attachFile = new File("README.md"); - WikiAttachment attachment = gitLabApi.getWikisApi().uploadAttachment(testProjectId, attachFile); + WikiAttachment attachment = gitLabApi.getWikisApi().uploadAttachment(testProject, attachFile); assertNotNull(attachment); assertEquals("README.md", attachment.getFileName()); } @@ -208,7 +173,7 @@ public class TestWikisApi { assertNotNull(wikiPage); File attachFile = new File("README.md"); - WikiAttachment attachment = gitLabApi.getWikisApi().uploadAttachment(testProjectId, attachFile, "master"); + WikiAttachment attachment = gitLabApi.getWikisApi().uploadAttachment(testProject, attachFile, "master"); assertNotNull(attachment); assertEquals("README.md", attachment.getFileName()); assertEquals("master", attachment.getBranch()); -- GitLab