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.v501;
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.migrations.DatabaseMigration;
30 import static junit.framework.TestCase.fail;
31 import static org.fest.assertions.Assertions.assertThat;
32 import static org.mockito.Mockito.mock;
33 import static org.mockito.Mockito.when;
35 public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest {
38 public static TestDatabase db = new TestDatabase().schema(AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.class, "schema.sql");
40 DatabaseMigration migration;
42 System2 system = mock(System2.class);
45 public void setUp() throws Exception {
46 db.executeUpdateSql("truncate table characteristics");
48 when(system.now()).thenReturn(DateUtils.parseDate("2015-02-15").getTime());
50 migration = new AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration(db.database(), system);
54 public void migrate() throws Exception {
55 db.prepareDbUnit(getClass(), "migrate.xml");
57 db.assertDbUnit(getClass(), "migrate-result.xml", "characteristics");
61 public void do_nothing_when_already_migrated() throws Exception {
62 db.prepareDbUnit(getClass(), "do_nothing_when_already_migrated.xml");
64 db.assertDbUnit(getClass(), "do_nothing_when_already_migrated.xml", "characteristics");
68 public void insert_usability_at_the_top_if_security_does_exists() throws Exception {
69 db.prepareDbUnit(getClass(), "insert_usability_at_the_top_if_security_does_exists.xml");
71 db.assertDbUnit(getClass(), "insert_usability_at_the_top_if_security_does_exists-result.xml", "characteristics");
75 public void update_usability_order_if_already_exists() throws Exception {
76 db.prepareDbUnit(getClass(), "update_usability_if_already_exists.xml");
78 db.assertDbUnit(getClass(), "update_usability_if_already_exists-result.xml", "characteristics");
82 public void fail_if_usability_exists_as_sub_characteristic() throws Exception {
83 db.prepareDbUnit(getClass(), "fail_if_usability_exists_as_sub_characteristic.xml");
88 } catch (Exception e) {
89 assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Usability' must be a characteristic");
94 public void fail_if_compliance_already_exists_as_characteristic() throws Exception {
95 db.prepareDbUnit(getClass(), "fail_if_compliance_already_exists_as_characteristic.xml");
100 } catch (Exception e) {
101 assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Compliance' must be a sub-characteristic");
106 public void fail_if_compliance_already_exists_under_wrong_characteristic() throws Exception {
107 db.prepareDbUnit(getClass(), "fail_if_compliance_already_exists_under_wrong_characteristic.xml");
112 } catch (Exception e) {
113 assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Reusability Compliance' must be defined under 'Reusability'");