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.
21 package org.sonar.server.db.migrations.v44;
23 import org.junit.Before;
24 import org.junit.ClassRule;
25 import org.junit.Test;
26 import org.sonar.core.persistence.TestDatabase;
27 import org.sonar.server.db.DbClient;
29 import java.sql.Connection;
30 import java.sql.ResultSet;
31 import java.sql.Statement;
33 import static org.fest.assertions.Assertions.assertThat;
35 public class ConvertProfileMeasuresMigrationTest {
38 public static TestDatabase db = new TestDatabase().schema(ConvertProfileMeasuresMigrationTest.class, "schema.sql");
40 ConvertProfileMeasuresMigration migration;
43 public void setUp() throws Exception {
44 DbClient dbClient = new DbClient(db.database(), db.myBatis());
45 migration = new ConvertProfileMeasuresMigration(dbClient);
49 public void generate_profiles_measure_as_json() throws Exception {
50 db.prepareDbUnit(getClass(), "before.xml");
54 Connection connection = db.openConnection();
55 Statement stmt = connection.createStatement();
56 ResultSet rs = stmt.executeQuery("select text_value from project_measures where id=2");
59 // pb of comparison of timezones..., so using startsWith instead of equals
60 assertThat(rs.getString(1)).startsWith("[{\"key\":\"java-sonar-way\",\"language\":\"java\",\"name\":\"Sonar way\",\"rulesUpdatedAt\":\"2014-01-04T");
69 * http://jira.codehaus.org/browse/SONAR-5515
70 * Version of quality profile was introduced in SQ 2.9. Migration must not fail
71 * when there are still some projects which last analysis was done with SQ <= 2.8.
74 public void missing_profile_version() throws Exception {
75 db.prepareDbUnit(getClass(), "missing_profile_version.xml");
79 Connection connection = db.openConnection();
80 Statement stmt = connection.createStatement();
81 ResultSet rs = stmt.executeQuery("select text_value from project_measures where id=2");
84 // pb of comparison of timezones..., so using startsWith instead of equals
85 assertThat(rs.getString(1)).startsWith("[{\"key\":\"java-sonar-way\",\"language\":\"java\",\"name\":\"Sonar way\",\"rulesUpdatedAt\":");