Skip to content

Commit 1f1deb7

Browse files
committed
Add API classes to manage bitbucket endpoints and hide the internal implementations
1 parent 49a2195 commit 1f1deb7

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketCloudEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public BitbucketCloudEndpoint(boolean enableCache, int teamCacheDuration, int re
9595
* credentials to use for auto-management of hooks.
9696
* @param enableHookSignature {@code true} hooks that comes Bitbucket Data
9797
* Center are signed.
98-
* @param credentialsId The {@link StringCredentials#getId()} of the
98+
* @param hookSignatureCredentialsId The {@link StringCredentials#getId()} of the
9999
* credentials to use for verify the signature of payload.
100100
*/
101101
@DataBoundConstructor

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketEndpointConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import jenkins.model.GlobalConfiguration;
4747
import jenkins.model.Jenkins;
4848
import net.sf.json.JSONObject;
49+
import org.apache.commons.collections.CollectionUtils;
4950
import org.apache.commons.lang3.StringUtils;
5051
import org.kohsuke.accmod.Restricted;
5152
import org.kohsuke.accmod.restrictions.NoExternalUse;
@@ -157,7 +158,7 @@ public List<BitbucketEndpoint> getEndpoints() {
157158
// TODO should we add a Jenkins.get().checkPermission(Jenkins.READ); ?
158159
// make a local copy so if changes in meanwhile you do not get NPE
159160
List<BitbucketEndpoint> localEndpoints = this.endpoints;
160-
return localEndpoints == null || localEndpoints.isEmpty()
161+
return CollectionUtils.isEmpty(localEndpoints)
161162
? List.of(new BitbucketCloudEndpoint())
162163
: Collections.unmodifiableList(localEndpoints);
163164
}
@@ -266,8 +267,7 @@ public synchronized BitbucketEndpoint getDefaultEndpoint() {
266267
*
267268
* @param serverURL the server URL.
268269
* @return the normalized server URL.
269-
* @deprecated
270-
* @see #normalizeServerURL
270+
* @deprecated Do not use at all, endpoint URL are already managed internally
271271
*/
272272
@CheckForNull
273273
@Deprecated(forRemoval = true)

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketServerEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public BitbucketServerEndpoint(@CheckForNull String displayName, @NonNull String
141141
* credentials to use for auto-management of hooks.
142142
* @param enableHookSignature {@code true} hooks that comes Bitbucket Data
143143
* Center are signed.
144-
* @param credentialsId The {@link StringCredentials#getId()} of the
144+
* @param hookSignatureCredentialsId The {@link StringCredentials#getId()} of the
145145
* credentials to use for verify the signature of payload.
146146
*/
147147
@DataBoundConstructor

src/test/java/com/cloudbees/jenkins/plugins/bitbucket/endpoints/BitbucketEndpointConfigurationTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ void given__instanceWithServer__when__updatingCloud__then__cloudAdded() {
295295
@Test
296296
void given__instanceWithServer__when__updatingDifferentServer__then__serverAdded() {
297297
BitbucketEndpointConfiguration instance = new BitbucketEndpointConfiguration();
298-
instance.setEndpoints(List.of(new BitbucketServerEndpoint("Example Inc", "https://bitbucket.example.com/", true, "dummy")));
298+
instance.setEndpoints(List.of(new BitbucketServerEndpoint("Example Inc", "https://bitbucket.example.com/", true, "dummy", false, null)));
299299
assumeTrue("dummy".equals(instance.getEndpoints().get(0).getCredentialsId()));
300300

301-
instance.updateEndpoint(new BitbucketServerEndpoint("Example Org", "http://example.org:8080/bitbucket/", true, "added"));
301+
instance.updateEndpoint(new BitbucketServerEndpoint("Example Org", "http://example.org:8080/bitbucket/", true, "added", false, null));
302302

303303
assertThat(instance.getEndpoints()).hasOnlyElementsOfType(BitbucketServerEndpoint.class);
304304
assertThat(instance.getEndpoints()).element(0).satisfies(endpoint -> {
@@ -328,8 +328,13 @@ void given__instanceWithServer__when__updatingSameServer__then__serverUpdated()
328328
@Test
329329
void given__newInstance__when__removingCloud__then__defaultRestored() {
330330
BitbucketEndpointConfiguration instance = new BitbucketEndpointConfiguration();
331-
assertThat(instance.getEndpoints().get(0).getCredentialsId()).isNull();
332-
assertThat(instance.removeEndpoint(buildEndpoint(true, "dummy"))).isTrue();
331+
// verify there is always a default endpoint
332+
assertThat(instance.getEndpoints()).isNotEmpty()
333+
.element(0)
334+
.satisfies(endpoint -> assertThat(endpoint.getCredentialsId()).isNull());
335+
// remove default does not really remove it
336+
assertThat(instance.removeEndpoint(buildEndpoint(true, "dummy"))).isFalse();
337+
// default always exists
333338
assertThat(instance.getEndpoints()).hasOnlyElementsOfType(BitbucketCloudEndpoint.class);
334339
}
335340

@@ -415,8 +420,7 @@ void given__instance__when__multipleEndpoints__then__endpointsSelectable() {
415420

416421
@Test
417422
void given__instanceWithCloudAndServers__when__findingExistingEndpoint__then__endpointFound() {
418-
BitbucketEndpointConfiguration instance = new BitbucketEndpointConfiguration();
419-
instance.setEndpoints(
423+
BitbucketEndpointConfiguration.get().setEndpoints(
420424
Arrays.asList(
421425
buildEndpoint(true, "first"),
422426
new BitbucketServerEndpoint("Example Inc", "https://bitbucket.example.com/", true, "second"),
@@ -445,8 +449,7 @@ void given__instanceWithCloudAndServers__when__findingExistingEndpoint__then__en
445449

446450
@Test
447451
void given__instanceWithServers__when__findingNonExistingEndpoint__then__endpointNotFound() {
448-
BitbucketEndpointConfiguration instance = new BitbucketEndpointConfiguration();
449-
instance.setEndpoints(
452+
BitbucketEndpointConfiguration.get().setEndpoints(
450453
Arrays.<AbstractBitbucketEndpoint>asList(
451454
new BitbucketServerEndpoint("Example Inc", "https://bitbucket.example.com/", true, "dummy"),
452455
new BitbucketServerEndpoint("Example Org", "http://example.org:8080/bitbucket/", true, "dummy")
@@ -463,8 +466,7 @@ void given__instanceWithServers__when__findingNonExistingEndpoint__then__endpoin
463466

464467
@Test
465468
void given__instanceWithCloudAndServers__when__findingInvalid__then__endpointNotFound() {
466-
BitbucketEndpointConfiguration instance = new BitbucketEndpointConfiguration();
467-
instance.setEndpoints(
469+
BitbucketEndpointConfiguration.get().setEndpoints(
468470
Arrays.asList(
469471
buildEndpoint(true, "first"),
470472
new BitbucketServerEndpoint("Example Inc", "https://bitbucket.example.com/", true, "second"),
@@ -526,7 +528,7 @@ void given__instanceWithCloudAndServers__when__resolvingNewEndpointAsSystem__the
526528
r.jenkins.setAuthorizationStrategy(mockStrategy);
527529
try (ACLContext context = ACL.as2(ACL.SYSTEM2)) {
528530
BitbucketEndpointConfiguration instance = new BitbucketEndpointConfiguration();
529-
instance.setEndpoints(List.of(new BitbucketServerEndpoint("existing", "https://bitbucket.test", false, null)));
531+
instance.setEndpoints(List.of(new BitbucketServerEndpoint("existing", "https://bitbucket.test", false, null, false, null)));
530532
assertThat(instance.getEndpointItems()).hasSize(1);
531533
assertThat(instance.readResolveServerUrl(null)).isEqualTo(BitbucketCloudEndpoint.SERVER_URL);
532534
assertThat(instance.getEndpointItems()).hasSize(2);

0 commit comments

Comments
 (0)