]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8445 move SQ 5.6.1 migration out of Ruby
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 13 Dec 2016 10:39:22 +0000 (11:39 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 14 Dec 2016 11:11:53 +0000 (12:11 +0100)
15 files changed:
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DbVersionModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/DbVersion561.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmpty.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/package-info.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/DbVersionModuleTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v561/DbVersion561Test.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmptyTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmptyTest/schema.sql [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1153_update_users_external_identity_when_empty.rb [deleted file]
sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
sonar-db/src/main/java/org/sonar/db/version/v561/UpdateUsersExternalIdentityWhenEmpty.java [deleted file]
sonar-db/src/main/java/org/sonar/db/version/v561/package-info.java [deleted file]
sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java
sonar-db/src/test/java/org/sonar/db/version/v561/UpdateUsersExternalIdentityWhenEmptyTest.java [deleted file]
sonar-db/src/test/resources/org/sonar/db/version/v561/UpdateUsersExternalIdentityWhenEmptyTest/schema.sql [deleted file]

index cde9590db53f85bcc140e35df44ff1cd7d9120b1..4fdb281ddbbbba48b086fde6bf6c2eba3fb88c7a 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.platform.db.migration.version;
 
 import org.sonar.core.platform.Module;
+import org.sonar.server.platform.db.migration.version.v561.DbVersion561;
 import org.sonar.server.platform.db.migration.version.v60.DbVersion60;
 import org.sonar.server.platform.db.migration.version.v61.DbVersion61;
 import org.sonar.server.platform.db.migration.version.v62.DbVersion62;
@@ -29,6 +30,7 @@ public class DbVersionModule extends Module {
   @Override
   protected void configureModule() {
     add(
+      DbVersion561.class,
       DbVersion60.class,
       DbVersion61.class,
       DbVersion62.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/DbVersion561.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/DbVersion561.java
new file mode 100644 (file)
index 0000000..60079df
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.server.platform.db.migration.version.v561;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+public class DbVersion561 implements DbVersion {
+  @Override
+  public void addSteps(MigrationStepRegistry registry) {
+    registry.add(1153, "Populate columns USERS.EXTERNAL_IDENTITY_*", UpdateUsersExternalIdentityWhenEmpty.class);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmpty.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmpty.java
new file mode 100644 (file)
index 0000000..a95fbca
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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.server.platform.db.migration.version.v561;
+
+import java.sql.SQLException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.Database;
+import org.sonar.db.version.MassUpdate;
+import org.sonar.db.version.Select;
+import org.sonar.db.version.SqlStatement;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+/**
+ * Update USERS.EXTERNAL_IDENTITY_PROVIDER to 'sonarqube' and USERS.EXTERNAL_IDENTITY to user's login when one of this 2 columns is null
+ */
+public class UpdateUsersExternalIdentityWhenEmpty extends DataChange {
+
+  private final System2 system2;
+
+  public UpdateUsersExternalIdentityWhenEmpty(Database db, System2 system2) {
+    super(db);
+    this.system2 = system2;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    MassUpdate massUpdate = context.prepareMassUpdate();
+    massUpdate.select("SELECT u.id, u.login FROM users u WHERE external_identity_provider IS NULL OR external_identity IS NULL");
+    massUpdate.update("UPDATE users SET external_identity_provider=?, external_identity=?, updated_at=? WHERE id=?");
+    massUpdate.rowPluralName("users");
+    massUpdate.execute(new MigrationHandler(system2.now()));
+  }
+
+  private static class MigrationHandler implements MassUpdate.Handler {
+
+    private final long now;
+
+    public MigrationHandler(long now) {
+      this.now = now;
+    }
+
+    @Override
+    public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+      update.setString(1, "sonarqube");
+      update.setString(2, row.getString(2));
+      update.setLong(3, now);
+      update.setLong(4, row.getLong(1));
+      return true;
+    }
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v561/package-info.java
new file mode 100644 (file)
index 0000000..a36da9f
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.platform.db.migration.version.v561;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
index 65795e2c0c4e0968c625434c3b254cd4213989a2..6f9226ab604a7196c5637a6d5ba7e88f73c81f8d 100644 (file)
@@ -36,7 +36,7 @@ public class DbVersionModuleTest {
     underTest.configure(container);
 
     assertThat(container.getPicoContainer().getComponentAdapters())
-      .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 4);
+      .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 5);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v561/DbVersion561Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v561/DbVersion561Test.java
new file mode 100644 (file)
index 0000000..61f1b3f
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.server.platform.db.migration.version.v561;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion561Test {
+  private DbVersion561 underTest = new DbVersion561();
+
+  @Test
+  public void verify_no_support_component() {
+    assertThat(underTest.getSupportComponents()).isEmpty();
+  }
+
+  @Test
+  public void migrationNumber_starts_at_1153() {
+    verifyMinimumMigrationNumber(underTest, 1153);
+  }
+
+  @Test
+  public void verify_migration_count() {
+    verifyMigrationCount(underTest, 1);
+  }
+
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmptyTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmptyTest.java
new file mode 100644 (file)
index 0000000..c792773
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * 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.server.platform.db.migration.version.v561;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class UpdateUsersExternalIdentityWhenEmptyTest {
+
+  private static final long PAST = 1_000_000_000_000L;
+  private static final long NOW = 1_500_000_000_000L;
+
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, UpdateUsersExternalIdentityWhenEmptyTest.class, "schema.sql");
+
+  private System2 system = mock(System2.class);
+
+  private UpdateUsersExternalIdentityWhenEmpty underTest = new UpdateUsersExternalIdentityWhenEmpty(db.database(), system);
+
+  @Before
+  public void setUp() throws Exception {
+    when(system.now()).thenReturn(NOW);
+  }
+
+  @Test
+  public void migrate_users() throws Exception {
+    insertUser("user-without-eternal-identity", null, null, PAST);
+    insertUser("user-with-only-eternal-identity-provider", "github", null, PAST);
+    insertUser("user-with-only-eternal-identity", null, "login1", PAST);
+    insertUser("user-with-both-eternal-identity", "github", "login2", PAST);
+
+    underTest.execute();
+
+    checkUserIsUpdated("user-without-eternal-identity");
+    checkUserIsUpdated("user-with-only-eternal-identity-provider");
+    checkUserIsUpdated("user-with-only-eternal-identity");
+
+    checkUserIsNotUpdated("user-with-both-eternal-identity");
+  }
+
+  @Test
+  public void doest_not_fail_when_no_user() throws Exception {
+    underTest.execute();
+  }
+
+  private void insertUser(String login, @Nullable String externalIdentity, @Nullable String externalIdentityProvider, long updatedAt) {
+    Map<String, Object> params = new HashMap<>();
+    params.put("LOGIN", login);
+    params.put("CREATED_AT", Long.toString(PAST));
+    params.put("UPDATED_AT", Long.toString(updatedAt));
+    if (externalIdentity != null) {
+      params.put("EXTERNAL_IDENTITY", externalIdentity);
+    }
+    if (externalIdentityProvider != null) {
+      params.put("EXTERNAL_IDENTITY_PROVIDER", externalIdentityProvider);
+    }
+
+    db.executeInsert("users", params);
+  }
+
+  private void checkUserIsUpdated(String login) {
+    Map<String, Object> row = db.selectFirst("select EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, UPDATED_AT from users where LOGIN='" + login + "'");
+    assertThat((String) row.get("EXTERNAL_IDENTITY_PROVIDER")).isEqualTo("sonarqube");
+    assertThat((String) row.get("EXTERNAL_IDENTITY")).isEqualTo(login);
+    assertThat(row.get("UPDATED_AT")).isEqualTo(NOW);
+  }
+
+  private void checkUserIsNotUpdated(String login) {
+    Map<String, Object> row = db.selectFirst("select EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, UPDATED_AT from users where LOGIN='" + login + "'");
+    assertThat((String) row.get("EXTERNAL_IDENTITY_PROVIDER")).isNotEmpty();
+    assertThat((String) row.get("EXTERNAL_IDENTITY")).isNotEmpty();
+    assertThat(row.get("UPDATED_AT")).isEqualTo(PAST);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmptyTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v561/UpdateUsersExternalIdentityWhenEmptyTest/schema.sql
new file mode 100644 (file)
index 0000000..127fc34
--- /dev/null
@@ -0,0 +1,17 @@
+CREATE TABLE "USERS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "LOGIN" VARCHAR(255),
+  "NAME" VARCHAR(200),
+  "EMAIL" VARCHAR(100),
+  "CRYPTED_PASSWORD" VARCHAR(40),
+  "SALT" VARCHAR(40),
+  "REMEMBER_TOKEN" VARCHAR(500),
+  "REMEMBER_TOKEN_EXPIRES_AT" TIMESTAMP,
+  "ACTIVE" BOOLEAN DEFAULT TRUE,
+  "SCM_ACCOUNTS" VARCHAR(4000),
+  "EXTERNAL_IDENTITY" VARCHAR(255),
+  "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100),
+  "USER_LOCAL" BOOLEAN,
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT
+);
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1153_update_users_external_identity_when_empty.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1153_update_users_external_identity_when_empty.rb
deleted file mode 100644 (file)
index a5079b3..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2016 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 5.6.1
-# SONAR-7686
-#
-class UpdateUsersExternalIdentityWhenEmpty < ActiveRecord::Migration
-
-  def self.up
-    execute_java_migration('org.sonar.db.version.v561.UpdateUsersExternalIdentityWhenEmpty')
-  end
-
-end
index 2bd6fc25b2c0b6a266db1a6fbc2dbcbeb78f6f3b..6e7ec450d6edc10844880acc7aea0ab6782c3edf 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.db.version;
 import org.sonar.core.platform.Module;
 import org.sonar.db.version.v56.CreateInitialSchema;
 import org.sonar.db.version.v56.PopulateInitialSchema;
-import org.sonar.db.version.v561.UpdateUsersExternalIdentityWhenEmpty;
 
 public class MigrationStepModule extends Module {
   @Override
@@ -30,9 +29,6 @@ public class MigrationStepModule extends Module {
     add(
       // 5.6
       CreateInitialSchema.class,
-      PopulateInitialSchema.class,
-
-      // 5.6.1
-      UpdateUsersExternalIdentityWhenEmpty.class);
+      PopulateInitialSchema.class);
   }
 }
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v561/UpdateUsersExternalIdentityWhenEmpty.java b/sonar-db/src/main/java/org/sonar/db/version/v561/UpdateUsersExternalIdentityWhenEmpty.java
deleted file mode 100644 (file)
index c7ebfb8..0000000
+++ /dev/null
@@ -1,69 +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.version.v561;
-
-import java.sql.SQLException;
-import org.sonar.api.utils.System2;
-import org.sonar.db.Database;
-import org.sonar.db.version.BaseDataChange;
-import org.sonar.db.version.MassUpdate;
-import org.sonar.db.version.Select;
-import org.sonar.db.version.SqlStatement;
-
-/**
- * Update USERS.EXTERNAL_IDENTITY_PROVIDER to 'sonarqube' and USERS.EXTERNAL_IDENTITY to user's login when one of this 2 columns is null
- */
-public class UpdateUsersExternalIdentityWhenEmpty extends BaseDataChange {
-
-  private final System2 system2;
-
-  public UpdateUsersExternalIdentityWhenEmpty(Database db, System2 system2) {
-    super(db);
-    this.system2 = system2;
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    MassUpdate massUpdate = context.prepareMassUpdate();
-    massUpdate.select("SELECT u.id, u.login FROM users u WHERE external_identity_provider IS NULL OR external_identity IS NULL");
-    massUpdate.update("UPDATE users SET external_identity_provider=?, external_identity=?, updated_at=? WHERE id=?");
-    massUpdate.rowPluralName("users");
-    massUpdate.execute(new MigrationHandler(system2.now()));
-  }
-
-  private static class MigrationHandler implements MassUpdate.Handler {
-
-    private final long now;
-
-    public MigrationHandler(long now) {
-      this.now = now;
-    }
-
-    @Override
-    public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
-      update.setString(1, "sonarqube");
-      update.setString(2, row.getString(2));
-      update.setLong(3, now);
-      update.setLong(4, row.getLong(1));
-      return true;
-    }
-  }
-
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v561/package-info.java b/sonar-db/src/main/java/org/sonar/db/version/v561/package-info.java
deleted file mode 100644 (file)
index 3c210ce..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.db.version.v561;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
index 5984fb5427bb6ea0a0d437474bb9be0ef1c435fb..60bf767ed9c7d2976d32af93bd139aa733189e34 100644 (file)
@@ -29,6 +29,6 @@ public class MigrationStepModuleTest {
   public void verify_count_of_added_MigrationStep_types() {
     ComponentContainer container = new ComponentContainer();
     new MigrationStepModule().configure(container);
-    assertThat(container.size()).isEqualTo(5);
+    assertThat(container.size()).isEqualTo(4);
   }
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/version/v561/UpdateUsersExternalIdentityWhenEmptyTest.java b/sonar-db/src/test/java/org/sonar/db/version/v561/UpdateUsersExternalIdentityWhenEmptyTest.java
deleted file mode 100644 (file)
index 7a32d59..0000000
+++ /dev/null
@@ -1,103 +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.version.v561;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.db.version.MigrationStep;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class UpdateUsersExternalIdentityWhenEmptyTest {
-
-  @Rule
-  public DbTester db = DbTester.createForSchema(System2.INSTANCE, UpdateUsersExternalIdentityWhenEmptyTest.class, "schema.sql");
-
-  static final long PAST = 1_000_000_000_000L;
-  static final long NOW = 1_500_000_000_000L;
-
-  System2 system = mock(System2.class);
-
-  MigrationStep underTest = new UpdateUsersExternalIdentityWhenEmpty(db.database(), system);
-
-  @Before
-  public void setUp() throws Exception {
-    when(system.now()).thenReturn(NOW);
-  }
-
-  @Test
-  public void migrate_users() throws Exception {
-    insertUser("user-without-eternal-identity", null, null, PAST);
-    insertUser("user-with-only-eternal-identity-provider", "github", null, PAST);
-    insertUser("user-with-only-eternal-identity", null, "login1", PAST);
-    insertUser("user-with-both-eternal-identity", "github", "login2", PAST);
-
-    underTest.execute();
-
-    checkUserIsUpdated("user-without-eternal-identity");
-    checkUserIsUpdated("user-with-only-eternal-identity-provider");
-    checkUserIsUpdated("user-with-only-eternal-identity");
-
-    checkUserIsNotUpdated("user-with-both-eternal-identity");
-  }
-
-  @Test
-  public void doest_not_fail_when_no_user() throws Exception {
-    underTest.execute();
-  }
-
-  private void insertUser(String login, @Nullable String externalIdentity, @Nullable String externalIdentityProvider, long updatedAt) {
-    Map<String, Object> params = new HashMap<>();
-    params.put("LOGIN", login);
-    params.put("CREATED_AT", Long.toString(PAST));
-    params.put("UPDATED_AT", Long.toString(updatedAt));
-    if (externalIdentity != null) {
-      params.put("EXTERNAL_IDENTITY", externalIdentity);
-    }
-    if (externalIdentityProvider != null) {
-      params.put("EXTERNAL_IDENTITY_PROVIDER", externalIdentityProvider);
-    }
-
-    db.executeInsert("users", params);
-  }
-
-  private void checkUserIsUpdated(String login) {
-    Map<String, Object> row = db.selectFirst("select EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, UPDATED_AT from users where LOGIN='" + login + "'");
-    assertThat((String) row.get("EXTERNAL_IDENTITY_PROVIDER")).isEqualTo("sonarqube");
-    assertThat((String) row.get("EXTERNAL_IDENTITY")).isEqualTo(login);
-    assertThat(row.get("UPDATED_AT")).isEqualTo(NOW);
-  }
-
-  private void checkUserIsNotUpdated(String login) {
-    Map<String, Object> row = db.selectFirst("select EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, UPDATED_AT from users where LOGIN='" + login + "'");
-    assertThat((String) row.get("EXTERNAL_IDENTITY_PROVIDER")).isNotEmpty();
-    assertThat((String) row.get("EXTERNAL_IDENTITY")).isNotEmpty();
-    assertThat(row.get("UPDATED_AT")).isEqualTo(PAST);
-  }
-
-}
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v561/UpdateUsersExternalIdentityWhenEmptyTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v561/UpdateUsersExternalIdentityWhenEmptyTest/schema.sql
deleted file mode 100644 (file)
index 127fc34..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-CREATE TABLE "USERS" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "LOGIN" VARCHAR(255),
-  "NAME" VARCHAR(200),
-  "EMAIL" VARCHAR(100),
-  "CRYPTED_PASSWORD" VARCHAR(40),
-  "SALT" VARCHAR(40),
-  "REMEMBER_TOKEN" VARCHAR(500),
-  "REMEMBER_TOKEN_EXPIRES_AT" TIMESTAMP,
-  "ACTIVE" BOOLEAN DEFAULT TRUE,
-  "SCM_ACCOUNTS" VARCHAR(4000),
-  "EXTERNAL_IDENTITY" VARCHAR(255),
-  "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100),
-  "USER_LOCAL" BOOLEAN,
-  "CREATED_AT" BIGINT,
-  "UPDATED_AT" BIGINT
-);