]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11021 Add default QProfile when creating organization
authorEric Hartmann <hartmann.eric@gmail.com>
Fri, 13 Jul 2018 08:59:07 +0000 (10:59 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 17 Jul 2018 18:21:27 +0000 (20:21 +0200)
even if the registry do not contains the QualityProfile. BuiltInQProfileRepository must not be used because
the plugin may have been uninstalled and when reinstalled this may break the contract.

server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java
server/sonar-server/src/main/java/org/sonar/server/organization/OrganizationUpdaterImpl.java
server/sonar-server/src/test/java/org/sonar/server/organization/OrganizationUpdaterImplTest.java

index 04e18cf48b9f2c19fc1bdaad9de9bf4e1ffcab01..89fd9e0e95ff7d68f3272c2e63bf1c63f2e5f2eb 100644 (file)
@@ -124,8 +124,10 @@ public class DefaultQProfileDaoTest {
     QProfileDto profileInOrg2 = dbTester.qualityProfiles().insert(org2, p -> p.setLanguage("java"));
     dbTester.qualityProfiles().setAsDefault(profileInOrg1);
 
-    //assertThat(underTest.selectUuidsOfOrganizationsWithoutDefaultProfile(dbSession, "java")).containsExactly(org2.getUuid());
-    assertThat(underTest.selectUuidsOfOrganizationsWithoutDefaultProfile(dbSession, "js")).containsExactlyInAnyOrder(org1.getUuid(), org2.getUuid());
+    assertThat(underTest.selectUuidsOfOrganizationsWithoutDefaultProfile(dbSession, "java"))
+      .containsExactly(org2.getUuid());
+    assertThat(underTest.selectUuidsOfOrganizationsWithoutDefaultProfile(dbSession, "js"))
+      .containsExactlyInAnyOrder(org1.getUuid(), org2.getUuid());
   }
 
   private void assertThatIsDefault(OrganizationDto org, QProfileDto profile) {
index f2ffd2e9e1a77de67c82a9f27d1e2c4a1508dabf..537a496b7ab5c1d50e543ddd471b04fa87a0c4c9 100644 (file)
@@ -297,13 +297,14 @@ public class OrganizationUpdaterImpl implements OrganizationUpdater {
 
       QProfileName name = new QProfileName(rulesProfile.getLanguage(), rulesProfile.getName());
       BuiltInQProfile builtIn = builtInsPerName.get(name);
-      if (builtIn != null && builtIn.isDefault()) {
+      if (builtIn == null || builtIn.isDefault()) {
+        // If builtIn == null, the plugin has been removed
         // rows of table default_qprofiles must be inserted after org_qprofiles
         // in order to benefit from batch SQL inserts
         defaults.add(new DefaultQProfileDto()
           .setQProfileUuid(dto.getUuid())
           .setOrganizationUuid(organization.getUuid())
-          .setLanguage(builtIn.getLanguage()));
+          .setLanguage(rulesProfile.getLanguage()));
       }
 
       dbClient.qualityProfileDao().insert(batchDbSession, dto);
index f021915ff4980f2a6b888743e6d5ec3733b4367c..14035a152be932f97194513b9ad53837cb481ce1 100644 (file)
@@ -305,17 +305,6 @@ public class OrganizationUpdaterImplTest {
     }
   }
 
-  @Test
-  public void create_fails_with_ISE_if_BuiltInQProfileRepository_has_not_been_initialized() throws OrganizationUpdater.KeyConflictException {
-    UserDto user = db.users().insertUser();
-    db.qualityGates().insertBuiltInQualityGate();
-
-    expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage("initialize must be called first");
-
-    underTest.create(dbSession, user, FULL_POPULATED_NEW_ORGANIZATION);
-  }
-
   @Test
   public void create_fails_with_KeyConflictException_if_org_with_key_in_NewOrganization_arg_already_exists_in_db() throws OrganizationUpdater.KeyConflictException {
     db.organizations().insertForKey(FULL_POPULATED_NEW_ORGANIZATION.getKey());