|
| 1 | +package org.kohsuke.github; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import java.io.IOException; |
| 6 | + |
| 7 | +import static org.hamcrest.Matchers.equalTo; |
| 8 | + |
| 9 | +// TODO: Auto-generated Javadoc |
| 10 | + |
| 11 | +/** |
| 12 | + * The Class GHTeamUpdateBuilderTest. |
| 13 | + * |
| 14 | + * @author Rory Kelly |
| 15 | + */ |
| 16 | +public class GHTeamUpdateBuilderTest extends AbstractGitHubWireMockTest { |
| 17 | + |
| 18 | + private static final String TEAM_TO_UPDATE_SLUG = "dummy-team-to-update"; |
| 19 | + |
| 20 | + private static final String TEAM_TO_UPDATE_NEW_NAME = "dummy-team-updated"; |
| 21 | + private static final String TEAM_TO_UPDATE_NEW_DESCRIPTION = "This is an updated description!"; |
| 22 | + private static final GHTeam.Privacy TEAM_TO_UPDATE_NEW_PRIVACY = GHTeam.Privacy.SECRET; |
| 23 | + private static final GHTeam.NotificationSetting TEAM_TO_UPDATE_NEW_NOTIFICATIONS = GHTeam.NotificationSetting.NOTIFICATIONS_DISABLED; |
| 24 | + @Deprecated |
| 25 | + private static final GHOrganization.Permission TEAM_TO_UPDATE_NEW_PERMISSIONS = GHOrganization.Permission.PUSH; |
| 26 | + |
| 27 | + // private static final String CURRENT_PARENT_TEAM_SLUG = "dummy-current-parent-team"; |
| 28 | + private static final String NEW_PARENT_TEAM_SLUG = "dummy-new-parent-team"; |
| 29 | + |
| 30 | + /** |
| 31 | + * Create default GHTeamBuilderTest instance |
| 32 | + */ |
| 33 | + public GHTeamUpdateBuilderTest() { |
| 34 | + } |
| 35 | + |
| 36 | + // update name, description, privacy, notifications, permission, no change to parent team |
| 37 | + // update parent team |
| 38 | + // update removal of parent team |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testUpdateTeamWithNewParentTeam() throws IOException { |
| 42 | + // Get the parent team |
| 43 | + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); |
| 44 | + GHTeam teamToUpdate = org.getTeamBySlug(TEAM_TO_UPDATE_SLUG); |
| 45 | + GHTeam newParentTeam = org.getTeamBySlug(NEW_PARENT_TEAM_SLUG); |
| 46 | + |
| 47 | + GHTeam updatedTeam = getCommonBuilder(teamToUpdate) |
| 48 | + .parentTeamId(newParentTeam.getId()) |
| 49 | + .update(); |
| 50 | + |
| 51 | + assertUpdatedTeam(updatedTeam); |
| 52 | + // assertThat(updatedTeam.getParentTeam().getId(), equalTo(newParentTeam.getId())); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testUpdateTeamWithNoChangeToParentTeam() throws IOException { |
| 57 | + // Get the parent team |
| 58 | + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); |
| 59 | + GHTeam teamToUpdate = org.getTeamBySlug(TEAM_TO_UPDATE_SLUG); |
| 60 | + // GHTeam existingParentTeam = org.getTeamBySlug(CURRENT_PARENT_TEAM_SLUG); |
| 61 | + |
| 62 | + GHTeam updatedTeam = getCommonBuilder(teamToUpdate).update(); |
| 63 | + |
| 64 | + assertUpdatedTeam(updatedTeam); |
| 65 | + // assertThat(teamToUpdate.getParentTeam().getId(), equalTo(existingParentTeam.getId())); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testUpdateTeamWithRemovedParentTeam() throws IOException { |
| 70 | + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); |
| 71 | + GHTeam teamToUpdate = org.getTeamBySlug(TEAM_TO_UPDATE_SLUG); |
| 72 | + |
| 73 | + GHTeam updatedTeam = getCommonBuilder(teamToUpdate) |
| 74 | + .parentTeamId(null) |
| 75 | + .update(); |
| 76 | + |
| 77 | + assertUpdatedTeam(updatedTeam); |
| 78 | + // assertThat(teamToUpdate.getParentTeam(), equalTo(null)); |
| 79 | + } |
| 80 | + |
| 81 | + private GHTeamUpdateBuilder getCommonBuilder(GHTeam teamToUpdate) { |
| 82 | + return teamToUpdate.updateTeam() |
| 83 | + .name(TEAM_TO_UPDATE_NEW_NAME) |
| 84 | + .description(TEAM_TO_UPDATE_NEW_DESCRIPTION) |
| 85 | + .privacy(TEAM_TO_UPDATE_NEW_PRIVACY) |
| 86 | + .notifications(TEAM_TO_UPDATE_NEW_NOTIFICATIONS) |
| 87 | + .permission(TEAM_TO_UPDATE_NEW_PERMISSIONS); |
| 88 | + } |
| 89 | + |
| 90 | + private void assertUpdatedTeam(GHTeam updatedTeam) { |
| 91 | + assertThat(updatedTeam.getName(), equalTo(TEAM_TO_UPDATE_NEW_NAME)); |
| 92 | + assertThat(updatedTeam.getDescription(), equalTo(TEAM_TO_UPDATE_NEW_DESCRIPTION)); |
| 93 | + assertThat(updatedTeam.getPrivacy(), equalTo(TEAM_TO_UPDATE_NEW_PRIVACY)); |
| 94 | + // assertThat(updatedTeam.getNotificationSetting(), equalTo(TEAM_TO_UPDATE_NEW_NOTIFICATIONS)); |
| 95 | + assertThat(updatedTeam.getPermission(), equalTo(TEAM_TO_UPDATE_NEW_PERMISSIONS)); |
| 96 | + } |
| 97 | +} |
0 commit comments