Commit 798c1ef2 authored by Greg Messner's avatar Greg Messner
Browse files

Mods to support split unit and integration tests (#311).

parent 053813a4
......@@ -38,17 +38,22 @@
</developers>
<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.level>8</java.level>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<jersey.version>2.28</jersey.version>
<jackson.version>2.9.8</jackson.version>
<javaServlet.version>4.0.1</javaServlet.version>
<junit.version>4.12</junit.version>
<mockito.version>2.19.0</mockito.version>
<hamcrest.version>1.3</hamcrest.version>
<systemRules.version>1.18.0</systemRules.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<changelog-lib.version>1.59</changelog-lib.version>
</properties>
......@@ -62,6 +67,7 @@
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
......@@ -191,14 +197,35 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<version>3.0.0-M3</version>
<configuration>
<excludedGroups>org.gitlab4j.api.IntegrationTest</excludedGroups>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<groups>org.gitlab4j.api.IntegrationTest</groups>
<includes>
<include>**/IntegrationTestSuite.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
......@@ -206,7 +233,7 @@
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.8</maxJdkVersion>
<maxJdkVersion>1.8</maxJdkVersion>
<ignoreClasses>
<ignoreClass>module-info</ignoreClass>
</ignoreClasses>
......@@ -230,10 +257,31 @@
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.17</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<id>check</id>
</execution>
</executions>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java1${java.level}</artifactId>
</signature>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- The se.bjurr.gitchangelog:git-changelog-maven-plugin needs to be in -->
<!-- this section (pluginManagement) for it to work correctly. -->
<plugin>
<groupId>se.bjurr.gitchangelog</groupId>
<artifactId>git-changelog-maven-plugin</artifactId>
......@@ -252,7 +300,6 @@
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
......@@ -319,7 +366,24 @@
<version>${systemRules.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.junit-toolbox</groupId>
<artifactId>junit-toolbox</artifactId>
<version>2.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- Needed for animal-sniffer -->
<dependency>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java18</artifactId>
<version>1.0</version>
<type>signature</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
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<String, BaseTestResources> baseTestResourcesMap =
Collections.synchronizedMap(new WeakHashMap<String, BaseTestResources>());
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);
}
}
}
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.
* <p>To mark a test class as an integration test add the following lines before the class declaration:</p>
*
* <pre><code>
* import org.junit.experimental.categories.Category;
*
* @Category(org.gitlab4j.api.IntegrationTest.class)
* </code></pre>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface IntegrationTest {
}
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
}
}
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());
}
}
......@@ -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<String, Object> 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);
......
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<Commit> commits = commitsApi.getCommits(testProject.getId(), "master", null);
List<Commit> 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<Commit> commits = gitLabApi.getCommitsApi().getCommits(project.getId(), "master", "this-file-does-not-exist.an-extension");
List<Commit> 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());
......
......@@ -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");
}
}
......
......@@ -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);
}
}
......
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
......
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
......
......@@ -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
......
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);
}
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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;
* <p>
* 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<Job> jobs = gitLabApi.getJobApi().getJobs(testProjectId.intValue());
List<Job> jobs = gitLabApi.getJobApi().getJobs(testProject);
assertNotNull(jobs);
}
}
......@@ -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
......
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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment