2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.db.migrations.v45;
22 import org.junit.Before;
23 import org.junit.ClassRule;
24 import org.junit.Test;
25 import org.sonar.api.utils.DateUtils;
26 import org.sonar.api.utils.System2;
27 import org.sonar.core.persistence.TestDatabase;
28 import org.sonar.server.db.DbClient;
29 import org.sonar.server.db.migrations.DatabaseMigration;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
34 public class AddMissingCustomRuleParametersMigrationTest {
37 public static TestDatabase db = new TestDatabase().schema(AddMissingCustomRuleParametersMigrationTest.class, "schema.sql");
39 DatabaseMigration migration;
40 System2 system = mock(System2.class);
43 public void setUp() throws Exception {
44 db.executeUpdateSql("truncate table rules");
45 db.executeUpdateSql("truncate table rules_parameters");
46 DbClient dbClient = new DbClient(db.database(), db.myBatis());
47 migration = new AddMissingCustomRuleParametersMigration(dbClient, system);
48 when(system.now()).thenReturn(DateUtils.parseDate("2014-10-09").getTime());
52 public void execute() throws Exception {
53 db.prepareDbUnit(getClass(), "execute.xml");
57 db.assertDbUnit(getClass(), "execute-result.xml", "rules", "rules_parameters");
61 public void execute_when_custom_rule_have_no_parameter() throws Exception {
62 db.prepareDbUnit(getClass(), "execute_when_custom_rule_have_no_parameter.xml");
66 db.assertDbUnit(getClass(), "execute_when_custom_rule_have_no_parameter-result.xml", "rules", "rules_parameters");
70 public void no_changes() throws Exception {
71 db.prepareDbUnit(getClass(), "no_changes.xml");
75 db.assertDbUnit(getClass(), "no_changes.xml", "rules", "rules_parameters");