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 395e4777440bcd15ffe9c9ed467c76e958149bee..fa1f4416cae660b583768a2ce7995af30f9abae5 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 3d1c7fd4f1c5589072ea9794ae05ffe87f77139b..10879138d6020551fe1a835f3eab10133a23150f 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 a12bd0d542706aa4bfd907b51779ba3c06a77bdc..78c632597e9974a28c97ccc9b163603de66cea47 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 da1a125211ca886d9a0a945c5683f887b2a04d90..addc607af8f459a0e016eb8729076283d12c891a 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 69d2d93a00be6603702cf628a23b6a209bfd8a7a..b570979f9c17d4f110b6489447dc98884ab198fe 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 5d3e18078f32b988d354b64bdb863d82415285cb..452de24bfbeea4217b9f0ee0f76c01f024e4dc35 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 9763352b68d049e884e6b00533760cd89bd1364f..f8695596336721804fbb85fc9045bc51afd5e057 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 2d3b313e245a539ff46ee18697b8ef43128c7b48..1ce08ac43ab22a5c8bb13d51d266badeaba5dac1 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 828f816c7d1ddd5fc3ec73d5ad7f2d6256172664..61f3dd889e1c543c71f05f4642c12256077c7acf 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 f30935a99c7bc60e5282308cc0de115fd1c4eea9..c7c57a33bc2c0d61fed1562147f53aa165f57865 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 dd7eb356e3256e92627cb03249c816cc2d2fbf15..68e1339e7f15005ce085cc239142d9daf61fc98f 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 fdca5ee94a8077805492c003a8db7419533f5b76..946c0c09145be45c32245d2797af1f664e917b70 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 e8a62209abd3e97a941eae7fde7ae7c539c556e1..7c538e4753de2ea0b925d36fa74b1a8ad35daccb 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 4cc44e9cddc165867511279ac09a912c769f5d1a..2984f30b8bd4be2ed51a2e89fc38c2008881701f 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 52efbf5feefecf2e07fe713c2ae8cfb907e3bd98..2ad50a90ad492b04c47638868e627d8b602ea6ac 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 21244596efa5c79ac3823f64f3b73b833988bda1..8ef1ab020d27328f4bdb4e202ce00cd09421f471 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 3a80cd8f0f08b2b6e48a6339e3aa4bf38d22b0bd..14910604c0d39072af8d464c9d100a2a0ce83b60 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 e7ba5ac06fd4cc5ca1bd9454d000dad015c9612d..11fa6cd9dcb1779640ac017a50f01c0b8baeee72 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 963f46e3329271d5f8748a9969320f199f45e8f1..f376f6137209760cebd4c9a4074c85dedfe11223 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 965e7759043f89221fb1869957b41b37f54a33d0..bc9c4fffce10d5fba1f37939ad0208a420404ff9 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 cbd9f4aedebee43b409fbbda46e17f6e225392b9..21cd9e06b37bf2570f3b00fb5bc7181ee4035aaf 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 8e56b6f0016f4c507a9ec569fe2c9e62b49e7541..c29e6f2b1039861fec0eb534ace5c53d8e1a101a 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 42daf14f30d05b7cef9a901c7cae4f0ad19e91fa..81ee693f32f36897254e9f0e61d74d6b3d0901e3 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 050ef1318a1435ed2871bde3825e454669d18e00..55788ebb36bd742f360b44cc260cde6023347d81 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 9298c20d017a4022061103e02a5d2bdad30e45d5..e91e14b420492edcd52a1d82eaa556d50cf6a610 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 acf0a457a6ababde1d5506a9505926b5074c10a3..f257c2c6327f20a737c6091831196bd8cca99738 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 8ba158289f863144466e944355955e50a4e25109..f2b335963533919931aac333124cf6f6974a085c 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 04785030219fa758951ea5bafc5a15422dcdb357..0228e0b31e503aabfb96356a7df75563eb931f6e 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 0a05973c1d489e899dd02d616f4260204d254eba..a76bf76dbef8a20aa3bec595415c0bfeeef5f385 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 b9146e6c32bd13e4d5ac0a09193bc41ed6eb5f2e..e505591a608a29e47b2385b699f8f4566470d3f2 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());