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 @@ ...@@ -38,17 +38,22 @@
</developers> </developers>
<properties> <properties>
<java.source.version>1.8</java.source.version> <java.level>8</java.level>
<java.target.version>1.8</java.target.version> <java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<jersey.version>2.28</jersey.version> <jersey.version>2.28</jersey.version>
<jackson.version>2.9.8</jackson.version> <jackson.version>2.9.8</jackson.version>
<javaServlet.version>4.0.1</javaServlet.version> <javaServlet.version>4.0.1</javaServlet.version>
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
<mockito.version>2.19.0</mockito.version> <mockito.version>2.19.0</mockito.version>
<hamcrest.version>1.3</hamcrest.version> <hamcrest.version>1.3</hamcrest.version>
<systemRules.version>1.18.0</systemRules.version> <systemRules.version>1.18.0</systemRules.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<changelog-lib.version>1.59</changelog-lib.version> <changelog-lib.version>1.59</changelog-lib.version>
</properties> </properties>
...@@ -62,6 +67,7 @@ ...@@ -62,6 +67,7 @@
<build> <build>
<defaultGoal>package</defaultGoal> <defaultGoal>package</defaultGoal>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId> <artifactId>maven-release-plugin</artifactId>
...@@ -191,14 +197,35 @@ ...@@ -191,14 +197,35 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version> <version>3.0.0-M3</version>
<configuration> <configuration>
<excludedGroups>org.gitlab4j.api.IntegrationTest</excludedGroups>
<systemPropertyVariables> <systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile> <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </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> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId> <artifactId>maven-enforcer-plugin</artifactId>
...@@ -206,7 +233,7 @@ ...@@ -206,7 +233,7 @@
<configuration> <configuration>
<rules> <rules>
<enforceBytecodeVersion> <enforceBytecodeVersion>
<maxJdkVersion>1.8</maxJdkVersion> <maxJdkVersion>1.8</maxJdkVersion>
<ignoreClasses> <ignoreClasses>
<ignoreClass>module-info</ignoreClass> <ignoreClass>module-info</ignoreClass>
</ignoreClasses> </ignoreClasses>
...@@ -230,10 +257,31 @@ ...@@ -230,10 +257,31 @@
</dependencies> </dependencies>
</plugin> </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> </plugins>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
<!-- The se.bjurr.gitchangelog:git-changelog-maven-plugin needs to be in -->
<!-- this section (pluginManagement) for it to work correctly. -->
<plugin> <plugin>
<groupId>se.bjurr.gitchangelog</groupId> <groupId>se.bjurr.gitchangelog</groupId>
<artifactId>git-changelog-maven-plugin</artifactId> <artifactId>git-changelog-maven-plugin</artifactId>
...@@ -252,7 +300,6 @@ ...@@ -252,7 +300,6 @@
</plugin> </plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>
<dependencies> <dependencies>
...@@ -319,7 +366,24 @@ ...@@ -319,7 +366,24 @@
<version>${systemRules.version}</version> <version>${systemRules.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.googlecode.junit-toolbox</groupId>
<artifactId>junit-toolbox</artifactId>
<version>2.4</version>
<scope>test</scope>
</dependency>
</dependencies> </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> </project>
package org.gitlab4j.api; 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.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
/** /**
* In order for these tests to run you must set the following properties in * In order for the integration tests to run you must set the following properties in test-gitlab4j.properties
* test-gitlab4j.properties * and the resources pointed to must exist.
* *
* TEST_NAMESPACE * TEST_NAMESPACE
* TEST_PROJECT_NAME * TEST_PROJECT_NAME
* TEST_HOST_URL * TEST_HOST_URL
* TEST_PRIVATE_TOKEN * 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_PROJECT_NAME;
protected static final String TEST_NAMESPACE; protected static final String TEST_NAMESPACE;
protected static final String TEST_HOST_URL; protected static final String TEST_HOST_URL;
...@@ -26,14 +30,38 @@ public class AbstractBaseTest { ...@@ -26,14 +30,38 @@ public class AbstractBaseTest {
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
} }
protected static Project testProject; protected static class BaseTestResources {
protected static GitLabApi gitLabApi; 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(); 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 = ""; String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
...@@ -54,15 +82,44 @@ public class AbstractBaseTest { ...@@ -54,15 +82,44 @@ public class AbstractBaseTest {
if (problems.isEmpty()) { if (problems.isEmpty()) {
try { try {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); GitLabApi gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); baseResources = new BaseTestResources(gitLabApi);
baseTestResourcesMap.put(callingClassName, baseResources);
return (gitLabApi);
} catch (Exception e) { } catch (Exception e) {
problems += e.getMessage() + "\n"; 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; package org.gitlab4j.api;
import static org.junit.Assert.assertNotNull; 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.Constants.TokenType;
import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.GitLabApi.ApiVersion;
...@@ -9,6 +9,7 @@ import org.gitlab4j.api.models.Version; ...@@ -9,6 +9,7 @@ import org.gitlab4j.api.models.Version;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -20,61 +21,52 @@ import org.junit.Test;
* If any of the above are NULL, all tests in this class will be skipped. * 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 // TEST_ACCESS_TOKEN must be defined to run this test
private static final String TEST_HOST_URL; private static final String TEST_ACCESS_TOKEN = TestUtils.getProperty("TEST_ACCESS_TOKEN");
private static final String TEST_ACCESS_TOKEN; private static GitLabApi gitLabApi;
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;
public TestAccessToken() { public TestAccessToken() {
super(); super();
} }
@BeforeClass @BeforeClass
public static void setup() { public static void testSetup() {
String problems = ""; // Must setup the connection to the GitLab test server
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { gitLabApi = baseTestSetup();
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_ACCESS_TOKEN == null || TEST_ACCESS_TOKEN.trim().isEmpty()) { if (TEST_ACCESS_TOKEN == null || TEST_ACCESS_TOKEN.trim().isEmpty()) {
problems += "TEST_ACCESS_TOKEN cannot be empty\n"; System.err.println("TEST_ACCESS_TOKEN cannot be empty");
}
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);
} }
} }
@Before @Before
public void beforeMethod() { public void beforeMethod() {
assumeTrue(setupOk); assumeNotNull(gitLabApi);
} }
@Test @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(); Version version = gitLabApi.getVersion();
assertNotNull(version); assertNotNull(version);
System.out.format("tokenType: %s, version=%s, revision=%s%n", TokenType.PRIVATE, gitLabApi.getIgnoreCertificateErrors(), version.getVersion(), version.getRevision()); System.out.format("tokenType: %s, version=%s, revision=%s%n", TokenType.PRIVATE, gitLabApi.getIgnoreCertificateErrors(), version.getVersion(), version.getRevision());
assertNotNull(version.getVersion()); assertNotNull(version.getVersion());
assertNotNull(version.getRevision()); 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; ...@@ -2,18 +2,18 @@ package org.gitlab4j.api;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.User; import org.gitlab4j.api.models.User;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
/** /**
...@@ -26,31 +26,24 @@ 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. * 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) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestAvatarUpload { public class TestAvatarUpload extends AbstractIntegrationTest {
// The following needs to be set to your test repository // 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_URI;
private static final String TEST_PROXY_USERNAME; private static final String TEST_PROXY_USERNAME;
private static final String TEST_PROXY_PASSWORD; private static final String TEST_PROXY_PASSWORD;
static { 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_URI = TestUtils.getProperty("TEST_PROXY_URI");
TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME"); TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME");
TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD"); TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD");
} }
private static final String AVATAR_FILENAME = "avatar.png"; private static final String AVATAR_FILENAME = "avatar.png";
private static GitLabApi gitLabApi; private static GitLabApi gitLabApi;
private static Project testProject;
public TestAvatarUpload() { public TestAvatarUpload() {
super(); super();
...@@ -58,44 +51,18 @@ public class TestAvatarUpload { ...@@ -58,44 +51,18 @@ public class TestAvatarUpload {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
// Must setup the connection to the GitLab test server and get the test Project instance
String problems = ""; gitLabApi = baseTestSetup();
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { testProject = getTestProject();
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);
} }
@Test @Test
public void testSetProjectAvatar() throws GitLabApiException { public void testSetProjectAvatar() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); assumeNotNull(testProject);
assertNotNull(project);
File avatarFile = new File("src/test/resources/org/gitlab4j/api", AVATAR_FILENAME); 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); assertNotNull(updatedProject);
assertTrue(updatedProject.getAvatarUrl().endsWith(AVATAR_FILENAME)); assertTrue(updatedProject.getAvatarUrl().endsWith(AVATAR_FILENAME));
} }
...@@ -103,6 +70,7 @@ public class TestAvatarUpload { ...@@ -103,6 +70,7 @@ public class TestAvatarUpload {
@Test @Test
public void testSetProjectAvatarWithProxy() throws GitLabApiException { public void testSetProjectAvatarWithProxy() throws GitLabApiException {
assumeNotNull(testProject);
assumeTrue(TEST_PROXY_URI != null && TEST_PROXY_USERNAME != null && TEST_PROXY_PASSWORD != null); 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); assumeTrue(TEST_PROXY_URI.length() > 0 && TEST_PROXY_USERNAME.length() > 0 && TEST_PROXY_PASSWORD.length() > 0);
...@@ -110,11 +78,8 @@ public class TestAvatarUpload { ...@@ -110,11 +78,8 @@ public class TestAvatarUpload {
Map<String, Object> clientConfig = ProxyClientConfig.createProxyClientConfig(TEST_PROXY_URI, TEST_PROXY_USERNAME, TEST_PROXY_PASSWORD); 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); 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); 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); assertNotNull(updatedProject);
assertTrue(updatedProject.getAvatarUrl().endsWith(AVATAR_FILENAME)); assertTrue(updatedProject.getAvatarUrl().endsWith(AVATAR_FILENAME));
} }
...@@ -122,6 +87,8 @@ public class TestAvatarUpload { ...@@ -122,6 +87,8 @@ public class TestAvatarUpload {
@Test @Test
public void testSetUserAvatar() throws GitLabApiException { public void testSetUserAvatar() throws GitLabApiException {
assumeNotNull(gitLabApi);
User user = gitLabApi.getUserApi().getCurrentUser(); User user = gitLabApi.getUserApi().getCurrentUser();
assertNotNull(user); assertNotNull(user);
......
package org.gitlab4j.api; 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.Comment;
import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.CommitRef; import org.gitlab4j.api.models.CommitRef;
...@@ -11,19 +21,9 @@ import org.junit.Before; ...@@ -11,19 +21,9 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters; 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 * 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; ...@@ -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. * 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) @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"; 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 GitLabApi gitLabApi;
private static Project testProject; private static Project testProject;
...@@ -59,37 +49,9 @@ public class TestCommitsApi { ...@@ -59,37 +49,9 @@ public class TestCommitsApi {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
// Must setup the connection to the GitLab test server and get the test Project instance
String problems = ""; gitLabApi = baseTestSetup();
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { testProject = getTestProject();
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);
}
} }
@Before @Before
...@@ -191,20 +153,20 @@ public class TestCommitsApi { ...@@ -191,20 +153,20 @@ public class TestCommitsApi {
assertNotNull(testProject); assertNotNull(testProject);
CommitsApi commitsApi = gitLabApi.getCommitsApi(); CommitsApi commitsApi = gitLabApi.getCommitsApi();
List<Commit> commits = commitsApi.getCommits(testProject.getId(), "master", null); List<Commit> commits = commitsApi.getCommits(testProject, "master", null);
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
commits = commitsApi.getCommits(testProject.getId(), "master", "README"); commits = commitsApi.getCommits(testProject, "master", "README");
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
commitsApi = gitLabApi.getCommitsApi(); commitsApi = gitLabApi.getCommitsApi();
commits = commitsApi.getCommits(testProject.getId(), "master", "README.md"); commits = commitsApi.getCommits(testProject, "master", "README.md");
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); 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); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
} }
...@@ -212,10 +174,9 @@ public class TestCommitsApi { ...@@ -212,10 +174,9 @@ public class TestCommitsApi {
@Test @Test
public void testCommitsByPathNotFound() throws GitLabApiException { public void testCommitsByPathNotFound() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
try { 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()); assertTrue(commits == null || commits.isEmpty());
} catch (GitLabApiException gle) { } catch (GitLabApiException gle) {
assertEquals(Response.Status.NOT_FOUND, gle.getHttpStatus()); assertEquals(Response.Status.NOT_FOUND, gle.getHttpStatus());
......
...@@ -2,9 +2,9 @@ package org.gitlab4j.api; ...@@ -2,9 +2,9 @@ package org.gitlab4j.api;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; 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 * 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; ...@@ -16,17 +16,11 @@ import org.junit.BeforeClass;
* If any of the above are NULL, all tests in this class will be skipped. * 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 // The following needs to be set to your test repository
private static final String TEST_HOST_URL; private static final String TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME");
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 GitLabApi gitLabApi; private static GitLabApi gitLabApi;
...@@ -37,23 +31,11 @@ public class TestDeployKeysApi { ...@@ -37,23 +31,11 @@ public class TestDeployKeysApi {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
String problems = ""; // Must setup the connection to the GitLab test server
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { gitLabApi = baseTestSetup();
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 (TEST_USERNAME == null || TEST_USERNAME.trim().isEmpty()) { if (TEST_USERNAME == null || TEST_USERNAME.trim().isEmpty()) {
problems += "TEST_USER_NAME cannot be empty\n"; System.err.println("TEST_USER_NAME cannot be empty");
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
} }
} }
......
...@@ -8,7 +8,6 @@ import java.text.ParseException; ...@@ -8,7 +8,6 @@ import java.text.ParseException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Event; import org.gitlab4j.api.models.Event;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.User; import org.gitlab4j.api.models.User;
...@@ -16,6 +15,7 @@ import org.gitlab4j.api.utils.ISO8601; ...@@ -16,6 +15,7 @@ import org.gitlab4j.api.utils.ISO8601;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -27,19 +27,8 @@ import org.junit.Test;
* *
* If any of the above are NULL, all tests in this class will be skipped. * If any of the above are NULL, all tests in this class will be skipped.
*/ */
public class TestEventsApi { @Category(org.gitlab4j.api.IntegrationTest.class)
public class TestEventsApi 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;
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 GitLabApi gitLabApi;
private static Project testProject; private static Project testProject;
...@@ -52,40 +41,16 @@ public class TestEventsApi { ...@@ -52,40 +41,16 @@ public class TestEventsApi {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
String problems = ""; // Must setup the connection to the GitLab test server and get the test Project instance
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { gitLabApi = baseTestSetup();
problems += "TEST_NAMESPACE cannot be empty\n"; testProject = getTestProject();
}
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());
}
if (gitLabApi != null) {
try { try {
testUser = gitLabApi.getUserApi().getCurrentUser(); testUser = gitLabApi.getUserApi().getCurrentUser();
} catch (GitLabApiException gle) { } catch (GitLabApiException gle) {
System.err.print(gle.getMessage()); System.err.print(gle.getMessage());
} }
} else {
System.err.print(problems);
} }
} }
......
package org.gitlab4j.api; package org.gitlab4j.api;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.FileUpload; import org.gitlab4j.api.models.FileUpload;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
/** /**
...@@ -25,22 +26,15 @@ 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. * 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) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestFileUpload { public class TestFileUpload extends AbstractIntegrationTest {
// The following needs to be set to your test repository // 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_URI;
private static final String TEST_PROXY_USERNAME; private static final String TEST_PROXY_USERNAME;
private static final String TEST_PROXY_PASSWORD; private static final String TEST_PROXY_PASSWORD;
static { 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_URI = TestUtils.getProperty("TEST_PROXY_URI");
TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME"); TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME");
TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD"); TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD");
...@@ -54,34 +48,13 @@ public class TestFileUpload { ...@@ -54,34 +48,13 @@ public class TestFileUpload {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
// Must setup the connection to the GitLab test server and get the test Project instance
String problems = ""; gitLabApi = baseTestSetup();
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 @Before
public void beforeMethod() { public void beforeMethod() {
assumeTrue(gitLabApi != null); assumeNotNull(gitLabApi);
} }
@Test @Test
......
package org.gitlab4j.api; package org.gitlab4j.api;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import java.util.Map; import java.util.Map;
...@@ -9,6 +10,7 @@ import org.gitlab4j.api.models.Version; ...@@ -9,6 +10,7 @@ import org.gitlab4j.api.models.Version;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -19,17 +21,14 @@ import org.junit.Test;
* If any of the above are NULL, all tests in this class will be skipped. * 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 // 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_URI;
private static final String TEST_PROXY_USERNAME; private static final String TEST_PROXY_USERNAME;
private static final String TEST_PROXY_PASSWORD; private static final String TEST_PROXY_PASSWORD;
static { 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_URI = TestUtils.getProperty("TEST_PROXY_URI");
TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME"); TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME");
TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD"); TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD");
...@@ -43,26 +42,13 @@ public class TestGitLabApi { ...@@ -43,26 +42,13 @@ public class TestGitLabApi {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
// Must setup the connection to the GitLab test server
String problems = ""; gitLabApi = baseTestSetup();
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);
}
} }
@Before @Before
public void beforeMethod() { public void beforeMethod() {
assumeTrue(gitLabApi != null); assumeNotNull(gitLabApi);
} }
@Test @Test
......
...@@ -5,19 +5,19 @@ import static org.junit.Assert.assertFalse; ...@@ -5,19 +5,19 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; 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.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.Visibility; import org.gitlab4j.api.models.Visibility;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -28,19 +28,8 @@ import org.junit.Test;
* *
* If any of the above are NULL, all tests in this class will be skipped. * If any of the above are NULL, all tests in this class will be skipped.
*/ */
public class TestGitLabApiException { @Category(org.gitlab4j.api.IntegrationTest.class)
public class TestGitLabApiException extends AbstractIntegrationTest {
// 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");
}
private static final String TEST_PROJECT_NAME_DUPLICATE = "test-gitlab4j-create-project-duplicate"; private static final String TEST_PROJECT_NAME_DUPLICATE = "test-gitlab4j-create-project-duplicate";
private static GitLabApi gitLabApi; private static GitLabApi gitLabApi;
...@@ -51,25 +40,8 @@ public class TestGitLabApiException { ...@@ -51,25 +40,8 @@ public class TestGitLabApiException {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
// Must setup the connection to the GitLab test server
String problems = ""; gitLabApi = baseTestSetup();
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);
}
deleteAllTestProjects(); deleteAllTestProjects();
} }
...@@ -90,7 +62,7 @@ public class TestGitLabApiException { ...@@ -90,7 +62,7 @@ public class TestGitLabApiException {
@Before @Before
public void beforeMethod() { public void beforeMethod() {
assumeTrue(gitLabApi != null); assumeNotNull(gitLabApi);
} }
@Test @Test
......
package org.gitlab4j.api; package org.gitlab4j.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
...@@ -11,6 +10,7 @@ import org.gitlab4j.api.utils.SecretString; ...@@ -11,6 +10,7 @@ import org.gitlab4j.api.utils.SecretString;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -22,6 +22,7 @@ import org.junit.Test;
* *
* If any of the above are NULL, all tests in this class will be skipped. * If any of the above are NULL, all tests in this class will be skipped.
*/ */
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestGitLabLogin { public class TestGitLabLogin {
// The following needs to be set to your test repository // The following needs to be set to your test repository
...@@ -89,28 +90,6 @@ public class TestGitLabLogin { ...@@ -89,28 +90,6 @@ public class TestGitLabLogin {
assumeTrue(problems != null && problems.isEmpty()); 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 @Test
public void testSessionFallover() throws GitLabApiException { public void testSessionFallover() throws GitLabApiException {
assumeFalse(hasSession); assumeFalse(hasSession);
...@@ -126,6 +105,7 @@ public class TestGitLabLogin { ...@@ -126,6 +105,7 @@ public class TestGitLabLogin {
GitLabApi gitLabApi = GitLabApi.oauth2Login(TEST_HOST_URL, TEST_LOGIN_USERNAME, TEST_LOGIN_PASSWORD, null, null, true); GitLabApi gitLabApi = GitLabApi.oauth2Login(TEST_HOST_URL, TEST_LOGIN_USERNAME, TEST_LOGIN_PASSWORD, null, null, true);
assertNotNull(gitLabApi); assertNotNull(gitLabApi);
Version version = gitLabApi.getVersion(); Version version = gitLabApi.getVersion();
System.out.println("ACCESS_TOKEN: " + gitLabApi.getAuthToken());
assertNotNull(version); assertNotNull(version);
} }
......
...@@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; ...@@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; 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.List;
import java.util.Optional; import java.util.Optional;
...@@ -20,6 +20,7 @@ import org.junit.AfterClass; ...@@ -20,6 +20,7 @@ import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -33,17 +34,14 @@ import org.junit.Test;
* If any of the above are NULL, all tests in this class will be skipped. * 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 // 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_USERNAME;
private static final String TEST_GROUP; private static final String TEST_GROUP;
private static final String TEST_GROUP_MEMBER_USERNAME; private static final String TEST_GROUP_MEMBER_USERNAME;
static { static {
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME"); TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME");
TEST_GROUP = TestUtils.getProperty("TEST_GROUP"); TEST_GROUP = TestUtils.getProperty("TEST_GROUP");
TEST_GROUP_MEMBER_USERNAME = TestUtils.getProperty("TEST_GROUP_MEMBER_USERNAME"); TEST_GROUP_MEMBER_USERNAME = TestUtils.getProperty("TEST_GROUP_MEMBER_USERNAME");
...@@ -60,20 +58,15 @@ public class TestGroupApi { ...@@ -60,20 +58,15 @@ public class TestGroupApi {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
String problems = ""; // Must setup the connection to the GitLab test server
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { gitLabApi = baseTestSetup();
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";
}
String problems = "";
if (TEST_USERNAME == null || TEST_USERNAME.trim().isEmpty()) { if (TEST_USERNAME == null || TEST_USERNAME.trim().isEmpty()) {
problems += "TEST_USER_NAME cannot be empty\n"; 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); gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
try { try {
...@@ -92,9 +85,7 @@ public class TestGroupApi { ...@@ -92,9 +85,7 @@ public class TestGroupApi {
} }
} }
if (problems.isEmpty()) { if (!problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems); System.err.print(problems);
} }
...@@ -108,21 +99,19 @@ public class TestGroupApi { ...@@ -108,21 +99,19 @@ public class TestGroupApi {
private static void removeGroupMember() { private static void removeGroupMember() {
if (gitLabApi != null) { if (gitLabApi != null && testGroup != null && testUser != null) {
try {
if (testGroup != null && testUser != null) { gitLabApi.getGroupApi().removeMember(testGroup.getId(), testUser.getId());
try { } catch (GitLabApiException ignore) {
gitLabApi.getGroupApi().removeMember(testGroup.getId(), testUser.getId());
} catch (GitLabApiException ignore) {
}
} }
} }
} }
@Before @Before
public void beforeMethod() { public void beforeMethod() {
assumeTrue(gitLabApi != null); assumeNotNull(gitLabApi);
assumeTrue(testGroup != null && testUser != null); assumeNotNull(testGroup);
assumeNotNull(testUser);
} }
@Test @Test
......
...@@ -7,6 +7,7 @@ import org.gitlab4j.api.models.HealthCheckInfo; ...@@ -7,6 +7,7 @@ import org.gitlab4j.api.models.HealthCheckInfo;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -17,6 +18,7 @@ import org.junit.Test;
* If any of the above are NULL, all tests in this class will be skipped. * If any of the above are NULL, all tests in this class will be skipped.
* *
*/ */
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestHealthCheckApi { public class TestHealthCheckApi {
// The following needs to be set to your test repository // The following needs to be set to your test repository
......
...@@ -10,6 +10,7 @@ import org.gitlab4j.api.models.Version; ...@@ -10,6 +10,7 @@ import org.gitlab4j.api.models.Version;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -20,6 +21,7 @@ import org.junit.Test;
* If any of the above are NULL, all tests in this class will be skipped. * If any of the above are NULL, all tests in this class will be skipped.
* *
*/ */
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestIgnoreCertificateErrors { public class TestIgnoreCertificateErrors {
// The following needs to be set to your test repository // The following needs to be set to your test repository
......
...@@ -27,7 +27,7 @@ import static org.junit.Assert.assertEquals; ...@@ -27,7 +27,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; 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.Arrays;
import java.util.Date; import java.util.Date;
...@@ -37,7 +37,6 @@ import java.util.Random; ...@@ -37,7 +37,6 @@ import java.util.Random;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.gitlab4j.api.Constants.IssueState; import org.gitlab4j.api.Constants.IssueState;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Duration; import org.gitlab4j.api.models.Duration;
import org.gitlab4j.api.models.Issue; import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.IssueFilter; import org.gitlab4j.api.models.IssueFilter;
...@@ -47,6 +46,7 @@ import org.junit.AfterClass; ...@@ -47,6 +46,7 @@ import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -58,20 +58,8 @@ import org.junit.Test;
* *
* If any of the above are NULL, all tests in this class will be skipped. * If any of the above are NULL, all tests in this class will be skipped.
*/ */
public class TestIssuesApi { @Category(org.gitlab4j.api.IntegrationTest.class)
public class TestIssuesApi 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;
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 GitLabApi gitLabApi;
private static Project testProject; private static Project testProject;
...@@ -87,37 +75,16 @@ public class TestIssuesApi { ...@@ -87,37 +75,16 @@ public class TestIssuesApi {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
String problems = ""; // Must setup the connection to the GitLab test server and get the test Project instance
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { gitLabApi = baseTestSetup();
problems += "TEST_NAMESPACE cannot be empty\n"; testProject = getTestProject();
}
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);
}
deleteAllTestIssues(); deleteAllTestIssues();
} }
@Before @Before
public void beforeMethod() { public void beforeMethod() {
assumeTrue(gitLabApi != null); assumeNotNull(gitLabApi);
} }
@AfterClass @AfterClass
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
package org.gitlab4j.api; package org.gitlab4j.api;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeNotNull;
import java.util.List; import java.util.List;
...@@ -34,6 +34,7 @@ import org.junit.AfterClass; ...@@ -34,6 +34,7 @@ import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -45,22 +46,11 @@ import org.junit.Test;
* <p> * <p>
* If any of the above are NULL, all tests in this class will be skipped. * 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 GitLabApi gitLabApi;
private static Integer testProjectId; private static Project testProject;
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 TestJobApi() { public TestJobApi() {
super(); super();
...@@ -68,35 +58,9 @@ public class TestJobApi { ...@@ -68,35 +58,9 @@ public class TestJobApi {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
// Must setup the connection to the GitLab test server and get the test Project instance
String problems = ""; gitLabApi = baseTestSetup();
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { testProject = getTestProject();
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;
}
}
} }
@AfterClass @AfterClass
...@@ -105,12 +69,12 @@ public class TestJobApi { ...@@ -105,12 +69,12 @@ public class TestJobApi {
@Before @Before
public void beforeMethod() { public void beforeMethod() {
assumeTrue(gitLabApi != null); assumeNotNull(testProject);
} }
@Test @Test
public void testGetJobs() throws GitLabApiException { public void testGetJobs() throws GitLabApiException {
List<Job> jobs = gitLabApi.getJobApi().getJobs(testProjectId.intValue()); List<Job> jobs = gitLabApi.getJobApi().getJobs(testProject);
assertNotNull(jobs); assertNotNull(jobs);
} }
} }
...@@ -3,15 +3,15 @@ package org.gitlab4j.api; ...@@ -3,15 +3,15 @@ package org.gitlab4j.api;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeNotNull;
import java.util.List; import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Namespace; import org.gitlab4j.api.models.Namespace;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; 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 * 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; ...@@ -23,18 +23,8 @@ import org.junit.Test;
* If any of the above are NULL, all tests in this class will be skipped. * If any of the above are NULL, all tests in this class will be skipped.
* *
*/ */
public class TestNamespaceApi { @Category(org.gitlab4j.api.IntegrationTest.class)
public class TestNamespaceApi extends AbstractIntegrationTest {
// 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");
}
private static GitLabApi gitLabApi; private static GitLabApi gitLabApi;
...@@ -44,30 +34,13 @@ public class TestNamespaceApi { ...@@ -44,30 +34,13 @@ public class TestNamespaceApi {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
// Must setup the connection to the GitLab test server
String problems = ""; gitLabApi = baseTestSetup();
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);
}
} }
@Before @Before
public void beforeMethod() { public void beforeMethod() {
assumeTrue(gitLabApi != null); assumeNotNull(gitLabApi);
} }
@Test @Test
......
package org.gitlab4j.api; 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.Constants.SortOrder;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Issue; import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.Note; import org.gitlab4j.api.models.Note;
...@@ -10,13 +14,9 @@ import org.junit.Before; ...@@ -10,13 +14,9 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters; 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 * 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; ...@@ -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. * 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) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestNotesApi { public class TestNotesApi 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;
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 GitLabApi gitLabApi;
...@@ -50,34 +39,13 @@ public class TestNotesApi { ...@@ -50,34 +39,13 @@ public class TestNotesApi {
@BeforeClass @BeforeClass
public static void setup() { public static void setup() {
// Must setup the connection to the GitLab test server
String problems = ""; gitLabApi = baseTestSetup();
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 @Before
public void beforeMethod() { public void beforeMethod() {
assumeTrue(gitLabApi != null); assumeNotNull(gitLabApi);
} }
@Test @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