]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8857 add organisation uuid to quality profile database table
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Wed, 1 Mar 2017 12:49:20 +0000 (13:49 +0100)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Fri, 3 Mar 2017 15:57:17 +0000 (16:57 +0100)
75 files changed:
server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/projects.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/AddQualityProfileOrganizationUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DropUniqueIndexOnQualityProfileKey.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/MakeQualityProfileOrganizationUuidAndKeyUnique.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/MakeQualityProfileOrganizationUuidNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToDefault.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/AddQualityProfileOrganizationUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/DbVersion64Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileKeyNotBeUniqueAnymoreTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileOrganizationUuidAndKeyBeUniqueTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToDefaultTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/AddQualityProfileOrganizationUuidTest/initial.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileKeyNotBeUniqueAnymoreTest/initial.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileOrganizationUuidAndKeyBeUniqueTest/initial.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToDefaultTest/initial.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToNotNullableTest/initial.sql [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ExportActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileFactoryTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RenameActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SetDefaultActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/AppActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleQueryFactoryTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest/index.xml
server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest/active_rule_with_inherited_inheritance.xml
server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest/active_rule_with_overrides_inheritance.xml
server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest/one_active_rule.xml
server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIteratorTest/shared.xml
server/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_active_rule_params-result.xml
server/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_active_rule_params.xml
server/sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_active_rules.xml
sonar-scanner-engine/src/test/resources/org/sonar/scanner/rule/ModuleQProfilesTest/shared.xml

index ca981dba0c0528c561190a8b5382ca54ea203708..1ecd670a4c81cb5edf6e9778af3e9e67aab09568 100644 (file)
@@ -534,6 +534,11 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1517');
 
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1600');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1601');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1602');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1603');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1604');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1605');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1606');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', false, '1418215735482', '1418215735482');
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index c23180d5a4417e61429ade27fd26a1fd9c1d76b3..3b50a832c0b6d686a6b4c7808033acc9f18ba0dc 100644 (file)
@@ -40,6 +40,7 @@ CREATE TABLE "RULES_PROFILES" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "NAME" VARCHAR(100) NOT NULL,
   "LANGUAGE" VARCHAR(20),
+  "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
   "KEE" VARCHAR(255) NOT NULL,
   "PARENT_KEE" VARCHAR(255),
   "RULES_UPDATED_AT" VARCHAR(100),
@@ -49,7 +50,7 @@ CREATE TABLE "RULES_PROFILES" (
   "LAST_USED" BIGINT,
   "USER_UPDATED_AT" BIGINT
 );
-CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
+CREATE UNIQUE INDEX "UNIQ_QPROF_ORG_AND_KEY" ON "RULES_PROFILES" ("ORGANIZATION_UUID", "KEE");
 
 
 CREATE TABLE "PROJECT_QPROFILES" (
index c8abfaa929003d1e7fc2ed269cf00be572845dbd..a55209ac99c52d3ceaf1973ac6d1d959d76f3bac 100644 (file)
@@ -24,10 +24,17 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.core.util.UtcDateUtils;
 import org.sonar.db.Dto;
+import org.sonar.db.organization.OrganizationDto;
 
 public class QualityProfileDto extends Dto<String> {
 
   private Integer id;
+  /**
+   * The organization, that this quality profile belongs to.
+   * Must not be null, but can be the default organization's uuid.
+   * Refers to {@link OrganizationDto#getUuid()}.
+   */
+  private String organizationUuid;
   private String kee;
   private String name;
   private String language;
@@ -45,6 +52,15 @@ public class QualityProfileDto extends Dto<String> {
 
   }
 
+  public String getOrganizationUuid() {
+    return organizationUuid;
+  }
+
+  public QualityProfileDto setOrganizationUuid(String organizationUuid) {
+    this.organizationUuid = organizationUuid;
+    return this;
+  }
+
   @Override
   public String getKey() {
     return kee;
index ff59efdc4172372819419efcf0063592ad6a1807..c29dbb7d974209672577f693fcfa0321ca0d2ee7 100644 (file)
@@ -5,6 +5,7 @@
 
   <sql id="profilesColumns">
     p.id as id,
+    p.organization_uuid as organizationUuid,
     p.kee as kee,
     p.name as name,
     p.language as language,
@@ -18,8 +19,9 @@
   </sql>
 
   <insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO rules_profiles (kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at, last_used, user_updated_at)
+    INSERT INTO rules_profiles (organization_uuid, kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at, last_used, user_updated_at)
     VALUES (
+    #{organizationUuid, jdbcType=VARCHAR},
     #{kee, jdbcType=VARCHAR},
     #{parentKee, jdbcType=VARCHAR},
     #{name, jdbcType=VARCHAR},
index 981bc293f6b31e814283ecc120601200a4e80c1a..9f6656c9d0987ffdf28e90af63c37a55ce88f0ab 100644 (file)
@@ -32,6 +32,8 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.RowNotFoundException;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.db.rule.RuleTesting;
@@ -55,8 +57,10 @@ public class ActiveRuleDaoTest {
 
   private static final long NOW = 10000000L;
 
-  private QualityProfileDto profile1 = QualityProfileDto.createFor("qp1").setName("QProile1");
-  private QualityProfileDto profile2 = QualityProfileDto.createFor("qp2").setName("QProile2");
+  private OrganizationDto organization = OrganizationTesting.newOrganizationDto();
+
+  private QualityProfileDto profile1 = QualityProfileDto.createFor("qp1").setOrganizationUuid(organization.getUuid()).setName("QProfile1");
+  private QualityProfileDto profile2 = QualityProfileDto.createFor("qp2").setOrganizationUuid(organization.getUuid()).setName("QProfile2");
 
   private RuleDto rule1 = RuleTesting.newDto(RuleTesting.XOO_X1);
   private RuleDto rule2 = RuleTesting.newDto(RuleTesting.XOO_X2);
index 41a7950cf357308645934b43b04535d84b6871bf..469a25429ca77d6c6cf6ff67392ad99011d4b43e 100644 (file)
@@ -29,6 +29,8 @@ import org.sonar.core.util.UtcDateUtils;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.organization.OrganizationTesting;
 
 import static com.google.common.collect.ImmutableList.of;
 import static com.google.common.collect.Lists.newArrayList;
@@ -50,6 +52,7 @@ public class QualityProfileDaoTest {
   private DbSession dbSession = dbTester.getSession();
   private QualityProfileDbTester qualityProfileDb = new QualityProfileDbTester(dbTester);
   private QualityProfileDao underTest = dbTester.getDbClient().qualityProfileDao();
+  private OrganizationDto organization = OrganizationTesting.newOrganizationDto();
 
   @Before
   public void before() {
@@ -61,6 +64,7 @@ public class QualityProfileDaoTest {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
 
     QualityProfileDto dto = QualityProfileDto.createFor("abcde")
+      .setOrganizationUuid("org-123")
       .setName("ABCDE")
       .setLanguage("xoo");
 
@@ -74,8 +78,9 @@ public class QualityProfileDaoTest {
   public void update() {
     dbTester.prepareDbUnit(getClass(), "shared.xml");
 
-    QualityProfileDto dto = new QualityProfileDto()
+    QualityProfileDto dto = QualityProfileDto.createFor("key")
       .setId(1)
+      .setOrganizationUuid(organization.getUuid())
       .setName("New Name")
       .setLanguage("js")
       .setParentKee("fghij")
@@ -376,7 +381,10 @@ public class QualityProfileDaoTest {
   }
 
   private QualityProfileDto insertQualityProfileDto(String key, String name, String language) {
-    QualityProfileDto dto = QualityProfileDto.createFor(key).setName(name).setLanguage(language);
+    QualityProfileDto dto = QualityProfileDto.createFor(key)
+      .setOrganizationUuid(organization.getUuid())
+      .setName(name)
+      .setLanguage(language);
     underTest.insert(dbSession, dto);
     return dto;
   }
index 208f4a7022697277b36408d1206857b6c40dce2b..20538cc463f468dce052c25c0f6565757f544ba0 100644 (file)
@@ -33,6 +33,7 @@ public class QualityProfileTesting {
   public static QualityProfileDto newQualityProfileDto() {
     String uuid = Uuids.createFast();
     QualityProfileDto dto = QualityProfileDto.createFor(uuid)
+      .setOrganizationUuid(randomAlphanumeric(40))
       .setName(uuid)
       .setLanguage(randomAlphanumeric(20))
       .setLastUsed(nextLong());
index b2344538ad3e3212a6249677f1e1a7701617eb28..b73e8d7872073eb851f0160a4d29f3ddbe92aa33 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
+  <rules_profiles id="2" name="Sonar Way" language="js" organization_uuid="org-123" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
 
 </dataset>
index 4768bc64707b7a034fcd8530258293db2e9243ca..99be6e6789813031ddcf0a0512037ddd7650cd1b 100644 (file)
@@ -1,23 +1,23 @@
 <dataset>
 
-  <rules_profiles id="1" name="Child1" language="java" parent_kee="java_parent" kee="java_child1" is_default="[false]"
+  <rules_profiles id="1" name="Child1" language="java" organization_uuid="org-123" parent_kee="java_parent" kee="java_child1" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Child2" language="java" parent_kee="java_parent" kee="java_child2" is_default="[false]"
+  <rules_profiles id="2" name="Child2" language="java" organization_uuid="org-123" parent_kee="java_parent" kee="java_child2" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="3" name="Parent" language="java" parent_kee="[null]" kee="java_parent" is_default="[false]"
+  <rules_profiles id="3" name="Parent" language="java" organization_uuid="org-123" parent_kee="[null]" kee="java_parent" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
   <!-- Same profile for another language -->
 
-  <rules_profiles id="4" name="Child1" language="js" parent_kee="js_parent" kee="js_child1" is_default="[false]"
+  <rules_profiles id="4" name="Child1" language="js" organization_uuid="org-123" parent_kee="js_parent" kee="js_child1" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="5" name="Child2" language="js" parent_kee="js_parent" kee="js_child2" is_default="[false]"
+  <rules_profiles id="5" name="Child2" language="js" organization_uuid="org-123" parent_kee="js_parent" kee="js_child2" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="6" name="Parent" language="js" parent_kee="[null]" kee="js_parent" is_default="[false]"
+  <rules_profiles id="6" name="Parent" language="js" organization_uuid="org-123" parent_kee="[null]" kee="js_parent" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
 </dataset>
index e8c8c219220b0b9e7f75e6a46b2219279d1ca90e..fda182db3af20a67dadfc4f4aaa3b86da6e15f62 100644 (file)
@@ -1,12 +1,12 @@
 <dataset>
 
-  <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
+  <rules_profiles id="1" name="Sonar Way" language="java" organization_uuid="org-123" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
+  <rules_profiles id="2" name="Sonar Way" language="js" organization_uuid="org-123" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
 
-  <rules_profiles id="3" name="ABCDE" language="xoo" parent_kee="[null]" kee="abcde" is_default="[false]"
+  <rules_profiles id="3" name="ABCDE" language="xoo" organization_uuid="org-123" parent_kee="[null]" kee="abcde" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
 
 
index 7c458bef8aebb75fc7510524d0396cce404d22f0..e34f6ff42f9fd59c04d644cc717918e18dc85dc6 100644 (file)
@@ -3,6 +3,7 @@
   <rules_profiles id="1"
                   name="Sonar Way"
                   language="java"
+                  organization_uuid="org-123"
                   parent_kee="[null]"
                   kee="java_sonar_way"
                   is_default="[true]"
@@ -12,6 +13,7 @@
   <rules_profiles id="2"
                   name="Sonar Way"
                   language="js"
+                  organization_uuid="org-123"
                   parent_kee="[null]"
                   kee="js_sonar_way"
                   is_default="[true]"
index 94e35a7f936cac796eaa02a24878e97d1e109dfc..c302685c291435146086a0deebdc7844bee1df72 100644 (file)
@@ -1,12 +1,12 @@
 <dataset>
 
-  <rules_profiles id="3" name="Third" language="js" parent_kee="[null]" kee="js_third" is_default="[false]"
+  <rules_profiles id="3" name="Third" language="js" organization_uuid="org-123" parent_kee="[null]" kee="js_third" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="1" name="First" language="js" parent_kee="[null]" kee="js_first" is_default="[false]"
+  <rules_profiles id="1" name="First" language="js" organization_uuid="org-123" parent_kee="[null]" kee="js_first" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Second" language="js" parent_kee="[null]" kee="js_second" is_default="[false]"
+  <rules_profiles id="2" name="Second" language="js" organization_uuid="org-123" parent_kee="[null]" kee="js_second" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
 
index 05dbd930efd0ecea87d8079c08ee27b0b36860de..76c84c783b90899c08c3f6acbe7f273e509d9ee1 100644 (file)
@@ -1,13 +1,13 @@
 <dataset>
 
-  <rules_profiles id="1" name="Sonar Way 1" language="java" parent_kee="[null]" kee="java_sonar_way"
+  <rules_profiles id="1" name="Sonar Way 1" language="java" organization_uuid="org-123" parent_kee="[null]" kee="java_sonar_way"
                   is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
+  <rules_profiles id="2" name="Sonar Way" language="js" organization_uuid="org-123" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="3" name="Sonar Way 2" language="java" parent_kee="[null]" kee="java_sonar_way2"
+  <rules_profiles id="3" name="Sonar Way 2" language="java" organization_uuid="org-123" parent_kee="[null]" kee="java_sonar_way2"
                   is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
index 5736ef59bd42d767d9b346dad42b6df7be7202d4..2e457f029904511d560ca3326b9db409be699aeb 100644 (file)
@@ -1,9 +1,9 @@
 <dataset>
 
-  <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
+  <rules_profiles id="1" name="Sonar Way" language="java" organization_uuid="org-123" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
+  <rules_profiles id="2" name="Sonar Way" language="js" organization_uuid="org-123" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
 
 </dataset>
index d7cb1a3a3a60f8aa7a2e08b103b7305a60bdcfe8..61606c037c0b0ddc749dc29d4842243ad3d41294 100644 (file)
@@ -1,8 +1,8 @@
 <dataset>
 
-  <rules_profiles id="1" name="New Name" language="js" parent_kee="fghij" kee="java_sonar_way" is_default="[false]"
+  <rules_profiles id="1" name="New Name" language="js" organization_uuid="org-123" parent_kee="fghij" kee="java_sonar_way" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
+  <rules_profiles id="2" name="Sonar Way" language="js" organization_uuid="org-123" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
                   rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
 </dataset>
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/AddQualityProfileOrganizationUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/AddQualityProfileOrganizationUuid.java
new file mode 100644 (file)
index 0000000..8098504
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddQualityProfileOrganizationUuid extends DdlChange {
+
+  public AddQualityProfileOrganizationUuid(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(
+      new AddColumnsBuilder(getDialect(), "rules_profiles")
+        .addColumn(newVarcharColumnDefBuilder()
+          .setColumnName("organization_uuid")
+          .setIsNullable(true)
+          .setLimit(UUID_SIZE)
+          .build())
+        .build());
+  }
+}
index 2eb29b7bcec7b909c6d95a777c073f2de2c32556..af45d314cf953a8547b6647e620e3e18f37fc3e9 100644 (file)
@@ -27,7 +27,12 @@ public class DbVersion64 implements DbVersion {
   @Override
   public void addSteps(MigrationStepRegistry registry) {
     registry
-      .add(1600, "Add Projects.TAGS", AddTagsToProjects.class)
-      .add(1601, "Set PROJECTS.COPY_COMPONENT_UUID on local views", SetCopyComponentUuidOnLocalViews.class);
+      .add(1600, "Add PROJECTS.TAGS", AddTagsToProjects.class)
+      .add(1601, "Set PROJECTS.COPY_COMPONENT_UUID on local views", SetCopyComponentUuidOnLocalViews.class)
+      .add(1602, "Add RULES_PROFILES.ORGANIZATION_UUID", AddQualityProfileOrganizationUuid.class)
+      .add(1603, "Set RULES_PROFILES.ORGANIZATION_UUID to default", SetQualityProfileOrganizationUuidToDefault.class)
+      .add(1604, "Make RULES_PROFILES.ORGANIZATION_UUID not nullable", MakeQualityProfileOrganizationUuidNotNullable.class)
+      .add(1605, "Drop unique index on RULES_PROFILES.KEE", DropUniqueIndexOnQualityProfileKey.class)
+      .add(1606, "Make RULES_PROFILES.ORGANIZATION_UUID and KEE unique", MakeQualityProfileOrganizationUuidAndKeyUnique.class);
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DropUniqueIndexOnQualityProfileKey.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/DropUniqueIndexOnQualityProfileKey.java
new file mode 100644 (file)
index 0000000..837a58c
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropUniqueIndexOnQualityProfileKey extends DdlChange {
+
+  public DropUniqueIndexOnQualityProfileKey(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(DdlChange.Context context) throws SQLException {
+    context.execute(
+      new DropIndexBuilder(getDialect())
+        .setTable("rules_profiles")
+        .setName("uniq_qprof_key")
+        .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/MakeQualityProfileOrganizationUuidAndKeyUnique.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/MakeQualityProfileOrganizationUuidAndKeyUnique.java
new file mode 100644 (file)
index 0000000..8db29ee
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeQualityProfileOrganizationUuidAndKeyUnique extends DdlChange {
+
+  public MakeQualityProfileOrganizationUuidAndKeyUnique(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(DdlChange.Context context) throws SQLException {
+    context.execute(
+      new CreateIndexBuilder(getDialect())
+        .setTable("rules_profiles")
+        .setName("uniq_qprof_org_and_key")
+        .addColumn(
+          newVarcharColumnDefBuilder()
+            .setColumnName("organization_uuid")
+            .setLimit(UUID_SIZE)
+            .build())
+        .addColumn(
+          newVarcharColumnDefBuilder()
+            .setColumnName("kee")
+            .setLimit(255)
+            .build())
+        .setUnique(true)
+        .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/MakeQualityProfileOrganizationUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/MakeQualityProfileOrganizationUuidNotNullable.java
new file mode 100644 (file)
index 0000000..cafac35
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeQualityProfileOrganizationUuidNotNullable extends DdlChange {
+
+  public MakeQualityProfileOrganizationUuidNotNullable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(DdlChange.Context context) throws SQLException {
+    context.execute(
+      new AlterColumnsBuilder(getDatabase().getDialect(), "rules_profiles")
+        .updateColumn(newVarcharColumnDefBuilder()
+          .setColumnName("organization_uuid")
+          .setLimit(UUID_SIZE)
+          .setIsNullable(false)
+          .build())
+        .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToDefault.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToDefault.java
new file mode 100644 (file)
index 0000000..2ab126c
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.version.v63.DefaultOrganizationUuid;
+
+public class SetQualityProfileOrganizationUuidToDefault extends DataChange {
+
+  private final DefaultOrganizationUuid defaultOrganizationUuid;
+
+  public SetQualityProfileOrganizationUuidToDefault(Database db, DefaultOrganizationUuid defaultOrganizationUuid) {
+    super(db);
+    this.defaultOrganizationUuid = defaultOrganizationUuid;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.prepareUpsert("update rules_profiles set organization_uuid=? where organization_uuid is null")
+      .setString(1, defaultOrganizationUuid.get(context))
+      .execute()
+      .commit();
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/AddQualityProfileOrganizationUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/AddQualityProfileOrganizationUuidTest.java
new file mode 100644 (file)
index 0000000..e481530
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class AddQualityProfileOrganizationUuidTest {
+
+  /** @see org.sonar.db.AbstractDbTester#assertColumnDefinition(String, String, int, Integer, Boolean) */
+  private static final boolean NULLABLE = true;
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddQualityProfileOrganizationUuidTest.class, "initial.sql");
+
+  public AddQualityProfileOrganizationUuid underTest = new AddQualityProfileOrganizationUuid(db.database());
+
+  @Test
+  public void test() throws SQLException {
+    underTest.execute();
+    db.assertColumnDefinition("rules_profiles", "organization_uuid", java.sql.Types.VARCHAR, 40, NULLABLE);
+  }
+}
index cbfdc7cd0691d37ce5d2ed583eeccdaca5a5efb9..76dfe4950c741cb947b2d4e1dedf6e4d2051644c 100644 (file)
@@ -35,7 +35,7 @@ public class DbVersion64Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 2);
+    verifyMigrationCount(underTest, 7);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileKeyNotBeUniqueAnymoreTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileKeyNotBeUniqueAnymoreTest.java
new file mode 100644 (file)
index 0000000..9005567
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class LetQualityProfileKeyNotBeUniqueAnymoreTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(LetQualityProfileKeyNotBeUniqueAnymoreTest.class, "initial.sql");
+
+  public DropUniqueIndexOnQualityProfileKey underTest = new DropUniqueIndexOnQualityProfileKey(db.database());
+
+  @Test
+  public void test() throws SQLException {
+    underTest.execute();
+    db.assertIndexDoesNotExist("rules_profiles", "uniq_qprof_key");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileOrganizationUuidAndKeyBeUniqueTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileOrganizationUuidAndKeyBeUniqueTest.java
new file mode 100644 (file)
index 0000000..6ed4042
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class LetQualityProfileOrganizationUuidAndKeyBeUniqueTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(LetQualityProfileOrganizationUuidAndKeyBeUniqueTest.class, "initial.sql");
+
+  public MakeQualityProfileOrganizationUuidAndKeyUnique underTest = new MakeQualityProfileOrganizationUuidAndKeyUnique(db.database());
+
+  @Test
+  public void test() throws SQLException {
+    underTest.execute();
+    db.assertUniqueIndex("rules_profiles", "uniq_qprof_org_and_key", "organization_uuid", "kee");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToDefaultTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToDefaultTest.java
new file mode 100644 (file)
index 0000000..51080d0
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.assertj.core.api.Assertions;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.version.v63.DefaultOrganizationUuid;
+import org.sonar.server.platform.db.migration.version.v63.TestDefaultOrganizationUuid;
+
+public class SetQualityProfileOrganizationUuidToDefaultTest {
+
+  private static final String DEFAULT_ORG = "some uuid";
+  private static final String PROFILE_KEY = "java-sonar-way-999999";
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(SetQualityProfileOrganizationUuidToDefaultTest.class, "initial.sql");
+
+  private DefaultOrganizationUuid defaultOrganization = new TestDefaultOrganizationUuid(DEFAULT_ORG);
+
+  public SetQualityProfileOrganizationUuidToDefault underTest = new SetQualityProfileOrganizationUuidToDefault(db.database(), defaultOrganization);
+
+  @Test
+  public void should_change_profile_without_organization() throws SQLException {
+    db.executeInsert("RULES_PROFILES", "NAME", "java", "kee", PROFILE_KEY);
+
+    underTest.execute();
+
+    Assertions.assertThat(db.selectFirst("SELECT ORGANIZATION_UUID FROM RULES_PROFILES WHERE KEE = '" + PROFILE_KEY + "'")).containsValue(DEFAULT_ORG);
+  }
+
+  @Test
+  public void should_keep_existing_organization() throws SQLException {
+    String otherOrg = "existing uuid";
+    db.executeInsert("RULES_PROFILES", "NAME", "java", "kee", PROFILE_KEY, "organization_uuid", otherOrg);
+
+    underTest.execute();
+
+    Assertions.assertThat(db.selectFirst("SELECT ORGANIZATION_UUID FROM RULES_PROFILES WHERE KEE = '" + PROFILE_KEY + "'")).containsValue(otherOrg);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToNotNullableTest.java
new file mode 100644 (file)
index 0000000..cd7df93
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.platform.db.migration.version.v64;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class SetQualityProfileOrganizationUuidToNotNullableTest {
+
+  /** @see org.sonar.db.AbstractDbTester#assertColumnDefinition(String, String, int, Integer, Boolean) */
+  private static final boolean NOT_NULLABLE = false;
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(SetQualityProfileOrganizationUuidToNotNullableTest.class, "initial.sql");
+
+  public MakeQualityProfileOrganizationUuidNotNullable underTest = new MakeQualityProfileOrganizationUuidNotNullable(db.database());
+
+  @Test
+  public void test() throws SQLException {
+    underTest.execute();
+    db.assertColumnDefinition("rules_profiles", "organization_uuid", java.sql.Types.VARCHAR, 40, NOT_NULLABLE);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/AddQualityProfileOrganizationUuidTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/AddQualityProfileOrganizationUuidTest/initial.sql
new file mode 100644 (file)
index 0000000..c78c7f1
--- /dev/null
@@ -0,0 +1,14 @@
+CREATE TABLE "RULES_PROFILES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "NAME" VARCHAR(100) NOT NULL,
+  "LANGUAGE" VARCHAR(20),
+  "KEE" VARCHAR(255) NOT NULL,
+  "PARENT_KEE" VARCHAR(255),
+  "RULES_UPDATED_AT" VARCHAR(100),
+  "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+  "LAST_USED" BIGINT,
+  "USER_UPDATED_AT" BIGINT
+);
+CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileKeyNotBeUniqueAnymoreTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileKeyNotBeUniqueAnymoreTest/initial.sql
new file mode 100644 (file)
index 0000000..0014a2d
--- /dev/null
@@ -0,0 +1,15 @@
+CREATE TABLE "RULES_PROFILES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "NAME" VARCHAR(100) NOT NULL,
+  "LANGUAGE" VARCHAR(20),
+  "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+  "KEE" VARCHAR(255) NOT NULL,
+  "PARENT_KEE" VARCHAR(255),
+  "RULES_UPDATED_AT" VARCHAR(100),
+  "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+  "LAST_USED" BIGINT,
+  "USER_UPDATED_AT" BIGINT
+);
+CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileOrganizationUuidAndKeyBeUniqueTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/LetQualityProfileOrganizationUuidAndKeyBeUniqueTest/initial.sql
new file mode 100644 (file)
index 0000000..29ff1d5
--- /dev/null
@@ -0,0 +1,14 @@
+CREATE TABLE "RULES_PROFILES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "NAME" VARCHAR(100) NOT NULL,
+  "LANGUAGE" VARCHAR(20),
+  "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+  "KEE" VARCHAR(255) NOT NULL,
+  "PARENT_KEE" VARCHAR(255),
+  "RULES_UPDATED_AT" VARCHAR(100),
+  "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+  "LAST_USED" BIGINT,
+  "USER_UPDATED_AT" BIGINT
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToDefaultTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToDefaultTest/initial.sql
new file mode 100644 (file)
index 0000000..a67a0e5
--- /dev/null
@@ -0,0 +1,15 @@
+CREATE TABLE "RULES_PROFILES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "NAME" VARCHAR(100) NOT NULL,
+  "LANGUAGE" VARCHAR(20),
+  "ORGANIZATION_UUID" VARCHAR(40) NULL,
+  "KEE" VARCHAR(255) NOT NULL,
+  "PARENT_KEE" VARCHAR(255),
+  "RULES_UPDATED_AT" VARCHAR(100),
+  "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+  "LAST_USED" BIGINT,
+  "USER_UPDATED_AT" BIGINT
+);
+CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToNotNullableTest/initial.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v64/SetQualityProfileOrganizationUuidToNotNullableTest/initial.sql
new file mode 100644 (file)
index 0000000..a67a0e5
--- /dev/null
@@ -0,0 +1,15 @@
+CREATE TABLE "RULES_PROFILES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "NAME" VARCHAR(100) NOT NULL,
+  "LANGUAGE" VARCHAR(20),
+  "ORGANIZATION_UUID" VARCHAR(40) NULL,
+  "KEE" VARCHAR(255) NOT NULL,
+  "PARENT_KEE" VARCHAR(255),
+  "RULES_UPDATED_AT" VARCHAR(100),
+  "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+  "LAST_USED" BIGINT,
+  "USER_UPDATED_AT" BIGINT
+);
+CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");
index 43a5eedc283815dd17eac74764d65caa722ef8a9..f286ae506710134564ab11ea7927673d89e4eb9e 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.organization.DefaultOrganizationProvider;
 
 import static org.sonar.server.qualityprofile.ActiveRuleChange.Type.DEACTIVATED;
 import static org.sonar.server.ws.WsUtils.checkFound;
@@ -46,9 +47,11 @@ import static org.sonar.server.ws.WsUtils.checkRequest;
 public class QProfileFactory {
 
   private final DbClient db;
+  private final DefaultOrganizationProvider defaultOrganizationProvider;
 
-  public QProfileFactory(DbClient db) {
+  public QProfileFactory(DbClient db, DefaultOrganizationProvider defaultOrganizationProvider) {
     this.db = db;
+    this.defaultOrganizationProvider = defaultOrganizationProvider;
   }
 
   // ------------- CREATION
@@ -76,6 +79,7 @@ public class QProfileFactory {
       String key = Slug.slugify(String.format("%s %s %s", name.getLanguage(), name.getName(), RandomStringUtils.randomNumeric(5)));
       QualityProfileDto dto = QualityProfileDto.createFor(key)
         .setName(name.getName())
+        .setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
         .setLanguage(name.getLanguage())
         .setRulesUpdatedAtAsDate(now);
       if (db.qualityProfileDao().selectByKey(dbSession, dto.getKey()) == null) {
index 0b2b434d7fa788ea3d0317d9ad1bf8d241e6e423..0d45ecf027df83f7ee2cbd9756494f9e0890b415 100644 (file)
@@ -602,7 +602,7 @@ public class ProjectDataLoaderMediumTest {
   }
 
   private void addDefaultProfile() {
-    QualityProfileDto profileDto = newQProfileDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
+    QualityProfileDto profileDto = newQProfileDto("org-123", QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
       formatDateTime(new Date())).setDefault(true);
     dbClient.qualityProfileDao().insert(dbSession, profileDto);
   }
index 5c9c7e515397616c5adf04af9bdee5b4db0543a8..b852d53de25f470c44cf655dd3ea10854e6b3028 100644 (file)
@@ -116,7 +116,7 @@ public class QProfileBackuperMediumTest {
     ruleIndexer.index();
 
     // create profile P1 with rules x2 and x1 activated
-    db.qualityProfileDao().insert(dbSession, newXooP1());
+    db.qualityProfileDao().insert(dbSession, newXooP1("org-123"));
     RuleActivation activation1 = new RuleActivation(XOO_X2).setSeverity("MINOR");
     RuleActivation activation2 = new RuleActivation(XOO_X1);
     RuleActivation activation3 = new RuleActivation(blahRuleKey);
@@ -174,7 +174,7 @@ public class QProfileBackuperMediumTest {
   @Test
   public void restore_and_update_profile() throws Exception {
     // create profile P1 with rules x1 and x2 activated
-    db.qualityProfileDao().insert(dbSession, newXooP1());
+    db.qualityProfileDao().insert(dbSession, newXooP1("org-123"));
     RuleActivation activation = new RuleActivation(XOO_X1);
     activation.setSeverity(Severity.INFO);
     activation.setParameter("max", "10");
@@ -213,8 +213,8 @@ public class QProfileBackuperMediumTest {
   public void restore_child_profile() throws Exception {
     // define two parent/child profiles
     db.qualityProfileDao().insert(dbSession,
-      newXooP1(),
-      newXooP2().setParentKee(XOO_P1_KEY));
+      newXooP1("org-123"),
+      newXooP2("org-123").setParentKee(XOO_P1_KEY));
     dbSession.commit();
 
     // rule x1 is activated on parent profile (so inherited by child profile)
@@ -261,8 +261,8 @@ public class QProfileBackuperMediumTest {
   public void restore_parent_profile() throws Exception {
     // define two parent/child profiles
     db.qualityProfileDao().insert(dbSession,
-      newXooP1(),
-      newXooP2().setParentKee(XOO_P1_KEY));
+      newXooP1("org-123"),
+      newXooP2("org-123").setParentKee(XOO_P1_KEY));
     dbSession.commit();
 
     // rule x1 is activated on parent profile (so inherited by child profile)
@@ -310,8 +310,8 @@ public class QProfileBackuperMediumTest {
   public void keep_other_inherited_rules() throws Exception {
     // define two parent/child profiles
     db.qualityProfileDao().insert(dbSession,
-      newXooP1(),
-      newXooP2().setParentKee(XOO_P1_KEY));
+      newXooP1("org-123"),
+      newXooP2("org-123").setParentKee(XOO_P1_KEY));
     dbSession.commit();
 
     // rule x1 is activated on parent profile and is inherited by child profile
index 2ed4bf64208879f8c0cc983e2af0478a49455b5e..acda317fa92d4227cffcd4fbd53d9129ef9363b4 100644 (file)
@@ -76,8 +76,8 @@ public class QProfileComparisonMediumTest {
     db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1)
       .setName("min").setType(RuleParamType.INTEGER.type()));
 
-    left = QProfileTesting.newXooP1();
-    right = QProfileTesting.newXooP2();
+    left = QProfileTesting.newXooP1("org-123");
+    right = QProfileTesting.newXooP2("org-123");
     db.qualityProfileDao().insert(dbSession, left, right);
 
     dbSession.commit();
index b9021bedeb7f7c62c92e145b300dc64b6f205239..7ec5bdcd442568ea1b6433155b67cb6fdf22a542 100644 (file)
@@ -84,7 +84,7 @@ public class QProfileCopierMediumTest {
       .setName("max").setDefaultValue("10").setType(RuleParamType.INTEGER.type()));
 
     // create pre-defined profile
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
     dbSession.commit();
     dbSession.clearCache();
     ruleIndexer.index();
@@ -124,7 +124,7 @@ public class QProfileCopierMediumTest {
     activeRuleIndexer.index();
 
     // create target with both x1 and x2 activated
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2("org-123"));
     activation = new RuleActivation(RuleTesting.XOO_X1);
     activation.setSeverity(Severity.CRITICAL);
     activation.setParameter("max", "20");
@@ -145,7 +145,7 @@ public class QProfileCopierMediumTest {
   @Test
   public void create_target_profile_with_same_parent_than_source() {
     // two profiles : parent and its child
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2().setParentKee(QProfileTesting.XOO_P1_KEY));
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2("org-123").setParentKee(QProfileTesting.XOO_P1_KEY));
 
     // parent and child with x1 activated
     RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
index a95f0e80661af8159fa4e1c009c94d8a6534452d..81bc80b56064304198b0f519105978382588817c 100644 (file)
@@ -104,7 +104,7 @@ public class QProfileExportersTest {
 
   @Test
   public void import_xml() {
-    QualityProfileDto profileDto = QProfileTesting.newQProfileDto(QProfileName.createFor("xoo", "import_xml"), "import_xml");
+    QualityProfileDto profileDto = QProfileTesting.newQProfileDto("org-123", QProfileName.createFor("xoo", "import_xml"), "import_xml");
     db.qualityProfileDao().insert(dbSession, profileDto);
     dbSession.commit();
 
@@ -127,7 +127,7 @@ public class QProfileExportersTest {
 
   @Test
   public void import_xml_return_messages() {
-    QProfileResult result = exporters.importXml(QProfileTesting.newXooP1(), "XooProfileImporterWithMessages", toInputStream("<xml/>", UTF_8), dbSession);
+    QProfileResult result = exporters.importXml(QProfileTesting.newXooP1("org-123"), "XooProfileImporterWithMessages", toInputStream("<xml/>", UTF_8), dbSession);
     dbSession.commit();
 
     assertThat(result.infos()).containsOnly("an info");
@@ -137,7 +137,7 @@ public class QProfileExportersTest {
   @Test
   public void fail_to_import_xml_when_error_in_importer() {
     try {
-      exporters.importXml(QProfileTesting.newXooP1(), "XooProfileImporterWithError", toInputStream("<xml/>", UTF_8), dbSession);
+      exporters.importXml(QProfileTesting.newXooP1("org-123"), "XooProfileImporterWithError", toInputStream("<xml/>", UTF_8), dbSession);
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("error!");
@@ -147,7 +147,7 @@ public class QProfileExportersTest {
   @Test
   public void fail_to_import_xml_on_unknown_importer() {
     try {
-      exporters.importXml(QProfileTesting.newXooP1(), "Unknown", toInputStream("<xml/>", UTF_8), dbSession);
+      exporters.importXml(QProfileTesting.newXooP1("org-123"), "Unknown", toInputStream("<xml/>", UTF_8), dbSession);
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("No such importer : Unknown");
index 01813ba655539d7e99b3511d5fcde2551cd56884..9c482b9cb4ae43480c27745ce1b438d2891c9549 100644 (file)
@@ -208,7 +208,7 @@ public class QProfileFactoryMediumTest {
   @Test
   public void delete() {
     initRules();
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
     tester.get(RuleActivator.class).activate(dbSession, new RuleActivation(RuleTesting.XOO_X1), XOO_P1_KEY);
     dbSession.commit();
     dbSession.clearCache();
@@ -230,7 +230,7 @@ public class QProfileFactoryMediumTest {
     initRules();
 
     // create parent and child profiles
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1(), QProfileTesting.newXooP2(), QProfileTesting.newXooP3());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"), QProfileTesting.newXooP2("org-123"), QProfileTesting.newXooP3("org-123"));
     List<ActiveRuleChange> changes = tester.get(RuleActivator.class).setParent(dbSession, XOO_P2_KEY, XOO_P1_KEY);
     changes.addAll(tester.get(RuleActivator.class).setParent(dbSession, XOO_P3_KEY, XOO_P1_KEY));
     changes.addAll(tester.get(RuleActivator.class).activate(dbSession, new RuleActivation(RuleTesting.XOO_X1), XOO_P1_KEY));
@@ -256,7 +256,7 @@ public class QProfileFactoryMediumTest {
 
   @Test
   public void do_not_delete_default_profile() {
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
     factory.setDefault(dbSession, XOO_P1_KEY);
     dbSession.commit();
     dbSession.clearCache();
@@ -274,7 +274,7 @@ public class QProfileFactoryMediumTest {
 
   @Test
   public void do_not_delete_if_default_descendant() {
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1(), QProfileTesting.newXooP2(), QProfileTesting.newXooP3());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"), QProfileTesting.newXooP2("org-123"), QProfileTesting.newXooP3("org-123"));
 
     List<ActiveRuleChange> changes = tester.get(RuleActivator.class).setParent(dbSession, XOO_P2_KEY, XOO_P1_KEY);
     changes.addAll(tester.get(RuleActivator.class).setParent(dbSession, XOO_P3_KEY, XOO_P1_KEY));
@@ -306,7 +306,7 @@ public class QProfileFactoryMediumTest {
 
   @Test
   public void set_default_profile() {
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
     dbSession.commit();
     dbSession.clearCache();
 
index 121d2a4e7256d929e90b8833503003df52a7b61a..de9ae43fc1cbba46bf8cdedc5e4bea63ab488120 100644 (file)
@@ -29,6 +29,8 @@ import org.sonar.db.DbTester;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.db.qualityprofile.QualityProfileTesting;
 import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.organization.DefaultOrganizationProvider;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -40,8 +42,9 @@ public class QProfileFactoryTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
+  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
   private DbSession dbSession = dbTester.getSession();
-  private QProfileFactory underTest = new QProfileFactory(dbTester.getDbClient());
+  private QProfileFactory underTest = new QProfileFactory(dbTester.getDbClient(), defaultOrganizationProvider);
 
   @Before
   public void setUp() throws Exception {
index b01cbc25a9caff7575f4713e353d78054ef5ceaf..74103b60b956551238c824f72613636ca9a5b6c3 100644 (file)
@@ -88,7 +88,7 @@ public class QProfileServiceMediumTest {
     dbClient.ruleDao().insert(dbSession, xooRule1);
 
     // create pre-defined profiles P1 and P2
-    dbClient.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1(), QProfileTesting.newXooP2());
+    dbClient.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"), QProfileTesting.newXooP2("org-123"));
 
     dbSession.commit();
     dbSession.clearCache();
index 1b4646c3d918b579e9a57d59e4cd0cbd95efb98e..f6ea9d12059be3d1e1e81527ff368da392ca1c33 100644 (file)
@@ -33,19 +33,19 @@ public class QProfileTesting {
   public static final QProfileName XOO_P3_NAME = new QProfileName("xoo", "P3");
   public static final String XOO_P3_KEY = "XOO_P3";
 
-  public static QualityProfileDto newQProfileDto(QProfileName name, String key) {
-    return QualityProfileDto.createFor(key).setName(name.getName()).setLanguage(name.getLanguage());
+  public static QualityProfileDto newQProfileDto(String organizationUuid, QProfileName name, String key) {
+    return QualityProfileDto.createFor(key).setOrganizationUuid(organizationUuid).setName(name.getName()).setLanguage(name.getLanguage());
   }
 
-  public static QualityProfileDto newXooP1() {
-    return newQProfileDto(XOO_P1_NAME, XOO_P1_KEY);
+  public static QualityProfileDto newXooP1(String organizationUuid) {
+    return newQProfileDto(organizationUuid, XOO_P1_NAME, XOO_P1_KEY);
   }
 
-  public static QualityProfileDto newXooP2() {
-    return newQProfileDto(XOO_P2_NAME, XOO_P2_KEY);
+  public static QualityProfileDto newXooP2(String organizationUuid) {
+    return newQProfileDto(organizationUuid, XOO_P2_NAME, XOO_P2_KEY);
   }
 
-  public static QualityProfileDto newXooP3() {
-    return newQProfileDto(XOO_P3_NAME, XOO_P3_KEY);
+  public static QualityProfileDto newXooP3(String organizationUuid) {
+    return newQProfileDto(organizationUuid, XOO_P3_NAME, XOO_P3_KEY);
   }
 }
index b7ffe8148a66e6b7bba6c494e83b9372aff6d16a..a5465f6e9f1e4125e9234a27d0c2af2ace3d8a15 100644 (file)
@@ -132,7 +132,7 @@ public class RuleActivatorMediumTest {
       .setName("format").setDefaultValue("txt").setType(RuleParamType.STRING.type()));
 
     // create pre-defined profile P1
-    profileDto = QProfileTesting.newXooP1();
+    profileDto = QProfileTesting.newXooP1("org-123");
     db.qualityProfileDao().insert(dbSession, profileDto);
     dbSession.commit();
     dbSession.clearCache();
@@ -944,7 +944,7 @@ public class RuleActivatorMediumTest {
     verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, MAJOR, null, ImmutableMap.of("max", "10"));
 
     // create profile P2 with x2
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2("org-123"));
     activation = new RuleActivation(XOO_X2);
     activation.setSeverity("MAJOR");
     activate(activation, XOO_P2_KEY);
@@ -993,7 +993,7 @@ public class RuleActivatorMediumTest {
     verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, MAJOR, null, ImmutableMap.of("max", "10"));
 
     // create empty profile P2
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2("org-123"));
     dbSession.commit();
     dbSession.clearCache();
 
@@ -1023,7 +1023,7 @@ public class RuleActivatorMediumTest {
     activate(activation, XOO_P1_KEY);
 
     // create profile P2
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2("org-123"));
 
     // mark rule x1 as REMOVED
     RuleDto rule = db.ruleDao().selectOrFailByKey(dbSession, XOO_X1);
@@ -1158,8 +1158,8 @@ public class RuleActivatorMediumTest {
   }
 
   private void createChildProfiles() {
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2().setParentKee(XOO_P1_KEY));
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP3().setParentKee(XOO_P2_KEY));
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2("org-123").setParentKee(XOO_P1_KEY));
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP3("org-123").setParentKee(XOO_P2_KEY));
     dbSession.commit();
   }
 
index a259f8fb6a12a393abf27b0ff1f8f263918ab16f..d31fd00411435bdfae53d186c311768cde2cf5d8 100644 (file)
@@ -28,6 +28,8 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.db.qualityprofile.QualityProfileDto;
@@ -63,6 +65,8 @@ public class ActiveRuleIndexerTest {
 
   private ActiveRuleIndexer indexer = new ActiveRuleIndexer(system2, dbTester.getDbClient(), esTester.client());
 
+  private OrganizationDto organization = OrganizationTesting.newOrganizationDto();
+
   @Test
   public void index_nothing() {
     indexer.index(Iterators.emptyIterator());
@@ -128,7 +132,10 @@ public class ActiveRuleIndexerTest {
     // Index one active rule
     RuleDto rule = RuleTesting.newDto(RULE_KEY_1);
     dbTester.getDbClient().ruleDao().insert(dbTester.getSession(), rule);
-    QualityProfileDto profile = QualityProfileDto.createFor("qp").setLanguage("xoo").setName("profile");
+    QualityProfileDto profile = QualityProfileDto.createFor("qp")
+      .setOrganizationUuid(organization.getUuid())
+      .setLanguage("xoo")
+      .setName("profile");
     dbTester.getDbClient().qualityProfileDao().insert(dbTester.getSession(), profile);
     ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity(Severity.BLOCKER)
       .setCreatedAt(yesterday).setUpdatedAt(yesterday);
index 4ba3206228b5aad4d3edb7bc7fc89dd67b46e283..c086786afef23f31ea5ba509dd54f50180e3c833 100644 (file)
@@ -78,7 +78,7 @@ public class AddProjectActionTest {
   @Test
   public void add_project() throws Exception {
     setUserAsQualityProfileAdmin();
-    QualityProfileDto profile = qualityProfileDbTester.insertQualityProfile(newQProfileDto(QProfileName.createFor(LANGUAGE_1, "profile1"), "Profile"));
+    QualityProfileDto profile = qualityProfileDbTester.insertQualityProfile(newQProfileDto("org-123", QProfileName.createFor(LANGUAGE_1, "profile1"), "Profile"));
     session.commit();
 
     executeRequest(project, profile);
@@ -89,8 +89,8 @@ public class AddProjectActionTest {
   @Test
   public void change_project_association() throws Exception {
     setUserAsQualityProfileAdmin();
-    QualityProfileDto profile1 = newQProfileDto(QProfileName.createFor(LANGUAGE_1, "profile1"), "Profile 1");
-    QualityProfileDto profile2 = newQProfileDto(QProfileName.createFor(LANGUAGE_1, "profile2"), "Profile 2");
+    QualityProfileDto profile1 = newQProfileDto("org-123", QProfileName.createFor(LANGUAGE_1, "profile1"), "Profile 1");
+    QualityProfileDto profile2 = newQProfileDto("org-123", QProfileName.createFor(LANGUAGE_1, "profile2"), "Profile 2");
     qualityProfileDbTester.insertQualityProfiles(profile1, profile2);
     qualityProfileDbTester.associateProjectWithQualityProfile(project, profile1);
     session.commit();
@@ -103,9 +103,9 @@ public class AddProjectActionTest {
   @Test
   public void change_project_association_when_project_is_linked_on_many_profiles() throws Exception {
     setUserAsQualityProfileAdmin();
-    QualityProfileDto profile1Language1 = newQProfileDto(QProfileName.createFor(LANGUAGE_1, "profile1"), "Profile 1");
-    QualityProfileDto profile2Language2 = newQProfileDto(QProfileName.createFor(LANGUAGE_2, "profile2"), "Profile 2");
-    QualityProfileDto profile3Language1 = newQProfileDto(QProfileName.createFor(LANGUAGE_1, "profile3"), "Profile 3");
+    QualityProfileDto profile1Language1 = newQProfileDto("org-123", QProfileName.createFor(LANGUAGE_1, "profile1"), "Profile 1");
+    QualityProfileDto profile2Language2 = newQProfileDto("org-123", QProfileName.createFor(LANGUAGE_2, "profile2"), "Profile 2");
+    QualityProfileDto profile3Language1 = newQProfileDto("org-123", QProfileName.createFor(LANGUAGE_1, "profile3"), "Profile 3");
     qualityProfileDbTester.insertQualityProfiles(profile1Language1, profile2Language2, profile3Language1);
     qualityProfileDbTester.associateProjectWithQualityProfile(project, profile1Language1, profile2Language2);
     session.commit();
index f0abd3e4fead64de8fba13d32958f3b239d94cf8..f61b6d97eec7ef3e965a22e089180982e023e6e4 100644 (file)
@@ -300,7 +300,7 @@ public class ChangeParentActionMediumTest {
   }
 
   private QualityProfileDto createProfile(String lang, String name) {
-    QualityProfileDto profile = QProfileTesting.newQProfileDto(new QProfileName(lang, name), "p" + lang + "-" + name.toLowerCase());
+    QualityProfileDto profile = QProfileTesting.newQProfileDto("org-123", new QProfileName(lang, name), "p" + lang + "-" + name.toLowerCase());
     db.qualityProfileDao().insert(session, profile);
     return profile;
   }
index 8cabdcd4d7bca3f211b2ff07c3b798a6eacfeb41..9acd608996368c39058f968ce737b4826d857ca1 100644 (file)
@@ -69,7 +69,7 @@ public class ChangelogActionTest {
 
   @Test
   public void changelog_empty() throws Exception {
-    when(profileFactory.find(any(DbSession.class), eq(QProfileRef.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1());
+    when(profileFactory.find(any(DbSession.class), eq(QProfileRef.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1("org-123"));
     when(changelogLoader.load(any(DbSession.class), any(QProfileChangeQuery.class))).thenReturn(new ChangelogLoader.Changelog(0, Collections.emptyList()));
 
     wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE_KEY, XOO_P1_KEY)
@@ -78,7 +78,7 @@ public class ChangelogActionTest {
 
   @Test
   public void changelog_nominal() throws Exception {
-    when(profileFactory.find(any(DbSession.class), eq(QProfileRef.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1());
+    when(profileFactory.find(any(DbSession.class), eq(QProfileRef.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1("org-123"));
     ChangelogLoader.Change change1 = new ChangelogLoader.Change("C1", "ACTIVATED", A_DATE, null, null, null, null, null, null);
     ChangelogLoader.Change change2 = new ChangelogLoader.Change("C2", "ACTIVATED", A_DATE + 10, null, null, null, null, null, null);
     List<ChangelogLoader.Change> changes = asList(change1, change2);
@@ -90,7 +90,7 @@ public class ChangelogActionTest {
 
   @Test
   public void changelog_with_all_fields() throws Exception {
-    when(profileFactory.find(any(DbSession.class), eq(QProfileRef.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1());
+    when(profileFactory.find(any(DbSession.class), eq(QProfileRef.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1("org-123"));
     ChangelogLoader.Change change1 = new ChangelogLoader.Change("C1", "ACTIVATED", A_DATE, "MAJOR", "marcel", "Marcel", "INHERITED", RuleTesting.XOO_X1, "X One");
     change1.getParams().put("foo", "foo_value");
     change1.getParams().put("bar", "bar_value");
@@ -103,7 +103,7 @@ public class ChangelogActionTest {
 
   @Test
   public void changelog_inclusive_for_dates() throws Exception {
-    when(profileFactory.find(any(DbSession.class), eq(QProfileRef.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1());
+    when(profileFactory.find(any(DbSession.class), eq(QProfileRef.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1("org-123"));
     when(changelogLoader.load(any(DbSession.class), any(QProfileChangeQuery.class))).thenReturn(new ChangelogLoader.Changelog(0, Collections.emptyList()));
 
     wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog")
index 9a0f25016e4af0628b8c5ff17addbeaf0aeed4a8..a24b9d1ff7d3d7d70fafbfcd550158cb56a22b10 100644 (file)
@@ -189,7 +189,7 @@ public class CompareActionMediumTest {
   }
 
   private QualityProfileDto createProfile(String lang, String name, String key) {
-    QualityProfileDto profile = QProfileTesting.newQProfileDto(new QProfileName(lang, name), key);
+    QualityProfileDto profile = QProfileTesting.newQProfileDto("org-123", new QProfileName(lang, name), key);
     db.qualityProfileDao().insert(session, profile);
     session.commit();
     return profile;
index 3baf4fb9dc4f548af14d932cd791b3b8d12bad11..c11c21af8c4f77878ce4c8168c34df2a59c41d80 100644 (file)
@@ -96,7 +96,7 @@ public class CreateActionTest {
     new RuleActivator(mock(System2.class), dbClient, ruleIndex, new RuleActivatorContextFactory(dbClient), null, activeRuleIndexer, userSession),
     profileImporters);
 
-  private CreateAction underTest = new CreateAction(dbClient, new QProfileFactory(dbClient), qProfileExporters,
+  private CreateAction underTest = new CreateAction(dbClient, new QProfileFactory(dbClient, defaultOrganizationProvider), qProfileExporters,
     newLanguages(XOO_LANGUAGE), new QProfileWsSupport(userSession, defaultOrganizationProvider),
     activeRuleIndexer, profileImporters);
   private WsActionTester wsTester = new WsActionTester(underTest);
index 8797ddea2ff022eb86c0f5579e77bc20dcc69b24..d052fa142905fbcea21f343666abfff4786e8294 100644 (file)
@@ -77,7 +77,8 @@ public class DeleteActionTest {
     tester = new WsTester(new QProfilesWs(
       mock(RuleActivationActions.class),
       mock(BulkRuleActivationActions.class),
-      new DeleteAction(new Languages(xoo1, xoo2), new QProfileFactory(dbClient), dbClient, new QProfileWsSupport(userSessionRule, defaultOrganizationProvider))));
+      new DeleteAction(new Languages(xoo1, xoo2), new QProfileFactory(dbClient, defaultOrganizationProvider), dbClient,
+        new QProfileWsSupport(userSessionRule, defaultOrganizationProvider))));
   }
 
   @After
@@ -91,7 +92,11 @@ public class DeleteActionTest {
 
     ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "polop");
     componentDao.insert(session, project);
-    qualityProfileDao.insert(session, QualityProfileDto.createFor(profileKey).setLanguage(xoo1.getKey()).setName("Sonar way"));
+    QualityProfileDto qualityProfile = QualityProfileDto.createFor(profileKey)
+      .setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
+      .setLanguage(xoo1.getKey())
+      .setName("Sonar way");
+    qualityProfileDao.insert(session, qualityProfile);
     qualityProfileDao.insertProjectProfileAssociation(project.uuid(), profileKey, session);
     session.commit();
 
@@ -109,7 +114,11 @@ public class DeleteActionTest {
 
     ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "polop");
     componentDao.insert(session, project);
-    qualityProfileDao.insert(session, QualityProfileDto.createFor(profileKey).setLanguage(xoo1.getKey()).setName("Sonar way"));
+    qualityProfileDao.insert(session,
+      QualityProfileDto.createFor(profileKey)
+        .setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
+        .setLanguage(xoo1.getKey())
+        .setName("Sonar way"));
     qualityProfileDao.insertProjectProfileAssociation(project.uuid(), profileKey, session);
     session.commit();
 
index 2d9e2c05106aa551bc9b9a41d5bd65915a61faaa..720013191a36fcf4852f072bb952033054182e54 100644 (file)
@@ -58,7 +58,7 @@ public class ExportActionTest {
 
   @Test
   public void export_without_format() throws Exception {
-    QualityProfileDto profile = db.qualityProfiles().insertQualityProfile(QProfileTesting.newXooP1());
+    QualityProfileDto profile = db.qualityProfiles().insertQualityProfile(QProfileTesting.newXooP1("org-123"));
 
     doAnswer(invocation -> {
       invocation.getArgumentAt(2, Writer.class).write("As exported by SQ !");
@@ -73,7 +73,7 @@ public class ExportActionTest {
 
   @Test
   public void export_with_format() throws Exception {
-    QualityProfileDto profile = db.qualityProfiles().insertQualityProfile(QProfileTesting.newXooP1());
+    QualityProfileDto profile = db.qualityProfiles().insertQualityProfile(QProfileTesting.newXooP1("org-123"));
 
     String result = newWsActionTester(newExporter("polop"), newExporter("palap")).newRequest().setParam("language", profile.getLanguage()).setParam("name", profile.getName())
       .setParam("exporterKey", "polop").execute()
@@ -84,7 +84,7 @@ public class ExportActionTest {
 
   @Test
   public void export_default_profile() throws Exception {
-    db.qualityProfiles().insertQualityProfiles(QProfileTesting.newXooP1(), QProfileTesting.newXooP2().setName("SonarWay").setDefault(true));
+    db.qualityProfiles().insertQualityProfiles(QProfileTesting.newXooP1("org-123"), QProfileTesting.newXooP2("org-123").setName("SonarWay").setDefault(true));
 
     String result = newWsActionTester(newExporter("polop"), newExporter("palap")).newRequest().setParam("language", "xoo").setParam("exporterKey", "polop").execute().getInput();
 
@@ -99,7 +99,7 @@ public class ExportActionTest {
 
   @Test
   public void fail_on_unknown_exporter() throws Exception {
-    db.qualityProfiles().insertQualityProfile(QProfileTesting.newXooP1());
+    db.qualityProfiles().insertQualityProfile(QProfileTesting.newXooP1("org-123"));
 
     expectedException.expect(IllegalArgumentException.class);
     newWsActionTester(newExporter("polop"), newExporter("palap")).newRequest().setParam("language", "xoo").setParam("exporterKey", "unknown").execute();
@@ -107,7 +107,7 @@ public class ExportActionTest {
 
   @Test
   public void does_not_fail_when_no_exporters() throws Exception {
-    QualityProfileDto profile = db.qualityProfiles().insertQualityProfile(QProfileTesting.newXooP1());
+    QualityProfileDto profile = db.qualityProfiles().insertQualityProfile(QProfileTesting.newXooP1("org-123"));
 
     newWsActionTester().newRequest().setParam("language", "xoo").setParam("name", profile.getName()).execute();
   }
index 3bee20910c53b249a03a13a37e9f78a231013a4a..c196290dd048baa9eeafb828e974326b39ce0510 100644 (file)
@@ -129,7 +129,7 @@ public class InheritanceActionMediumTest {
   }
 
   private QualityProfileDto createProfile(String lang, String name, String key) {
-    QualityProfileDto profile = QProfileTesting.newQProfileDto(new QProfileName(lang, name), key);
+    QualityProfileDto profile = QProfileTesting.newQProfileDto("org-123", new QProfileName(lang, name), key);
     db.qualityProfileDao().insert(session, profile);
     session.commit();
     return profile;
index 82b72a2b2c7e6febe05ed3c266e0785eb42537f1..4a5c8e67f482d20ac1d47eede28651cb895eb421 100644 (file)
@@ -201,8 +201,8 @@ public class ProjectsActionTest {
   }
 
   private void createProfiles() {
-    xooP1 = QProfileTesting.newXooP1();
-    xooP2 = QProfileTesting.newXooP2();
+    xooP1 = QProfileTesting.newXooP1("org-123");
+    xooP2 = QProfileTesting.newXooP2("org-123");
     dbClient.qualityProfileDao().insert(dbSession, xooP1, xooP2);
   }
 
index 86ca34419bc50a1d73d4bc5e557f33fb79ae2b19..7ed522e1d195906039d85b956e5c5789830d32a4 100644 (file)
@@ -29,6 +29,8 @@ import org.sonar.db.DbTester;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.db.qualityprofile.QualityProfileTesting;
 import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.organization.DefaultOrganizationProvider;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.qualityprofile.QProfileRef;
 
@@ -43,7 +45,9 @@ public class QProfileFactoryTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private QProfileFactory underTest = new QProfileFactory(dbTester.getDbClient());
+  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
+
+  private QProfileFactory underTest = new QProfileFactory(dbTester.getDbClient(), defaultOrganizationProvider);
 
   @Before
   public void setUp() throws Exception {
index 92e6bda9ba7e619b8ca3ebdebbe89ed5099384ee..1ccc3ed515563a420af4bb522d40a5599dea1580 100644 (file)
@@ -405,8 +405,8 @@ public class QProfilesWsMediumTest {
 
   @Test
   public void reset() throws Exception {
-    QualityProfileDto profile = QProfileTesting.newXooP1();
-    QualityProfileDto subProfile = QProfileTesting.newXooP2().setParentKee(QProfileTesting.XOO_P1_KEY);
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
+    QualityProfileDto subProfile = QProfileTesting.newXooP2("org-123").setParentKee(QProfileTesting.XOO_P1_KEY);
     db.qualityProfileDao().insert(session, profile, subProfile);
 
     RuleDto rule = createRule(profile.getLanguage(), "rule");
@@ -442,7 +442,7 @@ public class QProfilesWsMediumTest {
     db.organizationDao().insert(session, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L);
     db.componentDao().insert(session, project);
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     db.qualityProfileDao().insert(session, profile);
 
     session.commit();
@@ -465,8 +465,8 @@ public class QProfilesWsMediumTest {
     db.organizationDao().insert(session, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L);
     db.componentDao().insert(session, project);
-    QualityProfileDto profile1 = QProfileTesting.newXooP1();
-    QualityProfileDto profile2 = QProfileTesting.newXooP2();
+    QualityProfileDto profile1 = QProfileTesting.newXooP1("org-123");
+    QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123");
     db.qualityProfileDao().insert(session, profile1, profile2);
     db.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), profile1.getKey(), session);
 
@@ -484,7 +484,7 @@ public class QProfilesWsMediumTest {
     db.organizationDao().insert(session, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L);
     db.componentDao().insert(session, project);
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     db.qualityProfileDao().insert(session, profile);
 
     session.commit();
@@ -543,7 +543,7 @@ public class QProfilesWsMediumTest {
     db.organizationDao().insert(session, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L);
     db.componentDao().insert(session, project);
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     db.qualityProfileDao().insert(session, profile);
     db.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), profile.getKee(), session);
 
@@ -561,7 +561,7 @@ public class QProfilesWsMediumTest {
     db.organizationDao().insert(session, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L);
     db.componentDao().insert(session, project);
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     db.qualityProfileDao().insert(session, profile);
     db.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), profile.getKee(), session);
 
@@ -574,7 +574,7 @@ public class QProfilesWsMediumTest {
   }
 
   private QualityProfileDto createProfile(String lang) {
-    QualityProfileDto profile = QProfileTesting.newQProfileDto(new QProfileName(lang, "P" + lang), "p" + lang);
+    QualityProfileDto profile = QProfileTesting.newQProfileDto("org-123", new QProfileName(lang, "P" + lang), "p" + lang);
     db.qualityProfileDao().insert(session, profile);
     return profile;
   }
index 8b9757bb7008125defa82c40892f955e865c3e48..3e3122605297984d3bd3bb694509bee474762bbb 100644 (file)
@@ -64,7 +64,7 @@ public class RenameActionTest {
     tester = new WsTester(new QProfilesWs(
       mock(RuleActivationActions.class),
       mock(BulkRuleActivationActions.class),
-      new RenameAction(new QProfileFactory(dbClient), wsSupport)));
+      new RenameAction(new QProfileFactory(dbClient, defaultOrganizationProvider), wsSupport)));
   }
 
   @Test
@@ -154,10 +154,25 @@ public class RenameActionTest {
   }
 
   private void createProfiles() {
+    String orgUuid = defaultOrganizationProvider.get().getUuid();
     dbClient.qualityProfileDao().insert(db.getSession(),
-      QualityProfileDto.createFor("sonar-way-xoo1-12345").setLanguage(xoo1Key).setName("Sonar way").setDefault(true),
-      QualityProfileDto.createFor("sonar-way-xoo2-23456").setLanguage(xoo2Key).setName("Sonar way"),
-      QualityProfileDto.createFor("my-sonar-way-xoo2-34567").setLanguage(xoo2Key).setName("My Sonar way").setParentKee("sonar-way-xoo2-23456").setDefault(true));
+      QualityProfileDto.createFor("sonar-way-xoo1-12345")
+        .setOrganizationUuid(orgUuid)
+        .setLanguage(xoo1Key)
+        .setName("Sonar way")
+        .setDefault(true),
+
+      QualityProfileDto.createFor("sonar-way-xoo2-23456")
+        .setOrganizationUuid(orgUuid)
+        .setLanguage(xoo2Key)
+        .setName("Sonar way"),
+
+      QualityProfileDto.createFor("my-sonar-way-xoo2-34567")
+        .setOrganizationUuid(orgUuid)
+        .setLanguage(xoo2Key)
+        .setName("My Sonar way")
+        .setParentKee("sonar-way-xoo2-23456")
+        .setDefault(true));
     db.commit();
   }
 
index b464d5a0c3be15fd5d21033a4c6dcd0fbbd651e0..a03b65e143cb9d895fc2f9a94902144ef998611d 100644 (file)
@@ -42,6 +42,8 @@ import org.sonar.db.qualityprofile.QualityProfileDbTester;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.language.LanguageTesting;
+import org.sonar.server.organization.DefaultOrganizationProvider;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.qualityprofile.QProfileLookup;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
@@ -61,7 +63,9 @@ import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto;
 import static org.sonar.test.JsonAssert.assertJson;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.*;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_NAME;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY;
 
 public class SearchActionTest {
 
@@ -74,6 +78,7 @@ public class SearchActionTest {
   DbClient dbClient = db.getDbClient();
   DbSession dbSession = db.getSession();
   QualityProfileDao qualityProfileDao = dbClient.qualityProfileDao();
+  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
 
   private ActiveRuleIndex activeRuleIndex = mock(ActiveRuleIndex.class);
 
@@ -92,7 +97,7 @@ public class SearchActionTest {
       new SearchDataLoader(
         languages,
         new QProfileLookup(dbClient),
-        new QProfileFactory(dbClient),
+        new QProfileFactory(dbClient, defaultOrganizationProvider),
         dbClient,
         new ComponentFinder(dbClient), activeRuleIndex),
       languages));
@@ -108,11 +113,31 @@ public class SearchActionTest {
       "my-sonar-way-xoo2-34567", 2L));
 
     OrganizationDto organizationDto = db.organizations().insert();
+    String organizationUuid = organizationDto.getUuid();
     qualityProfileDao.insert(dbSession,
-      QualityProfileDto.createFor("sonar-way-xoo1-12345").setLanguage(xoo1.getKey()).setName("Sonar way").setDefault(true),
-      QualityProfileDto.createFor("sonar-way-xoo2-23456").setLanguage(xoo2.getKey()).setName("Sonar way"),
-      QualityProfileDto.createFor("my-sonar-way-xoo2-34567").setLanguage(xoo2.getKey()).setName("My Sonar way").setParentKee("sonar-way-xoo2-23456"),
-      QualityProfileDto.createFor("sonar-way-other-666").setLanguage("other").setName("Sonar way").setDefault(true));
+      QualityProfileDto.createFor("sonar-way-xoo1-12345")
+        .setOrganizationUuid(organizationUuid)
+        .setLanguage(xoo1.getKey())
+        .setName("Sonar way")
+        .setDefault(true),
+
+      QualityProfileDto
+        .createFor("sonar-way-xoo2-23456")
+        .setOrganizationUuid(organizationUuid)
+        .setLanguage(xoo2.getKey())
+        .setName("Sonar way"),
+
+      QualityProfileDto
+        .createFor("my-sonar-way-xoo2-34567")
+        .setOrganizationUuid(organizationUuid)
+        .setLanguage(xoo2.getKey())
+        .setName("My Sonar way")
+        .setParentKee("sonar-way-xoo2-23456"),
+
+      QualityProfileDto.createFor("sonar-way-other-666")
+        .setOrganizationUuid(organizationUuid)
+        .setLanguage("other").setName("Sonar way")
+        .setDefault(true));
     new ComponentDao().insert(dbSession,
       newProjectDto(organizationDto, "project-uuid1"),
       newProjectDto(organizationDto, "project-uuid2"));
@@ -144,7 +169,11 @@ public class SearchActionTest {
 
   @Test
   public void search_for_language() throws Exception {
-    qualityProfileDb.insertQualityProfiles(QualityProfileDto.createFor("sonar-way-xoo1-12345").setLanguage(xoo1.getKey()).setName("Sonar way"));
+    qualityProfileDb.insertQualityProfiles(
+      QualityProfileDto.createFor("sonar-way-xoo1-12345")
+        .setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
+        .setLanguage(xoo1.getKey())
+        .setName("Sonar way"));
 
     String result = ws.newRequest().setParam("language", xoo1.getKey()).execute().getInput();
 
@@ -154,22 +183,26 @@ public class SearchActionTest {
   @Test
   public void search_for_project_qp() {
     long time = DateUtils.parseDateTime("2016-12-22T19:10:03+0100").getTime();
+    OrganizationDto org = db.organizations().insert();
     QualityProfileDto qualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-12345")
+      .setOrganizationUuid(org.getUuid())
       .setLanguage(xoo1.getKey())
       .setRulesUpdatedAt("2016-12-21T19:10:03+0100")
       .setLastUsed(time)
       .setName("Sonar way");
     QualityProfileDto qualityProfileOnXoo2 = QualityProfileDto.createFor("sonar-way-xoo2-12345")
+      .setOrganizationUuid(org.getUuid())
       .setLanguage(xoo2.getKey())
       .setRulesUpdatedAt("2016-12-21T19:10:03+0100")
       .setLastUsed(time)
       .setName("Sonar way");
     QualityProfileDto anotherQualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-45678")
+      .setOrganizationUuid(org.getUuid())
       .setLanguage(xoo1.getKey())
       .setRulesUpdatedAt("2016-12-21T19:10:03+0100")
       .setLastUsed(time)
       .setName("Another way");
-    ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
+    ComponentDto project = newProjectDto(org, "project-uuid");
     qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
     qualityProfileDb.insertProjectWithQualityProfileAssociations(project, qualityProfileOnXoo1, qualityProfileOnXoo2);
 
@@ -187,15 +220,19 @@ public class SearchActionTest {
 
   @Test
   public void search_for_default_qp_with_profile_name() {
+    String orgUuid = defaultOrganizationProvider.get().getUuid();
     QualityProfileDto qualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-12345")
+      .setOrganizationUuid(orgUuid)
       .setLanguage(xoo1.getKey())
       .setName("Sonar way")
       .setDefault(false);
     QualityProfileDto qualityProfileOnXoo2 = QualityProfileDto.createFor("sonar-way-xoo2-12345")
+      .setOrganizationUuid(orgUuid)
       .setLanguage(xoo2.getKey())
       .setName("Sonar way")
       .setDefault(true);
     QualityProfileDto anotherQualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-45678")
+      .setOrganizationUuid(orgUuid)
       .setLanguage(xoo1.getKey())
       .setName("Another way")
       .setDefault(true);
@@ -213,20 +250,24 @@ public class SearchActionTest {
 
   @Test
   public void search_by_profile_name() {
+    OrganizationDto org = db.organizations().insert();
     QualityProfileDto qualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-12345")
+      .setOrganizationUuid(org.getUuid())
       .setLanguage(xoo1.getKey())
       .setRulesUpdatedAtAsDate(new Date())
       .setName("Sonar way");
     QualityProfileDto qualityProfileOnXoo2 = QualityProfileDto.createFor("sonar-way-xoo2-12345")
+      .setOrganizationUuid(org.getUuid())
       .setLanguage(xoo2.getKey())
       .setRulesUpdatedAtAsDate(new Date())
       .setName("Sonar way");
     QualityProfileDto anotherQualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-45678")
+      .setOrganizationUuid(org.getUuid())
       .setLanguage(xoo1.getKey())
       .setRulesUpdatedAtAsDate(new Date())
       .setName("Another way");
     qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
-    ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+    ComponentDto project = componentDb.insertComponent(newProjectDto(org, "project-uuid"));
 
     String result = ws.newRequest()
       .setParam(PARAM_PROJECT_KEY, project.key())
index 407181880ac5ff937fcce901c98d8d2f224e220a..d08f7144bea7d3c2b776de3d14207ecad65f4c27 100644 (file)
@@ -66,7 +66,7 @@ public class SetDefaultActionTest {
     tester = new WsTester(new QProfilesWs(
       mock(RuleActivationActions.class),
       mock(BulkRuleActivationActions.class),
-      new SetDefaultAction(LanguageTesting.newLanguages(xoo1Key, xoo2Key), new QProfileLookup(dbClient), new QProfileFactory(dbClient), wsSupport)));
+      new SetDefaultAction(LanguageTesting.newLanguages(xoo1Key, xoo2Key), new QProfileLookup(dbClient), new QProfileFactory(dbClient, defaultOrganizationProvider), wsSupport)));
   }
 
   @Test
@@ -152,9 +152,23 @@ public class SetDefaultActionTest {
 
   private void createProfiles() {
     dbClient.qualityProfileDao().insert(db.getSession(),
-      QualityProfileDto.createFor("sonar-way-xoo1-12345").setLanguage(xoo1Key).setName("Sonar way").setDefault(true),
-      QualityProfileDto.createFor("sonar-way-xoo2-23456").setLanguage(xoo2Key).setName("Sonar way"),
-      QualityProfileDto.createFor("my-sonar-way-xoo2-34567").setLanguage(xoo2Key).setName("My Sonar way").setParentKee("sonar-way-xoo2-23456").setDefault(true));
+      QualityProfileDto.createFor("sonar-way-xoo1-12345")
+        .setOrganizationUuid("org-123")
+        .setLanguage(xoo1Key)
+        .setName("Sonar way")
+        .setDefault(true),
+
+      QualityProfileDto.createFor("sonar-way-xoo2-23456")
+        .setOrganizationUuid("org-123")
+        .setLanguage(xoo2Key)
+        .setName("Sonar way"),
+
+      QualityProfileDto.createFor("my-sonar-way-xoo2-34567")
+        .setOrganizationUuid("org-123")
+        .setLanguage(xoo2Key)
+        .setName("My Sonar way")
+        .setParentKee("sonar-way-xoo2-23456")
+        .setDefault(true));
     db.commit();
   }
 
index 9bcfdee0ec944d7d25f409f32188f73d64d1f971..527c989fc4e74d871d6acb78ad5c7079d24e4e6e 100644 (file)
@@ -119,7 +119,7 @@ public class RegisterRulesMediumTest {
 
     // Create a profile and activate rule
     logInAsQProfileAdministrator();
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
     dbSession.commit();
     dbSession.clearCache();
     RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
@@ -151,7 +151,7 @@ public class RegisterRulesMediumTest {
 
     // create a profile and activate rule
     logInAsQProfileAdministrator();
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
     dbSession.commit();
     dbSession.clearCache();
     RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
@@ -186,7 +186,7 @@ public class RegisterRulesMediumTest {
 
     // Create profile and activate rule
     logInAsQProfileAdministrator();
-    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
+    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
     dbSession.commit();
     dbSession.clearCache();
     RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
index 6639720aa077a3adf484d250ad93c469c79cc8bb..24bef246ab7a163df516d602bf562f2f0610e6af 100644 (file)
@@ -90,7 +90,7 @@ public class RuleDeleterMediumTest {
     dao.insert(dbSession, customRule);
 
     // Create a quality profile
-    QualityProfileDto profileDto = QProfileTesting.newXooP1();
+    QualityProfileDto profileDto = QProfileTesting.newXooP1("org-123");
     db.qualityProfileDao().insert(dbSession, profileDto);
     dbSession.commit();
     dbSession.clearCache();
index f1aa7bd433d95bf31818526b13daff72f78babe9..9163089e19a53b43c46ceac9767216ce4923fabe 100644 (file)
@@ -435,7 +435,7 @@ public class RuleUpdaterMediumTest {
     ruleDao.insertRuleParam(dbSession, customRule, templateRuleParam3);
 
     // Create a quality profile
-    QualityProfileDto profileDto = QProfileTesting.newXooP1();
+    QualityProfileDto profileDto = QProfileTesting.newXooP1("org-123");
     db.qualityProfileDao().insert(dbSession, profileDto);
     dbSession.commit();
 
index 9b1015f439b3eb0e812f533aef24128551b34816..670916f5ae547c89427539d06012b63fa94f9d32 100644 (file)
@@ -61,8 +61,8 @@ public class AppActionTest {
 
     userSessionRule.addPermission(ADMINISTER_QUALITY_PROFILES, defaultOrganizationProvider.get().getUuid());
 
-    QualityProfileDto profile1 = QProfileTesting.newXooP1();
-    QualityProfileDto profile2 = QProfileTesting.newXooP2().setParentKee(QProfileTesting.XOO_P1_KEY);
+    QualityProfileDto profile1 = QProfileTesting.newXooP1("org-123");
+    QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123").setParentKee(QProfileTesting.XOO_P1_KEY);
     db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1);
     db.getDbClient().qualityProfileDao().insert(db.getSession(), profile2);
     db.commit();
index 70761fbe04cf2c4585870cb677d5140caa48dc92..7e7c398531ad9bb8bc24d4d82cd4b92717a17f44 100644 (file)
@@ -28,6 +28,8 @@ import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 import org.sonar.server.rule.index.RuleQuery;
 import org.sonar.server.ws.TestRequest;
@@ -75,6 +77,7 @@ public class RuleQueryFactoryTest {
   RuleQueryFactory underTest = new RuleQueryFactory(dbClient);
 
   FakeAction fakeAction = new FakeAction(underTest);
+  OrganizationDto organization = OrganizationTesting.newOrganizationDto();
 
   @Test
   public void create_empty_query() throws Exception {
@@ -150,7 +153,10 @@ public class RuleQueryFactoryTest {
   @Test
   public void create_query_add_language_from_profile() throws Exception {
     String profileKey = "sonar-way";
-    dbClient.qualityProfileDao().insert(dbSession, QualityProfileDto.createFor(profileKey).setName("Sonar Way").setLanguage("xoo"));
+    dbClient.qualityProfileDao().insert(dbSession, QualityProfileDto.createFor(profileKey)
+      .setOrganizationUuid(organization.getUuid())
+      .setName("Sonar Way")
+      .setLanguage("xoo"));
     dbSession.commit();
 
     RuleQuery result = execute(
index ae8c67e1d11c6cfd3c8c9d8a03741869501ed64b..562e9331f1213f49a5fb87bc83168f8354d34155 100644 (file)
@@ -101,7 +101,7 @@ public class RulesWsMediumTest {
 
   @Test
   public void show_rule() throws Exception {
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     tester.get(QualityProfileDao.class).insert(session, profile);
 
     RuleDto rule = RuleTesting.newXooX1();
@@ -131,7 +131,7 @@ public class RulesWsMediumTest {
 
   @Test
   public void get_tags() throws Exception {
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     tester.get(QualityProfileDao.class).insert(session, profile);
 
     RuleDto rule = RuleTesting.newXooX1().
index 9e759db6a7e157701a12682c18d4b491f3d58e9f..e48bd3dbda7be0aa1ed17cafce2437604959ec55 100644 (file)
@@ -305,7 +305,7 @@ public class SearchActionMediumTest {
 
   @Test
   public void search_all_active_rules() throws Exception {
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     tester.get(QualityProfileDao.class).insert(dbSession, profile);
 
     RuleDto rule = RuleTesting.newXooX1();
@@ -329,10 +329,10 @@ public class SearchActionMediumTest {
 
   @Test
   public void search_profile_active_rules() throws Exception {
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     tester.get(QualityProfileDao.class).insert(dbSession, profile);
 
-    QualityProfileDto profile2 = QProfileTesting.newXooP2();
+    QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123");
     tester.get(QualityProfileDao.class).insert(dbSession, profile2);
 
     dbSession.commit();
@@ -401,10 +401,10 @@ public class SearchActionMediumTest {
 
   @Test
   public void search_profile_active_rules_with_inheritance() throws Exception {
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     tester.get(QualityProfileDao.class).insert(dbSession, profile);
 
-    QualityProfileDto profile2 = QProfileTesting.newXooP2().setParentKee(profile.getKee());
+    QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123").setParentKee(profile.getKee());
     tester.get(QualityProfileDao.class).insert(dbSession, profile2);
 
     dbSession.commit();
@@ -432,7 +432,7 @@ public class SearchActionMediumTest {
 
   @Test
   public void search_all_active_rules_params() throws Exception {
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     tester.get(QualityProfileDao.class).insert(dbSession, profile);
     RuleDto rule = RuleTesting.newXooX1();
     ruleDao.insert(dbSession, rule);
@@ -478,7 +478,7 @@ public class SearchActionMediumTest {
 
   @Test
   public void get_note_as_markdown_and_html() throws Exception {
-    QualityProfileDto profile = QProfileTesting.newXooP1();
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
     tester.get(QualityProfileDao.class).insert(dbSession, profile);
     RuleDto rule = RuleTesting.newXooX1().setNoteData("this is *bold*");
     ruleDao.insert(dbSession, rule);
index 39848e958f2e0ced5fba7e501373661be2d1df64..8b0537b960246cc4502af2a8285d6f68a5601b86 100644 (file)
@@ -59,9 +59,11 @@ public class ShowActionMediumTest {
   @ClassRule
   public static ServerTester tester = new ServerTester().withEsIndexes();
 
+  DefaultOrganizationProvider defaultOrganizationProvider = tester.get(DefaultOrganizationProvider.class);
+
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).logIn()
-    .addPermission(ADMINISTER_QUALITY_PROFILES, tester.get(DefaultOrganizationProvider.class).get().getUuid());
+    .addPermission(ADMINISTER_QUALITY_PROFILES, defaultOrganizationProvider.get().getUuid());
 
   WsTester wsTester;
 
@@ -266,7 +268,10 @@ public class ShowActionMediumTest {
     RuleParamDto regexParam = RuleParamDto.createFor(ruleDto).setName("regex").setType("STRING").setDescription("Reg *exp*").setDefaultValue(".*");
     ruleDao.insertRuleParam(session, ruleDto, regexParam);
 
-    QualityProfileDto profile = QualityProfileDto.createFor("profile").setName("Profile").setLanguage("xoo");
+    QualityProfileDto profile = QualityProfileDto.createFor("profile")
+      .setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
+      .setName("Profile")
+      .setLanguage("xoo");
     tester.get(QualityProfileDao.class).insert(session, profile);
     ActiveRuleDto activeRuleDto = new ActiveRuleDto()
       .setProfileId(profile.getId())
index d2a59d2049cb1db3e701e4c70db7b9f4850a644d..80edf1f90356f9e757087f6b14f0f1ba50985dff 100644 (file)
@@ -6,7 +6,7 @@
          tags="bug,performance" system_tags="cwe"
          created_at="1500000000000" updated_at="1600000000000"/>
 
-  <rules_profiles id="100" name="Sonar Way" kee="sonar-way" language="xoo" parent_kee="[null]" is_default="[false]"/>
+  <rules_profiles id="100" name="Sonar Way" organization_uuid="org-123" kee="sonar-way" language="xoo" parent_kee="[null]" is_default="[false]"/>
 
   <active_rules id="1" profile_id="100" rule_id="10" failure_level="3" inheritance="[null]"
                 created_at="1500000000000" updated_at="1600000000000"/>
index 3a0f5ddb92d43af15f9075f5416f4d80b35fb7bc..52b6bca6dfcd5ece26d0564084bc6f06577f00f7 100644 (file)
@@ -6,9 +6,9 @@
          tags="bug,performance" system_tags="cwe"
          created_at="1500000000000" updated_at="1600000000000"/>
 
-  <rules_profiles id="1" name="Parent" kee="parent" language="xoo" parent_kee="[null]" is_default="[false]"/>
+  <rules_profiles id="1" name="Parent" organization_uuid="org-123" kee="parent" language="xoo" parent_kee="[null]" is_default="[false]"/>
 
-  <rules_profiles id="2" name="Child" kee="child" language="xoo" parent_kee="parent" is_default="[false]"/>
+  <rules_profiles id="2" name="Child" organization_uuid="org-123" kee="child" language="xoo" parent_kee="parent" is_default="[false]"/>
 
   <active_rules id="1" profile_id="2" rule_id="10" failure_level="4" inheritance="INHERITED"
                 created_at="1500000000000" updated_at="1600000000000"/>
index b5a820cd45919b5d653cb9adf8f6de8211919244..9becffa199fee8e4128372bc412f3011f185872a 100644 (file)
@@ -6,9 +6,9 @@
          tags="bug,performance" system_tags="cwe"
          created_at="1500000000000" updated_at="1600000000000"/>
 
-  <rules_profiles id="1" name="Parent" kee="parent" language="xoo" parent_kee="[null]" is_default="[false]"/>
+  <rules_profiles id="1" name="Parent" organization_uuid="org-123" kee="parent" language="xoo" parent_kee="[null]" is_default="[false]"/>
 
-  <rules_profiles id="2" name="Child" kee="child" language="xoo" parent_kee="parent" is_default="[false]"/>
+  <rules_profiles id="2" name="Child" organization_uuid="org-123" kee="child" language="xoo" parent_kee="parent" is_default="[false]"/>
 
   <active_rules id="1" profile_id="2" rule_id="10" failure_level="2" inheritance="OVERRIDES"
                 created_at="1500000000000" updated_at="1600000000000"/>
index d2a59d2049cb1db3e701e4c70db7b9f4850a644d..80edf1f90356f9e757087f6b14f0f1ba50985dff 100644 (file)
@@ -6,7 +6,7 @@
          tags="bug,performance" system_tags="cwe"
          created_at="1500000000000" updated_at="1600000000000"/>
 
-  <rules_profiles id="100" name="Sonar Way" kee="sonar-way" language="xoo" parent_kee="[null]" is_default="[false]"/>
+  <rules_profiles id="100" name="Sonar Way" organization_uuid="org-123" kee="sonar-way" language="xoo" parent_kee="[null]" is_default="[false]"/>
 
   <active_rules id="1" profile_id="100" rule_id="10" failure_level="3" inheritance="[null]"
                 created_at="1500000000000" updated_at="1600000000000"/>
index 3e6062ccc972a3e3b0885bc3c105fffac4b8cb66..dbb7ec73ccaf2bf7c0e61e260a10d97c0ce2d236 100644 (file)
@@ -16,9 +16,9 @@
          tags="[null]" system_tags="[null]"
          created_at="2000000000000" updated_at="2100000000000"/>
 
-  <rules_profiles id="1" name="Parent" kee="parent" language="xoo" parent_kee="[null]" is_default="[false]"/>
+  <rules_profiles id="1" name="Parent" organization_uuid="org-123" kee="parent" language="xoo" parent_kee="[null]" is_default="[false]"/>
 
-  <rules_profiles id="2" name="Child" kee="child" language="xoo" parent_kee="parent" is_default="[false]"/>
+  <rules_profiles id="2" name="Child" organization_uuid="org-123" kee="child" language="xoo" parent_kee="parent" is_default="[false]"/>
 
   <active_rules id="1" profile_id="2" rule_id="10" failure_level="4" inheritance="INHERITED"
                 created_at="1500000000000" updated_at="1600000000000"/>
@@ -27,7 +27,7 @@
   <active_rules id="2" profile_id="1" rule_id="10" failure_level="0" inheritance="[null]"
                 created_at="1700000000000" updated_at="1800000000000"/>
 
-  <rules_profiles id="3" name="Sonar Way" kee="sonar-way" language="xoo" parent_kee="[null]" is_default="[false]"/>
+  <rules_profiles id="3" name="Sonar Way" organization_uuid="org-123" kee="sonar-way" language="xoo" parent_kee="[null]" is_default="[false]"/>
 
   <active_rules id="3" profile_id="3" rule_id="11" failure_level="3" inheritance="[null]"
                 created_at="2000000000000" updated_at="2100000000000"/>
index 42737fdef0a41d37327d0796faa75f513bae43a5..01c06ecbbceacad98bd288f6322737b2ec979f78 100644 (file)
@@ -9,7 +9,7 @@
   <rules_parameters id="1" rule_id="1" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
   <rules_parameters id="2" rule_id="1" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
 
-  <rules_profiles id="1" version="1" used_profile="true" name="profile name" language="java" is_default="[false]"/>
+  <rules_profiles id="1" version="1" used_profile="true" organization_uuid="org-123" name="profile name" language="java" is_default="[false]"/>
   <active_rules created_at="[null]" updated_at="[null]" id="1" rule_id="1" profile_id="1" failure_level="4" inheritance="[null]" />
   <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="one" rules_parameter_key="[null]"/>
   <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" value="two" rules_parameter_key="[null]"/>
index 38b34acb5c5f0c73628ecf6e2ddbd262369eca51..38eec579dee9982ed94a4444fbca68ddc541843a 100644 (file)
@@ -10,7 +10,7 @@
   <rules_parameters id="3" rule_id="1" name="param3" description="[null]" param_type="STRING"/>
 
 
-  <rules_profiles id="1" version="1" used_profile="true" name="profile name" language="java" is_default="[false]"/>
+  <rules_profiles id="1" version="1" used_profile="true" organization_uuid="org-123" name="profile name" language="java" is_default="[false]"/>
   <active_rules created_at="[null]" updated_at="[null]" id="1" rule_id="1" profile_id="1" failure_level="4" />
   <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="one" />
   <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" value="two" />
index e4ea6ca07f133e523c1ad20058458a1e1d5b9622..5c0785e9d56caca15db74fd937345b825ac80b68 100644 (file)
@@ -8,7 +8,7 @@
 
   <rules_parameters id="1" rule_id="1" name="deprecated-prop" description="[null]" param_type="STRING"/>
 
-  <rules_profiles id="1" version="1" used_profile="true" name="sonar way" language="java" is_default="[false]"/>
+  <rules_profiles id="1" version="1" organization_uuid="org-123" used_profile="true" name="sonar way" language="java" is_default="[false]"/>
   <active_rules created_at="[null]" updated_at="[null]" id="1" rule_id="1" profile_id="1" failure_level="4" />
   <active_rules created_at="[null]" updated_at="[null]" id="2" rule_id="2" profile_id="1" failure_level="0" />
 
index feb234f20e8fcbcc9ed7107795fc4a8cd4fc74de..b96eaa263799bd55d7e3b6e4b86bf06db44a131c 100644 (file)
@@ -1,18 +1,18 @@
 <dataset>
 
-  <rules_profiles id="1" name="Java One" language="java" parent_kee="[null]" kee="java-one" is_default="[false]"
+  <rules_profiles id="1" name="Java One" language="java" organization_uuid="org-123" parent_kee="[null]" kee="java-one" is_default="[false]"
                   created_at="2014-01-20" updated_at="2014-01-20"
                   rules_updated_at="2014-01-20T12:00:00+0000"/>
 
-  <rules_profiles id="2" name="Java Two" language="java" parent_kee="[null]" kee="java-two" is_default="[false]"
+  <rules_profiles id="2" name="Java Two" language="java" organization_uuid="org-123" parent_kee="[null]" kee="java-two" is_default="[false]"
                   created_at="2014-01-20" updated_at="2014-01-20"
                   rules_updated_at="2014-01-20T12:00:00+0000"/>
 
-  <rules_profiles id="3" name="Php One" language="php" parent_kee="[null]" kee="php-one" is_default="[false]"
+  <rules_profiles id="3" name="Php One" language="php" organization_uuid="org-123" parent_kee="[null]" kee="php-one" is_default="[false]"
                   created_at="2014-01-20" updated_at="2014-01-20"
                   rules_updated_at="2014-01-20T12:00:00+0000"/>
 
-  <rules_profiles id="4" name="Cobol One" language="cbl" parent_kee="[null]" kee="cobol-one" is_default="[false]"
+  <rules_profiles id="4" name="Cobol One" language="cbl" organization_uuid="org-123" parent_kee="[null]" kee="cobol-one" is_default="[false]"
                   created_at="2014-01-20" updated_at="2014-01-20"
                   rules_updated_at="2014-01-20T12:00:00+0000"/>