]> source.dussan.org Git - sonarqube.git/commitdiff
NO-JIRA - rename isEnable to isAvailable for feature flag, as features can be availab...
authorPierre <pierre.guillot@sonarsource.com>
Mon, 20 Mar 2023 14:19:33 +0000 (15:19 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 22 Mar 2023 20:04:08 +0000 (20:04 +0000)
18 files changed:
server/sonar-server-common/src/main/java/org/sonar/server/almsettings/MultipleAlmFeature.java
server/sonar-server-common/src/main/java/org/sonar/server/feature/SonarQubeFeature.java
server/sonar-server-common/src/main/java/org/sonar/server/loginmessage/LoginMessageFeature.java
server/sonar-server-common/src/test/java/org/sonar/server/almsettings/MultipleAlmFeatureTest.java
server/sonar-server-common/src/test/java/org/sonar/server/loginmessage/LoginMessageFeatureTest.java
server/sonar-webserver-api/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java
server/sonar-webserver-api/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateAzureActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateBitbucketCloudActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGithubActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/CreateGitlabActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateGitlabActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/AlmSettingsSupport.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/feature/ws/ListAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/LoginMessageAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/feature/ws/ListActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/LoginMessageActionTest.java

index ef93d1db0268393bc23f349f62d8df9421733f41..f09a7e5ae7d9d4db967026e8aaf607b041ce5f77 100644 (file)
@@ -43,7 +43,7 @@ public class MultipleAlmFeature implements SonarQubeFeature {
   }
 
   @Override
-  public boolean isEnabled() {
+  public boolean isAvailable() {
     return sonarRuntime.getEdition() == ENTERPRISE || sonarRuntime.getEdition() == DATACENTER;
   }
 
index bb5993cbe2fec5154968f6c3c93f93cd2bdea68d..13def5b399a2c318c0e8c093d822141f301cbcfa 100644 (file)
@@ -23,5 +23,5 @@ public interface SonarQubeFeature {
 
   String getName();
 
-  boolean isEnabled();
+  boolean isAvailable();
 }
index 7b1ca516eb950bbc400b34a985c753d1661cc0d2..5c71d978dfb7f41405fa46b2ada47d526cadceca 100644 (file)
@@ -41,7 +41,7 @@ public class LoginMessageFeature implements SonarQubeFeature {
   }
 
   @Override
-  public boolean isEnabled() {
+  public boolean isAvailable() {
     return sonarRuntime.getEdition() == ENTERPRISE || sonarRuntime.getEdition() == DATACENTER;
   }
 
index 2287c9731bd396943843b44c759783fe79497c14..5f582d8105300e666849a9828a8f3d2762f4c018 100644 (file)
@@ -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
index ccf31f34292766d9feb3f3f4a192025e7b115d05..6131523e0f1cb6874253051fcd3942251730313e 100644 (file)
@@ -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
index dc496b1e250456e3bab231c5246990e7a1b2051f..e7b3a1055f3eaa3af9f118a86d967df42ff3cfc3 100644 (file)
@@ -31,6 +31,6 @@ public class BranchFeatureProxyImpl implements BranchFeatureProxy {
 
   @Override
   public boolean isEnabled() {
-    return branchFeatureExtension != null && branchFeatureExtension.isEnabled();
+    return branchFeatureExtension != null && branchFeatureExtension.isAvailable();
   }
 }
index d211b9f6a6c6d5809e31fa9a183f1404c743a160..26c3e94728daf4993b32b708c49fa36efbd872a7 100644 (file)
@@ -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();
   }
 }
index bedb89fc0676c2503be30a0c2346de1bf954ab30..e543d039ecbb0fdda6ca1b892fa4984576449559 100644 (file)
@@ -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();
index 225b156e40fa3f8134f4cc75f9b0b1218b1e0c1e..f9b270f87d13cc0d5ee5e8df6a36053129be979c 100644 (file)
@@ -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();
index bb37976d64f4790c11fd2082429adc908a0617c0..07d907af827c2265d164e74db3800cf0e909e3c9 100644 (file)
@@ -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();
index 128c6d4a6f2a59ea3bd1de6601d7bc9bc7922360..7c0d645471ea5c6a0a58fa6ac19db81e4bd9ccb9 100644 (file)
@@ -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();
index dd31ef9a71c73d9a766e2829f3e948d1feaf4905..d9bbbf3545a4b9464bb4a8f4ee08b1ea8b8ed171 100644 (file)
@@ -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();
index f4203a8c015a876984a852e3e43e5e7cef32564a..bb6bd4187c93421a7f4b96efe8d4f1e35b18a1b4 100644 (file)
@@ -60,7 +60,7 @@ public class UpdateGitlabActionIT {
 
   @Before
   public void before() {
-    when(multipleAlmFeature.isEnabled()).thenReturn(true);
+    when(multipleAlmFeature.isAvailable()).thenReturn(true);
   }
 
   @Test
index 81f73ca6d595f9d7653dbdb49ce790d0d22f53af..3f5b5bb1881e760bea7a6392e6f4552709df94f5 100644 (file)
@@ -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");
       }
     }
index a283c1e4c93ecf912e465951dc6a64bd98a8658c..765b4c89aff34608b7dd37a0a777488694ddf195 100644 (file)
@@ -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();
     }
index eec955093ef83cbd520e24a569bffd841daf2981..ecf405197ca98b2a0f72261e1ff0e4b12992609d 100644 (file)
@@ -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();
     }
index a6764946804e91593648cf52c3c0ea430716d699..b3ceefafc8ab5dcc46456627fbb9ea7673158e26 100644 (file)
@@ -86,7 +86,7 @@ public class ListActionTest {
     }
 
     @Override
-    public boolean isEnabled() {
+    public boolean isAvailable() {
       return enabled;
     }
   }
index 0fc1d0ebaf42adf445b5e73d23368532aebdc7c1..064759532ac6f9706ec70c71fa9fa5b17ecf669b 100644 (file)
@@ -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);