-
Notifications
You must be signed in to change notification settings - Fork 775
Expand file tree
/
Copy pathGHTeamUpdateBuilderTest.java
More file actions
120 lines (100 loc) · 4.97 KB
/
GHTeamUpdateBuilderTest.java
File metadata and controls
120 lines (100 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package org.kohsuke.github;
import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
// TODO: Auto-generated Javadoc
/**
* The Class GHTeamUpdateBuilderTest.
*
* @author Rory Kelly
*/
public class GHTeamUpdateBuilderTest extends AbstractGitHubWireMockTest {
private static final String TEAM_TO_UPDATE_SLUG = "dummy-team-to-update";
private static final String TEAM_TO_UPDATE_NEW_NAME = "dummy-team-updated";
private static final String TEAM_TO_UPDATE_NEW_DESCRIPTION = "This is an updated description!";
private static final GHTeam.Privacy TEAM_TO_UPDATE_NEW_PRIVACY = GHTeam.Privacy.SECRET;
private static final GHTeam.NotificationSetting TEAM_TO_UPDATE_NEW_NOTIFICATIONS = GHTeam.NotificationSetting.NOTIFICATIONS_DISABLED;
@Deprecated
private static final GHOrganization.Permission TEAM_TO_UPDATE_NEW_PERMISSIONS = GHOrganization.Permission.PUSH;
// private static final String CURRENT_PARENT_TEAM_SLUG = "dummy-current-parent-team";
private static final String NEW_PARENT_TEAM_SLUG = "dummy-new-parent-team";
/**
* Create default GHTeamBuilderTest instance
*/
public GHTeamUpdateBuilderTest() {
}
/**
* Given a team, when updating the team with a different parent team, then the team is updated with the new parent team.
* @throws IOException exception thrown if there is an issue with Wiremock
*/
@Test
public void testUpdateTeamWithNewParentTeam() throws IOException {
// Get the org and teams
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam teamToUpdate = org.getTeamBySlug(TEAM_TO_UPDATE_SLUG);
GHTeam newParentTeam = org.getTeamBySlug(NEW_PARENT_TEAM_SLUG);
// Update team with different parent team
GHTeam updatedTeam = getCommonBuilder(teamToUpdate)
.parentTeamId(newParentTeam.getId())
.update();
assertUpdatedTeam(updatedTeam);
// assertThat(updatedTeam.getParentTeam().getId(), equalTo(newParentTeam.getId()));
}
/**
* Given a team, when updating the team with no change to parent team, then the team is updated with no change to the parent team.
* @throws IOException exception thrown if there is an issue with Wiremock
*/
@Test
public void testUpdateTeamWithNoChangeToParentTeam() throws IOException {
// Get the org and team
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam teamToUpdate = org.getTeamBySlug(TEAM_TO_UPDATE_SLUG);
// GHTeam existingParentTeam = org.getTeamBySlug(CURRENT_PARENT_TEAM_SLUG);
// update team with no change to parent team
GHTeam updatedTeam = getCommonBuilder(teamToUpdate).update();
assertUpdatedTeam(updatedTeam);
// assertThat(teamToUpdate.getParentTeam().getId(), equalTo(existingParentTeam.getId()));
}
/**
* Given a team, when updating the team with a removed parent team, then the team is updated and has no parent team.
* @throws IOException exception thrown if there is an issue with Wiremock
*/
@Test
public void testUpdateTeamWithRemovedParentTeam() throws IOException {
// Get the org and team
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam teamToUpdate = org.getTeamBySlug(TEAM_TO_UPDATE_SLUG);
// Update team with removed parent team
GHTeam updatedTeam = getCommonBuilder(teamToUpdate)
.parentTeamId(null)
.update();
assertUpdatedTeam(updatedTeam);
// assertThat(teamToUpdate.getParentTeam(), equalTo(null));
}
/**
* Get the GHTeamUpdateBuilder instance with the common fields set for updating a team, to be used in the different update scenarios.
*
* @param teamToUpdate the base team to update
* @return the GHTeamUpdateBuilder instance with the common fields set for updating a team
*/
private GHTeamUpdateBuilder getCommonBuilder(GHTeam teamToUpdate) {
return teamToUpdate.updateTeam()
.name(TEAM_TO_UPDATE_NEW_NAME)
.description(TEAM_TO_UPDATE_NEW_DESCRIPTION)
.privacy(TEAM_TO_UPDATE_NEW_PRIVACY)
.notifications(TEAM_TO_UPDATE_NEW_NOTIFICATIONS)
.permission(TEAM_TO_UPDATE_NEW_PERMISSIONS);
}
/**
* Assert that the updated team has the expected updated values.
*
* @param updatedTeam the team to assert the updated values on
*/
private void assertUpdatedTeam(GHTeam updatedTeam) {
assertThat(updatedTeam.getName(), equalTo(TEAM_TO_UPDATE_NEW_NAME));
assertThat(updatedTeam.getDescription(), equalTo(TEAM_TO_UPDATE_NEW_DESCRIPTION));
assertThat(updatedTeam.getPrivacy(), equalTo(TEAM_TO_UPDATE_NEW_PRIVACY));
// assertThat(updatedTeam.getNotificationSetting(), equalTo(TEAM_TO_UPDATE_NEW_NOTIFICATIONS));
assertThat(updatedTeam.getPermission(), equalTo(TEAM_TO_UPDATE_NEW_PERMISSIONS));
}
}