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.source.index;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.ClassRule;
25 import org.junit.Test;
26 import org.junit.experimental.categories.Category;
27 import org.sonar.core.persistence.DbTester;
28 import org.sonar.server.db.DbClient;
29 import org.sonar.server.source.db.FileSourceTesting;
30 import org.sonar.test.DbTests;
32 import java.sql.Connection;
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.junit.Assert.fail;
37 @Category(DbTests.class)
38 public class SourceLineResultSetIteratorTest {
41 public static DbTester db = new DbTester().schema(SourceLineResultSetIteratorTest.class, "schema.sql");
45 Connection connection;
48 public void setUp() throws Exception {
49 dbClient = new DbClient(db.database(), db.myBatis());
50 connection = db.openConnection();
54 public void after() throws Exception {
59 public void parse_db_and_generate_source_line_documents() throws Exception {
60 db.prepareDbUnit(getClass(), "shared.xml");
61 FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newFakeData(3).build());
63 SourceLineResultSetIterator iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L);
64 assertThat(iterator.hasNext()).isTrue();
65 SourceLineResultSetIterator.SourceFile file = iterator.next();
66 assertThat(file.getLines()).hasSize(3);
67 SourceLineDoc firstLine = file.getLines().get(0);
68 assertThat(firstLine.projectUuid()).isEqualTo("PROJECT_UUID");
69 assertThat(firstLine.fileUuid()).isEqualTo("FILE_UUID");
70 assertThat(firstLine.line()).isEqualTo(1);
71 assertThat(firstLine.scmRevision()).isEqualTo("REVISION_1");
72 assertThat(firstLine.scmAuthor()).isEqualTo("AUTHOR_1");
73 assertThat(firstLine.highlighting()).isEqualTo("HIGHLIGHTING_1");
74 assertThat(firstLine.symbols()).isEqualTo("SYMBOLS_1");
75 assertThat(firstLine.source()).isEqualTo("SOURCE_1");
76 assertThat(firstLine.utLineHits()).isEqualTo(1);
77 assertThat(firstLine.utConditions()).isEqualTo(2);
78 assertThat(firstLine.utCoveredConditions()).isEqualTo(3);
79 assertThat(firstLine.itLineHits()).isEqualTo(4);
80 assertThat(firstLine.itConditions()).isEqualTo(5);
81 assertThat(firstLine.itCoveredConditions()).isEqualTo(6);
82 assertThat(firstLine.overallLineHits()).isEqualTo(7);
83 assertThat(firstLine.overallConditions()).isEqualTo(8);
84 assertThat(firstLine.overallCoveredConditions()).isEqualTo(9);
89 public void should_ignore_lines_already_handled() throws Exception {
90 db.prepareDbUnit(getClass(), "shared.xml");
92 SourceLineResultSetIterator iterator = SourceLineResultSetIterator.create(dbClient, connection, 2000000000000L);
93 assertThat(iterator.hasNext()).isFalse();
98 public void should_fail_on_bad_data_format() throws Exception {
99 db.prepareDbUnit(getClass(), "shared.xml");
101 FileSourceTesting.updateDataColumn(connection, "FILE_UUID", "THIS_IS_NOT_PROTOBUF".getBytes());
103 SourceLineResultSetIterator iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L);
105 assertThat(iterator.hasNext()).isTrue();
108 } catch (IllegalStateException e) {