From 0189b8720f1298d75d4b22847a02c73c95dfb425 Mon Sep 17 00:00:00 2001 From: Greg Messner Date: Sat, 15 Jun 2019 21:41:06 -0700 Subject: [PATCH] Added testing of sub groups. --- .../gitlab4j/api/AbstractIntegrationTest.java | 1 + .../org/gitlab4j/api/IntegrationTestSuite.java | 16 ++++++++++++++++ .../java/org/gitlab4j/api/PropertyConstants.java | 3 ++- .../java/org/gitlab4j/api/TestNamespaceApi.java | 7 +++++++ src/test/resources/test-gitlab4j.properties | 3 ++- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/gitlab4j/api/AbstractIntegrationTest.java b/src/test/java/org/gitlab4j/api/AbstractIntegrationTest.java index ab285f49..e4427b49 100644 --- a/src/test/java/org/gitlab4j/api/AbstractIntegrationTest.java +++ b/src/test/java/org/gitlab4j/api/AbstractIntegrationTest.java @@ -28,6 +28,7 @@ public class AbstractIntegrationTest implements PropertyConstants { protected static final String TEST_GROUP_PROJECT_NAME = HelperUtils.getProperty(GROUP_PROJECT_KEY); protected static final String TEST_NAMESPACE = HelperUtils.getProperty(NAMESPACE_KEY, TEST_LOGIN_USERNAME); protected static final String TEST_PRIVATE_TOKEN = HelperUtils.getProperty(PRIVATE_TOKEN_KEY); + protected static final String TEST_SUB_GROUP = HelperUtils.getProperty(SUB_GROUP_KEY); protected static class BaseTestResources { protected GitLabApi gitLabApi; diff --git a/src/test/java/org/gitlab4j/api/IntegrationTestSuite.java b/src/test/java/org/gitlab4j/api/IntegrationTestSuite.java index 6f1cd5ab..85bd1325 100644 --- a/src/test/java/org/gitlab4j/api/IntegrationTestSuite.java +++ b/src/test/java/org/gitlab4j/api/IntegrationTestSuite.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.util.Arrays; +import java.util.List; import java.util.Optional; import org.gitlab4j.api.models.Group; @@ -42,6 +43,7 @@ public class IntegrationTestSuite implements PropertyConstants { private static final String TEST_PROJECT_NAME = HelperUtils.getProperty(PROJECT_NAME_KEY); private static final String TEST_GROUP = HelperUtils.getProperty(GROUP_KEY); private static final String TEST_GROUP_PROJECT_NAME = HelperUtils.getProperty(GROUP_PROJECT_KEY); + private static final String TEST_SUB_GROUP = HelperUtils.getProperty(SUB_GROUP_KEY); protected static final String TEST_PRIVATE_TOKEN_NAME = "GitLab4J Test Private Token - " + HelperUtils.getRandomInt(1000); protected static String TEST_PRIVATE_TOKEN = HelperUtils.getProperty(PRIVATE_TOKEN_KEY); @@ -283,5 +285,19 @@ public class IntegrationTestSuite implements PropertyConstants { gitLabApi.getRepositoryFileApi().updateFile(testProject, repoFile, "master", "Updated contents"); System.out.format("Updated %s repository file in %s%n", repoFile.getFilePath(), TEST_GROUP_PROJECT_NAME); } + + // Create a subgroup + List subGroups = gitLabApi.getGroupApi().getSubGroups(TEST_GROUP, null, null, TEST_SUB_GROUP, null, null, null, null); + if (subGroups.isEmpty()) { + Group groupSettings = new Group() + .withName(TEST_SUB_GROUP) + .withPath(TEST_SUB_GROUP) + .withDescription("Test Sub-Group") + .withVisibility(Visibility.PUBLIC) + .withRequestAccessEnabled(true) + .withParentId(testGroup.getId()); + Group testSubGroup = gitLabApi.getGroupApi().addGroup(groupSettings); + System.out.format("Created %s sub-group (%s)%n", testSubGroup.getName(), testSubGroup.getPath()); + } } } diff --git a/src/test/java/org/gitlab4j/api/PropertyConstants.java b/src/test/java/org/gitlab4j/api/PropertyConstants.java index b5430b3c..5a7c7f0d 100644 --- a/src/test/java/org/gitlab4j/api/PropertyConstants.java +++ b/src/test/java/org/gitlab4j/api/PropertyConstants.java @@ -23,8 +23,9 @@ public interface PropertyConstants { public static final String PROXY_PASSWORD_KEY = "TEST_PROXY_PASSWORD"; public static final String PROXY_URI_KEY = "TEST_PROXY_URI"; public static final String PROXY_USERNAME_KEY = "TEST_PROXY_USERNAME"; - public static final String TEST_REQUEST_ACCESS_USERNAME_KEY = "TEST_REQUEST_ACCESS_USERNAME"; + public static final String SUB_GROUP_KEY = "TEST_SUB_GROUP"; public static final String SUDO_AS_USERNAME_KEY = "TEST_SUDO_AS_USERNAME"; + public static final String TEST_REQUEST_ACCESS_USERNAME_KEY = "TEST_REQUEST_ACCESS_USERNAME"; public static final String USERNAME_KEY = "TEST_USERNAME"; public static final String XFER_NAMESPACE_KEY = "TEST_XFER_NAMESPACE"; } diff --git a/src/test/java/org/gitlab4j/api/TestNamespaceApi.java b/src/test/java/org/gitlab4j/api/TestNamespaceApi.java index 42727a88..f7e42f91 100644 --- a/src/test/java/org/gitlab4j/api/TestNamespaceApi.java +++ b/src/test/java/org/gitlab4j/api/TestNamespaceApi.java @@ -90,6 +90,13 @@ public class TestNamespaceApi extends AbstractIntegrationTest { assertEquals(TEST_NAMESPACE, namespaces.get(0).getName()); } + @Test + public void testFindSubgroupNamespaces() throws GitLabApiException { + List namespaces = gitLabApi.getNamespaceApi().findNamespaces(TEST_SUB_GROUP); + assertNotNull(namespaces); + assertEquals(TEST_SUB_GROUP, namespaces.get(0).getName()); + } + @Test public void testFindNamespacesByPage() throws GitLabApiException { List namespaces = gitLabApi.getNamespaceApi().findNamespaces(TEST_NAMESPACE, 1, 10); diff --git a/src/test/resources/test-gitlab4j.properties b/src/test/resources/test-gitlab4j.properties index 0b10bfd7..794cf038 100644 --- a/src/test/resources/test-gitlab4j.properties +++ b/src/test/resources/test-gitlab4j.properties @@ -36,11 +36,12 @@ TEST_BLOCK_USERNAME=user1 TEST_XFER_NAMESPACE=user1 TEST_REQUEST_ACCESS_USERNAME=user1 -# This specifies the group, a project owned by the specified group, and a username to +# This specifies the group, a project owned by the specified group, a username, and a sub-group to # test group membership functionality TEST_GROUP=test-group TEST_GROUP_PROJECT=test-group-project TEST_GROUP_MEMBER_USERNAME=user1 +TEST_SUB_GROUP=subgroup # OPTIONAL: To test using GitLab4J-API with a proxy, set the following properties TEST_PROXY_URI= -- GitLab