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