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

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

parent 053813a4
......@@ -3,11 +3,11 @@ package org.gitlab4j.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeNotNull;
import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Group;
import org.gitlab4j.api.models.NotificationSettings;
import org.gitlab4j.api.models.Project;
......@@ -15,6 +15,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
/**
......@@ -28,22 +29,12 @@ import org.junit.runners.MethodSorters;
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestNotificationSettingsApi {
public class TestNotificationSettingsApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_PROJECT_NAME;
private static final String TEST_NAMESPACE;
private static final String TEST_GROUP;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_GROUP = TestUtils.getProperty("TEST_GROUP");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
private static final String TEST_GROUP = TestUtils.getProperty("TEST_GROUP");
private static GitLabApi gitLabApi;
......@@ -53,34 +44,13 @@ public class TestNotificationSettingsApi {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) {
problems += "TEST_PROJECT_NAME cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
}
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
}
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
}
@Test
......@@ -100,6 +70,7 @@ public class TestNotificationSettingsApi {
@Test
public void testGroupNotificationSettings() throws GitLabApiException {
assumeFalse(TEST_GROUP == null || TEST_GROUP.trim().isEmpty());
List<Group> groups = gitLabApi.getGroupApi().getGroups(TEST_GROUP);
assertNotNull(groups);
assertFalse(groups.isEmpty());
......
......@@ -3,11 +3,10 @@ package org.gitlab4j.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeNotNull;
import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Branch;
import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.Member;
......@@ -16,6 +15,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
/**
......@@ -30,21 +30,9 @@ import org.junit.runners.MethodSorters;
*
* NOTE: &amp;FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that the tests are in the correct order
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestPager {
// The following needs to be set to your test repository
private static final String TEST_NAMESPACE;
private static final String TEST_PROJECT_NAME;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
public class TestPager extends AbstractIntegrationTest {
private static GitLabApi gitLabApi;
......@@ -54,34 +42,13 @@ public class TestPager {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) {
problems += "TEST_PROJECT_NAME cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
}
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
}
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
}
@Test
......
......@@ -4,31 +4,20 @@ import static java.util.stream.Collectors.toList;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeNotNull;
import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.PipelineSchedule;
import org.gitlab4j.api.models.Project;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
public class TestPipelineApi {
// The following needs to be set to your test repository
private static final String TEST_NAMESPACE;
private static final String TEST_PROJECT_NAME;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestPipelineApi extends AbstractIntegrationTest {
private static final String SCHEDULE_DESCRIPTION = "Test pipeline schedule - DELETE AFTER TEST";
......@@ -64,33 +53,9 @@ public class TestPipelineApi {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
try {
testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
} catch (GitLabApiException gle) {
}
deleteTestSchedules();
} else {
System.err.print(problems);
}
// Must setup the connection to the GitLab test server and get the test Project instance
gitLabApi = baseTestSetup();
testProject = getTestProject();
}
@AfterClass
......@@ -98,10 +63,9 @@ public class TestPipelineApi {
deleteTestSchedules();
}
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
}
@Test
......
......@@ -28,6 +28,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue;
import java.util.Arrays;
......@@ -38,7 +39,6 @@ import java.util.stream.Stream;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.AccessLevel;
import org.gitlab4j.api.models.Group;
import org.gitlab4j.api.models.Project;
......@@ -49,6 +49,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
/**
......@@ -64,23 +65,15 @@ import org.junit.runners.MethodSorters;
*
* NOTE: &amp;FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that the tests are in the correct order
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestProjectApi {
public class TestProjectApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_NAMESPACE;
private static final String TEST_PROJECT_NAME;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
private static final String TEST_GROUP;
private static final String TEST_GROUP_PROJECT;
private static final String TEST_XFER_NAMESPACE;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
TEST_GROUP = TestUtils.getProperty("TEST_GROUP");
TEST_GROUP_PROJECT = TestUtils.getProperty("TEST_GROUP_PROJECT");
TEST_XFER_NAMESPACE = TestUtils.getProperty("TEST_XFER_NAMESPACE");
......@@ -100,24 +93,8 @@ public class TestProjectApi {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
}
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
deleteAllTestProjects();
}
......@@ -128,65 +105,67 @@ public class TestProjectApi {
}
private static void deleteAllTestProjects() {
if (gitLabApi != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_1);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
if (gitLabApi == null) {
return;
}
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_2);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_1);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_UPDATE);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_XFER_PROJECT_NAME);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_2);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_UPDATE);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
if (TEST_GROUP != null && TEST_PROJECT_NAME != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
List<Group> groups = gitLabApi.getGroupApi().getGroups(TEST_GROUP);
gitLabApi.getProjectApi().unshareProject(project.getId(), groups.get(0).getId());
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_XFER_PROJECT_NAME);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
List<Variable> variables = gitLabApi.getProjectApi().getVariables(project);
if (variables != null) {
if (TEST_GROUP != null && TEST_PROJECT_NAME != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
List<Group> groups = gitLabApi.getGroupApi().getGroups(TEST_GROUP);
gitLabApi.getProjectApi().unshareProject(project.getId(), groups.get(0).getId());
for (Variable variable : variables) {
if (variable.getKey().startsWith(TEST_VARIABLE_KEY_PREFIX)) {
gitLabApi.getProjectApi().deleteVariable(project, variable.getKey());
}
List<Variable> variables = gitLabApi.getProjectApi().getVariables(project);
if (variables != null) {
for (Variable variable : variables) {
if (variable.getKey().startsWith(TEST_VARIABLE_KEY_PREFIX)) {
gitLabApi.getProjectApi().deleteVariable(project, variable.getKey());
}
}
} catch (GitLabApiException ignore) {
}
} catch (GitLabApiException ignore) {
}
}
if (TEST_GROUP != null && TEST_GROUP_PROJECT != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_GROUP_PROJECT);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
}
if (TEST_GROUP != null && TEST_GROUP_PROJECT != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_GROUP_PROJECT);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
}
if (TEST_XFER_NAMESPACE != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_XFER_NAMESPACE, TEST_XFER_PROJECT_NAME);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
}
if (TEST_XFER_NAMESPACE != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_XFER_NAMESPACE, TEST_XFER_PROJECT_NAME);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {}
}
}
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
}
@Test
......
......@@ -26,11 +26,10 @@ package org.gitlab4j.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeNotNull;
import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.Visibility;
......@@ -38,6 +37,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
/**
* In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties
......@@ -49,24 +49,12 @@ import org.junit.Test;
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
public class TestProjectApiSnippets {
// The following needs to be set to your test repository
private static final String TEST_NAMESPACE;
private static final String TEST_PROJECT_NAME;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestProjectApiSnippets extends AbstractIntegrationTest {
private static final String TEST_SNIPPET_TITLE_PREFIX = "Test Snippet: ";
private static GitLabApi gitLabApi;
private static Integer testProjectId;
private static Project testProject;
public TestProjectApiSnippets() {
super();
......@@ -75,34 +63,9 @@ public class TestProjectApiSnippets {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
}
if (gitLabApi != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
testProjectId = project.getId();
} catch (Exception e) {
System.err.print(e.getMessage());
gitLabApi = null;
}
}
// Must setup the connection to the GitLab test server and get the test Project instance
gitLabApi = baseTestSetup();
testProject = getTestProject();
deleteAllTestSnippets();
}
......@@ -115,11 +78,11 @@ public class TestProjectApiSnippets {
private static void deleteAllTestSnippets() {
if (gitLabApi != null) {
try {
List<Snippet> snippets = gitLabApi.getProjectApi().getSnippets(testProjectId);
List<Snippet> snippets = gitLabApi.getProjectApi().getSnippets(testProject);
if (snippets != null) {
for (Snippet snippet : snippets) {
if (snippet.getTitle().startsWith(TEST_SNIPPET_TITLE_PREFIX)) {
gitLabApi.getProjectApi().deleteSnippet(testProjectId, snippet.getId());
gitLabApi.getProjectApi().deleteSnippet(testProject, snippet.getId());
}
}
}
......@@ -130,12 +93,12 @@ public class TestProjectApiSnippets {
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
}
private Snippet createSnippet(String title, String filename, String description,
String code, Visibility visibility) throws GitLabApiException {
return (gitLabApi.getProjectApi().createSnippet(testProjectId, title, filename, description, code, visibility));
return (gitLabApi.getProjectApi().createSnippet(testProject, title, filename, description, code, visibility));
}
@Test
......@@ -155,6 +118,8 @@ public class TestProjectApiSnippets {
@Test
public void testUpdate() throws GitLabApiException {
assumeNotNull(testProject);
String title = TEST_SNIPPET_TITLE_PREFIX + "Test createSnippet()";
String filename = "test-update-snippet.js";
String description = null;
......@@ -164,7 +129,7 @@ public class TestProjectApiSnippets {
assertNotNull(snippet);
title = TEST_SNIPPET_TITLE_PREFIX + "Test updateSnippet()";
snippet = gitLabApi.getProjectApi().updateSnippet(testProjectId, snippet.getId(), title, null, null, null, null);
snippet = gitLabApi.getProjectApi().updateSnippet(testProject, snippet.getId(), title, null, null, null, null);
assertEquals(title, snippet.getTitle());
assertEquals(filename, snippet.getFileName());
}
......@@ -172,6 +137,8 @@ public class TestProjectApiSnippets {
@Test
public void testListSnippets() throws GitLabApiException {
assumeNotNull(testProject);
String title = TEST_SNIPPET_TITLE_PREFIX + "Test listSnippets()";
String filename = "test-list-snippets.js";
String description = null;
......@@ -181,7 +148,7 @@ public class TestProjectApiSnippets {
assertNotNull(newSnippet);
int snippetId = newSnippet.getId();
List<Snippet> snippets = gitLabApi.getProjectApi().getSnippets(testProjectId);
List<Snippet> snippets = gitLabApi.getProjectApi().getSnippets(testProject);
assertNotNull(snippets);
for (Snippet snippet : snippets) {
if (snippet.getId() == snippetId) {
......@@ -195,6 +162,8 @@ public class TestProjectApiSnippets {
@Test
public void testDeleteSnippet() throws GitLabApiException {
assumeNotNull(testProject);
String title = TEST_SNIPPET_TITLE_PREFIX + "Test listSnippets()";
String filename = "test-delete-snippet.js";
String description = null;
......@@ -204,8 +173,8 @@ public class TestProjectApiSnippets {
assertNotNull(createdSnippet);
int snippetId = createdSnippet.getId();
gitLabApi.getProjectApi().deleteSnippet(testProjectId, snippetId);
List<Snippet> snippets = gitLabApi.getProjectApi().getSnippets(testProjectId);
gitLabApi.getProjectApi().deleteSnippet(testProject, snippetId);
List<Snippet> snippets = gitLabApi.getProjectApi().getSnippets(testProject);
if (snippets != null) {
for (Snippet snippet : snippets) {
if (snippet.getId() == snippetId) {
......@@ -218,6 +187,8 @@ public class TestProjectApiSnippets {
@Test
public void testSnippetContent() throws GitLabApiException {
assumeNotNull(testProject);
String title = TEST_SNIPPET_TITLE_PREFIX + "Test getRawSnippetContent()";
String filename = "test-raw-snippet.js";
String description = null;
......@@ -226,7 +197,7 @@ public class TestProjectApiSnippets {
Snippet createdSnippet = createSnippet(title, filename, description, code, visibility);
assertNotNull(createdSnippet);
String rawContent = gitLabApi.getProjectApi().getRawSnippetContent(testProjectId, createdSnippet.getId());
String rawContent = gitLabApi.getProjectApi().getRawSnippetContent(testProject.getId(), createdSnippet.getId());
assertEquals(code, rawContent);
}
}
......@@ -3,7 +3,7 @@ package org.gitlab4j.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeNotNull;
import java.util.List;
......@@ -15,6 +15,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
/**
......@@ -29,20 +30,9 @@ import org.junit.runners.MethodSorters;
*
* NOTE: &amp;FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that testCreate() is executed first.
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestProtectedBranchesApi {
// The following needs to be set to your test repository
private static final String TEST_PROJECT_NAME;
private static final String TEST_NAMESPACE;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
public class TestProtectedBranchesApi extends AbstractIntegrationTest {
private static GitLabApi gitLabApi;
......@@ -52,29 +42,8 @@ public class TestProtectedBranchesApi {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) {
problems += "TEST_PROJECT_NAME cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(GitLabApi.ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
}
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
}
@AfterClass
......@@ -102,7 +71,7 @@ public class TestProtectedBranchesApi {
@Before
public void beforeMethod() throws GitLabApiException {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
Branch protectedBranch;
try {
......
......@@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeNotNull;
import java.io.File;
import java.io.IOException;
......@@ -24,6 +24,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
/**
......@@ -38,21 +39,9 @@ import org.junit.runners.MethodSorters;
*
* NOTE: &amp;FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that testCreate() is executed first.
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestRepositoryApi {
// The following needs to be set to your test repository
private static final String TEST_PROJECT_NAME;
private static final String TEST_NAMESPACE;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
public class TestRepositoryApi extends AbstractIntegrationTest {
private static final String TEST_BRANCH_NAME = "feature/test_branch";
private static final String TEST_BRANCH1 = "feature/test_branch1";
......@@ -67,29 +56,10 @@ public class TestRepositoryApi {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) {
problems += "TEST_PROJECT_NAME cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(TEST_HOST_URL, TEST_PRIVATE_TOKEN);
teardown();
} else {
System.err.print(problems);
}
teardown();
}
@AfterClass
......@@ -123,7 +93,7 @@ public class TestRepositoryApi {
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
}
@Test
......
......@@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeNotNull;
import java.io.File;
import java.io.IOException;
......@@ -22,6 +22,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
/**
......@@ -36,20 +37,9 @@ import org.junit.runners.MethodSorters;
*
* NOTE: &amp;FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that testCreate() is executed first.
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestRepositoryFileApi {
// The following needs to be set to your test repository
private static final String TEST_PROJECT_NAME;
private static final String TEST_NAMESPACE;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
public class TestRepositoryFileApi extends AbstractIntegrationTest {
private static final String TEST_CONTENT = "This is some content to test file content 1234567890 !@#$%^&().";
private static final String TEST_ADDITIONAL_CONTENT = "\n\nThis is an additional line";
......@@ -65,29 +55,10 @@ public class TestRepositoryFileApi {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) {
problems += "TEST_PROJECT_NAME cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(TEST_HOST_URL, TEST_PRIVATE_TOKEN);
teardown();
} else {
System.err.print(problems);
}
teardown();
}
@AfterClass
......@@ -114,7 +85,7 @@ public class TestRepositoryFileApi {
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
}
@Test
......
......@@ -44,6 +44,7 @@ import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
/**
......@@ -54,6 +55,7 @@ import org.junit.rules.TemporaryFolder;
* <p>
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestRequestResponseLogging {
@ClassRule
......
......@@ -30,7 +30,6 @@ import static org.junit.Assume.assumeTrue;
import java.util.Arrays;
import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.Runner;
import org.gitlab4j.api.models.RunnerDetail;
......@@ -38,6 +37,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
/**
......@@ -51,19 +51,9 @@ import org.junit.runners.MethodSorters;
* <p>
* NOTE: &amp;FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that the tests are in the correct order
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
@FixMethodOrder(MethodSorters.JVM)
public class TestRunnersApi {
// The following needs to be set to your test repository
private static final String TEST_NAMESPACE;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
public class TestRunnersApi extends AbstractIntegrationTest {
private static GitLabApi gitLabApi;
......@@ -74,24 +64,8 @@ public class TestRunnersApi {
@BeforeClass
public static void setup() throws GitLabApiException {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
}
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
List<Runner> allRunners = gitLabApi.getRunnersApi().getAllRunners();
......
......@@ -4,9 +4,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeNotNull;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.services.ExternalWikiService;
import org.gitlab4j.api.services.JiraService;
......@@ -15,6 +14,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
/**
......@@ -27,20 +27,9 @@ import org.junit.runners.MethodSorters;
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestServicesApi {
// The following needs to be set to your test repository
private static final String TEST_PROJECT_NAME;
private static final String TEST_NAMESPACE;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
public class TestServicesApi extends AbstractIntegrationTest {
private static GitLabApi gitLabApi;
private static Project testProject;
......@@ -52,42 +41,19 @@ public class TestServicesApi {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_PROJECT_NAME == null || TEST_PROJECT_NAME.trim().isEmpty()) {
problems += "TEST_PROJECT_NAME cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
// Must setup the connection to the GitLab test server and get the test Project instance
gitLabApi = baseTestSetup();
testProject = getTestProject();
try {
testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
try { gitLabApi.getServicesApi().deleteJiraService(testProject); } catch (Exception ignore) {}
try { gitLabApi.getServicesApi().deleteSlackService(testProject); } catch (Exception ignore) {}
} catch (GitLabApiException gle) {
System.err.print(gle.getMessage());
}
} else {
System.err.print(problems);
if (testProject != null) {
try { gitLabApi.getServicesApi().deleteJiraService(testProject); } catch (Exception ignore) {}
try { gitLabApi.getServicesApi().deleteSlackService(testProject); } catch (Exception ignore) {}
}
}
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null && testProject != null);
assumeNotNull(testProject);
}
@Test
......
......@@ -4,24 +4,19 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNotNull;
import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.Visibility;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
public class TestSnippetsApi {
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestSnippetsApi extends AbstractIntegrationTest {
private static GitLabApi gitLabApi;
private static final String TEST_SNIPPET_TITLE_1 = "test-snippet-title-1";
......@@ -32,22 +27,13 @@ public class TestSnippetsApi {
@BeforeClass
public static void setup() {
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
}
String problems = "";
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
}
@Before
public void beforeMethod() {
assumeNotNull(gitLabApi);
}
@Test
......
......@@ -4,16 +4,16 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeNotNull;
import java.util.List;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.SystemHook;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
/**
......@@ -24,19 +24,13 @@ import org.junit.runners.MethodSorters;
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(org.gitlab4j.api.IntegrationTest.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestSystemHooksApi {
public class TestSystemHooksApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_HOST_URL;
private static final String TEST_HOOK_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_HOOK_URL = "http://hook.example.com/hook/callback";
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
private static final String TEST_HOOK_URL = "http://hook.example.com/hook/callback";
private static final String TEST_SECRET_TOKEN = "123456abcd";
private static GitLabApi gitLabApi;
......@@ -48,29 +42,17 @@ public class TestSystemHooksApi {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_HOOK_URL == null || TEST_HOOK_URL.trim().isEmpty()) {
problems += "TEST_HOOK_URL cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
System.err.println("TEST_HOOK_URL cannot be empty");
} else {
System.err.print(problems);
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
}
}
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
}
@Test
......
......@@ -9,27 +9,34 @@ import static org.junit.Assume.assumeTrue;
import java.util.List;
import java.util.Optional;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.Release;
import org.gitlab4j.api.models.Tag;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
public class TestTagsApi extends AbstractBaseTest {
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestTagsApi extends AbstractIntegrationTest {
private static final String TEST_TAG_NAME_1 = "test-tag-1";
private static final String TEST_TAG_NAME_0 = "test-tag-0";
private static GitLabApi gitLabApi;
private static Project testProject;
public TestTagsApi() {
super();
}
@BeforeClass
public static void setup() {
public static void testSetup() {
// Must setup the connection to the GitLab test server
AbstractBaseTest.testSetup();
// Must setup the connection to the GitLab test server and get the test Project instance
gitLabApi = baseTestSetup();
testProject = getTestProject();
if (testProject != null) {
try {
......
......@@ -16,7 +16,6 @@ import java.util.Optional;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.ImpersonationToken;
import org.gitlab4j.api.models.ImpersonationToken.Scope;
import org.gitlab4j.api.models.SshKey;
......@@ -26,6 +25,7 @@ import org.gitlab4j.api.utils.ISO8601;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
/**
* In order for these tests to run you must set the following properties in test-gitlab4j.properties
......@@ -45,18 +45,15 @@ import org.junit.Test;
* If this is null the SSH key tests will be skipped.
*
*/
public class TestUserApi {
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestUserApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
private static final String TEST_USERNAME;
private static final String TEST_BLOCK_USERNAME;
private static final String TEST_SUDO_AS_USERNAME;
private static final String TEST_SSH_KEY;
static {
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME");
TEST_BLOCK_USERNAME = TestUtils.getProperty("TEST_BLOCK_USERNAME");
TEST_SUDO_AS_USERNAME = TestUtils.getProperty("TEST_SUDO_AS_USERNAME");
......@@ -80,10 +77,6 @@ public class TestUserApi {
public static void setup() {
String problems = "";
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
......@@ -93,28 +86,33 @@ public class TestUserApi {
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
if (TEST_BLOCK_USERNAME != null) {
try {
blockUser = gitLabApi.getUserApi().getUser(TEST_BLOCK_USERNAME);
if (blockUser != null) {
gitLabApi.getUserApi().unblockUser(blockUser.getId());
}
} catch (Exception ignore) {}
}
if (TEST_SSH_KEY != null) {
try {
List<SshKey> sshKeys = gitLabApi.getUserApi().getSshKeys();
if (sshKeys != null) {
for (SshKey key : sshKeys) {
if (TEST_SSH_KEY.equals(key.getKey())) {
gitLabApi.getUserApi().deleteSshKey(key.getId());
// Must setup the connection to the GitLab test server
gitLabApi = baseTestSetup();
if (gitLabApi != null) {
if (TEST_BLOCK_USERNAME != null) {
try {
blockUser = gitLabApi.getUserApi().getUser(TEST_BLOCK_USERNAME);
if (blockUser != null) {
gitLabApi.getUserApi().unblockUser(blockUser.getId());
}
} catch (Exception ignore) {}
}
if (TEST_SSH_KEY != null) {
try {
List<SshKey> sshKeys = gitLabApi.getUserApi().getSshKeys();
if (sshKeys != null) {
for (SshKey key : sshKeys) {
if (TEST_SSH_KEY.equals(key.getKey())) {
gitLabApi.getUserApi().deleteSshKey(key.getId());
}
}
}
}
} catch (Exception ignore) {}
} catch (Exception ignore) {}
}
}
} else {
......@@ -124,7 +122,7 @@ public class TestUserApi {
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(gitLabApi);
}
@Test
......@@ -175,7 +173,7 @@ public class TestUserApi {
optional = gitLabApi.getUserApi().getOptionalUser("this-username-does-not-exist");
assertNotNull(optional);
assertFalse(optional.isPresent());
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), GitLabApi.getOptionalException(optional).getHttpStatus());
assertNull(GitLabApi.getOptionalException(optional));
}
@Test
......
......@@ -63,6 +63,20 @@ public class TestUtils {
return (testProperties.getProperty(key));
}
/**
* Set a named property, this will amend and overwrite properties read from the test-gitlab4j.properties file.
*
* @param key the key of the property to get
* @return the named property from the test-gitlab4j.properties file
*/
public static final void setProperty(String key, String value) {
if (value == null) {
testProperties.remove(key);
} else {
testProperties.setProperty(key, value);
}
}
/**
* Get a random integer between 1 and the specified value (inclusive).
*
......
......@@ -23,7 +23,14 @@
package org.gitlab4j.api;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeNotNull;
import java.io.File;
import java.util.List;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.WikiAttachment;
import org.gitlab4j.api.models.WikiPage;
......@@ -31,12 +38,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
import org.junit.experimental.categories.Category;
/**
* In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties
......@@ -48,25 +50,14 @@ import static org.junit.Assume.assumeTrue;
* <p>
* If any of the above are NULL, all tests in this class will be skipped.
*/
public class TestWikisApi {
@Category(org.gitlab4j.api.IntegrationTest.class)
public class TestWikisApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_NAMESPACE;
private static final String TEST_PROJECT_NAME;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
private static final String TEST_WIKI_TITLE_PREFIX = "Test Wiki: ";
private static GitLabApi gitLabApi;
private static Integer testProjectId;
private static Project testProject;
private static String testContent;
static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
public TestWikisApi() {
super();
}
......@@ -74,37 +65,11 @@ public class TestWikisApi {
@BeforeClass
public static void setup() {
String problems = "";
if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) {
problems += "TEST_NAMESPACE cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
} else {
System.err.print(problems);
}
if (gitLabApi != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
testProjectId = project.getId();
} catch (Exception e) {
System.err.print(e.getMessage());
gitLabApi = null;
}
}
// Must setup the connection to the GitLab test server and get the test Project instance
gitLabApi = baseTestSetup();
testProject = getTestProject();
testContent = "This is a test content and must be deleted after testing.";
deleteAllTestWikiPages();
}
......@@ -114,12 +79,12 @@ public class TestWikisApi {
}
private static void deleteAllTestWikiPages() {
if (gitLabApi != null) {
if (testProject != null) {
try {
List<WikiPage> wikiPages = gitLabApi.getWikisApi().getPages(testProjectId);
List<WikiPage> wikiPages = gitLabApi.getWikisApi().getPages(testProject);
wikiPages.stream().filter(wp -> wp.getTitle().startsWith(TEST_WIKI_TITLE_PREFIX)).map(WikiPage::getSlug).forEach(slug -> {
try {
gitLabApi.getWikisApi().deletePage(testProjectId, slug);
gitLabApi.getWikisApi().deletePage(testProject, slug);
} catch (GitLabApiException ignored) {
}
});
......@@ -131,11 +96,11 @@ public class TestWikisApi {
@Before
public void beforeMethod() {
assumeTrue(gitLabApi != null);
assumeNotNull(testProject);
}
private WikiPage createWikiPage(String title, String content) throws GitLabApiException {
return (gitLabApi.getWikisApi().createPage(testProjectId, title, content));
return (gitLabApi.getWikisApi().createPage(testProject.getId(), title, content));
}
@Test
......@@ -154,7 +119,7 @@ public class TestWikisApi {
assertNotNull(wikiPage);
title = TEST_WIKI_TITLE_PREFIX + "Test updateWikiPage()";
wikiPage = gitLabApi.getWikisApi().updatePage(testProjectId, wikiPage.getSlug(), title, "some content");
wikiPage = gitLabApi.getWikisApi().updatePage(testProject, wikiPage.getSlug(), title, "some content");
assertEquals(title, wikiPage.getTitle());
assertEquals("some content", wikiPage.getContent());
}
......@@ -166,7 +131,7 @@ public class TestWikisApi {
assertNotNull(newWikiPage);
String wikiPageSlug = newWikiPage.getSlug();
List<WikiPage> wikiPages = gitLabApi.getWikisApi().getPages(testProjectId);
List<WikiPage> wikiPages = gitLabApi.getWikisApi().getPages(testProject);
assertNotNull(wikiPages);
wikiPages.stream().filter(wp -> wp.getSlug().equals(wikiPageSlug)).forEach(wp -> {
......@@ -182,8 +147,8 @@ public class TestWikisApi {
assertNotNull(createdWikiPage);
String wikiPageSlug = createdWikiPage.getSlug();
gitLabApi.getWikisApi().deletePage(testProjectId, wikiPageSlug);
List<WikiPage> wikiPages = gitLabApi.getWikisApi().getPages(testProjectId);
gitLabApi.getWikisApi().deletePage(testProject, wikiPageSlug);
List<WikiPage> wikiPages = gitLabApi.getWikisApi().getPages(testProject);
if (wikiPages.stream().anyMatch(wp -> wp.getSlug().equals(wikiPageSlug))) {
fail("WikiPage was not deleted.");
}
......@@ -196,7 +161,7 @@ public class TestWikisApi {
assertNotNull(wikiPage);
File attachFile = new File("README.md");
WikiAttachment attachment = gitLabApi.getWikisApi().uploadAttachment(testProjectId, attachFile);
WikiAttachment attachment = gitLabApi.getWikisApi().uploadAttachment(testProject, attachFile);
assertNotNull(attachment);
assertEquals("README.md", attachment.getFileName());
}
......@@ -208,7 +173,7 @@ public class TestWikisApi {
assertNotNull(wikiPage);
File attachFile = new File("README.md");
WikiAttachment attachment = gitLabApi.getWikisApi().uploadAttachment(testProjectId, attachFile, "master");
WikiAttachment attachment = gitLabApi.getWikisApi().uploadAttachment(testProject, attachFile, "master");
assertNotNull(attachment);
assertEquals("README.md", attachment.getFileName());
assertEquals("master", attachment.getBranch());
......
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