Commit cf5cb33a authored by Greg Messner's avatar Greg Messner
Browse files

Mods to support PropertyConstants and use of personal access tokens created by test setup (#311).

parent ea90e565
......@@ -2,6 +2,7 @@ package org.gitlab4j.api.utils;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.Scanner;
import javax.ws.rs.core.Response;
......@@ -75,4 +76,23 @@ public class FileUtils {
return (in.next());
}
}
/**
* Reads the content of a Reader instance and returns it as a String.
*
* @param reader
* @return the content of a Reader instance as a String
* @throws IOException
*/
public static String getReaderContentAsString(Reader reader) throws IOException {
int count;
final char[] buffer = new char[2048];
final StringBuilder out = new StringBuilder();
while ((count = reader.read(buffer, 0, buffer.length)) >= 0) {
out.append(buffer, 0, count);
}
return (out.toString());
}
}
......@@ -16,19 +16,13 @@ import org.gitlab4j.api.models.Project;
* TEST_HOST_URL
* TEST_PRIVATE_TOKEN
*/
public class AbstractIntegrationTest {
public class AbstractIntegrationTest implements PropertyConstants {
// Get the values of the minimum required test properties.
protected static final String TEST_PROJECT_NAME;
protected static final String TEST_NAMESPACE;
protected static final String TEST_HOST_URL;
protected 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");
}
protected static final String TEST_PROJECT_NAME = HelperUtils.getProperty(PROJECT_NAME_KEY);
protected static final String TEST_NAMESPACE = HelperUtils.getProperty(NAMESPACE_KEY);
protected static final String TEST_HOST_URL = HelperUtils.getProperty(HOST_URL_KEY);
protected static String TEST_PRIVATE_TOKEN;
protected static class BaseTestResources {
protected GitLabApi gitLabApi;
......@@ -76,6 +70,10 @@ public class AbstractIntegrationTest {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (TEST_PRIVATE_TOKEN == null) {
TEST_PRIVATE_TOKEN = HelperUtils.getProperty(PRIVATE_TOKEN_KEY);
}
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) {
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
}
......
package org.gitlab4j.api;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.Arrays;
import org.gitlab4j.api.utils.AccessTokenUtils;
import org.junit.BeforeClass;
import org.junit.experimental.categories.Categories.IncludeCategory;
import org.junit.runner.RunWith;
......@@ -10,14 +17,57 @@ import com.googlecode.junittoolbox.WildcardPatternSuite;
@RunWith(WildcardPatternSuite.class)
@SuiteClasses({"**/Test*.class"})
@IncludeCategory(IntegrationTest.class)
public class IntegrationTestSuite {
public class IntegrationTestSuite implements PropertyConstants {
private static final String TEST_LOGIN_USERNAME = HelperUtils.getProperty(LOGIN_USERNAME_KEY);
private static final String TEST_LOGIN_PASSWORD = HelperUtils.getProperty(LOGIN_PASSWORD_KEY);
private static final String TEST_HOST_URL = HelperUtils.getProperty(HOST_URL_KEY);
protected static final String TEST_PROJECT_NAME = HelperUtils.getProperty(PROJECT_NAME_KEY);
protected static final String TEST_NAMESPACE = HelperUtils.getProperty(NAMESPACE_KEY);
protected static String TEST_PRIVATE_TOKEN;
protected static String TEST_ACCESS_TOKEN;
private static String problems = "";
@BeforeClass
public static void suiteSetup() {
public static void suiteSetup() throws GitLabApiException {
System.out.println("********************************************************");
System.out.println(" Test Suite Setup");
System.out.println("* Test Suite Setup *");
System.out.println("********************************************************");
// TODO Create default test resources if not present
if (TEST_LOGIN_USERNAME == null || TEST_LOGIN_USERNAME.trim().isEmpty()) {
problems += "TEST_LOGIN_USERNAME cannot be empty\n";
}
if (TEST_LOGIN_PASSWORD == null || TEST_LOGIN_PASSWORD.trim().isEmpty()) {
problems += "TEST_LOGIN_PASSWORD cannot be empty\n";
}
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) {
problems += "TEST_HOST_URL cannot be empty\n";
}
if (!problems.isEmpty()) {
fail(problems);
}
// Create a new personal access token for both the private and access tokens
TEST_PRIVATE_TOKEN = AccessTokenUtils.createPersonalAccessToken(
TEST_HOST_URL, TEST_LOGIN_USERNAME, TEST_LOGIN_PASSWORD,
"GitLab4J Test Private Token", Arrays.asList("api", "sudo"));
System.out.println("Created private token: " + TEST_PRIVATE_TOKEN);
assertNotNull(TEST_PRIVATE_TOKEN);
assertFalse(TEST_PRIVATE_TOKEN.trim().isEmpty());
HelperUtils.setProperty(PRIVATE_TOKEN_KEY, TEST_PRIVATE_TOKEN);
TEST_ACCESS_TOKEN = AccessTokenUtils.createPersonalAccessToken(
TEST_HOST_URL, TEST_LOGIN_USERNAME, TEST_LOGIN_PASSWORD,
"GitLab4J Test Access Token", Arrays.asList("api", "sudo"));
System.out.println("Created private token: " + TEST_ACCESS_TOKEN);
assertNotNull(TEST_ACCESS_TOKEN);
assertFalse(TEST_ACCESS_TOKEN.trim().isEmpty());
HelperUtils.setProperty(ACCESS_TOKEN_KEY, TEST_ACCESS_TOKEN);
}
}
......@@ -25,7 +25,7 @@ import org.junit.experimental.categories.Category;
public class TestAccessToken extends AbstractIntegrationTest {
// TEST_ACCESS_TOKEN must be defined to run this test
private static final String TEST_ACCESS_TOKEN = TestUtils.getProperty("TEST_ACCESS_TOKEN");
private static final String TEST_ACCESS_TOKEN = HelperUtils.getProperty("TEST_ACCESS_TOKEN");
private static GitLabApi gitLabApi;
public TestAccessToken() {
......
......@@ -35,9 +35,9 @@ public class TestAvatarUpload extends AbstractIntegrationTest {
private static final String TEST_PROXY_USERNAME;
private static final String TEST_PROXY_PASSWORD;
static {
TEST_PROXY_URI = TestUtils.getProperty("TEST_PROXY_URI");
TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME");
TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD");
TEST_PROXY_URI = HelperUtils.getProperty("TEST_PROXY_URI");
TEST_PROXY_USERNAME = HelperUtils.getProperty("TEST_PROXY_USERNAME");
TEST_PROXY_PASSWORD = HelperUtils.getProperty("TEST_PROXY_PASSWORD");
}
private static final String AVATAR_FILENAME = "avatar.png";
......
......@@ -20,7 +20,7 @@ import org.junit.experimental.categories.Category;
public class TestDeployKeysApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME");
private static final String TEST_USERNAME = HelperUtils.getProperty(USERNAME_KEY);
private static GitLabApi gitLabApi;
......
......@@ -31,14 +31,9 @@ import org.junit.runners.MethodSorters;
public class TestFileUpload extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_PROXY_URI;
private static final String TEST_PROXY_USERNAME;
private static final String TEST_PROXY_PASSWORD;
static {
TEST_PROXY_URI = TestUtils.getProperty("TEST_PROXY_URI");
TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME");
TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD");
}
private static final String TEST_PROXY_URI = HelperUtils.getProperty("TEST_PROXY_URI");
private static final String TEST_PROXY_USERNAME = HelperUtils.getProperty("TEST_PROXY_USERNAME");
private static final String TEST_PROXY_PASSWORD = HelperUtils.getProperty("TEST_PROXY_PASSWORD");
private static GitLabApi gitLabApi;
......
......@@ -25,14 +25,9 @@ import org.junit.experimental.categories.Category;
public class TestGitLabApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_PROXY_URI;
private static final String TEST_PROXY_USERNAME;
private static final String TEST_PROXY_PASSWORD;
static {
TEST_PROXY_URI = TestUtils.getProperty("TEST_PROXY_URI");
TEST_PROXY_USERNAME = TestUtils.getProperty("TEST_PROXY_USERNAME");
TEST_PROXY_PASSWORD = TestUtils.getProperty("TEST_PROXY_PASSWORD");
}
private static final String TEST_PROXY_URI = HelperUtils.getProperty(PROXY_URI_KEY);
private static final String TEST_PROXY_USERNAME = HelperUtils.getProperty(PROXY_USERNAME_KEY);
private static final String TEST_PROXY_PASSWORD = HelperUtils.getProperty(PROXY_PASSWORD_KEY);
private static GitLabApi gitLabApi;
......
......@@ -23,19 +23,13 @@ import org.junit.experimental.categories.Category;
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(IntegrationTest.class)
public class TestGitLabLogin {
public class TestGitLabLogin implements PropertyConstants {
// The following needs to be set to your test repository
private static final String TEST_LOGIN_USERNAME;
private static final String TEST_LOGIN_PASSWORD;
private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN;
static {
TEST_LOGIN_USERNAME = TestUtils.getProperty("TEST_LOGIN_USERNAME");
TEST_LOGIN_PASSWORD = TestUtils.getProperty("TEST_LOGIN_PASSWORD");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
}
private static final String TEST_LOGIN_USERNAME = HelperUtils.getProperty(LOGIN_USERNAME_KEY);
private static final String TEST_LOGIN_PASSWORD = HelperUtils.getProperty(LOGIN_PASSWORD_KEY);
private static final String TEST_HOST_URL = HelperUtils.getProperty(HOST_URL_KEY);
private static final String TEST_PRIVATE_TOKEN = HelperUtils.getProperty(PRIVATE_TOKEN_KEY);
private static String problems = "";
private static boolean hasSession;
......
......@@ -38,14 +38,9 @@ import org.junit.experimental.categories.Category;
public class TestGroupApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_USERNAME;
private static final String TEST_GROUP;
private static final String TEST_GROUP_MEMBER_USERNAME;
static {
TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME");
TEST_GROUP = TestUtils.getProperty("TEST_GROUP");
TEST_GROUP_MEMBER_USERNAME = TestUtils.getProperty("TEST_GROUP_MEMBER_USERNAME");
}
private static final String TEST_USERNAME = HelperUtils.getProperty(USERNAME_KEY);
private static final String TEST_GROUP = HelperUtils.getProperty(GROUP_KEY);
private static final String TEST_GROUP_MEMBER_USERNAME = HelperUtils.getProperty(GROUP_MEMBER_USERNAME_KEY);
private static GitLabApi gitLabApi;
private static Group testGroup;
......
......@@ -19,15 +19,11 @@ import org.junit.experimental.categories.Category;
*
*/
@Category(IntegrationTest.class)
public class TestHealthCheckApi {
public class TestHealthCheckApi implements PropertyConstants {
// The following needs to be set to your test repository
private static final String TEST_HOST_URL;
private static final String TEST_HEALTH_CHECK_TOKEN;
static {
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_HEALTH_CHECK_TOKEN = TestUtils.getProperty("TEST_HEALTH_CHECK_TOKEN");
}
private static final String TEST_HOST_URL = HelperUtils.getProperty(HOST_URL_KEY);
private static final String TEST_HEALTH_CHECK_TOKEN = HelperUtils.getProperty(HEALTH_CHECK_TOKEN_KEY);
private static GitLabApi gitLabApi;
......
......@@ -22,15 +22,11 @@ import org.junit.experimental.categories.Category;
*
*/
@Category(IntegrationTest.class)
public class TestIgnoreCertificateErrors {
public class TestIgnoreCertificateErrors implements PropertyConstants {
// The following needs to be set to your test repository
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 final String TEST_HOST_URL = HelperUtils.getProperty(HOST_URL_KEY);
private static final String TEST_PRIVATE_TOKEN = HelperUtils.getProperty(PRIVATE_TOKEN_KEY);
private static boolean setupOk;
......
......@@ -34,7 +34,7 @@ import org.junit.runners.MethodSorters;
public class TestNotificationSettingsApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_GROUP = TestUtils.getProperty("TEST_GROUP");
private static final String TEST_GROUP = HelperUtils.getProperty(GROUP_KEY);
private static GitLabApi gitLabApi;
......
......@@ -70,14 +70,9 @@ import org.junit.runners.MethodSorters;
public class TestProjectApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
private static final String TEST_GROUP;
private static final String TEST_GROUP_PROJECT;
private static final String TEST_XFER_NAMESPACE;
static {
TEST_GROUP = TestUtils.getProperty("TEST_GROUP");
TEST_GROUP_PROJECT = TestUtils.getProperty("TEST_GROUP_PROJECT");
TEST_XFER_NAMESPACE = TestUtils.getProperty("TEST_XFER_NAMESPACE");
}
private static final String TEST_GROUP = HelperUtils.getProperty(GROUP_KEY);
private static final String TEST_GROUP_PROJECT = HelperUtils.getProperty(GROUP_PROJECT_KEY);
private static final String TEST_XFER_NAMESPACE = HelperUtils.getProperty(XFER_NAMESPACE_KEY);
private static final String TEST_PROJECT_NAME_1 = "test-gitlab4j-create-project";
private static final String TEST_PROJECT_NAME_2 = "test-gitlab4j-create-project-2";
......@@ -590,8 +585,8 @@ public class TestProjectApi extends AbstractIntegrationTest {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
assertNotNull(project);
String key = TEST_VARIABLE_KEY_PREFIX + TestUtils.getRandomInt() + "_" + TestUtils.getRandomInt();
String value = "TEST_VARIABLE_VALUE_" + TestUtils.getRandomInt() + "_" + TestUtils.getRandomInt();
String key = TEST_VARIABLE_KEY_PREFIX + HelperUtils.getRandomInt() + "_" + HelperUtils.getRandomInt();
String value = "TEST_VARIABLE_VALUE_" + HelperUtils.getRandomInt() + "_" + HelperUtils.getRandomInt();
Variable variable = gitLabApi.getProjectApi().createVariable(project, key, value, null, null);
assertNotNull(variable);
......
......@@ -56,7 +56,7 @@ import org.junit.rules.TemporaryFolder;
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(IntegrationTest.class)
public class TestRequestResponseLogging {
public class TestRequestResponseLogging implements PropertyConstants {
@ClassRule
public final static SystemErrRule systemErrorRule = new SystemErrRule().enableLog();
......@@ -66,12 +66,8 @@ public class TestRequestResponseLogging {
// The following needs to be set to your test repository
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 final String TEST_HOST_URL = HelperUtils.getProperty(HOST_URL_KEY);
private static final String TEST_PRIVATE_TOKEN = HelperUtils.getProperty(PRIVATE_TOKEN_KEY);
private static GitLabApi gitLabApiWithEntityLogging;
private static GitLabApi gitLabApiNoEntityLogging;
......
......@@ -46,25 +46,21 @@ import org.junit.experimental.categories.Category;
*
*/
@Category(IntegrationTest.class)
public class TestUserApi extends AbstractIntegrationTest {
public class TestUserApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
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_USERNAME = TestUtils.getProperty("TEST_USERNAME");
TEST_BLOCK_USERNAME = TestUtils.getProperty("TEST_BLOCK_USERNAME");
TEST_SUDO_AS_USERNAME = TestUtils.getProperty("TEST_SUDO_AS_USERNAME");
TEST_SSH_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvbkmGRaANy2nmLrfYa9LkjMqjs9twYZXQKUPK18j" +
"BWmNgnAm818IikxjfFit3Gqnnh9zdNzlzUYs2osmfdHwRLeFY3hKVR6WckGYVroQuV5ArUA4+oME+IIQ2soCv/" +
"vNWfEmp2N1mpBTwi2mIYKurCKv6UpIpGK9D+ezNk5H0waVTK8EvZ/ey69Nu7C7RsbTYeyi5WY/jaUG5JbsEeKY" +
"IW/2DIlUts7gcB2hzXtt7r7+6DLx82Vb+S2jPZu2JQaB4zfgS7LQgzHUy1aAAgUUpuAbvWzuGHKO0p551Ru4qi" +
"tyXN2+OUVXcYAsuIIdGGB0wLvTDgiOOSZWnSE+sg6XX user@example.com";
}
private static final String TEST_USERNAME = HelperUtils.getProperty(USERNAME_KEY);
private static final String TEST_BLOCK_USERNAME = HelperUtils.getProperty(BLOCK_USERNAME_KEY);
private static final String TEST_SUDO_AS_USERNAME = HelperUtils.getProperty(SUDO_AS_USERNAME_KEY);
private static final String TEST_IMPERSONATION_TOKEN_NAME = "token1";
private static final String TEST_SSH_KEY =
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvbkmGRaANy2nmLrfYa9LkjMqjs9twYZXQKUPK18j" +
"BWmNgnAm818IikxjfFit3Gqnnh9zdNzlzUYs2osmfdHwRLeFY3hKVR6WckGYVroQuV5ArUA4+oME+IIQ2soCv/" +
"vNWfEmp2N1mpBTwi2mIYKurCKv6UpIpGK9D+ezNk5H0waVTK8EvZ/ey69Nu7C7RsbTYeyi5WY/jaUG5JbsEeKY" +
"IW/2DIlUts7gcB2hzXtt7r7+6DLx82Vb+S2jPZu2JQaB4zfgS7LQgzHUy1aAAgUUpuAbvWzuGHKO0p551Ru4qi" +
"tyXN2+OUVXcYAsuIIdGGB0wLvTDgiOOSZWnSE+sg6XX user@example.com";
private static GitLabApi gitLabApi;
private static User blockUser;
......
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