@@ -122,7 +122,7 @@ public class ComputeEngineContainerImplTest { | |||
); | |||
assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize( | |||
CONTAINER_ITSELF | |||
+ 6 // MigrationConfigurationModule | |||
+ 7 // MigrationConfigurationModule | |||
+ 16 // level 2 | |||
); | |||
assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize( |
@@ -27,6 +27,7 @@ import org.sonar.server.platform.db.migration.step.MigrationStepsProvider; | |||
import org.sonar.server.platform.db.migration.version.v00.DbVersion00; | |||
import org.sonar.server.platform.db.migration.version.v80.DbVersion80; | |||
import org.sonar.server.platform.db.migration.version.v81.DbVersion81; | |||
import org.sonar.server.platform.db.migration.version.v82.DbVersion82; | |||
public class MigrationConfigurationModule extends Module { | |||
@Override | |||
@@ -36,6 +37,7 @@ public class MigrationConfigurationModule extends Module { | |||
DbVersion00.class, | |||
DbVersion80.class, | |||
DbVersion81.class, | |||
DbVersion82.class, | |||
// migration steps | |||
MigrationStepRegistryImpl.class, |
@@ -42,8 +42,6 @@ public class DbVersion81 implements DbVersion { | |||
RenameDaysBeforeDeletingInactiveSLBSetting.class) | |||
.add(3112, "Migrate short and long living branches types to common BRANCH type", MigrateSlbsAndLlbsToCommonType.class) | |||
.add(3113, "Migrate short and long living branches types to common BRANCH type in ce tasks table", | |||
MigrateSlbsAndLlbsToCommonTypeInCeTasks.class) | |||
.add(3114, "Drop 'In Review' Security Hotspots status ", DropSecurityHotSpotsInReviewStatus.class) | |||
.add(3115, "Migrate Manual Vulnerabilities to Security Hotspots ", MigrateManualVulnerabilitiesToSecurityHotSpots.class); | |||
MigrateSlbsAndLlbsToCommonTypeInCeTasks.class); | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v81; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.step.DataChange; | |||
public class RemoveNewsboxDismissHotspotsProperty extends DataChange { | |||
public RemoveNewsboxDismissHotspotsProperty(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
protected void execute(Context context) throws SQLException { | |||
context.prepareUpsert("delete from user_properties where kee='newsbox.dismiss.hotspots'") | |||
.execute() | |||
.commit(); | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v82; | |||
import org.sonar.server.platform.db.migration.step.MigrationStepRegistry; | |||
import org.sonar.server.platform.db.migration.version.DbVersion; | |||
public class DbVersion82 implements DbVersion { | |||
@Override | |||
public void addSteps(MigrationStepRegistry registry) { | |||
registry | |||
.add(3200, "Drop 'In Review' Security Hotspots status ", DropSecurityHotSpotsInReviewStatus.class) | |||
.add(3201, "Migrate Manual Vulnerabilities to Security Hotspots ", MigrateManualVulnerabilitiesToSecurityHotSpots.class) | |||
.add(3202, "Remove 'newsbox.dismiss.hotspots' user property", RemoveNewsboxDismissHotspotsProperty.class); | |||
} | |||
} |
@@ -17,7 +17,7 @@ | |||
* 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.v81; | |||
package org.sonar.server.platform.db.migration.version.v82; | |||
import java.sql.SQLException; | |||
import org.sonar.api.utils.System2; |
@@ -17,7 +17,7 @@ | |||
* 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.v81; | |||
package org.sonar.server.platform.db.migration.version.v82; | |||
import java.sql.SQLException; | |||
import org.sonar.api.utils.System2; |
@@ -0,0 +1,38 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v82; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.step.DataChange; | |||
public class RemoveNewsboxDismissHotspotsProperty extends DataChange { | |||
public RemoveNewsboxDismissHotspotsProperty(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
protected void execute(Context context) throws SQLException { | |||
context.prepareUpsert("delete from user_properties where kee='newsbox.dismiss.hotspots'") | |||
.execute() | |||
.commit(); | |||
} | |||
} |
@@ -37,7 +37,7 @@ public class MigrationConfigurationModuleTest { | |||
assertThat(container.getPicoContainer().getComponentAdapters()) | |||
.hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER | |||
// DbVersion classes | |||
+ 3 | |||
+ 4 | |||
// Others | |||
+ 4); | |||
} |
@@ -36,7 +36,7 @@ public class DbVersion81Test { | |||
@Test | |||
public void verify_migration_count() { | |||
verifyMigrationCount(underTest, 16); | |||
verifyMigrationCount(underTest, 14); | |||
} | |||
} |
@@ -0,0 +1,93 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v81; | |||
import java.sql.SQLException; | |||
import java.time.Instant; | |||
import java.util.Random; | |||
import java.util.UUID; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.db.CoreDbTester; | |||
import static java.lang.String.format; | |||
import static org.junit.Assert.assertEquals; | |||
public class RemoveNewsboxDismissHotspotsPropertyTest { | |||
private static final String USER_PROPERTIES_TABLE_NAME = "user_properties"; | |||
private static final int TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES = 10; | |||
@Rule | |||
public CoreDbTester dbTester = CoreDbTester.createForSchema(RemoveNewsboxDismissHotspotsPropertyTest.class, "schema.sql"); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private Random random = new Random(); | |||
private RemoveNewsboxDismissHotspotsProperty underTest = new RemoveNewsboxDismissHotspotsProperty(dbTester.database()); | |||
@Before | |||
public void setup() { | |||
insertUserProperty("some-user-uuid", "some-property", random.nextBoolean()); | |||
for (int i = 1; i <= TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES; i++) { | |||
insertUserProperty(format("user-uuid-%s", i), "newsbox.dismiss.hotspots", random.nextBoolean()); | |||
} | |||
int propertiesCount = dbTester.countRowsOfTable(USER_PROPERTIES_TABLE_NAME); | |||
assertEquals(TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES + 1, propertiesCount); | |||
} | |||
@Test | |||
public void remove_newsbox_dismiss_hotspot_property() throws SQLException { | |||
underTest.execute(); | |||
verifyResult(); | |||
} | |||
@Test | |||
public void migration_is_re_entrant() throws SQLException { | |||
underTest.execute(); | |||
underTest.execute(); | |||
verifyResult(); | |||
} | |||
private void verifyResult() { | |||
int hotspotDismissPropertiesCount = dbTester.countSql("select count(uuid) from user_properties where kee = 'newsbox.dismiss.hotspots'"); | |||
assertEquals(0, hotspotDismissPropertiesCount); | |||
int otherPropertiesCount = dbTester.countSql("select count(uuid) from user_properties where kee != 'newsbox.dismiss.hotspots'"); | |||
assertEquals(1, otherPropertiesCount); | |||
} | |||
private void insertUserProperty(String userUuid, String key, boolean value) { | |||
dbTester.executeInsert(USER_PROPERTIES_TABLE_NAME, | |||
"uuid", UUID.randomUUID().toString(), | |||
"kee", key, | |||
"user_uuid", userUuid, | |||
"text_value", value, | |||
"created_at", Instant.now().toEpochMilli(), | |||
"updated_at", Instant.now().toEpochMilli()); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v82; | |||
import org.junit.Test; | |||
import org.sonar.server.platform.db.migration.version.DbVersion; | |||
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount; | |||
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber; | |||
public class DbVersion82Test { | |||
private DbVersion underTest = new DbVersion82(); | |||
@Test | |||
public void migrationNumber_starts_at_3000() { | |||
verifyMinimumMigrationNumber(underTest, 3200); | |||
} | |||
@Test | |||
public void verify_migration_count() { | |||
verifyMigrationCount(underTest, 3); | |||
} | |||
} |
@@ -17,7 +17,7 @@ | |||
* 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.v81; | |||
package org.sonar.server.platform.db.migration.version.v82; | |||
import java.sql.SQLException; | |||
import java.util.List; |
@@ -17,7 +17,7 @@ | |||
* 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.v81; | |||
package org.sonar.server.platform.db.migration.version.v82; | |||
import java.sql.SQLException; | |||
import java.util.ArrayList; |
@@ -0,0 +1,93 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v82; | |||
import java.sql.SQLException; | |||
import java.time.Instant; | |||
import java.util.Random; | |||
import java.util.UUID; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.db.CoreDbTester; | |||
import static java.lang.String.format; | |||
import static org.junit.Assert.assertEquals; | |||
public class RemoveNewsboxDismissHotspotsPropertyTest { | |||
private static final String USER_PROPERTIES_TABLE_NAME = "user_properties"; | |||
private static final int TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES = 10; | |||
@Rule | |||
public CoreDbTester dbTester = CoreDbTester.createForSchema(RemoveNewsboxDismissHotspotsPropertyTest.class, "schema.sql"); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private Random random = new Random(); | |||
private RemoveNewsboxDismissHotspotsProperty underTest = new RemoveNewsboxDismissHotspotsProperty(dbTester.database()); | |||
@Before | |||
public void setup() { | |||
insertUserProperty("some-user-uuid", "some-property", random.nextBoolean()); | |||
for (int i = 1; i <= TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES; i++) { | |||
insertUserProperty(format("user-uuid-%s", i), "newsbox.dismiss.hotspots", random.nextBoolean()); | |||
} | |||
int propertiesCount = dbTester.countRowsOfTable(USER_PROPERTIES_TABLE_NAME); | |||
assertEquals(TOTAL_NUMBER_OF_HOTSPOTS_DISMISS_USER_PROPERTIES + 1, propertiesCount); | |||
} | |||
@Test | |||
public void remove_newsbox_dismiss_hotspot_property() throws SQLException { | |||
underTest.execute(); | |||
verifyResult(); | |||
} | |||
@Test | |||
public void migration_is_re_entrant() throws SQLException { | |||
underTest.execute(); | |||
underTest.execute(); | |||
verifyResult(); | |||
} | |||
private void verifyResult() { | |||
int hotspotDismissPropertiesCount = dbTester.countSql("select count(uuid) from user_properties where kee = 'newsbox.dismiss.hotspots'"); | |||
assertEquals(0, hotspotDismissPropertiesCount); | |||
int otherPropertiesCount = dbTester.countSql("select count(uuid) from user_properties where kee != 'newsbox.dismiss.hotspots'"); | |||
assertEquals(1, otherPropertiesCount); | |||
} | |||
private void insertUserProperty(String userUuid, String key, boolean value) { | |||
dbTester.executeInsert(USER_PROPERTIES_TABLE_NAME, | |||
"uuid", UUID.randomUUID().toString(), | |||
"kee", key, | |||
"user_uuid", userUuid, | |||
"text_value", value, | |||
"created_at", Instant.now().toEpochMilli(), | |||
"updated_at", Instant.now().toEpochMilli()); | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
CREATE TABLE "USER_PROPERTIES" ( | |||
"UUID" VARCHAR(40) NOT NULL, | |||
"USER_UUID" VARCHAR(255) NOT NULL, | |||
"KEE" VARCHAR(100) NOT NULL, | |||
"TEXT_VALUE" VARCHAR(4000) NOT NULL, | |||
"CREATED_AT" BIGINT NOT NULL, | |||
"UPDATED_AT" BIGINT NOT NULL, | |||
CONSTRAINT "PK_USER_PROPERTIES" PRIMARY KEY ("UUID") | |||
); | |||
CREATE UNIQUE INDEX "USER_PROPERTIES_USER_UUID_KEE" ON "USER_PROPERTIES" ("USER_UUID", "KEE"); |
@@ -0,0 +1,11 @@ | |||
CREATE TABLE "USER_PROPERTIES" ( | |||
"UUID" VARCHAR(40) NOT NULL, | |||
"USER_UUID" VARCHAR(255) NOT NULL, | |||
"KEE" VARCHAR(100) NOT NULL, | |||
"TEXT_VALUE" VARCHAR(4000) NOT NULL, | |||
"CREATED_AT" BIGINT NOT NULL, | |||
"UPDATED_AT" BIGINT NOT NULL, | |||
CONSTRAINT "PK_USER_PROPERTIES" PRIMARY KEY ("UUID") | |||
); | |||
CREATE UNIQUE INDEX "USER_PROPERTIES_USER_UUID_KEE" ON "USER_PROPERTIES" ("USER_UUID", "KEE"); |
@@ -57,7 +57,7 @@ public class SetSettingAction implements UsersWsAction { | |||
.setRequired(true) | |||
.setMaximumLength(100) | |||
.setDescription("Setting key") | |||
.setPossibleValues("notifications.optOut", UserUpdater.NOTIFICATIONS_READ_DATE, "newsbox.dismiss.hotspots"); | |||
.setPossibleValues("notifications.optOut", UserUpdater.NOTIFICATIONS_READ_DATE); | |||
action.createParam(PARAM_VALUE) | |||
.setRequired(true) |
@@ -91,17 +91,11 @@ public class SetSettingActionTest { | |||
.setParam("value", "true") | |||
.execute(); | |||
ws.newRequest() | |||
.setParam("key", "newsbox.dismiss.hotspots") | |||
.setParam("value", "true") | |||
.execute(); | |||
assertThat(db.getDbClient().userPropertiesDao().selectByUser(db.getSession(), user)) | |||
.extracting(UserPropertyDto::getKey, UserPropertyDto::getValue) | |||
.containsExactlyInAnyOrder( | |||
tuple("notifications.readDate", "1234"), | |||
tuple("notifications.optOut", "true"), | |||
tuple("newsbox.dismiss.hotspots", "true")); | |||
tuple("notifications.optOut", "true")); | |||
} | |||
@Test | |||
@@ -131,8 +125,7 @@ public class SetSettingActionTest { | |||
assertThat(definition.param("key").possibleValues()).containsExactlyInAnyOrder( | |||
"notifications.optOut", | |||
"notifications.readDate", | |||
"newsbox.dismiss.hotspots"); | |||
"notifications.readDate"); | |||
} | |||
} |