@@ -59,15 +59,23 @@ public void beforeMethod() {
5959 public void testAddSystemHook () throws GitLabApiException {
6060
6161 SystemHook hook = gitLabApi .getSystemHooksApi ().addSystemHook (TEST_HOOK_URL , TEST_SECRET_TOKEN , true , false , true );
62- assertNotNull (hook );
63- assertEquals (TEST_HOOK_URL , hook .getUrl ());
64- assertTrue (hook .getPushEvents ());
65- assertFalse (hook .getTagPushEvents ());
66- assertFalse (hook .getMergeRequestsEvents ());
67- assertTrue (hook .getRepositoryUpdateEvents ());
68- assertTrue (hook .getEnableSslVerification ());
69-
70- gitLabApi .getSystemHooksApi ().deleteSystemHook (hook );
62+ try {
63+ assertNotNull (hook );
64+ assertEquals (TEST_HOOK_URL , hook .getUrl ());
65+ assertTrue (hook .getPushEvents ());
66+ assertFalse (hook .getTagPushEvents ());
67+ assertFalse (hook .getMergeRequestsEvents ());
68+
69+ // TODO: Attribute "repository_update_events" is not being honored by GitLab API as per issue
70+ // https://gitlab.com/gitlab-org/gitlab/-/issues/335129
71+ // Revisit and update this test if/when the GitLab API/documentation is fixed
72+ assertTrue (hook .getRepositoryUpdateEvents ());
73+
74+ assertTrue (hook .getEnableSslVerification ());
75+ } finally {
76+ // Ensure we remove the hook we added even if we had failures
77+ gitLabApi .getSystemHooksApi ().deleteSystemHook (hook );
78+ }
7179
7280 hook .withPushEvents (false )
7381 .withTagPushEvents (true )
@@ -76,15 +84,23 @@ public void testAddSystemHook() throws GitLabApiException {
7684 .withEnableSslVerification (false );
7785
7886 SystemHook updatedHook = gitLabApi .getSystemHooksApi ().addSystemHook (TEST_HOOK_URL , TEST_SECRET_TOKEN , hook );
79- assertNotNull (updatedHook );
80- assertEquals (TEST_HOOK_URL , updatedHook .getUrl ());
81- assertFalse (hook .getPushEvents ());
82- assertTrue (hook .getTagPushEvents ());
83- assertTrue (hook .getMergeRequestsEvents ());
84- assertFalse (hook .getRepositoryUpdateEvents ());
85- assertFalse (hook .getEnableSslVerification ());
86-
87- gitLabApi .getSystemHooksApi ().deleteSystemHook (updatedHook );
87+ try {
88+ assertNotNull (updatedHook );
89+ assertEquals (TEST_HOOK_URL , updatedHook .getUrl ());
90+ assertFalse (updatedHook .getPushEvents ());
91+ assertTrue (updatedHook .getTagPushEvents ());
92+ assertTrue (updatedHook .getMergeRequestsEvents ());
93+
94+ // TODO: Attribute "repository_update_events" is not being honored by GitLab API as per issue
95+ // https://gitlab.com/gitlab-org/gitlab/-/issues/335129
96+ // Revisit and update this test if/when the GitLab API/documentation is fixed
97+ assertTrue (updatedHook .getRepositoryUpdateEvents ());
98+
99+ assertFalse (updatedHook .getEnableSslVerification ());
100+ } finally {
101+ // Ensure we remove the hook we added even if we had failures
102+ gitLabApi .getSystemHooksApi ().deleteSystemHook (updatedHook );
103+ }
88104
89105 }
90106
0 commit comments