]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13999 drop leftovers of organization from QualityProfile WSs
authorJacek <jacek.poreda@sonarsource.com>
Thu, 17 Dec 2020 08:46:33 +0000 (09:46 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 22 Dec 2020 20:09:38 +0000 (20:09 +0000)
27 files changed:
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileReference.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileCopierTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java [deleted file]
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddGroupActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddUserActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveGroupActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveUserActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RestoreActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchGroupsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchUsersActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleUpdaterTest.java

index 001576115b0cac65d8cc03103332867f434e17fd..bb404d594bd159018f1085e94980e109df2f0f44 100644 (file)
@@ -38,7 +38,7 @@ import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.
  * The two exclusive options to reference a profile are:
  * <ul>
  * <li>by its id (to be deprecated)</li>
- * <li>by the tuple {organizationKey, language, name}</li>
+ * <li>by the tuple {language, name}</li>
  * </ul>
  */
 public class QProfileReference {
index ce8eece577c6074f0e7328ba3eb724812e0c7c7b..c262b55730c44cb5f255f9e84e1b91054ca03ec0 100644 (file)
@@ -58,7 +58,7 @@ public class QProfileWsSupport {
   /**
    * Get the Quality profile specified by the reference {@code ref}.
    *
-   * @throws org.sonar.server.exceptions.NotFoundException if the specified organization or profile do not exist
+   * @throws org.sonar.server.exceptions.NotFoundException if the specified profile do not exist
    */
   public QProfileDto getProfile(DbSession dbSession, QProfileReference ref) {
     QProfileDto profile;
index da9b72c4f17c0e6453b0242660335e7bbaafa974..fe515bba887f59bdd40b85657e0bf68d57139cc5 100644 (file)
@@ -38,7 +38,6 @@ import org.sonar.api.rules.RuleType;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.ActiveRuleParamDto;
 import org.sonar.db.qualityprofile.QProfileDto;
@@ -64,18 +63,18 @@ public class QProfileBackuperImplTest {
     "<rules/>" +
     "</profile>";
 
-  private System2 system2 = new AlwaysIncreasingSystem2();
+  private final System2 system2 = new AlwaysIncreasingSystem2();
 
   @Rule
   public ExpectedException expectedException = none();
   @Rule
   public DbTester db = DbTester.create(system2);
 
-  private DummyReset reset = new DummyReset();
-  private QProfileFactory profileFactory = new DummyProfileFactory();
-  private RuleCreator ruleCreator = mock(RuleCreator.class);
+  private final DummyReset reset = new DummyReset();
+  private final QProfileFactory profileFactory = new DummyProfileFactory();
+  private final RuleCreator ruleCreator = mock(RuleCreator.class);
 
-  private QProfileBackuper underTest = new QProfileBackuperImpl(db.getDbClient(), reset, profileFactory, ruleCreator, new QProfileParser());
+  private final QProfileBackuper underTest = new QProfileBackuperImpl(db.getDbClient(), reset, profileFactory, ruleCreator, new QProfileParser());
 
   @Test
   public void backup_generates_xml_file() {
@@ -350,7 +349,6 @@ public class QProfileBackuperImplTest {
   @Test
   public void fail_to_restore_external_rule() {
     db.rules().insert(RuleKey.of("sonarjs", "s001"), r -> r.setIsExternal(true));
-    OrganizationDto organization = db.organizations().getDefaultOrganization();
     Reader backup = new StringReader("<?xml version='1.0' encoding='UTF-8'?>" +
       "<profile><name>foo</name>" +
       "<language>js</language>" +
index 22be30aa93e02c5da8a3ebbb16b85bf1075542e2..52a5645b3c5919acf06ca8fe0273888704932f90 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.qualityprofile.QualityProfileTesting;
 import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.db.rule.RuleTesting;
@@ -86,8 +87,8 @@ public class QProfileComparisonTest {
     db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1)
       .setName("min").setType(RuleParamType.INTEGER.type()));
 
-    left = QProfileTesting.newXooP1();
-    right = QProfileTesting.newXooP2();
+    left = QualityProfileTesting.newQualityProfileDto().setLanguage("xoo");
+    right = QualityProfileTesting.newQualityProfileDto().setLanguage("xoo");
     db.qualityProfileDao().insert(dbSession, left, right);
 
     dbSession.commit();
index 8289f7ec0886a9dfe5877d263c79da46d532f77a..14026337365fa10743b0cd13ddaa2918dd597a3a 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.api.impl.utils.JUnitTempFolder;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualityprofile.QProfileDto;
 import org.sonar.db.qualityprofile.QualityProfileTesting;
 
@@ -44,7 +43,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
 public class QProfileCopierTest {
 
   private static final String BACKUP = "<backup/>";
-  private System2 system2 = new AlwaysIncreasingSystem2();
+  private final System2 system2 = new AlwaysIncreasingSystem2();
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
@@ -53,9 +52,9 @@ public class QProfileCopierTest {
   @Rule
   public JUnitTempFolder temp = new JUnitTempFolder();
 
-  private DummyProfileFactory profileFactory = new DummyProfileFactory();
-  private QProfileBackuper backuper = mock(QProfileBackuper.class);
-  private QProfileCopier underTest = new QProfileCopier(db.getDbClient(), profileFactory, backuper);
+  private final DummyProfileFactory profileFactory = new DummyProfileFactory();
+  private final QProfileBackuper backuper = mock(QProfileBackuper.class);
+  private final QProfileCopier underTest = new QProfileCopier(db.getDbClient(), profileFactory, backuper);
 
   @Test
   public void create_target_profile_and_copy_rules() {
@@ -99,7 +98,6 @@ public class QProfileCopierTest {
 
   @Test
   public void copy_to_existing_profile() {
-    OrganizationDto organization = db.organizations().getDefaultOrganization();
     QProfileDto profile1 = db.qualityProfiles().insert();
     QProfileDto profile2 = db.qualityProfiles().insert(p -> p.setLanguage(profile1.getLanguage()));
 
@@ -125,7 +123,8 @@ public class QProfileCopierTest {
       throw new UnsupportedOperationException();
     }
 
-    @Override public QProfileDto createCustom(DbSession dbSession, QProfileName key, @Nullable String parentKey) {
+    @Override
+    public QProfileDto createCustom(DbSession dbSession, QProfileName key, @Nullable String parentKey) {
       createdProfile = QualityProfileTesting.newQualityProfileDto()
         .setLanguage(key.getLanguage())
         .setParentKee(parentKey)
index cfd30e4588141c95e5c62327ea3096f9b5291183..b2955027080347c7b4c39754ec7e4ca06a787050 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.qualityprofile;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.Reader;
 import java.io.StringWriter;
 import java.io.Writer;
@@ -43,39 +44,38 @@ import org.sonar.db.qualityprofile.QProfileDto;
 import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.rule.DefaultRuleFinder;
 import org.sonar.server.tester.UserSessionRule;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.commons.io.IOUtils.toInputStream;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto;
 
 public class QProfileExportersTest {
 
   @org.junit.Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
-  private System2 system2 = new AlwaysIncreasingSystem2();
+  private final System2 system2 = new AlwaysIncreasingSystem2();
 
   @org.junit.Rule
   public ExpectedException expectedException = ExpectedException.none();
   @org.junit.Rule
   public DbTester db = DbTester.create(system2);
 
-  private RuleFinder ruleFinder = new DefaultRuleFinder(db.getDbClient());
-  private ProfileExporter[] exporters = new ProfileExporter[] {
+  private final RuleFinder ruleFinder = new DefaultRuleFinder(db.getDbClient());
+  private final ProfileExporter[] exporters = new ProfileExporter[] {
     new StandardExporter(), new XooExporter()};
-  private ProfileImporter[] importers = new ProfileImporter[] {
+  private final ProfileImporter[] importers = new ProfileImporter[] {
     new XooProfileImporter(), new XooProfileImporterWithMessages(), new XooProfileImporterWithError()};
   private RuleDefinitionDto rule;
-  private QProfileRules qProfileRules = mock(QProfileRules.class);
-  private QProfileExporters underTest = new QProfileExporters(db.getDbClient(), ruleFinder, qProfileRules, exporters, importers);
+  private final QProfileRules qProfileRules = mock(QProfileRules.class);
+  private final QProfileExporters underTest = new QProfileExporters(db.getDbClient(), ruleFinder, qProfileRules, exporters, importers);
 
   @Before
   public void setUp() {
@@ -101,7 +101,6 @@ public class QProfileExportersTest {
   public void import_xml() {
     QProfileDto profile = createProfile();
 
-
     underTest.importXml(profile, "XooProfileImporter", toInputStream("<xml/>", UTF_8), db.getSession());
 
     ArgumentCaptor<QProfileDto> profileCapture = ArgumentCaptor.forClass(QProfileDto.class);
@@ -129,22 +128,23 @@ public class QProfileExportersTest {
 
   @Test
   public void fail_to_import_xml_when_error_in_importer() {
-    try {
-      underTest.importXml(QProfileTesting.newXooP1(), "XooProfileImporterWithError", toInputStream("<xml/>", UTF_8), db.getSession());
-      fail();
-    } catch (BadRequestException e) {
-      assertThat(e).hasMessage("error!");
-    }
+    QProfileDto qProfileDto = newQualityProfileDto();
+    InputStream inputStream = toInputStream("<xml/>", UTF_8);
+    DbSession dbSession = db.getSession();
+    assertThatThrownBy(() -> underTest.importXml(
+      qProfileDto, "XooProfileImporterWithError", inputStream, dbSession))
+        .isInstanceOf(BadRequestException.class)
+        .hasMessage("error!");
   }
 
   @Test
   public void fail_to_import_xml_on_unknown_importer() {
-    try {
-      underTest.importXml(QProfileTesting.newXooP1(), "Unknown", toInputStream("<xml/>", UTF_8), db.getSession());
-      fail();
-    } catch (BadRequestException e) {
-      assertThat(e).hasMessage("No such importer : Unknown");
-    }
+    QProfileDto qProfileDto = newQualityProfileDto();
+    InputStream inputStream = toInputStream("<xml/>", UTF_8);
+    DbSession dbSession = db.getSession();
+    assertThatThrownBy(() -> underTest.importXml(qProfileDto, "Unknown", inputStream, dbSession))
+      .isInstanceOf(BadRequestException.class)
+      .hasMessage("No such importer : Unknown");
   }
 
   @Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java
deleted file mode 100644 (file)
index 3c2da44..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.qualityprofile;
-
-import org.sonar.db.qualityprofile.QProfileDto;
-
-/**
- * Utility class for tests involving quality profiles.
- * @deprecated replaced by {@link org.sonar.db.qualityprofile.QualityProfileDbTester}
- */
-@Deprecated
-public class QProfileTesting {
-
-  public static final QProfileName XOO_P1_NAME = new QProfileName("xoo", "P1");
-  public static final String XOO_P1_KEY = "XOO_P1";
-  public static final QProfileName XOO_P2_NAME = new QProfileName("xoo", "P2");
-  public static final String XOO_P2_KEY = "XOO_P2";
-  public static final QProfileName XOO_P3_NAME = new QProfileName("xoo", "P3");
-  public static final String XOO_P3_KEY = "XOO_P3";
-
-  /**
-   * @deprecated provide organization as dto
-   */
-  @Deprecated
-  public static QProfileDto newQProfileDto(QProfileName name, String key) {
-    return new QProfileDto()
-      .setKee(key)
-      .setRulesProfileUuid("rp-" + key)
-      .setName(name.getName())
-      .setLanguage(name.getLanguage());
-  }
-
-  /**
-   * @deprecated provide organization as dto
-   */
-  @Deprecated
-  public static QProfileDto newXooP1() {
-    return newQProfileDto(XOO_P1_NAME, XOO_P1_KEY);
-  }
-
-  /**
-   * @deprecated provide organization as dto
-   */
-  @Deprecated
-  public static QProfileDto newXooP2() {
-    return newQProfileDto(XOO_P2_NAME, XOO_P2_KEY);
-  }
-
-  /**
-   * @deprecated provide organization as dto
-   */
-  @Deprecated
-  public static QProfileDto newXooP3() {
-    return newQProfileDto(XOO_P3_NAME, XOO_P3_KEY);
-  }
-}
index e07057725f0abe7838527c0abc66be51ab5bd75e..561ff19fef9bd1ea176b5ae19176dea05cade038 100644 (file)
@@ -67,12 +67,12 @@ public class ActivateRuleActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private ArgumentCaptor<Collection<RuleActivation>> ruleActivationCaptor = ArgumentCaptor.forClass(Collection.class);
-  private DbClient dbClient = db.getDbClient();
-  private QProfileRules qProfileRules = mock(QProfileRules.class);
+  private final ArgumentCaptor<Collection<RuleActivation>> ruleActivationCaptor = ArgumentCaptor.forClass(Collection.class);
+  private final DbClient dbClient = db.getDbClient();
+  private final QProfileRules qProfileRules = mock(QProfileRules.class);
   private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
 
-  private WsActionTester ws = new WsActionTester(new ActivateRuleAction(dbClient, qProfileRules, userSession, wsSupport));
+  private final WsActionTester ws = new WsActionTester(new ActivateRuleAction(dbClient, qProfileRules, userSession, wsSupport));
 
   @Before
   public void before() {
@@ -100,7 +100,7 @@ public class ActivateRuleActionTest {
   }
 
   @Test
-  public void fail_if_not_organization_quality_profile_administrator() {
+  public void fail_if_not_global_quality_profile_administrator() {
     userSession.logIn(db.users().insertUser());
     QProfileDto qualityProfile = db.qualityProfiles().insert();
     TestRequest request = ws.newRequest()
index b32b4818d175627ba19b4beebd4d05a37220019e..196fb809ed6dab44c991d2277bb5531686666d08 100644 (file)
@@ -58,9 +58,9 @@ public class AddGroupActionTest {
   public DbTester db = DbTester.create();
 
   private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
-  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+  private final UuidFactory uuidFactory = UuidFactoryFast.getInstance();
 
-  private WsActionTester ws = new WsActionTester(new AddGroupAction(db.getDbClient(), uuidFactory, wsSupport, LANGUAGES));
+  private final WsActionTester ws = new WsActionTester(new AddGroupAction(db.getDbClient(), uuidFactory, wsSupport, LANGUAGES));
 
   @Test
   public void test_definition() {
@@ -154,7 +154,7 @@ public class AddGroupActionTest {
   }
 
   @Test
-  public void uses_default_organization_when_no_organization() {
+  public void uses_global_permission() {
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
     GroupDto group = db.users().insertGroup();
     userSession.logIn().addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
index 8b7aa5a1505d927bf24a957f3beffe85f4e400ce..43ac22c7528e696d37a1dc213c29b4730f630a3c 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.qualityprofile.QProfileDto;
 import org.sonar.db.user.UserDto;
@@ -59,11 +58,11 @@ public class AddProjectActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
-  private DbClient dbClient = db.getDbClient();
-  private Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
-  private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
-  private AddProjectAction underTest = new AddProjectAction(dbClient, userSession, languages, TestComponentFinder.from(db), wsSupport);
-  private WsActionTester tester = new WsActionTester(underTest);
+  private final DbClient dbClient = db.getDbClient();
+  private final Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
+  private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
+  private final AddProjectAction underTest = new AddProjectAction(dbClient, userSession, languages, TestComponentFinder.from(db), wsSupport);
+  private final WsActionTester tester = new WsActionTester(underTest);
 
   @Test
   public void definition() {
@@ -84,7 +83,7 @@ public class AddProjectActionTest {
   @Test
   public void add_project_on_profile() {
     logInAsProfileAdmin();
-    ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+    ProjectDto project = db.components().insertPrivateProjectDto();
     QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
 
     TestResponse response = call(project, profile);
@@ -107,10 +106,10 @@ public class AddProjectActionTest {
   }
 
   @Test
-  public void change_association_in_default_organization() {
+  public void change_association() {
     logInAsProfileAdmin();
 
-    ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+    ProjectDto project = db.components().insertPrivateProjectDto();
     // two profiles on same language
     QProfileDto profile1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
     QProfileDto profile2 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
@@ -125,7 +124,7 @@ public class AddProjectActionTest {
   @Test
   public void changing_association_does_not_change_other_language_associations() {
     logInAsProfileAdmin();
-    ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+    ProjectDto project = db.components().insertPrivateProjectDto();
     QProfileDto profile1Language1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
     QProfileDto profile2Language2 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_2));
     QProfileDto profile3Language1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
@@ -139,7 +138,7 @@ public class AddProjectActionTest {
 
   @Test
   public void project_administrator_can_change_profile() {
-    ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+    ProjectDto project = db.components().insertPrivateProjectDto();
     QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
     userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project);
 
@@ -149,9 +148,9 @@ public class AddProjectActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_project_nor_organization_administrator() {
+  public void throw_ForbiddenException_if_not_project_nor_global_administrator() {
     userSession.logIn(db.users().insertUser());
-    ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+    ProjectDto project = db.components().insertPrivateProjectDto();
     QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
 
     expectedException.expect(ForbiddenException.class);
@@ -163,7 +162,7 @@ public class AddProjectActionTest {
   @Test
   public void throw_UnauthorizedException_if_not_logged_in() {
     userSession.anonymous();
-    ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+    ProjectDto project = db.components().insertPrivateProjectDto();
     QProfileDto profile = db.qualityProfiles().insert();
 
     expectedException.expect(UnauthorizedException.class);
@@ -189,7 +188,7 @@ public class AddProjectActionTest {
   @Test
   public void throw_NotFoundException_if_profile_does_not_exist() {
     logInAsProfileAdmin();
-    ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
+    ComponentDto project = db.components().insertPrivateProject();
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("Quality Profile for language 'xoo' and name 'unknown' does not exist");
@@ -238,13 +237,4 @@ public class AddProjectActionTest {
       .setParam("qualityProfile", qualityProfile.getName());
     return request.execute();
   }
-
-  private TestResponse call(OrganizationDto organization, ProjectDto project, QProfileDto qualityProfile) {
-    TestRequest request = tester.newRequest()
-      .setParam("organization", organization.getKey())
-      .setParam("project", project.getKey())
-      .setParam("language", qualityProfile.getLanguage())
-      .setParam("qualityProfile", qualityProfile.getName());
-    return request.execute();
-  }
 }
index bf30a046b498a46a395ef6df7d50beda4a2e0fc1..1c68f56f350744980b8fdaed22bef7494f8f3c2b 100644 (file)
@@ -40,7 +40,6 @@ import org.sonar.server.ws.WsActionTester;
 
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
 import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
 import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LOGIN;
 import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE;
@@ -135,21 +134,6 @@ public class AddUserActionTest {
     assertThat(db.getDbClient().qProfileEditUsersDao().exists(db.getSession(), profile, user)).isTrue();
   }
 
-  @Test
-  public void uses_default_organization_when_no_organization() {
-    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
-    UserDto user = db.users().insertUser();
-    userSession.logIn().addPermission(ADMINISTER_QUALITY_PROFILES);
-
-    ws.newRequest()
-      .setParam(PARAM_QUALITY_PROFILE, profile.getName())
-      .setParam(PARAM_LANGUAGE, XOO)
-      .setParam(PARAM_LOGIN, user.getLogin())
-      .execute();
-
-    assertThat(db.getDbClient().qProfileEditUsersDao().exists(db.getSession(), profile, user)).isTrue();
-  }
-
   @Test
   public void fail_when_user_does_not_exist() {
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
index 340394bc72dccb5d0cf4ebd8b0ddef21fdddceff..15ee94823438c025922e8233980e2e23a0b16968 100644 (file)
@@ -47,10 +47,10 @@ public class BackupActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
-  private QProfileBackuper backuper = new QProfileBackuperImpl(db.getDbClient(), null, null, null, new QProfileParser());
+  private final QProfileBackuper backuper = new QProfileBackuperImpl(db.getDbClient(), null, null, null, new QProfileParser());
   private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
-  private Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
-  private WsActionTester tester = new WsActionTester(new BackupAction(db.getDbClient(), backuper, wsSupport, languages));
+  private final Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
+  private final WsActionTester tester = new WsActionTester(new BackupAction(db.getDbClient(), backuper, wsSupport, languages));
 
   @Test
   public void returns_backup_of_profile_with_specified_key() {
@@ -66,7 +66,7 @@ public class BackupActionTest {
   }
 
   @Test
-  public void returns_backup_of_profile_with_specified_name_on_default_organization() {
+  public void returns_backup_of_profile_with_specified_name() {
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(A_LANGUAGE));
 
     TestResponse response = tester.newRequest()
index cd800af8792b2cee6aa881bddfd2638de6f2c4cf..5e56dabbb01801597b993174af6f183796177b25 100644 (file)
@@ -52,7 +52,7 @@ public class ChangelogActionTest {
 
   private static final String DATE = "2011-04-25T01:15:42+0100";
 
-  private TestSystem2 system2 = new TestSystem2().setNow(DateUtils.parseDateTime(DATE).getTime());
+  private final TestSystem2 system2 = new TestSystem2().setNow(DateUtils.parseDateTime(DATE).getTime());
 
   @Rule
   public DbTester db = DbTester.create(system2);
@@ -61,8 +61,8 @@ public class ChangelogActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
-  private WsActionTester ws = new WsActionTester(new ChangelogAction(wsSupport, new Languages(), db.getDbClient()));
+  private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
+  private final WsActionTester ws = new WsActionTester(new ChangelogAction(wsSupport, new Languages(), db.getDbClient()));
 
   @Test
   public void return_change_with_all_fields() {
@@ -168,38 +168,6 @@ public class ChangelogActionTest {
       "}");
   }
 
-  @Test
-  public void find_changelog_by_organization_and_language_and_name() {
-    QProfileDto qualityProfile = db.qualityProfiles().insert();
-    RuleDefinitionDto rule = db.rules().insert();
-    UserDto user = db.users().insertUser();
-    insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user,
-      ImmutableMap.of(
-        "ruleUuid", rule.getUuid(),
-        "severity", "MINOR"));
-
-    String response = ws.newRequest()
-      .setParam(PARAM_LANGUAGE, qualityProfile.getLanguage())
-      .setParam(PARAM_QUALITY_PROFILE, qualityProfile.getName())
-      .execute()
-      .getInput();
-
-    assertJson(response).isSimilarTo("{\n" +
-      "  \"events\": [\n" +
-      "    {\n" +
-      "      \"date\": \"" + DATE + "\",\n" +
-      "      \"authorLogin\": \"" + user.getLogin() + "\",\n" +
-      "      \"action\": \"ACTIVATED\",\n" +
-      "      \"ruleKey\": \"" + rule.getKey() + "\",\n" +
-      "      \"ruleName\": \"" + rule.getName() + "\",\n" +
-      "      \"params\": {\n" +
-      "        \"severity\": \"MINOR\"\n" +
-      "      }\n" +
-      "    }\n" +
-      "  ]\n" +
-      "}");
-  }
-
   @Test
   public void changelog_empty() {
     QProfileDto qualityProfile = db.qualityProfiles().insert();
index 8b0ef3fb3dff7d59d7e3d5767b1c354a6495eda9..c44de89bf60467420d6aebdcc37832119e42bdaa 100644 (file)
@@ -139,7 +139,7 @@ public class CopyActionTest {
   }
 
   @Test
-  public void copy_rules_on_existing_profile_in_default_organization() {
+  public void copy_rules_on_existing_profile() {
     logInAsQProfileAdministrator();
     QProfileDto sourceProfile = db.qualityProfiles().insert(p -> p.setLanguage(A_LANGUAGE));
     QProfileDto targetProfile = db.qualityProfiles().insert(p -> p.setLanguage(A_LANGUAGE));
@@ -213,7 +213,7 @@ public class CopyActionTest {
   }
 
   @Test
-  public void throw_ForbiddenException_if_not_profile_administrator_of_organization() {
+  public void throw_ForbiddenException_if_not_profile_global_administrator() {
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(A_LANGUAGE));
     userSession.logIn().addPermission(GlobalPermission.SCAN);
 
index 78a907c433877c6ce59bd549de65a5b5f372ae7a..0c160b1992ee6be5544fe5fc9140b78eaefc86c2 100644 (file)
@@ -63,12 +63,12 @@ public class DeactivateRuleActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private ArgumentCaptor<Collection<String>> ruleUuidsCaptor = ArgumentCaptor.forClass(Collection.class);
-  private DbClient dbClient = db.getDbClient();
-  private QProfileRules qProfileRules = mock(QProfileRules.class);
+  private final ArgumentCaptor<Collection<String>> ruleUuidsCaptor = ArgumentCaptor.forClass(Collection.class);
+  private final DbClient dbClient = db.getDbClient();
+  private final QProfileRules qProfileRules = mock(QProfileRules.class);
   private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
-  private DeactivateRuleAction underTest = new DeactivateRuleAction(dbClient, qProfileRules, userSession, wsSupport);
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final DeactivateRuleAction underTest = new DeactivateRuleAction(dbClient, qProfileRules, userSession, wsSupport);
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Before
   public void before() {
@@ -84,7 +84,7 @@ public class DeactivateRuleActionTest {
   }
 
   @Test
-  public void deactivate_rule_in_default_organization() {
+  public void deactivate_rule() {
     userSession.logIn(db.users().insertUser()).addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
     QProfileDto qualityProfile = db.qualityProfiles().insert();
     RuleDefinitionDto rule = db.rules().insert(RuleTesting.randomRuleKey());
index 85f27004939258ed1c007c9104c05e826a0dbd29..a0201b8f93045f86cf623040f44ee2594485f987 100644 (file)
@@ -63,18 +63,18 @@ public class DeleteActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
-  private DbClient dbClient = db.getDbClient();
-  private DbSession dbSession = db.getSession();
-  private ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class);
+  private final DbClient dbClient = db.getDbClient();
+  private final DbSession dbSession = db.getSession();
+  private final ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class);
 
-  private DeleteAction underTest = new DeleteAction(
+  private final DeleteAction underTest = new DeleteAction(
     new Languages(LanguageTesting.newLanguage(A_LANGUAGE)),
     new QProfileFactoryImpl(dbClient, UuidFactoryFast.getInstance(), System2.INSTANCE, activeRuleIndexer), dbClient, userSession,
     new QProfileWsSupport(dbClient, userSession));
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
-  public void delete_profile_by_language_and_name_in_default_organization() {
+  public void delete_profile_by_language_and_name() {
     ProjectDto project = db.components().insertPrivateProjectDto();
     QProfileDto profile1 = createProfile();
     QProfileDto profile2 = createProfile();
@@ -94,25 +94,6 @@ public class DeleteActionTest {
     verifyProfileExists(profile2);
   }
 
-  @Test
-  public void delete_profile_by_language_and_name_in_specified_organization() {
-    ProjectDto project = db.components().insertPrivateProjectDto();
-    QProfileDto profile1 = createProfile();
-    QProfileDto profile2 = createProfile();
-    db.qualityProfiles().associateWithProject(project, profile1);
-    logInAsQProfileAdministrator();
-
-    TestResponse response = ws.newRequest()
-      .setMethod("POST")
-      .setParam(PARAM_LANGUAGE, profile1.getLanguage())
-      .setParam(PARAM_QUALITY_PROFILE, profile1.getName())
-      .execute();
-    assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
-
-    verifyProfileDoesNotExist(profile1);
-    verifyProfileExists(profile2);
-  }
-
   @Test
   public void as_qprofile_editor() {
     QProfileDto profile = createProfile();
index 41c7ef9c31ef9d835a2df189d7988881e9defd13..2c3a93929473effbc9681ab869c95de7c2c91c48 100644 (file)
@@ -35,7 +35,6 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.qualityprofile.QProfileDto;
-import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.language.LanguageTesting;
 import org.sonar.server.qualityprofile.QProfileBackuper;
@@ -46,7 +45,6 @@ import org.sonar.server.ws.WsActionTester;
 
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.organization.OrganizationDto.Subscription.PAID;
 
 public class ExportActionTest {
 
@@ -60,11 +58,11 @@ public class ExportActionTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private DbClient dbClient = db.getDbClient();
-  private QProfileBackuper backuper = new TestBackuper();
+  private final DbClient dbClient = db.getDbClient();
+  private final QProfileBackuper backuper = new TestBackuper();
 
   @Test
-  public void export_profile_in_default_organization() {
+  public void export_profile() {
     QProfileDto profile = createProfile(false);
 
     WsActionTester tester = newWsActionTester(newExporter("polop"), newExporter("palap"));
@@ -106,7 +104,7 @@ public class ExportActionTest {
   }
 
   @Test
-  public void throw_NotFoundException_if_profile_with_specified_name_does_not_exist_in_default_organization() {
+  public void throw_NotFoundException_if_profile_with_specified_name_does_not_exist() {
     expectedException.expect(NotFoundException.class);
 
     newWsActionTester().newRequest()
index 11369776308b6b18d86e3eb229d1953b2f2fb8d4..dac5c4c166eb4e337c8e239b5a2b72a1ca3fca19 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.qualityprofile.QProfileDto;
 import org.sonar.db.user.UserDto;
@@ -51,7 +50,7 @@ public class ProjectsActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
-  private WsActionTester ws = new WsActionTester(new ProjectsAction(db.getDbClient(), userSession));
+  private final WsActionTester ws = new WsActionTester(new ProjectsAction(db.getDbClient(), userSession));
 
   @Test
   public void list_authorized_projects_only() {
@@ -80,11 +79,10 @@ public class ProjectsActionTest {
 
   @Test
   public void paginate() {
-    OrganizationDto organization = db.organizations().getDefaultOrganization();
-    ProjectDto project1 = db.components().insertPublicProjectDto(organization, p -> p.setName("Project One"));
-    ProjectDto project2 = db.components().insertPublicProjectDto(organization, p -> p.setName("Project Two"));
-    ProjectDto project3 = db.components().insertPublicProjectDto(organization, p -> p.setName("Project Three"));
-    ProjectDto project4 = db.components().insertPublicProjectDto(organization, p -> p.setName("Project Four"));
+    ProjectDto project1 = db.components().insertPublicProjectDto(p -> p.setName("Project One"));
+    ProjectDto project2 = db.components().insertPublicProjectDto(p -> p.setName("Project Two"));
+    ProjectDto project3 = db.components().insertPublicProjectDto(p -> p.setName("Project Three"));
+    ProjectDto project4 = db.components().insertPublicProjectDto(p -> p.setName("Project Four"));
     QProfileDto qualityProfile = db.qualityProfiles().insert();
     associateProjectsWithProfile(qualityProfile, project1, project2, project3, project4);
 
index ea77a357e523ed306405e99d10ca49cc5d7edf91..9b7b4e14e3e8c8591a62e19c8e12f9b9686ea49a 100644 (file)
@@ -35,15 +35,14 @@ import org.sonar.db.DbTester;
 import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.qualityprofile.QualityProfileTesting;
 import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.db.rule.RuleTesting;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.qualityprofile.QProfileName;
 import org.sonar.server.qualityprofile.QProfileRules;
 import org.sonar.server.qualityprofile.QProfileRulesImpl;
-import org.sonar.server.qualityprofile.QProfileTesting;
 import org.sonar.server.qualityprofile.RuleActivator;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
 import org.sonar.server.rule.index.RuleIndex;
@@ -76,14 +75,14 @@ public class QProfilesWsMediumTest {
   @Rule
   public DbTester dbTester = DbTester.create();
 
-  private DbClient dbClient = dbTester.getDbClient();
-  private DbSession dbSession = dbTester.getSession();
-  private RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
-  private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), dbClient);
-  private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(dbClient, es.client());
-  private TypeValidations typeValidations = new TypeValidations(emptyList());
-  private RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, dbClient, typeValidations, userSessionRule);
-  private QProfileRules qProfileRules = new QProfileRulesImpl(dbClient, ruleActivator, ruleIndex, activeRuleIndexer);
+  private final DbClient dbClient = dbTester.getDbClient();
+  private final DbSession dbSession = dbTester.getSession();
+  private final RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
+  private final RuleIndexer ruleIndexer = new RuleIndexer(es.client(), dbClient);
+  private final ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(dbClient, es.client());
+  private final TypeValidations typeValidations = new TypeValidations(emptyList());
+  private final RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, dbClient, typeValidations, userSessionRule);
+  private final QProfileRules qProfileRules = new QProfileRulesImpl(dbClient, ruleActivator, ruleIndex, activeRuleIndexer);
   private final QProfileWsSupport qProfileWsSupport = new QProfileWsSupport(dbClient, userSessionRule);
   private final RuleQueryFactory ruleQueryFactory = new RuleQueryFactory(dbClient);
 
@@ -397,8 +396,8 @@ public class QProfilesWsMediumTest {
 
   @Test
   public void reset() {
-    QProfileDto profile = QProfileTesting.newXooP1();
-    QProfileDto childProfile = QProfileTesting.newXooP2().setParentKee(QProfileTesting.XOO_P1_KEY);
+    QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setLanguage("java");
+    QProfileDto childProfile = QualityProfileTesting.newQualityProfileDto().setParentKee(profile.getKee()).setLanguage("java");
     dbClient.qualityProfileDao().insert(dbSession, profile, childProfile);
 
     RuleDefinitionDto rule = createRule(profile.getLanguage(), "rule");
@@ -432,7 +431,7 @@ public class QProfilesWsMediumTest {
   }
 
   private QProfileDto createProfile(String lang) {
-    QProfileDto profile = QProfileTesting.newQProfileDto(new QProfileName(lang, "P" + lang), "p" + lang);
+    QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setName("P" + lang).setLanguage(lang);
     dbClient.qualityProfileDao().insert(dbSession, profile);
     return profile;
   }
index 85fc13c707c4f81a7fa0a23a310b216f7d5c79fa..69133c65ea22752ab0ff3ba7d723c6f19bee4bfe 100644 (file)
@@ -57,7 +57,7 @@ public class RemoveGroupActionTest {
 
   private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
 
-  private WsActionTester ws = new WsActionTester(new RemoveGroupAction(db.getDbClient(), wsSupport, LANGUAGES));
+  private final WsActionTester ws = new WsActionTester(new RemoveGroupAction(db.getDbClient(), wsSupport, LANGUAGES));
 
   @Test
   public void test_definition() {
@@ -135,22 +135,6 @@ public class RemoveGroupActionTest {
     assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isFalse();
   }
 
-  @Test
-  public void uses_default_organization_when_no_organization() {
-    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
-    GroupDto group = db.users().insertGroup();
-    db.qualityProfiles().addGroupPermission(profile, group);
-    userSession.logIn().addPermission(GlobalPermission.ADMINISTER_QUALITY_PROFILES);
-
-    ws.newRequest()
-      .setParam(PARAM_QUALITY_PROFILE, profile.getName())
-      .setParam(PARAM_LANGUAGE, XOO)
-      .setParam(PARAM_GROUP, group.getName())
-      .execute();
-
-    assertThat(db.getDbClient().qProfileEditGroupsDao().exists(db.getSession(), profile, group)).isFalse();
-  }
-
   @Test
   public void fail_when_group_does_not_exist() {
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
index 046269a7b5feec9958b6561fd76ee2d7221bb647..c97cae4adcd0b11406e49db05eceb90eb4944182 100644 (file)
@@ -59,13 +59,13 @@ public class RemoveProjectActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
-  private DbClient dbClient = db.getDbClient();
-  private Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
+  private final DbClient dbClient = db.getDbClient();
+  private final Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
   private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
 
-  private RemoveProjectAction underTest = new RemoveProjectAction(dbClient, userSession, languages,
+  private final RemoveProjectAction underTest = new RemoveProjectAction(dbClient, userSession, languages,
     new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT)), wsSupport);
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Test
   public void definition() {
@@ -88,7 +88,7 @@ public class RemoveProjectActionTest {
   public void remove_profile_from_project() {
     logInAsProfileAdmin();
 
-    ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+    ProjectDto project = db.components().insertPrivateProjectDto();
     QProfileDto profileLang1 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_1));
     QProfileDto profileLang2 = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE_2));
     db.qualityProfiles().associateWithProject(project, profileLang1);
@@ -116,7 +116,7 @@ public class RemoveProjectActionTest {
 
   @Test
   public void project_administrator_can_remove_profile() {
-    ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+    ProjectDto project = db.components().insertPrivateProjectDto();
     QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
     db.qualityProfiles().associateWithProject(project, profile);
     userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project);
@@ -143,7 +143,7 @@ public class RemoveProjectActionTest {
   @Test
   public void fail_if_not_enough_permissions() {
     userSession.logIn(db.users().insertUser());
-    ProjectDto project = db.components().insertPrivateProjectDto(db.getDefaultOrganization());
+    ProjectDto project = db.components().insertPrivateProjectDto();
     QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setLanguage("xoo"));
 
     expectedException.expect(ForbiddenException.class);
index c51d018274914185de473156567ec8b67fa1a7ca..c95c35c742c0eb6990828f1bde9e7e97139add05 100644 (file)
@@ -135,7 +135,7 @@ public class RemoveUserActionTest {
   }
 
   @Test
-  public void uses_default_organization_when_no_organization() {
+  public void uses_global_permission() {
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
     UserDto user = db.users().insertUser();
     db.qualityProfiles().addUserPermission(profile, user);
index f74bcc637f2866999d6f95b737c301bf9aa457fd..c341fe39b8911dbf813bd609a749a8e694988b04 100644 (file)
@@ -31,13 +31,10 @@ import org.sonar.api.resources.Languages;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualityprofile.QProfileDto;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualityprofile.BulkChangeResult;
 import org.sonar.server.qualityprofile.QProfileBackuper;
 import org.sonar.server.qualityprofile.QProfileRestoreSummary;
@@ -61,10 +58,9 @@ public class RestoreActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
-  private TestBackuper backuper = new TestBackuper();
-  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
-  private Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
-  private WsActionTester tester = new WsActionTester(new RestoreAction(db.getDbClient(), backuper, languages, userSession));
+  private final TestBackuper backuper = new TestBackuper();
+  private final Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
+  private final WsActionTester tester = new WsActionTester(new RestoreAction(db.getDbClient(), backuper, languages, userSession));
 
   @Test
   public void test_definition() {
@@ -83,9 +79,9 @@ public class RestoreActionTest {
   }
 
   @Test
-  public void profile_is_restored_on_default_organization_with_the_name_provided_in_backup() {
+  public void profile_is_restored_with_the_name_provided_in_backup() {
     logInAsQProfileAdministrator();
-    TestResponse response = restore("<backup/>", null);
+    TestResponse response = restore("<backup/>");
 
     assertThat(backuper.restoredBackup).isEqualTo("<backup/>");
     assertThat(backuper.restoredSummary.getProfile().getName()).isEqualTo("the-name-in-backup");
@@ -102,28 +98,6 @@ public class RestoreActionTest {
       "}");
   }
 
-  @Test
-  public void profile_is_restored_on_specified_organization_with_the_name_provided_in_backup() {
-    OrganizationDto org = db.organizations().insert();
-    logInAsQProfileAdministrator();
-    TestResponse response = restore("<backup/>", org.getKey());
-
-    assertThat(backuper.restoredBackup).isEqualTo("<backup/>");
-    assertThat(backuper.restoredSummary.getProfile().getName()).isEqualTo("the-name-in-backup");
-    JsonAssert.assertJson(response.getInput()).isSimilarTo("{" +
-      "  \"profile\": {" +
-      "    \"name\": \"the-name-in-backup\"," +
-      "    \"language\": \"xoo\"," +
-      "    \"languageName\": \"Xoo\"," +
-      "    \"isDefault\": false," +
-      "    \"isInherited\": false" +
-      "  }," +
-      "  \"ruleSuccesses\": 0," +
-      "  \"ruleFailures\": 0" +
-      "}");
-
-  }
-
   @Test
   public void throw_IAE_if_backup_is_missing() {
     logInAsQProfileAdministrator();
@@ -143,7 +117,7 @@ public class RestoreActionTest {
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
 
-    restore("<backup/>", null);
+    restore("<backup/>");
   }
 
   @Test
@@ -153,7 +127,7 @@ public class RestoreActionTest {
     expectedException.expect(UnauthorizedException.class);
     expectedException.expectMessage("Authentication is required");
 
-    restore("<backup/>", null);
+    restore("<backup/>");
   }
 
   private void logInAsQProfileAdministrator() {
@@ -162,13 +136,10 @@ public class RestoreActionTest {
       .addPermission(ADMINISTER_QUALITY_PROFILES);
   }
 
-  private TestResponse restore(String backupContent, @Nullable String organizationKey) {
+  private TestResponse restore(String backupContent) {
     TestRequest request = tester.newRequest()
       .setMethod("POST")
       .setParam("backup", backupContent);
-    if (organizationKey != null) {
-      request.setParam("organization", organizationKey);
-    }
     return request.execute();
   }
 
@@ -206,7 +177,8 @@ public class RestoreActionTest {
       throw new UnsupportedOperationException();
     }
 
-    @Override public QProfileRestoreSummary copy(DbSession dbSession, QProfileDto from, QProfileDto to) {
+    @Override
+    public QProfileRestoreSummary copy(DbSession dbSession, QProfileDto from, QProfileDto to) {
       throw new UnsupportedOperationException();
     }
   }
index ade503e11a1469ccd1c0f83d423981b75385f927..4e3144bca82191f3aad5f856d6f70507df7ebdbc 100644 (file)
@@ -32,7 +32,6 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.qualityprofile.QProfileDto;
@@ -65,9 +64,9 @@ import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.
 
 public class SearchActionTest {
 
-  private static Language XOO1 = newLanguage("xoo1");
-  private static Language XOO2 = newLanguage("xoo2");
-  private static Languages LANGUAGES = new Languages(XOO1, XOO2);
+  private static final Language XOO1 = newLanguage("xoo1");
+  private static final Language XOO2 = newLanguage("xoo2");
+  private static final Languages LANGUAGES = new Languages(XOO1, XOO2);
 
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
@@ -75,8 +74,8 @@ public class SearchActionTest {
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
-  private QualityProfileDbTester qualityProfileDb = db.qualityProfiles();
-  private DbClient dbClient = db.getDbClient();
+  private final QualityProfileDbTester qualityProfileDb = db.qualityProfiles();
+  private final DbClient dbClient = db.getDbClient();
 
   private SearchAction underTest = new SearchAction(userSession, LANGUAGES, dbClient, new ComponentFinder(dbClient, null));
   private WsActionTester ws = new WsActionTester(underTest);
@@ -98,17 +97,6 @@ public class SearchActionTest {
     assertThat(result.getProfilesList()).isEmpty();
   }
 
-  @Test
-  public void default_organization() {
-    QProfileDto profile1OnDefaultOrg = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
-    QProfileDto profile2OnDefaultOrg = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
-
-    SearchWsResponse result = call(ws.newRequest());
-
-    assertThat(result.getProfilesList()).extracting(QualityProfile::getKey)
-      .containsExactlyInAnyOrder(profile1OnDefaultOrg.getKee(), profile2OnDefaultOrg.getKee());
-  }
-
   @Test
   public void filter_on_default_profile() {
     QProfileDto defaultProfile1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
@@ -264,7 +252,6 @@ public class SearchActionTest {
 
   @Test
   public void actions_when_user_is_global_qprofile_administer() {
-    OrganizationDto organization = db.organizations().getDefaultOrganization();
     QProfileDto customProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
     QProfileDto builtInProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()).setIsBuiltIn(true));
     QProfileDto defaultProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
@@ -286,7 +273,6 @@ public class SearchActionTest {
 
   @Test
   public void actions_when_user_can_edit_profile() {
-    OrganizationDto organization = db.organizations().getDefaultOrganization();
     QProfileDto profile1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
     QProfileDto profile2 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
     QProfileDto profile3 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
index 319cc795a37cdb0bff1d281aa0efebd685bcb6a4..5214c568fc421355acb5991aa3846628bb26a2f0 100644 (file)
@@ -64,7 +64,7 @@ public class SearchGroupsActionTest {
 
   private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
 
-  private WsActionTester ws = new WsActionTester(new SearchGroupsAction(db.getDbClient(), wsSupport, LANGUAGES));
+  private final WsActionTester ws = new WsActionTester(new SearchGroupsAction(db.getDbClient(), wsSupport, LANGUAGES));
 
   @Test
   public void test_definition() {
@@ -234,7 +234,7 @@ public class SearchGroupsActionTest {
   }
 
   @Test
-  public void uses_default_organization_when_no_organization() {
+  public void uses_global_permission() {
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
     GroupDto group = db.users().insertGroup();
     db.qualityProfiles().addGroupPermission(profile, group);
index 232fe883c5d5cead12a7d4d2cba950f9fba0c2a5..da64f6b6cadcc488f03bc0a5263af21bda65f180 100644 (file)
@@ -257,7 +257,7 @@ public class SearchUsersActionTest {
   }
 
   @Test
-  public void uses_default_organization_when_no_organization() {
+  public void uses_global_permission() {
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO));
     UserDto user1 = db.users().insertUser();
     db.qualityProfiles().addUserPermission(profile, user1);
index 5b7981176c606c9b1246acd8c97e8787d03b458e..c5861108c6569c466e3eec72ca10b205e8fe4c6e 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.db.qualityprofile.ActiveRuleParamDto;
 import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.qualityprofile.QualityProfileTesting;
 import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
@@ -49,7 +50,6 @@ import org.sonar.db.rule.RuleTesting;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.es.SearchOptions;
-import org.sonar.server.qualityprofile.QProfileTesting;
 import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.rule.index.RuleQuery;
@@ -65,7 +65,7 @@ public class RuleUpdaterTest {
 
   static final RuleKey RULE_KEY = RuleKey.of("squid", "S001");
 
-  private System2 system2 = new TestSystem2().setNow(Instant.now().toEpochMilli());
+  private final System2 system2 = new TestSystem2().setNow(Instant.now().toEpochMilli());
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
@@ -79,11 +79,11 @@ public class RuleUpdaterTest {
   @Rule
   public EsTester es = EsTester.create();
 
-  private RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
-  private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
-  private DbSession dbSession = db.getSession();
+  private final RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
+  private final RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
+  private final DbSession dbSession = db.getSession();
 
-  private RuleUpdater underTest = new RuleUpdater(db.getDbClient(), ruleIndexer, system2);
+  private final RuleUpdater underTest = new RuleUpdater(db.getDbClient(), ruleIndexer, system2);
 
   @Test
   public void do_not_update_rule_with_removed_status() {
@@ -96,7 +96,7 @@ public class RuleUpdaterTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Rule with REMOVED status cannot be updated: squid:S001");
 
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
   }
 
   @Test
@@ -115,7 +115,7 @@ public class RuleUpdaterTest {
 
     RuleUpdate update = createForPluginRule(RULE_KEY);
     assertThat(update.isEmpty()).isTrue();
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
 
     dbSession.clearCache();
     RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
@@ -147,7 +147,7 @@ public class RuleUpdaterTest {
 
     RuleUpdate update = createForPluginRule(RULE_KEY)
       .setMarkdownNote("my *note*");
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
 
     dbSession.clearCache();
     RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
@@ -173,7 +173,7 @@ public class RuleUpdaterTest {
 
     RuleUpdate update = createForPluginRule(RULE_KEY)
       .setMarkdownNote(null);
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
 
     dbSession.clearCache();
     RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
@@ -194,7 +194,7 @@ public class RuleUpdaterTest {
     // java8 is a system tag -> ignore
     RuleUpdate update = createForPluginRule(RULE_KEY)
       .setTags(Sets.newHashSet("bug", "java8"));
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
 
     RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
     assertThat(rule.getTags()).containsOnly("bug");
@@ -217,7 +217,7 @@ public class RuleUpdaterTest {
 
     RuleUpdate update = createForPluginRule(RULE_KEY)
       .setTags(null);
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
 
     dbSession.clearCache();
     RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
@@ -240,7 +240,7 @@ public class RuleUpdaterTest {
     DefaultDebtRemediationFunction fn = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "1min");
     RuleUpdate update = createForPluginRule(RULE_KEY)
       .setDebtRemediationFunction(fn);
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
     dbSession.clearCache();
 
     // verify debt is overridden
@@ -264,7 +264,7 @@ public class RuleUpdaterTest {
 
     RuleUpdate update = createForPluginRule(RULE_KEY)
       .setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "2d", null));
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
     dbSession.clearCache();
 
     // verify debt is overridden
@@ -288,7 +288,7 @@ public class RuleUpdaterTest {
 
     RuleUpdate update = createForPluginRule(RULE_KEY)
       .setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "10min"));
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
     dbSession.clearCache();
 
     // verify debt is overridden
@@ -317,7 +317,7 @@ public class RuleUpdaterTest {
 
     RuleUpdate update = createForPluginRule(RULE_KEY)
       .setDebtRemediationFunction(null);
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
     dbSession.clearCache();
 
     // verify debt is coming from default values
@@ -357,7 +357,7 @@ public class RuleUpdaterTest {
       .setSeverity("MAJOR")
       .setStatus(RuleStatus.READY)
       .setParameters(ImmutableMap.of("regex", "b.*"));
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
 
     dbSession.clearCache();
 
@@ -405,7 +405,7 @@ public class RuleUpdaterTest {
       .setMarkdownDescription("New description")
       .setSeverity("MAJOR")
       .setStatus(RuleStatus.READY);
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
 
     dbSession.clearCache();
 
@@ -435,7 +435,7 @@ public class RuleUpdaterTest {
     db.rules().insertRuleParam(customRule, param -> param.setName("message").setType("STRING").setDescription("message"));
 
     // Create a quality profile
-    QProfileDto profileDto = QProfileTesting.newXooP1();
+    QProfileDto profileDto = QualityProfileTesting.newQualityProfileDto();
     db.getDbClient().qualityProfileDao().insert(dbSession, profileDto);
     dbSession.commit();
 
@@ -455,7 +455,7 @@ public class RuleUpdaterTest {
     // Update custom rule parameter 'regex', add 'message' and remove 'format'
     RuleUpdate update = createForCustomRule(customRule.getKey())
       .setParameters(ImmutableMap.of("regex", "b.*", "message", "a message"));
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
 
     // Verify custom rule parameters has been updated
     List<RuleParamDto> params = db.getDbClient().ruleDao().selectRuleParamsByRuleKey(dbSession, customRule.getKey());
@@ -503,7 +503,7 @@ public class RuleUpdaterTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The name is missing");
 
-    underTest.update(dbSession, update,  userSessionRule);
+    underTest.update(dbSession, update, userSessionRule);
   }
 
   @Test
@@ -523,7 +523,7 @@ public class RuleUpdaterTest {
 
     underTest.update(dbSession,
       createForCustomRule(customRule.getKey()).setName("New name").setMarkdownDescription(""),
-       userSessionRule);
+      userSessionRule);
   }
 
   @Test