Commit 2b60bfd1 authored by Mirko Friedenhagen's avatar Mirko Friedenhagen

Make integrative test run as during phase verify.

Right now java-gitlab-api fails during Maven phase test when no
GITLAB instance is running on localhost.

Make this test run during `mvn verify` only and check beforehand
whether the GITLAB instance is reachable. Furthermore the
instance-under-test may be changed by adding two system properties
during invocation.

Running:
```
mvn clean verify -DTEST_TOKEN=ADMIN_TOKEN -DTEST_URL=https://GITLAB_URL
```
will pick up the values and use this instance/token.
parent 6bcb05f1
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<parent> <parent>
<groupId>org.sonatype.oss</groupId> <groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId> <artifactId>oss-parent</artifactId>
<version>7</version> <version>9</version>
</parent> </parent>
<developers> <developers>
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> </properties>
<dependencies> <dependencies>
...@@ -104,6 +105,30 @@ ...@@ -104,6 +105,30 @@
<target>1.6</target> <target>1.6</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>default-integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>default-verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
package org.gitlab.api; package org.gitlab.api;
import org.gitlab.api.models.GitlabUser; import org.gitlab.api.models.GitlabUser;
import static org.hamcrest.CoreMatchers.is;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -11,21 +12,33 @@ import java.net.URL; ...@@ -11,21 +12,33 @@ import java.net.URL;
import java.util.UUID; import java.util.UUID;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeNoException;
import static org.junit.Assume.assumeThat;
public class GitlabAPITest { import java.net.ConnectException;
public class GitlabAPIT {
GitlabAPI _api; GitlabAPI _api;
private static final String TEST_URL = "http://localhost"; private static final String TEST_URL = System.getProperty("TEST_URL", "http://localhost");
private static final String TEST_TOKEN = "y0E5b9761b7y4qk"; private static final String TEST_TOKEN = System.getProperty("TEST_TOKEN", "y0E5b9761b7y4qk");
String rand = UUID.randomUUID().toString().replace("-", "").substring(0, 8); String rand = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
@Before @Before
public void setup() { public void setup() throws IOException {
_api = GitlabAPI.connect(TEST_URL, TEST_TOKEN); _api = GitlabAPI.connect(TEST_URL, TEST_TOKEN);
try {
_api.dispatch().with("login", "INVALID").with("password", rand).to("session", GitlabUser.class);
} catch (ConnectException e) {
assumeNoException("GITLAB not running on localhost, skipping...", e);
} catch (IOException e) {
final String message = e.getMessage();
assumeThat(message, is("{\"message\":\"401 Unauthorized\"}"));
}
} }
@Test @Test
......
Markdown is supported
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