diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-09-05 10:24:10 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-09-05 14:24:05 +0200 |
commit | 9cff6b3dbd1f2ceb973f3ccec234c344a5809aba (patch) | |
tree | 1223dd1347aae500f581646ab4c0ef10a748fea0 /server/sonar-db-migration | |
parent | 71422cb936386b11517ec067b0fd2fb051f02aca (diff) | |
download | sonarqube-9cff6b3dbd1f2ceb973f3ccec234c344a5809aba.tar.gz sonarqube-9cff6b3dbd1f2ceb973f3ccec234c344a5809aba.zip |
SONAR-9577 Add missing unit test on migration
Diffstat (limited to 'server/sonar-db-migration')
2 files changed, 87 insertions, 0 deletions
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/AddIncrementalColumnToSnapshotsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/AddIncrementalColumnToSnapshotsTableTest.java new file mode 100644 index 00000000000..0519ba270b7 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/AddIncrementalColumnToSnapshotsTableTest.java @@ -0,0 +1,58 @@ +/* + * 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.v66; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.CoreDbTester; + +public class AddIncrementalColumnToSnapshotsTableTest { + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddIncrementalColumnToSnapshotsTableTest.class, "old_snapshots.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private AddIncrementalColumnToSnapshotsTable underTest = new AddIncrementalColumnToSnapshotsTable(db.database()); + + @Test + public void migration_adds_column_to_empty_table() throws SQLException { + underTest.execute(); + + verifyAddedColumns(); + } + + @Test + public void migration_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Fail to execute "); + underTest.execute(); + } + + private void verifyAddedColumns() { + db.assertColumnDefinition("snapshots", "incremental", Types.BOOLEAN, null, true); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/AddIncrementalColumnToSnapshotsTableTest/old_snapshots.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/AddIncrementalColumnToSnapshotsTableTest/old_snapshots.sql new file mode 100644 index 00000000000..b5ef3ce6992 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/AddIncrementalColumnToSnapshotsTableTest/old_snapshots.sql @@ -0,0 +1,29 @@ + +CREATE TABLE "SNAPSHOTS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "UUID" VARCHAR(50) NOT NULL, + "CREATED_AT" BIGINT, + "BUILD_DATE" BIGINT, + "COMPONENT_UUID" VARCHAR(50) NOT NULL, + "STATUS" VARCHAR(4) NOT NULL DEFAULT 'U', + "PURGE_STATUS" INTEGER, + "ISLAST" BOOLEAN NOT NULL DEFAULT FALSE, + "VERSION" VARCHAR(500), + "PERIOD1_MODE" VARCHAR(100), + "PERIOD1_PARAM" VARCHAR(100), + "PERIOD1_DATE" BIGINT, + "PERIOD2_MODE" VARCHAR(100), + "PERIOD2_PARAM" VARCHAR(100), + "PERIOD2_DATE" BIGINT, + "PERIOD3_MODE" VARCHAR(100), + "PERIOD3_PARAM" VARCHAR(100), + "PERIOD3_DATE" BIGINT, + "PERIOD4_MODE" VARCHAR(100), + "PERIOD4_PARAM" VARCHAR(100), + "PERIOD4_DATE" BIGINT, + "PERIOD5_MODE" VARCHAR(100), + "PERIOD5_PARAM" VARCHAR(100), + "PERIOD5_DATE" BIGINT +); +CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID"); +CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID"); |