]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8134 add db column groups.organization_uuid
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 28 Sep 2016 17:04:51 +0000 (19:04 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 13 Oct 2016 10:13:10 +0000 (12:13 +0200)
21 files changed:
server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1403_add_organization_uuid_to_groups.rb [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/user/GroupDao.java
sonar-db/src/main/java/org/sonar/db/user/GroupDto.java
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
sonar-db/src/main/java/org/sonar/db/version/v62/AddOrganizationUuidToGroups.java [new file with mode: 0644]
sonar-db/src/main/resources/org/sonar/db/user/GroupMapper.xml
sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
sonar-db/src/test/java/org/sonar/db/user/GroupDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/GroupDtoTest.java [deleted file]
sonar-db/src/test/java/org/sonar/db/user/GroupTesting.java
sonar-db/src/test/java/org/sonar/db/version/v62/AddOrganizationUuidToGroupsTest.java [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/empty.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/find_by_user_login.xml
sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/insert-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/select_by_key.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/select_by_query.xml
sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/update-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/update.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/version/v62/AddOrganizationUuidToGroupsTest/previous-groups.sql [new file with mode: 0644]

index 5c52cef1c238f6e5ec8e5a280f30b735db4d9cb3..94207c0b7ca5ed6321bb55217e37753efd6e686d 100644 (file)
@@ -419,7 +419,7 @@ public class UserUpdater {
 
     @Override
     public boolean apply(@Nullable GroupDto input) {
-      return input != null && input.getKey().equals(key);
+      return input != null && input.getName().equals(key);
     }
   }
 }
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1403_add_organization_uuid_to_groups.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1403_add_organization_uuid_to_groups.rb
new file mode 100644 (file)
index 0000000..d1a3dad
--- /dev/null
@@ -0,0 +1,29 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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.
+#
+
+#
+# SonarQube 6.2
+#
+class AddOrganizationUuidToGroups < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration('org.sonar.db.version.v62.AddOrganizationUuidToGroups')
+  end
+end
index 03b1c582ca817f302d4892af62b3a42682ae97ac..77e6178cfea5d3d9840791ab450d13abe492ff6d 100644 (file)
@@ -44,19 +44,31 @@ public class GroupDao implements Dao {
     this.system = system;
   }
 
-  public GroupDto selectOrFailByName(DbSession session, String key) {
-    GroupDto group = selectByName(session, key);
+  /**
+   * @deprecated organization should be added as a parameter
+   */
+  @Deprecated
+  public GroupDto selectOrFailByName(DbSession session, String name) {
+    GroupDto group = selectByName(session, name);
     if (group == null) {
-      throw new RowNotFoundException(String.format("Could not find a group with name '%s'", key));
+      throw new RowNotFoundException(String.format("Could not find a group with name '%s'", name));
     }
     return group;
   }
 
+  /**
+   * @deprecated organization should be added as a parameter
+   */
+  @Deprecated
   @CheckForNull
   public GroupDto selectByName(DbSession session, String key) {
     return mapper(session).selectByKey(key);
   }
 
+  /**
+   * @deprecated organization should be added as a parameter
+   */
+  @Deprecated
   public List<GroupDto> selectByNames(DbSession session, Collection<String> names) {
     return executeLargeInputs(names, mapper(session)::selectByNames);
   }
index 84ebb0cdf4e414b7d36a51d85986c08c4f5f840b..fc964ffc221acccc3df241449220a94b6ad35e92 100644 (file)
  */
 package org.sonar.db.user;
 
+import java.util.Date;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import org.sonar.db.Dto;
 
-public class GroupDto extends Dto<String> {
+public class GroupDto {
 
   private Long id;
   private String name;
   private String description;
+  private String organizationUuid;
+  private Date createdAt;
+  private Date updatedAt;
+
+  public final Date getCreatedAt() {
+    return this.createdAt;
+  }
+
+  public final Date getUpdatedAt() {
+    return this.updatedAt;
+  }
 
   public Long getId() {
     return id;
@@ -57,9 +68,36 @@ public class GroupDto extends Dto<String> {
     return this;
   }
 
-  @Override
-  public String getKey() {
-    return name;
+  public String getOrganizationUuid() {
+    return organizationUuid;
+  }
+
+  public GroupDto setOrganizationUuid(String s) {
+    this.organizationUuid = s;
+    return this;
   }
 
+  public GroupDto setCreatedAt(Date d) {
+    this.createdAt = d;
+    return this;
+  }
+
+  public GroupDto setUpdatedAt(Date d) {
+    this.updatedAt = d;
+    return this;
+  }
+
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("GroupDto{");
+    sb.append("id=").append(id);
+    sb.append(", name='").append(name).append('\'');
+    sb.append(", description='").append(description).append('\'');
+    sb.append(", organizationUuid='").append(organizationUuid).append('\'');
+    sb.append(", createdAt=").append(createdAt);
+    sb.append(", updatedAt=").append(updatedAt);
+    sb.append('}');
+    return sb.toString();
+  }
 }
index 1ba8da19a942407b44ff253a50987f743d9ecc7d..d03bc6d1de4cfc8c371b2cdefc14609f2cb47083 100644 (file)
@@ -37,7 +37,7 @@ public class DatabaseVersion {
    * versions must be previously upgraded to LTS version.
    * Note that the value can't be less than current LTS version.
    */
-  public static final int MIN_UPGRADE_VERSION = 1152;
+  public static final int MIN_UPGRADE_VERSION = 1_152;
 
   /**
    * These tables are still involved in DB migrations, so potentially
index e3ae06632f563fc90704128bd9853e98b41ab19e..1de7f2384ab18970229ffefca6b9ffb31594a84b 100644 (file)
@@ -159,7 +159,11 @@ import org.sonar.db.version.v61.DropIsGlobalFromDashboards;
 import org.sonar.db.version.v61.PopulateTableProperties2;
 import org.sonar.db.version.v61.RemoveViewsDefinitionFromProperties;
 import org.sonar.db.version.v61.ShrinkModuleUuidPathOfProjects;
+<<<<<<< HEAD
 import org.sonar.db.version.v62.AddIsRootColumnOnTableUsers;
+=======
+import org.sonar.db.version.v62.AddOrganizationUuidToGroups;
+>>>>>>> SONAR-8134 add db column groups.organization_uuid
 import org.sonar.db.version.v62.CreateDefaultOrganization;
 import org.sonar.db.version.v62.CreateTableOrganizations;
 import org.sonar.db.version.v62.DeletePermissionShareDashboard;
@@ -348,8 +352,13 @@ public class MigrationStepModule extends Module {
       CreateTableOrganizations.class,
       CreateDefaultOrganization.class,
       DeletePermissionShareDashboard.class,
+<<<<<<< HEAD
       AddIsRootColumnOnTableUsers.class,
       PopulateIsRootColumnOnTableUsers.class,
       MakeRootColumnNotNullOnTableUsers.class);
+=======
+      AddOrganizationUuidToGroups.class
+    );
+>>>>>>> SONAR-8134 add db column groups.organization_uuid
   }
 }
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v62/AddOrganizationUuidToGroups.java b/sonar-db/src/main/java/org/sonar/db/version/v62/AddOrganizationUuidToGroups.java
new file mode 100644 (file)
index 0000000..5453b32
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v62;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.version.AddColumnsBuilder;
+import org.sonar.db.version.DdlChange;
+import org.sonar.db.version.VarcharColumnDef;
+
+import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddOrganizationUuidToGroups extends DdlChange {
+
+  public AddOrganizationUuidToGroups(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    VarcharColumnDef column = newVarcharColumnDefBuilder()
+      .setColumnName("organization_uuid")
+      .setIsNullable(true)
+      .setLimit(40)
+      .build();
+    context.execute(new AddColumnsBuilder(getDialect(), "groups").addColumn(column).build());
+  }
+}
index 650e144d630aa91507a26bb126b9780b68113645..062a999936fa76ba04c2518e0e9f363231bd33a5 100644 (file)
@@ -8,6 +8,7 @@
     g.id as id,
     g.name as name,
     g.description as description,
+    g.organization_uuid as organizationUuid,
     g.created_at as "createdAt",
     g.updated_at as "updatedAt"
   </sql>
   </delete>
 
   <select id="selectByUserLogin" parameterType="string" resultType="Group">
-    SELECT
+    select
     <include refid="groupColumns"/>
-    FROM groups g
-    INNER JOIN groups_users gu on gu.group_id=g.id
-    INNER JOIN users u on u.id=gu.user_id
-    <where>
-      u.login=#{login}
-    </where>
+    from groups g
+    inner join groups_users gu on gu.group_id = g.id
+    inner join users u on u.id = gu.user_id
+    where  u.login=#{login}
   </select>
 
   <select id="selectByNames" parameterType="map" resultType="Group">
   </select>
 
   <insert id="insert" parameterType="Group" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO groups (name, description, created_at, updated_at)
-    VALUES (#{name}, #{description}, #{createdAt}, #{updatedAt})
+    insert into groups (organization_uuid, name, description, created_at, updated_at)
+    values (
+      #{organizationUuid,jdbcType=VARCHAR},
+      #{name,jdbcType=VARCHAR},
+      #{description,jdbcType=VARCHAR},
+      #{createdAt},
+      #{updatedAt}
+    )
   </insert>
 
   <update id="update" parameterType="Group">
index a7c3f3a293928896573454be70e440c25f94d80b..ce26a7e769100bda8b17e11762a41223a6bf7810 100644 (file)
@@ -59,6 +59,7 @@ CREATE TABLE "WIDGETS" (
 
 CREATE TABLE "GROUPS" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "ORGANIZATION_UUID" VARCHAR(40),
   "NAME" VARCHAR(500),
   "DESCRIPTION" VARCHAR(200),
   "CREATED_AT" TIMESTAMP,
index 153aaefc849da28d42530a46c5f4caddbd2bd6a7..baffd349b2d17c3117e1c13412419f13ab10ac2d 100644 (file)
 package org.sonar.db.user;
 
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.RowNotFoundException;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.singletonList;
@@ -38,44 +40,56 @@ import static org.sonar.db.user.GroupTesting.newGroupDto;
 
 public class GroupDaoTest {
 
-  @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  private static final long NOW = 1_500_000L;
 
-  final DbSession dbSession = db.getSession();
-  System2 system2 = mock(System2.class);
+  private System2 system2 = mock(System2.class);
 
-  GroupDao underTest = new GroupDao(system2);
+  @Rule
+  public DbTester db = DbTester.create(system2);
+  private final DbSession dbSession = db.getSession();
+  private GroupDao underTest = new GroupDao(system2);
+
+  // not static as group id is changed in each test
+  private final GroupDto aGroup = new GroupDto()
+    .setName("the-name")
+    .setDescription("the description")
+    .setOrganizationUuid("org1");
+
+  @Before
+  public void setUp() {
+    when(system2.now()).thenReturn(NOW);
+  }
 
   @Test
-  public void select_by_key() {
-    db.prepareDbUnit(getClass(), "select_by_key.xml");
+  public void test_insert_and_selectOrFailByName() {
+    db.getDbClient().groupDao().insert(dbSession, aGroup);
+
+    GroupDto group = underTest.selectOrFailByName(dbSession, aGroup.getName());
 
-    GroupDto group = underTest.selectOrFailByName(dbSession, "sonar-users");
+    assertThat(group.getId()).isNotNull();
+    assertThat(group.getOrganizationUuid()).isEqualTo(aGroup.getOrganizationUuid());
+    assertThat(group.getName()).isEqualTo(aGroup.getName());
+    assertThat(group.getDescription()).isEqualTo(aGroup.getDescription());
+    assertThat(group.getCreatedAt()).isEqualTo(new Date(NOW));
+    assertThat(group.getUpdatedAt()).isEqualTo(new Date(NOW));
+  }
 
-    assertThat(group).isNotNull();
-    assertThat(group.getId()).isEqualTo(1L);
-    assertThat(group.getName()).isEqualTo("sonar-users");
-    assertThat(group.getDescription()).isEqualTo("Sonar Users");
-    assertThat(group.getCreatedAt()).isEqualTo(DateUtils.parseDate("2014-09-07"));
-    assertThat(group.getUpdatedAt()).isEqualTo(DateUtils.parseDate("2014-09-08"));
+  @Test(expected = RowNotFoundException.class)
+  public void selectOrFailByName_throws_NFE_if_not_found() {
+    underTest.selectOrFailByName(dbSession, "missing");
   }
 
   @Test
-  public void select_by_id() {
-    db.prepareDbUnit(getClass(), "select_by_key.xml");
+  public void selectOrFailById() {
+    db.getDbClient().groupDao().insert(dbSession, aGroup);
 
-    GroupDto group = underTest.selectOrFailById(dbSession, 1L);
+    GroupDto group = underTest.selectOrFailById(dbSession, aGroup.getId());
 
-    assertThat(group).isNotNull();
-    assertThat(group.getId()).isEqualTo(1L);
-    assertThat(group.getName()).isEqualTo("sonar-users");
-    assertThat(group.getDescription()).isEqualTo("Sonar Users");
-    assertThat(group.getCreatedAt()).isEqualTo(DateUtils.parseDate("2014-09-07"));
-    assertThat(group.getUpdatedAt()).isEqualTo(DateUtils.parseDate("2014-09-08"));
+    assertThat(group.getName()).isEqualTo(aGroup.getName());
   }
 
   @Test
-  public void find_by_user_login() {
+  public void selectByUserLogin() {
     db.prepareDbUnit(getClass(), "find_by_user_login.xml");
 
     assertThat(underTest.selectByUserLogin(dbSession, "john")).hasSize(2);
@@ -83,50 +97,43 @@ public class GroupDaoTest {
   }
 
   @Test
-  public void select_by_names() {
-    underTest.insert(dbSession, new GroupDto().setName("group1"));
-    underTest.insert(dbSession, new GroupDto().setName("group2"));
-    underTest.insert(dbSession, new GroupDto().setName("group3"));
+  public void selectByNames() {
+    underTest.insert(dbSession, newGroupDto().setName("group1"));
+    underTest.insert(dbSession, newGroupDto().setName("group2"));
+    underTest.insert(dbSession, newGroupDto().setName("group3"));
     dbSession.commit();
 
     assertThat(underTest.selectByNames(dbSession, asList("group1", "group2", "group3"))).hasSize(3);
     assertThat(underTest.selectByNames(dbSession, singletonList("group1"))).hasSize(1);
     assertThat(underTest.selectByNames(dbSession, asList("group1", "unknown"))).hasSize(1);
-    assertThat(underTest.selectByNames(dbSession, Collections.<String>emptyList())).isEmpty();
-  }
-
-  @Test
-  public void insert() {
-    when(system2.now()).thenReturn(DateUtils.parseDate("2014-09-08").getTime());
-    db.prepareDbUnit(getClass(), "empty.xml");
-    GroupDto dto = new GroupDto()
-      .setId(1L)
-      .setName("sonar-users")
-      .setDescription("Sonar Users");
-
-    underTest.insert(dbSession, dto);
-    dbSession.commit();
-
-    db.assertDbUnit(getClass(), "insert-result.xml", "groups");
+    assertThat(underTest.selectByNames(dbSession, Collections.emptyList())).isEmpty();
   }
 
   @Test
   public void update() {
-    when(system2.now()).thenReturn(DateUtils.parseDate("2013-07-25").getTime());
-    db.prepareDbUnit(getClass(), "update.xml");
+    db.getDbClient().groupDao().insert(dbSession, aGroup);
     GroupDto dto = new GroupDto()
-      .setId(1L)
+      .setId(aGroup.getId())
       .setName("new-name")
-      .setDescription("New Description");
+      .setDescription("New description")
+      .setOrganizationUuid("another-org")
+      .setCreatedAt(new Date(NOW + 1_000L));
 
     underTest.update(dbSession, dto);
-    dbSession.commit();
 
-    db.assertDbUnit(getClass(), "update-result.xml", "groups");
+    GroupDto reloaded = underTest.selectById(dbSession, aGroup.getId());
+
+    // verify mutable fields
+    assertThat(reloaded.getName()).isEqualTo("new-name");
+    assertThat(reloaded.getDescription()).isEqualTo("New description");
+
+    // immutable fields --> to be ignored
+    assertThat(reloaded.getOrganizationUuid()).isEqualTo(aGroup.getOrganizationUuid());
+    assertThat(reloaded.getCreatedAt()).isEqualTo(aGroup.getCreatedAt());
   }
 
   @Test
-  public void select_by_query() {
+  public void selectByQuery() {
     db.prepareDbUnit(getClass(), "select_by_query.xml");
 
     /*
@@ -174,7 +181,7 @@ public class GroupDaoTest {
   }
 
   @Test
-  public void count_by_query() {
+  public void countByQuery() {
     db.prepareDbUnit(getClass(), "select_by_query.xml");
 
     // Null query
@@ -188,14 +195,12 @@ public class GroupDaoTest {
   }
 
   @Test
-  public void delete_by_id() {
-    db.prepareDbUnit(getClass(), "select_by_key.xml");
+  public void deleteById() {
+    db.getDbClient().groupDao().insert(dbSession, aGroup);
 
-    GroupDao groupDao = underTest;
-    groupDao.deleteById(dbSession, 1L);
-    dbSession.commit();
+    underTest.deleteById(dbSession, aGroup.getId());
 
-    assertThat(groupDao.countByQuery(dbSession, null)).isZero();
+    assertThat(db.countRowsOfTable(dbSession, "groups")).isEqualTo(0);
   }
 
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/user/GroupDtoTest.java b/sonar-db/src/test/java/org/sonar/db/user/GroupDtoTest.java
deleted file mode 100644 (file)
index 96a803a..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.db.user;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class GroupDtoTest {
-
-  @Test
-  public void getter_and_setter() {
-    GroupDto dto = new GroupDto()
-      .setId(1L)
-      .setName("sonar-users")
-      .setDescription("Sonar users");
-
-    assertThat(dto.getKey()).isEqualTo("sonar-users");
-    assertThat(dto.getName()).isEqualTo("sonar-users");
-    assertThat(dto.getId()).isEqualTo(1L);
-    assertThat(dto.getDescription()).isEqualTo("Sonar users");
-  }
-
-}
index 2fcf8eefae37c9569a4842fcee331b6ea1d9756d..9291bffa9fb7915120549ed10b039a9f8adfde50 100644 (file)
@@ -26,12 +26,17 @@ import static org.apache.commons.lang.math.RandomUtils.nextLong;
 
 public class GroupTesting {
 
+  private GroupTesting() {
+    // only statics
+  }
+
   public static GroupDto newGroupDto() {
     GroupDto group = new GroupDto()
+      .setOrganizationUuid(randomAlphanumeric(40))
       .setName(randomAlphanumeric(255))
-      .setDescription(randomAlphanumeric(200));
-    group.setCreatedAt(new Date(nextLong()));
-    group.setUpdatedAt(new Date(nextLong()));
+      .setDescription(randomAlphanumeric(200))
+      .setCreatedAt(new Date(nextLong()))
+      .setUpdatedAt(new Date(nextLong()));
     return group;
   }
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/version/v62/AddOrganizationUuidToGroupsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v62/AddOrganizationUuidToGroupsTest.java
new file mode 100644 (file)
index 0000000..79590a1
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v62;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+
+public class AddOrganizationUuidToGroupsTest {
+
+  @Rule
+  public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, AddOrganizationUuidToGroupsTest.class, "previous-groups.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private AddOrganizationUuidToGroups underTest = new AddOrganizationUuidToGroups(dbTester.database());
+
+  @Test
+  public void creates_table_on_empty_db() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertColumnDefinition("groups", "organization_uuid", Types.VARCHAR, 40, true);
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+}
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/empty.xml b/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/empty.xml
deleted file mode 100644 (file)
index a1c54e4..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<dataset>
-
-
-</dataset>
index a7dda4cf7892d40d904cb129d767b0331e106d75..6ceac57ea809208b25df41a7d7bf3a2a0349c1a1 100644 (file)
@@ -4,17 +4,20 @@
           name="sonar-users"
           description="Sonar Users"
           created_at="2014-09-07"
-          updated_at="2014-09-08"/>
+          updated_at="2014-09-08"
+          organization_uuid="org1"/>
   <groups id="2"
           name="sonar-admins"
           description="Sonar Admins"
           created_at="2014-09-07"
-          updated_at="2014-09-08"/>
+          updated_at="2014-09-08"
+          organization_uuid="org1"/>
   <groups id="3"
           name="sonar-reviewers"
           description="Sonar Reviewers"
           created_at="2014-09-07"
-          updated_at="2014-09-08"/>
+          updated_at="2014-09-08"
+          organization_uuid="org1"/>
 
   <groups_users user_id="100"
                 group_id="1"/>
@@ -27,7 +30,6 @@
          email="jo@hn.com"
          created_at="1418215735482"
          updated_at="1418215735482"
-         active="[true]"
-         is_root="[false]"/>
+         active="[true]"/>
 
 </dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/insert-result.xml
deleted file mode 100644 (file)
index ebbd59a..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-
-  <groups id="1" name="sonar-users" description="Sonar Users" created_at="2014-09-08" updated_at="2014-09-08"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/select_by_key.xml b/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/select_by_key.xml
deleted file mode 100644 (file)
index e3ec011..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<dataset>
-
-  <groups id="1" name="sonar-users" description="Sonar Users" created_at="2014-09-07" updated_at="2014-09-08"/>
-
-</dataset>
index 983f6ad99801b52887f73237f540fed87bc1871f..2df4e55073d332f43159887743066440925d8e28 100644 (file)
@@ -1,9 +1,34 @@
 <dataset>
 
-  <groups id="1" name="sonar-users" description="Sonar Users" created_at="2014-09-07" updated_at="2014-09-08"/>
-  <groups id="2" name="SONAR-ADMINS" description="Sonar Admins" created_at="2014-09-07" updated_at="2014-09-08"/>
-  <groups id="3" name="customers-group1" description="Group 1" created_at="2014-09-07" updated_at="2014-09-08"/>
-  <groups id="4" name="customers-group2" description="Group 2" created_at="2014-09-07" updated_at="2014-09-08"/>
-  <groups id="5" name="customers-group3" description="Group 3" created_at="2014-09-07" updated_at="2014-09-08"/>
+  <groups id="1"
+          name="sonar-users"
+          description="Sonar Users"
+          created_at="2014-09-07"
+          updated_at="2014-09-08"
+          organization_uuid="org1"/>
+  <groups id="2"
+          name="SONAR-ADMINS"
+          description="Sonar Admins"
+          created_at="2014-09-07"
+          updated_at="2014-09-08"
+          organization_uuid="org1"/>
+  <groups id="3"
+          name="customers-group1"
+          description="Group 1"
+          created_at="2014-09-07"
+          updated_at="2014-09-08"
+          organization_uuid="org1"/>
+  <groups id="4"
+          name="customers-group2"
+          description="Group 2"
+          created_at="2014-09-07"
+          updated_at="2014-09-08"
+          organization_uuid="org1"/>
+  <groups id="5"
+          name="customers-group3"
+          description="Group 3"
+          created_at="2014-09-07"
+          updated_at="2014-09-08"
+          organization_uuid="org1"/>
 
 </dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/update-result.xml b/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/update-result.xml
deleted file mode 100644 (file)
index 7fdf00c..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-
-  <groups id="1" name="new-name" description="New Description" created_at="2011-04-25" updated_at="2013-07-25"/>
-
-  <groups id="2" name="untouched" description="Untouched" created_at="2003-03-23" updated_at="2006-09-09"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/update.xml b/sonar-db/src/test/resources/org/sonar/db/user/GroupDaoTest/update.xml
deleted file mode 100644 (file)
index df225b5..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-
-  <groups id="1" name="old-name" description="Old Description" created_at="2011-04-25" updated_at="2011-04-25"/>
-
-  <groups id="2" name="untouched" description="Untouched" created_at="2003-03-23" updated_at="2006-09-09"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v62/AddOrganizationUuidToGroupsTest/previous-groups.sql b/sonar-db/src/test/resources/org/sonar/db/version/v62/AddOrganizationUuidToGroupsTest/previous-groups.sql
new file mode 100644 (file)
index 0000000..250a9a8
--- /dev/null
@@ -0,0 +1,7 @@
+CREATE TABLE "GROUPS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "NAME" VARCHAR(500),
+  "DESCRIPTION" VARCHAR(200),
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP
+);