Skip to content

Commit 0189b87

Browse files
committed
Added testing of sub groups.
1 parent 85631bb commit 0189b87

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

src/test/java/org/gitlab4j/api/AbstractIntegrationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class AbstractIntegrationTest implements PropertyConstants {
2828
protected static final String TEST_GROUP_PROJECT_NAME = HelperUtils.getProperty(GROUP_PROJECT_KEY);
2929
protected static final String TEST_NAMESPACE = HelperUtils.getProperty(NAMESPACE_KEY, TEST_LOGIN_USERNAME);
3030
protected static final String TEST_PRIVATE_TOKEN = HelperUtils.getProperty(PRIVATE_TOKEN_KEY);
31+
protected static final String TEST_SUB_GROUP = HelperUtils.getProperty(SUB_GROUP_KEY);
3132

3233
protected static class BaseTestResources {
3334
protected GitLabApi gitLabApi;

src/test/java/org/gitlab4j/api/IntegrationTestSuite.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.junit.Assert.fail;
66

77
import java.util.Arrays;
8+
import java.util.List;
89
import java.util.Optional;
910

1011
import org.gitlab4j.api.models.Group;
@@ -42,6 +43,7 @@ public class IntegrationTestSuite implements PropertyConstants {
4243
private static final String TEST_PROJECT_NAME = HelperUtils.getProperty(PROJECT_NAME_KEY);
4344
private static final String TEST_GROUP = HelperUtils.getProperty(GROUP_KEY);
4445
private static final String TEST_GROUP_PROJECT_NAME = HelperUtils.getProperty(GROUP_PROJECT_KEY);
46+
private static final String TEST_SUB_GROUP = HelperUtils.getProperty(SUB_GROUP_KEY);
4547

4648
protected static final String TEST_PRIVATE_TOKEN_NAME = "GitLab4J Test Private Token - " + HelperUtils.getRandomInt(1000);
4749
protected static String TEST_PRIVATE_TOKEN = HelperUtils.getProperty(PRIVATE_TOKEN_KEY);
@@ -283,5 +285,19 @@ private static void seedData() throws GitLabApiException {
283285
gitLabApi.getRepositoryFileApi().updateFile(testProject, repoFile, "master", "Updated contents");
284286
System.out.format("Updated %s repository file in %s%n", repoFile.getFilePath(), TEST_GROUP_PROJECT_NAME);
285287
}
288+
289+
// Create a subgroup
290+
List<Group> subGroups = gitLabApi.getGroupApi().getSubGroups(TEST_GROUP, null, null, TEST_SUB_GROUP, null, null, null, null);
291+
if (subGroups.isEmpty()) {
292+
Group groupSettings = new Group()
293+
.withName(TEST_SUB_GROUP)
294+
.withPath(TEST_SUB_GROUP)
295+
.withDescription("Test Sub-Group")
296+
.withVisibility(Visibility.PUBLIC)
297+
.withRequestAccessEnabled(true)
298+
.withParentId(testGroup.getId());
299+
Group testSubGroup = gitLabApi.getGroupApi().addGroup(groupSettings);
300+
System.out.format("Created %s sub-group (%s)%n", testSubGroup.getName(), testSubGroup.getPath());
301+
}
286302
}
287303
}

src/test/java/org/gitlab4j/api/PropertyConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public interface PropertyConstants {
2323
public static final String PROXY_PASSWORD_KEY = "TEST_PROXY_PASSWORD";
2424
public static final String PROXY_URI_KEY = "TEST_PROXY_URI";
2525
public static final String PROXY_USERNAME_KEY = "TEST_PROXY_USERNAME";
26-
public static final String TEST_REQUEST_ACCESS_USERNAME_KEY = "TEST_REQUEST_ACCESS_USERNAME";
26+
public static final String SUB_GROUP_KEY = "TEST_SUB_GROUP";
2727
public static final String SUDO_AS_USERNAME_KEY = "TEST_SUDO_AS_USERNAME";
28+
public static final String TEST_REQUEST_ACCESS_USERNAME_KEY = "TEST_REQUEST_ACCESS_USERNAME";
2829
public static final String USERNAME_KEY = "TEST_USERNAME";
2930
public static final String XFER_NAMESPACE_KEY = "TEST_XFER_NAMESPACE";
3031
}

src/test/java/org/gitlab4j/api/TestNamespaceApi.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ public void testFindNamespaces() throws GitLabApiException {
9090
assertEquals(TEST_NAMESPACE, namespaces.get(0).getName());
9191
}
9292

93+
@Test
94+
public void testFindSubgroupNamespaces() throws GitLabApiException {
95+
List<Namespace> namespaces = gitLabApi.getNamespaceApi().findNamespaces(TEST_SUB_GROUP);
96+
assertNotNull(namespaces);
97+
assertEquals(TEST_SUB_GROUP, namespaces.get(0).getName());
98+
}
99+
93100
@Test
94101
public void testFindNamespacesByPage() throws GitLabApiException {
95102
List<Namespace> namespaces = gitLabApi.getNamespaceApi().findNamespaces(TEST_NAMESPACE, 1, 10);

src/test/resources/test-gitlab4j.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ TEST_BLOCK_USERNAME=user1
3636
TEST_XFER_NAMESPACE=user1
3737
TEST_REQUEST_ACCESS_USERNAME=user1
3838

39-
# This specifies the group, a project owned by the specified group, and a username to
39+
# This specifies the group, a project owned by the specified group, a username, and a sub-group to
4040
# test group membership functionality
4141
TEST_GROUP=test-group
4242
TEST_GROUP_PROJECT=test-group-project
4343
TEST_GROUP_MEMBER_USERNAME=user1
44+
TEST_SUB_GROUP=subgroup
4445

4546
# OPTIONAL: To test using GitLab4J-API with a proxy, set the following properties
4647
TEST_PROXY_URI=

0 commit comments

Comments
 (0)