From: Pierre Date: Mon, 20 Mar 2023 14:19:33 +0000 (+0100) Subject: NO-JIRA - rename isEnable to isAvailable for feature flag, as features can be availab... X-Git-Tag: 10.0.0.68432~84 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=168dc5e1454f76ef9916f9de4095a074fa847b2d;p=sonarqube.git NO-JIRA - rename isEnable to isAvailable for feature flag, as features can be available in an edition but not enabled. --- diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/almsettings/MultipleAlmFeature.java b/server/sonar-server-common/src/main/java/org/sonar/server/almsettings/MultipleAlmFeature.java index ef93d1db026..f09a7e5ae7d 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/almsettings/MultipleAlmFeature.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/almsettings/MultipleAlmFeature.java @@ -43,7 +43,7 @@ public class MultipleAlmFeature implements SonarQubeFeature { } @Override - public boolean isEnabled() { + public boolean isAvailable() { return sonarRuntime.getEdition() == ENTERPRISE || sonarRuntime.getEdition() == DATACENTER; } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/feature/SonarQubeFeature.java b/server/sonar-server-common/src/main/java/org/sonar/server/feature/SonarQubeFeature.java index bb5993cbe2f..13def5b399a 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/feature/SonarQubeFeature.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/feature/SonarQubeFeature.java @@ -23,5 +23,5 @@ public interface SonarQubeFeature { String getName(); - boolean isEnabled(); + boolean isAvailable(); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/loginmessage/LoginMessageFeature.java b/server/sonar-server-common/src/main/java/org/sonar/server/loginmessage/LoginMessageFeature.java index 7b1ca516eb9..5c71d978dfb 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/loginmessage/LoginMessageFeature.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/loginmessage/LoginMessageFeature.java @@ -41,7 +41,7 @@ public class LoginMessageFeature implements SonarQubeFeature { } @Override - public boolean isEnabled() { + public boolean isAvailable() { return sonarRuntime.getEdition() == ENTERPRISE || sonarRuntime.getEdition() == DATACENTER; } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/almsettings/MultipleAlmFeatureTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/almsettings/MultipleAlmFeatureTest.java index 2287c9731bd..5f582d81053 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/almsettings/MultipleAlmFeatureTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/almsettings/MultipleAlmFeatureTest.java @@ -48,9 +48,9 @@ public class MultipleAlmFeatureTest { public void isEnabled_shouldOnlyBeEnabledInEnterpriseEditionPlus(SonarEdition edition, boolean shouldBeEnabled) { when(sonarRuntime.getEdition()).thenReturn(edition); - boolean isEnabled = underTest.isEnabled(); + boolean isAvailable = underTest.isAvailable(); - assertThat(isEnabled).isEqualTo(shouldBeEnabled); + assertThat(isAvailable).isEqualTo(shouldBeEnabled); } @DataProvider diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/loginmessage/LoginMessageFeatureTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/loginmessage/LoginMessageFeatureTest.java index ccf31f34292..6131523e0f1 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/loginmessage/LoginMessageFeatureTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/loginmessage/LoginMessageFeatureTest.java @@ -40,12 +40,12 @@ public class LoginMessageFeatureTest { @Test @UseDataProvider("editionsAndLoginMessageFeatureAvailability") - public void isEnabled_shouldOnlyBeEnabledInEnterpriseEditionPlus(SonarEdition edition, boolean shouldBeEnabled) { + public void isAvailable_shouldOnlyBeEnabledInEnterpriseEditionPlus(SonarEdition edition, boolean shouldBeEnabled) { when(sonarRuntime.getEdition()).thenReturn(edition); - boolean isEnabled = underTest.isEnabled(); + boolean isAvailable = underTest.isAvailable(); - assertThat(isEnabled).isEqualTo(shouldBeEnabled); + assertThat(isAvailable).isEqualTo(shouldBeEnabled); } @Test diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java index dc496b1e250..e7b3a1055f3 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java @@ -31,6 +31,6 @@ public class BranchFeatureProxyImpl implements BranchFeatureProxy { @Override public boolean isEnabled() { - return branchFeatureExtension != null && branchFeatureExtension.isEnabled(); + return branchFeatureExtension != null && branchFeatureExtension.isAvailable(); } } diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java index d211b9f6a6c..26c3e94728d 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java @@ -36,13 +36,13 @@ public class BranchFeatureProxyImplTest { @Test public void return_false_when_extension_returns_false() { - when(branchFeatureExtension.isEnabled()).thenReturn(false); + when(branchFeatureExtension.isAvailable()).thenReturn(false); assertThat(new BranchFeatureProxyImpl(branchFeatureExtension).isEnabled()).isFalse(); } @Test public void return_true_when_extension_returns_ftrue() { - when(branchFeatureExtension.isEnabled()).thenReturn(true); + when(branchFeatureExtension.isAvailable()).thenReturn(true); assertThat(new BranchFeatureProxyImpl(branchFeatureExtension).isEnabled()).isTrue(); } } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateAzureActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateAzureActionIT.java index bedb89fc067..e543d039ecb 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateAzureActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateAzureActionIT.java @@ -56,7 +56,7 @@ public class CreateAzureActionIT { @Before public void before() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); } @Test @@ -79,7 +79,7 @@ public class CreateAzureActionIT { @Test public void fail_when_key_is_already_used() { - when(multipleAlmFeature.isEnabled()).thenReturn(true); + when(multipleAlmFeature.isAvailable()).thenReturn(true); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); AlmSettingDto azureAlmSetting = db.almSettings().insertAzureAlmSetting(); @@ -95,7 +95,7 @@ public class CreateAzureActionIT { @Test public void fail_when_no_multiple_instance_allowed() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); db.almSettings().insertAzureAlmSetting(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketActionIT.java index 225b156e40f..f9b270f87d1 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketActionIT.java @@ -56,7 +56,7 @@ public class CreateBitbucketActionIT { @Before public void before() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); } @Test @@ -77,7 +77,7 @@ public class CreateBitbucketActionIT { @Test public void fail_when_key_is_already_used() { - when(multipleAlmFeature.isEnabled()).thenReturn(true); + when(multipleAlmFeature.isAvailable()).thenReturn(true); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); AlmSettingDto bitbucketAlmSetting = db.almSettings().insertBitbucketAlmSetting(); @@ -93,7 +93,7 @@ public class CreateBitbucketActionIT { @Test public void fail_when_no_multiple_instance_allowed() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); db.almSettings().insertBitbucketAlmSetting(); @@ -109,7 +109,7 @@ public class CreateBitbucketActionIT { @Test public void fail_when_no_multiple_instance_allowed_and_bitbucket_cloud_exists() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); db.almSettings().insertBitbucketCloudAlmSetting(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketCloudActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketCloudActionIT.java index bb37976d64f..07d907af827 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketCloudActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketCloudActionIT.java @@ -58,7 +58,7 @@ public class CreateBitbucketCloudActionIT { @Before public void before() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); } @Test @@ -80,7 +80,7 @@ public class CreateBitbucketCloudActionIT { @Test public void fail_when_key_is_already_used() { - when(multipleAlmFeature.isEnabled()).thenReturn(true); + when(multipleAlmFeature.isAvailable()).thenReturn(true); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); AlmSettingDto bitbucketAlmSetting = db.almSettings().insertBitbucketAlmSetting(); @@ -97,7 +97,7 @@ public class CreateBitbucketCloudActionIT { @Test public void fail_when_no_multiple_instance_allowed() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); db.almSettings().insertBitbucketCloudAlmSetting(); @@ -114,7 +114,7 @@ public class CreateBitbucketCloudActionIT { @Test public void fail_when_no_multiple_instance_allowed_and_bitbucket_server_exists() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); db.almSettings().insertBitbucketAlmSetting(); @@ -145,7 +145,7 @@ public class CreateBitbucketCloudActionIT { @Test public void fail_when_workspace_id_format_is_incorrect() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); String workspace = "workspace/name"; UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); @@ -166,7 +166,7 @@ public class CreateBitbucketCloudActionIT { @Test public void do_not_fail_when_workspace_id_format_is_correct() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); String workspace = "work-space_123"; UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGithubActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGithubActionIT.java index 128c6d4a6f2..7c0d645471e 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGithubActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGithubActionIT.java @@ -63,7 +63,7 @@ public class CreateGithubActionIT { @Before public void setUp() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); } @@ -120,7 +120,7 @@ public class CreateGithubActionIT { @Test public void fail_when_key_is_already_used() { - when(multipleAlmFeature.isEnabled()).thenReturn(true); + when(multipleAlmFeature.isAvailable()).thenReturn(true); AlmSettingDto gitHubAlmSetting = db.almSettings().insertGitHubAlmSetting(); TestRequest request = buildTestRequest().setParam("key", gitHubAlmSetting.getKey()); @@ -132,7 +132,7 @@ public class CreateGithubActionIT { @Test public void fail_when_no_multiple_instance_allowed() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); db.almSettings().insertGitHubAlmSetting(); TestRequest request = buildTestRequest(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGitlabActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGitlabActionIT.java index dd31ef9a71c..d9bbbf3545a 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGitlabActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGitlabActionIT.java @@ -59,7 +59,7 @@ public class CreateGitlabActionIT { @Before public void before() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); } @Test @@ -109,7 +109,7 @@ public class CreateGitlabActionIT { @Test public void fail_when_key_is_already_used() { - when(multipleAlmFeature.isEnabled()).thenReturn(true); + when(multipleAlmFeature.isAvailable()).thenReturn(true); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); AlmSettingDto gitlabAlmSetting = db.almSettings().insertGitlabAlmSetting(); @@ -125,7 +125,7 @@ public class CreateGitlabActionIT { @Test public void fail_when_no_multiple_instance_allowed() { - when(multipleAlmFeature.isEnabled()).thenReturn(false); + when(multipleAlmFeature.isAvailable()).thenReturn(false); UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); db.almSettings().insertGitlabAlmSetting(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateGitlabActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateGitlabActionIT.java index f4203a8c015..bb6bd4187c9 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateGitlabActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateGitlabActionIT.java @@ -60,7 +60,7 @@ public class UpdateGitlabActionIT { @Before public void before() { - when(multipleAlmFeature.isEnabled()).thenReturn(true); + when(multipleAlmFeature.isAvailable()).thenReturn(true); } @Test diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsSupport.java index 81f73ca6d59..3f5b5bb1881 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsSupport.java @@ -67,7 +67,7 @@ public class AlmSettingsSupport { public void checkAlmMultipleFeatureEnabled(ALM alm) { try (DbSession dbSession = dbClient.openSession(false)) { - if (!multipleAlmFeature.isEnabled() && !dbClient.almSettingDao().selectByAlm(dbSession, alm).isEmpty()) { + if (!multipleAlmFeature.isAvailable() && !dbClient.almSettingDao().selectByAlm(dbSession, alm).isEmpty()) { throw BadRequestException.create("A " + alm + " setting is already defined"); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/feature/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/feature/ws/ListAction.java index a283c1e4c93..765b4c89aff 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/feature/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/feature/ws/ListAction.java @@ -51,7 +51,7 @@ public class ListAction implements WsAction { try (JsonWriter json = response.newJsonWriter()) { json.beginArray(); sonarQubeFeatures.stream() - .filter(SonarQubeFeature::isEnabled) + .filter(SonarQubeFeature::isAvailable) .forEach(f -> json.value(f.getName())); json.endArray(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/LoginMessageAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/LoginMessageAction.java index eec955093ef..ecf405197ca 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/LoginMessageAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/LoginMessageAction.java @@ -55,7 +55,7 @@ public class LoginMessageAction implements SettingsWsAction { public void handle(Request request, Response response) throws Exception { try (JsonWriter writer = response.newJsonWriter()) { writer.beginObject() - .prop("message", isMessageDisplayEnabled() && loginMessageFeature.isEnabled() ? Markdown.convertToHtml(getLoginMessage()) : "") + .prop("message", isMessageDisplayEnabled() && loginMessageFeature.isAvailable() ? Markdown.convertToHtml(getLoginMessage()) : "") .endObject() .close(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/feature/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/feature/ws/ListActionTest.java index a6764946804..b3ceefafc8a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/feature/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/feature/ws/ListActionTest.java @@ -86,7 +86,7 @@ public class ListActionTest { } @Override - public boolean isEnabled() { + public boolean isAvailable() { return enabled; } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/LoginMessageActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/LoginMessageActionTest.java index 0fc1d0ebaf4..064759532ac 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/LoginMessageActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/LoginMessageActionTest.java @@ -51,7 +51,7 @@ public class LoginMessageActionTest { @Before public void setup() { propertiesDao = mock(PropertiesDao.class); - doReturn(true).when(loginMessageFeature).isEnabled(); + doReturn(true).when(loginMessageFeature).isAvailable(); doReturn(propertiesDao).when(dbClient).propertiesDao(); } @@ -86,7 +86,7 @@ public class LoginMessageActionTest { public void return_empty_message_when_feature_not_enabled() { mockProperty(SONAR_LOGIN_DISPLAY_MESSAGE, "true"); mockProperty(SONAR_LOGIN_MESSAGE, LOGIN_MESSAGE_TEXT); - when(loginMessageFeature.isEnabled()).thenReturn(false); + when(loginMessageFeature.isAvailable()).thenReturn(false); TestResponse response = ws.newRequest().execute(); assertThat(response.getInput()).isEqualTo(EMPTY_JSON_RESPONSE);