From 76cf8c975dcbb2cdc3756eab2d680aa8d6e576ac Mon Sep 17 00:00:00 2001 From: Zipeng WU Date: Fri, 29 Jan 2021 13:37:29 +0100 Subject: [PATCH] SONAR-14372 move BitBucket Server alm settings WS to CE --- .../almsettings/ws/AlmSettingsWsModule.java | 5 +- .../almsettings/ws/CreateBitBucketAction.java | 98 +++++++++++ .../almsettings/ws/UpdateBitbucketAction.java | 104 +++++++++++ .../ws/AlmSettingsWsModuleTest.java | 2 +- .../ws/CreateBitbucketActionTest.java | 153 ++++++++++++++++ .../ws/UpdateBitbucketActionTest.java | 165 ++++++++++++++++++ 6 files changed, 525 insertions(+), 2 deletions(-) create mode 100644 server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/CreateBitBucketAction.java create mode 100644 server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java create mode 100644 server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CreateBitbucketActionTest.java create mode 100644 server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionTest.java diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsWsModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsWsModule.java index ca593a0be6d..2df9ad0b351 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsWsModule.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsWsModule.java @@ -32,7 +32,10 @@ public class AlmSettingsWsModule extends Module { ListDefinitionsAction.class, //Azure alm settings, CreateAzureAction.class, - UpdateAzureAction.class + UpdateAzureAction.class, + //Bitbucket alm settings + CreateBitBucketAction.class, + UpdateBitbucketAction.class ); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/CreateBitBucketAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/CreateBitBucketAction.java new file mode 100644 index 00000000000..0e99a8c6fdd --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/CreateBitBucketAction.java @@ -0,0 +1,98 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.almsettings.ws; + +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.alm.setting.AlmSettingDto; +import org.sonar.server.user.UserSession; + +import static org.sonar.db.alm.setting.ALM.BITBUCKET; +import static org.sonar.db.alm.setting.ALM.BITBUCKET_CLOUD; + +public class CreateBitBucketAction implements AlmSettingsWsAction { + + private static final String PARAM_KEY = "key"; + private static final String PARAM_URL = "url"; + private static final String PARAM_PERSONAL_ACCESS_TOKEN = "personalAccessToken"; + + private final DbClient dbClient; + private UserSession userSession; + private final AlmSettingsSupport almSettingsSupport; + + public CreateBitBucketAction(DbClient dbClient, UserSession userSession, AlmSettingsSupport almSettingsSupport) { + this.dbClient = dbClient; + this.userSession = userSession; + this.almSettingsSupport = almSettingsSupport; + } + + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context.createAction("create_bitbucket") + .setDescription("Create Bitbucket ALM instance Setting.
" + + "Requires the 'Administer System' permission") + .setPost(true) + .setSince("8.1") + .setHandler(this); + + action.createParam(PARAM_KEY) + .setRequired(true) + .setMaximumLength(200) + .setDescription("Unique key of the Bitbucket instance setting"); + action.createParam(PARAM_URL) + .setRequired(true) + .setMaximumLength(2000) + .setDescription("BitBucket server API URL"); + action.createParam(PARAM_PERSONAL_ACCESS_TOKEN) + .setRequired(true) + .setMaximumLength(2000) + .setDescription("Bitbucket personal access token"); + } + + @Override + public void handle(Request request, Response response) { + userSession.checkIsSystemAdministrator(); + doHandle(request); + response.noContent(); + } + + private void doHandle(Request request) { + String key = request.mandatoryParam(PARAM_KEY); + String url = request.mandatoryParam(PARAM_URL); + String pat = request.mandatoryParam(PARAM_PERSONAL_ACCESS_TOKEN); + try (DbSession dbSession = dbClient.openSession(false)) { + // We do not treat Bitbucket Server and Bitbucket Cloud as different ALMs when it comes to limiting the + // number of connections. + almSettingsSupport.checkAlmMultipleFeatureEnabled(BITBUCKET); + almSettingsSupport.checkAlmMultipleFeatureEnabled(BITBUCKET_CLOUD); + almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, key); + dbClient.almSettingDao().insert(dbSession, new AlmSettingDto() + .setAlm(BITBUCKET) + .setKey(key) + .setUrl(url) + .setPersonalAccessToken(pat)); + dbSession.commit(); + } + } + +} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java new file mode 100644 index 00000000000..5d5fb161702 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/UpdateBitbucketAction.java @@ -0,0 +1,104 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.almsettings.ws; + +import org.sonar.api.server.ws.Change; +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.alm.setting.AlmSettingDto; +import org.sonar.server.user.UserSession; + +import static org.apache.commons.lang.StringUtils.isNotBlank; + +public class UpdateBitbucketAction implements AlmSettingsWsAction { + + private static final String PARAM_KEY = "key"; + private static final String PARAM_NEW_KEY = "newKey"; + private static final String PARAM_URL = "url"; + private static final String PARAM_PERSONAL_ACCESS_TOKEN = "personalAccessToken"; + + private final DbClient dbClient; + private UserSession userSession; + private final AlmSettingsSupport almSettingsSupport; + + public UpdateBitbucketAction(DbClient dbClient, UserSession userSession, AlmSettingsSupport almSettingsSupport) { + this.dbClient = dbClient; + this.userSession = userSession; + this.almSettingsSupport = almSettingsSupport; + } + + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context.createAction("update_bitbucket") + .setDescription("Update Bitbucket ALM instance Setting.
" + + "Requires the 'Administer System' permission") + .setPost(true) + .setSince("8.1") + .setChangelog(new Change("8.7", String.format("Parameter '%s' is no longer required", PARAM_PERSONAL_ACCESS_TOKEN))) + .setHandler(this); + + action.createParam(PARAM_KEY) + .setRequired(true) + .setMaximumLength(200) + .setDescription("Unique key of the Bitbucket instance setting"); + action.createParam(PARAM_NEW_KEY) + .setRequired(false) + .setMaximumLength(200) + .setDescription("Optional new value for an unique key of the Bitbucket instance setting"); + action.createParam(PARAM_URL) + .setRequired(true) + .setMaximumLength(2000) + .setDescription("Bitbucket API URL"); + action.createParam(PARAM_PERSONAL_ACCESS_TOKEN) + .setRequired(false) + .setMaximumLength(2000) + .setDescription("Bitbucket personal access token"); + } + + @Override + public void handle(Request request, Response response) throws Exception { + userSession.checkIsSystemAdministrator(); + doHandle(request); + response.noContent(); + } + + private void doHandle(Request request) { + String key = request.mandatoryParam(PARAM_KEY); + String newKey = request.param(PARAM_NEW_KEY); + String url = request.mandatoryParam(PARAM_URL); + String pat = request.param(PARAM_PERSONAL_ACCESS_TOKEN); + + try (DbSession dbSession = dbClient.openSession(false)) { + AlmSettingDto almSettingDto = almSettingsSupport.getAlmSetting(dbSession, key); + if (isNotBlank(newKey) && !newKey.equals(key)) { + almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey); + } + dbClient.almSettingDao().update(dbSession, almSettingDto + .setKey(isNotBlank(newKey) ? newKey : key) + .setUrl(url) + .setPersonalAccessToken(isNotBlank(pat) ? pat : almSettingDto.getPersonalAccessToken())); + dbSession.commit(); + } + } + +} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/AlmSettingsWsModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/AlmSettingsWsModuleTest.java index 39e1a866fe6..92808f0c2fa 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/AlmSettingsWsModuleTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/AlmSettingsWsModuleTest.java @@ -31,7 +31,7 @@ public class AlmSettingsWsModuleTest { public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new AlmSettingsWsModule().configure(container); - assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 7); + assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 9); } } \ No newline at end of file diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CreateBitbucketActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CreateBitbucketActionTest.java new file mode 100644 index 00000000000..ae8fe639867 --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CreateBitbucketActionTest.java @@ -0,0 +1,153 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.almsettings.ws; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.server.ws.WebService; +import org.sonar.db.DbTester; +import org.sonar.db.alm.setting.AlmSettingDto; +import org.sonar.db.user.UserDto; +import org.sonar.server.almsettings.MultipleAlmFeatureProvider; +import org.sonar.server.component.ComponentFinder; +import org.sonar.server.exceptions.BadRequestException; +import org.sonar.server.exceptions.ForbiddenException; +import org.sonar.server.tester.UserSessionRule; +import org.sonar.server.ws.WsActionTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.groups.Tuple.tuple; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class CreateBitbucketActionTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Rule + public UserSessionRule userSession = UserSessionRule.standalone(); + @Rule + public DbTester db = DbTester.create(); + + private MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class); + + private WsActionTester ws = new WsActionTester(new CreateBitBucketAction(db.getDbClient(), userSession, + new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null), + multipleAlmFeatureProvider))); + + @Before + public void before(){ + when(multipleAlmFeatureProvider.enabled()).thenReturn(false); + } + + @Test + public void create() { + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + + ws.newRequest() + .setParam("key", "Bitbucket Server - Dev Team") + .setParam("url", "https://bitbucket.enterprise.com") + .setParam("personalAccessToken", "98765432100") + .execute(); + + assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())) + .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken) + .containsOnly(tuple("Bitbucket Server - Dev Team", "https://bitbucket.enterprise.com", "98765432100")); + } + + @Test + public void fail_when_key_is_already_used() { + when(multipleAlmFeatureProvider.enabled()).thenReturn(true); + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + AlmSettingDto bitbucketAlmSetting = db.almSettings().insertBitbucketAlmSetting(); + + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage(String.format("An ALM setting with key '%s' already exist", bitbucketAlmSetting.getKey())); + + ws.newRequest() + .setParam("key", bitbucketAlmSetting.getKey()) + .setParam("url", "https://bitbucket.enterprise.com") + .setParam("personalAccessToken", "98765432100") + .execute(); + } + + @Test + public void fail_when_no_multiple_instance_allowed() { + when(multipleAlmFeatureProvider.enabled()).thenReturn(false); + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + db.almSettings().insertBitbucketAlmSetting(); + + expectedException.expect(BadRequestException.class); + expectedException.expectMessage("A BITBUCKET setting is already defined"); + + ws.newRequest() + .setParam("key", "otherKey") + .setParam("url", "https://bitbucket.enterprise.com") + .setParam("personalAccessToken", "98765432100") + .execute(); + } + + @Test + public void fail_when_no_multiple_instance_allowed_and_bitbucket_cloud_exists() { + when(multipleAlmFeatureProvider.enabled()).thenReturn(false); + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + db.almSettings().insertBitbucketCloudAlmSetting(); + + expectedException.expect(BadRequestException.class); + expectedException.expectMessage("A BITBUCKET_CLOUD setting is already defined"); + + ws.newRequest() + .setParam("key", "otherKey") + .setParam("url", "https://bitbucket.enterprise.com") + .setParam("personalAccessToken", "98765432100") + .execute(); + } + + @Test + public void fail_when_missing_administer_system_permission() { + UserDto user = db.users().insertUser(); + userSession.logIn(user); + + expectedException.expect(ForbiddenException.class); + + ws.newRequest() + .setParam("key", "Bitbucket Server - Dev Team") + .setParam("url", "https://bitbucket.enterprise.com") + .setParam("personalAccessToken", "98765432100") + .execute(); + } + + @Test + public void definition() { + WebService.Action def = ws.getDef(); + + assertThat(def.since()).isEqualTo("8.1"); + assertThat(def.isPost()).isTrue(); + assertThat(def.params()) + .extracting(WebService.Param::key, WebService.Param::isRequired) + .containsExactlyInAnyOrder(tuple("key", true), tuple("url", true), tuple("personalAccessToken", true)); + } +} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionTest.java new file mode 100644 index 00000000000..f05b53c083f --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionTest.java @@ -0,0 +1,165 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.almsettings.ws; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.server.ws.WebService; +import org.sonar.db.DbTester; +import org.sonar.db.alm.setting.AlmSettingDto; +import org.sonar.db.user.UserDto; +import org.sonar.server.almsettings.MultipleAlmFeatureProvider; +import org.sonar.server.component.ComponentFinder; +import org.sonar.server.exceptions.ForbiddenException; +import org.sonar.server.exceptions.NotFoundException; +import org.sonar.server.tester.UserSessionRule; +import org.sonar.server.ws.WsActionTester; + +import static java.lang.String.format; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.groups.Tuple.tuple; +import static org.mockito.Mockito.mock; + +public class UpdateBitbucketActionTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Rule + public UserSessionRule userSession = UserSessionRule.standalone(); + @Rule + public DbTester db = DbTester.create(); + + private WsActionTester ws = new WsActionTester(new UpdateBitbucketAction(db.getDbClient(), userSession, + new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null), + mock(MultipleAlmFeatureProvider.class)))); + + @Test + public void update() { + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting(); + + ws.newRequest() + .setParam("key", almSettingDto.getKey()) + .setParam("url", "https://bitbucket.enterprise-unicorn.com") + .setParam("personalAccessToken", "10987654321") + .execute(); + + assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())) + .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken) + .containsOnly(tuple(almSettingDto.getKey(), "https://bitbucket.enterprise-unicorn.com", "10987654321")); + } + + @Test + public void update_with_new_key() { + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + + AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting(); + + ws.newRequest() + .setParam("key", almSettingDto.getKey()) + .setParam("newKey", "Bitbucket Server - Infra Team") + .setParam("url", "https://bitbucket.enterprise-unicorn.com") + .setParam("personalAccessToken", "0123456789") + .execute(); + assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())) + .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken) + .containsOnly(tuple("Bitbucket Server - Infra Team", "https://bitbucket.enterprise-unicorn.com", "0123456789")); + } + + @Test + public void update_without_pat() { + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + + AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting(); + + ws.newRequest() + .setParam("key", almSettingDto.getKey()) + .setParam("url", "https://bitbucket.enterprise-unicorn.com") + .execute(); + assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())) + .extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getPersonalAccessToken) + .containsOnly(tuple(almSettingDto.getKey(), "https://bitbucket.enterprise-unicorn.com", almSettingDto.getPersonalAccessToken())); + } + + @Test + public void fail_when_key_does_not_match_existing_alm_setting() { + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + + expectedException.expect(NotFoundException.class); + expectedException.expectMessage("ALM setting with key 'unknown' cannot be found"); + + ws.newRequest() + .setParam("key", "unknown") + .setParam("url", "https://bitbucket.enterprise-unicorn.com") + .setParam("personalAccessToken", "0123456789") + .execute(); + } + + @Test + public void fail_when_new_key_matches_existing_alm_setting() { + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + AlmSettingDto almSetting1 = db.almSettings().insertBitbucketAlmSetting(); + AlmSettingDto almSetting2 = db.almSettings().insertBitbucketAlmSetting(); + + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage(format("An ALM setting with key '%s' already exists", almSetting2.getKey())); + + ws.newRequest() + .setParam("key", almSetting1.getKey()) + .setParam("newKey", almSetting2.getKey()) + .setParam("url", "https://bitbucket.enterprise-unicorn.com") + .setParam("personalAccessToken", "0123456789") + .execute(); + } + + @Test + public void fail_when_missing_administer_system_permission() { + UserDto user = db.users().insertUser(); + userSession.logIn(user); + AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting(); + + expectedException.expect(ForbiddenException.class); + + ws.newRequest() + .setParam("key", almSettingDto.getKey()) + .setParam("newKey", "Bitbucket Server - Infra Team") + .setParam("url", "https://bitbucket.enterprise-unicorn.com") + .setParam("personalAccessToken", "0123456789") + .execute(); + } + + @Test + public void definition() { + WebService.Action def = ws.getDef(); + + assertThat(def.since()).isEqualTo("8.1"); + assertThat(def.isPost()).isTrue(); + assertThat(def.params()) + .extracting(WebService.Param::key, WebService.Param::isRequired) + .containsExactlyInAnyOrder(tuple("key", true), tuple("newKey", false), tuple("url", true), tuple("personalAccessToken", false)); + } + +} -- 2.39.5