diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-17 17:05:56 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-18 09:35:05 +0100 |
commit | cfcbe278f7ced12599d898d50f3fe68bfbf95155 (patch) | |
tree | 5b4116ad08a8ba87ffc5bf9f159a431b9609b48f /sonar-batch-protocol/src/test | |
parent | 38ce80934961773a9a35ec0401994b3d726597dc (diff) | |
download | sonarqube-cfcbe278f7ced12599d898d50f3fe68bfbf95155.tar.gz sonarqube-cfcbe278f7ced12599d898d50f3fe68bfbf95155.zip |
Rename batch into scanner
Diffstat (limited to 'sonar-batch-protocol/src/test')
10 files changed, 0 insertions, 925 deletions
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java deleted file mode 100644 index fe0643b5c45..00000000000 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.batch.protocol.input; - -import org.apache.commons.io.IOUtils; -import org.junit.Test; - -import static net.javacrumbs.jsonunit.assertj.JsonAssert.assertThatJson; -import static org.assertj.core.api.Assertions.assertThat; - -public class GlobalRepositoriesTest { - - @Test - public void to_json() throws Exception { - GlobalRepositories ref = new GlobalRepositories(); - ref.addMetric(new Metric(1, "ncloc", "INT", "Description", -1, "NCLOC", true, false, 2.0, 1.0, true)); - ref.addGlobalSetting("prop", "value"); - ref.setTimestamp(10); - - assertThatJson(ref.toJson()) - .isEqualTo(IOUtils.toString(getClass().getResource("GlobalRepositoriesTest/expected.json"))); - } - - @Test - public void from_json() { - GlobalRepositories ref = GlobalRepositories - .fromJson( - "{timestamp:1," - + "metrics:[{id:1,key:ncloc,valueType:DATA,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}]," - + "globalSettings:{prop:value}}"); - - assertThat(ref.timestamp()).isEqualTo(1); - Metric metric = ref.metrics().iterator().next(); - assertThat(metric.id()).isEqualTo(1); - assertThat(metric.key()).isEqualTo("ncloc"); - assertThat(metric.valueType()).isEqualTo("DATA"); - assertThat(metric.description()).isEqualTo("Description"); - assertThat(metric.direction()).isEqualTo(-1); - assertThat(metric.name()).isEqualTo("NCLOC"); - assertThat(metric.isQualitative()).isTrue(); - assertThat(metric.isUserManaged()).isFalse(); - assertThat(metric.worstValue()).isEqualTo(2.0); - assertThat(metric.bestValue()).isEqualTo(1.0); - assertThat(metric.isOptimizedBestValue()).isTrue(); - - assertThat(ref.globalSettings()).containsEntry("prop", "value"); - } -} diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java deleted file mode 100644 index 540bfbe4c53..00000000000 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java +++ /dev/null @@ -1,388 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.batch.protocol.output; - -import com.google.common.collect.Lists; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.batch.protocol.Constants; -import org.sonar.core.util.CloseableIterator; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; - -public class BatchReportReaderTest { - - private static int UNKNOWN_COMPONENT_REF = 123; - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - File dir; - - BatchReportReader underTest; - - @Before - public void setUp() throws Exception { - dir = temp.newFolder(); - underTest = new BatchReportReader(dir); - } - - @Test - public void read_metadata() { - BatchReportWriter writer = new BatchReportWriter(dir); - BatchReport.Metadata.Builder metadata = BatchReport.Metadata.newBuilder() - .setAnalysisDate(15000000L) - .setProjectKey("PROJECT_A") - .setRootComponentRef(1) - .setCrossProjectDuplicationActivated(true); - writer.writeMetadata(metadata.build()); - - BatchReport.Metadata readMetadata = underTest.readMetadata(); - assertThat(readMetadata.getAnalysisDate()).isEqualTo(15000000L); - assertThat(readMetadata.getProjectKey()).isEqualTo("PROJECT_A"); - assertThat(readMetadata.getRootComponentRef()).isEqualTo(1); - assertThat(readMetadata.getCrossProjectDuplicationActivated()).isTrue(); - } - - @Test(expected = IllegalStateException.class) - public void fail_if_missing_metadata_file() { - underTest.readMetadata(); - } - - @Test - public void read_components() { - BatchReportWriter writer = new BatchReportWriter(dir); - BatchReport.Component.Builder component = BatchReport.Component.newBuilder() - .setRef(1) - .setPath("src/main/java/Foo.java"); - writer.writeComponent(component.build()); - - assertThat(underTest.readComponent(1).getPath()).isEqualTo("src/main/java/Foo.java"); - } - - @Test(expected = IllegalStateException.class) - public void fail_if_missing_file_on_component() { - underTest.readComponent(UNKNOWN_COMPONENT_REF); - } - - @Test - public void read_issues() { - BatchReportWriter writer = new BatchReportWriter(dir); - BatchReport.Issue issue = BatchReport.Issue.newBuilder() - .setLine(50) - .build(); - writer.writeComponentIssues(1, asList(issue)); - - assertThat(underTest.readComponentIssues(1)).hasSize(1); - assertThat(underTest.readComponentIssues(200)).isEmpty(); - } - - @Test - public void empty_list_if_no_issue_found() { - assertThat(underTest.readComponentIssues(UNKNOWN_COMPONENT_REF)).isEmpty(); - } - - @Test - public void read_measures() { - BatchReportWriter writer = new BatchReportWriter(dir); - BatchReport.Measure.Builder measure = BatchReport.Measure.newBuilder() - .setStringValue("value_a"); - writer.writeComponentMeasures(1, asList(measure.build())); - - assertThat(underTest.readComponentMeasures(1)).hasSize(1); - } - - @Test - public void empty_list_if_no_measure_found() { - assertThat(underTest.readComponentMeasures(UNKNOWN_COMPONENT_REF)).isEmpty(); - } - - @Test - public void read_changesets() { - BatchReportWriter writer = new BatchReportWriter(dir); - BatchReport.Changesets.Builder scm = BatchReport.Changesets.newBuilder() - .setComponentRef(1) - .addChangeset(BatchReport.Changesets.Changeset.newBuilder().setDate(123_456_789).setAuthor("jack.daniels").setRevision("123-456-789")); - writer.writeComponentChangesets(scm.build()); - - assertThat(underTest.readChangesets(1).getChangesetList()).hasSize(1); - assertThat(underTest.readChangesets(1).getChangeset(0).getDate()).isEqualTo(123_456_789L); - } - - @Test - public void null_if_no_changeset_found() { - assertThat(underTest.readChangesets(UNKNOWN_COMPONENT_REF)).isNull(); - } - - @Test - public void read_duplications() { - BatchReportWriter writer = new BatchReportWriter(dir); - writer.writeMetadata(BatchReport.Metadata.newBuilder() - .setRootComponentRef(1).build()); - writer.writeComponent(BatchReport.Component.newBuilder() - .setRef(1).build()); - - BatchReport.Duplication duplication = BatchReport.Duplication.newBuilder() - .setOriginPosition(BatchReport.TextRange.newBuilder() - .setStartLine(1) - .setEndLine(5) - .build()) - .addDuplicate(BatchReport.Duplicate.newBuilder() - .setOtherFileRef(2) - .setRange(BatchReport.TextRange.newBuilder() - .setStartLine(6) - .setEndLine(10) - .build()) - .build()) - .build(); - writer.writeComponentDuplications(1, asList(duplication)); - - BatchReportReader sut = new BatchReportReader(dir); - assertThat(sut.readComponentDuplications(1)).hasSize(1); - } - - @Test - public void empty_list_if_no_duplication_found() { - assertThat(underTest.readComponentDuplications(UNKNOWN_COMPONENT_REF)).isEmpty(); - } - - @Test - public void read_duplication_blocks() { - BatchReportWriter writer = new BatchReportWriter(dir); - writer.writeMetadata(BatchReport.Metadata.newBuilder() - .setRootComponentRef(1).build()); - writer.writeComponent(BatchReport.Component.newBuilder() - .setRef(1).build()); - - BatchReport.CpdTextBlock duplicationBlock = BatchReport.CpdTextBlock.newBuilder() - .setHash("abcdefghijklmnop") - .setStartLine(1) - .setEndLine(2) - .setStartTokenIndex(10) - .setEndTokenIndex(15) - .build(); - writer.writeCpdTextBlocks(1, singletonList(duplicationBlock)); - - BatchReportReader sut = new BatchReportReader(dir); - assertThat(sut.readCpdTextBlocks(1)).hasSize(1); - } - - @Test - public void empty_list_if_no_duplication_block_found() { - assertThat(underTest.readComponentDuplications(UNKNOWN_COMPONENT_REF)).isEmpty(); - } - - @Test - public void read_syntax_highlighting() throws Exception { - BatchReportWriter writer = new BatchReportWriter(dir); - writer.writeMetadata(BatchReport.Metadata.newBuilder() - .setRootComponentRef(1) - .build()); - writer.writeComponent(BatchReport.Component.newBuilder() - .setRef(1).build()); - - writer.writeComponentSyntaxHighlighting(1, asList( - BatchReport.SyntaxHighlighting.newBuilder() - .setRange(BatchReport.TextRange.newBuilder() - .setStartLine(1) - .setEndLine(10) - .build()) - .setType(Constants.HighlightingType.ANNOTATION) - .build())); - - try (CloseableIterator<BatchReport.SyntaxHighlighting> it = underTest.readComponentSyntaxHighlighting(1)) { - BatchReport.SyntaxHighlighting syntaxHighlighting = it.next(); - assertThat(syntaxHighlighting.getRange()).isNotNull(); - assertThat(syntaxHighlighting.getRange().getStartLine()).isEqualTo(1); - assertThat(syntaxHighlighting.getRange().getEndLine()).isEqualTo(10); - assertThat(syntaxHighlighting.getType()).isEqualTo(Constants.HighlightingType.ANNOTATION); - } - } - - @Test - public void return_empty_if_no_highlighting_found() { - assertThat(underTest.readComponentSyntaxHighlighting(UNKNOWN_COMPONENT_REF)).isEmpty(); - } - - @Test - public void read_symbols() { - BatchReportWriter writer = new BatchReportWriter(dir); - writer.writeMetadata(BatchReport.Metadata.newBuilder() - .setRootComponentRef(1) - .build()); - writer.writeComponent(BatchReport.Component.newBuilder() - .setRef(1).build()); - - writer.writeComponentSymbols(1, asList(BatchReport.Symbol.newBuilder() - .setDeclaration(BatchReport.TextRange.newBuilder() - .setStartLine(1) - .setStartOffset(3) - .setEndLine(1) - .setEndOffset(5) - .build()) - .addReference(BatchReport.TextRange.newBuilder() - .setStartLine(10) - .setStartOffset(15) - .setEndLine(11) - .setEndOffset(2) - .build()) - .build())); - - underTest = new BatchReportReader(dir); - assertThat(underTest.readComponentSymbols(1)).hasSize(1); - } - - @Test - public void empty_list_if_no_symbol_found() { - assertThat(underTest.readComponentSymbols(UNKNOWN_COMPONENT_REF)).isEmpty(); - } - - @Test - public void read_coverage() throws Exception { - BatchReportWriter writer = new BatchReportWriter(dir); - writer.writeMetadata(BatchReport.Metadata.newBuilder() - .setRootComponentRef(1) - .build()); - writer.writeComponent(BatchReport.Component.newBuilder() - .setRef(1).build()); - - writer.writeComponentCoverage(1, asList( - BatchReport.Coverage.newBuilder() - .setLine(1) - .setConditions(1) - .setUtHits(true) - .setItHits(false) - .setUtCoveredConditions(1) - .setItCoveredConditions(1) - .setOverallCoveredConditions(1) - .build(), - BatchReport.Coverage.newBuilder() - .setLine(2) - .setConditions(5) - .setUtHits(false) - .setItHits(false) - .setUtCoveredConditions(4) - .setItCoveredConditions(5) - .setOverallCoveredConditions(5) - .build())); - - underTest = new BatchReportReader(dir); - try (CloseableIterator<BatchReport.Coverage> it = new BatchReportReader(dir).readComponentCoverage(1)) { - BatchReport.Coverage coverage = it.next(); - assertThat(coverage.getLine()).isEqualTo(1); - assertThat(coverage.getConditions()).isEqualTo(1); - assertThat(coverage.getUtHits()).isTrue(); - assertThat(coverage.getItHits()).isFalse(); - assertThat(coverage.getUtCoveredConditions()).isEqualTo(1); - assertThat(coverage.getItCoveredConditions()).isEqualTo(1); - assertThat(coverage.getOverallCoveredConditions()).isEqualTo(1); - } - } - - @Test - public void return_empty_iterator_if_no_coverage_found() { - assertThat(underTest.readComponentCoverage(UNKNOWN_COMPONENT_REF)).isEmpty(); - } - - @Test - public void read_source_lines() throws Exception { - BatchReportWriter writer = new BatchReportWriter(dir); - File file = writer.getFileStructure().fileFor(FileStructure.Domain.SOURCE, 1); - FileUtils.writeLines(file, Lists.newArrayList("line1", "line2")); - - File sourceFile = new BatchReportReader(dir).readFileSource(1); - assertThat(sourceFile).isEqualTo(file); - } - - @Test - public void read_tests() throws Exception { - BatchReportWriter writer = new BatchReportWriter(dir); - writer.writeTests(1, asList( - BatchReport.Test.newBuilder() - .setDurationInMs(60_000) - .setStacktrace("stacktrace") - .setMsg("message") - .setStatus(Constants.TestStatus.OK) - .build())); - - try (InputStream inputStream = FileUtils.openInputStream(underTest.readTests(1))) { - BatchReport.Test testResult = BatchReport.Test.PARSER.parseDelimitedFrom(inputStream); - assertThat(testResult.getDurationInMs()).isEqualTo(60_000); - assertThat(testResult.getStacktrace()).isEqualTo("stacktrace"); - assertThat(testResult.getMsg()).isEqualTo("message"); - assertThat(testResult.getStatus()).isEqualTo(Constants.TestStatus.OK); - } - } - - @Test - public void null_if_no_test_found() { - assertThat(underTest.readTests(UNKNOWN_COMPONENT_REF)).isNull(); - } - - @Test - public void read_coverage_details() throws Exception { - BatchReportWriter writer = new BatchReportWriter(dir); - writer.writeCoverageDetails(1, asList( - BatchReport.CoverageDetail.newBuilder() - .setTestName("test-name") - .addCoveredFile(BatchReport.CoverageDetail.CoveredFile.newBuilder() - .addAllCoveredLine(asList(1, 2, 3, 5, 7)) - .setFileRef(2)) - .build())); - - try (InputStream inputStream = FileUtils.openInputStream(underTest.readCoverageDetails(1))) { - BatchReport.CoverageDetail coverageDetail = BatchReport.CoverageDetail.PARSER.parseDelimitedFrom(inputStream); - assertThat(coverageDetail.getTestName()).isEqualTo("test-name"); - assertThat(coverageDetail.getCoveredFile(0).getFileRef()).isEqualTo(2); - assertThat(coverageDetail.getCoveredFile(0).getCoveredLineList()).containsExactly(1, 2, 3, 5, 7); - } - } - - @Test - public void null_if_no_coverage_detail_found() { - assertThat(underTest.readCoverageDetails(UNKNOWN_COMPONENT_REF)).isNull(); - } - - @Test - public void read_file_source() throws Exception { - BatchReportWriter writer = new BatchReportWriter(dir); - try (FileOutputStream outputStream = new FileOutputStream(writer.getSourceFile(1))) { - IOUtils.write("line1\nline2", outputStream); - } - - try (InputStream inputStream = FileUtils.openInputStream(underTest.readFileSource(1))) { - assertThat(IOUtils.readLines(inputStream)).containsOnly("line1", "line2"); - } - } - - @Test - public void return_null_when_no_file_source() throws Exception { - assertThat(underTest.readFileSource(UNKNOWN_COMPONENT_REF)).isNull(); - } -} diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java deleted file mode 100644 index fc594c00068..00000000000 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.batch.protocol.output; - -import com.google.common.collect.Iterators; -import java.io.File; -import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.batch.protocol.Constants; -import org.sonar.core.util.CloseableIterator; -import org.sonar.core.util.Protobuf; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; - -public class BatchReportWriterTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - File dir; - BatchReportWriter underTest; - - @Before - public void setUp() throws Exception { - dir = temp.newFolder(); - underTest = new BatchReportWriter(dir); - } - - @Test - public void create_dir_if_does_not_exist() { - FileUtils.deleteQuietly(dir); - underTest = new BatchReportWriter(dir); - - assertThat(dir).isDirectory().exists(); - } - - @Test - public void write_metadata() { - BatchReport.Metadata.Builder metadata = BatchReport.Metadata.newBuilder() - .setAnalysisDate(15000000L) - .setProjectKey("PROJECT_A") - .setRootComponentRef(1); - underTest.writeMetadata(metadata.build()); - - BatchReport.Metadata read = Protobuf.read(underTest.getFileStructure().metadataFile(), BatchReport.Metadata.PARSER); - assertThat(read.getAnalysisDate()).isEqualTo(15000000L); - assertThat(read.getProjectKey()).isEqualTo("PROJECT_A"); - assertThat(read.getRootComponentRef()).isEqualTo(1); - } - - @Test - public void write_component() { - // no data yet - assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isFalse(); - - // write data - BatchReport.Component.Builder component = BatchReport.Component.newBuilder() - .setRef(1) - .setLanguage("java") - .setPath("src/Foo.java") - .setType(Constants.ComponentType.FILE) - .setIsTest(false) - .addChildRef(5) - .addChildRef(42); - underTest.writeComponent(component.build()); - - assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue(); - File file = underTest.getFileStructure().fileFor(FileStructure.Domain.COMPONENT, 1); - assertThat(file).exists().isFile(); - BatchReport.Component read = Protobuf.read(file, BatchReport.Component.PARSER); - assertThat(read.getRef()).isEqualTo(1); - assertThat(read.getChildRefList()).containsOnly(5, 42); - assertThat(read.hasName()).isFalse(); - assertThat(read.getIsTest()).isFalse(); - } - - @Test - public void write_issues() { - // no data yet - assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isFalse(); - - // write data - BatchReport.Issue issue = BatchReport.Issue.newBuilder() - .setLine(50) - .setMsg("the message") - .build(); - - underTest.writeComponentIssues(1, asList(issue)); - - assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isTrue(); - File file = underTest.getFileStructure().fileFor(FileStructure.Domain.ISSUES, 1); - assertThat(file).exists().isFile(); - try (CloseableIterator<BatchReport.Issue> read = Protobuf.readStream(file, BatchReport.Issue.PARSER)) { - assertThat(Iterators.size(read)).isEqualTo(1); - } - } - - @Test - public void write_measures() { - assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isFalse(); - - BatchReport.Measure measure = BatchReport.Measure.newBuilder() - .setStringValue("text-value") - .setDoubleValue(2.5d) - .setValueType(Constants.MeasureValueType.DOUBLE) - .build(); - - underTest.writeComponentMeasures(1, asList(measure)); - - assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isTrue(); - File file = underTest.getFileStructure().fileFor(FileStructure.Domain.MEASURES, 1); - assertThat(file).exists().isFile(); - try (CloseableIterator<BatchReport.Measure> read = Protobuf.readStream(file, BatchReport.Measure.PARSER)) { - assertThat(Iterators.size(read)).isEqualTo(1); - } - } - - @Test - public void write_scm() { - assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGESETS, 1)).isFalse(); - - BatchReport.Changesets scm = BatchReport.Changesets.newBuilder() - .setComponentRef(1) - .addChangesetIndexByLine(0) - .addChangeset(BatchReport.Changesets.Changeset.newBuilder() - .setRevision("123-456-789") - .setAuthor("author") - .setDate(123_456_789L)) - .build(); - - underTest.writeComponentChangesets(scm); - - assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGESETS, 1)).isTrue(); - File file = underTest.getFileStructure().fileFor(FileStructure.Domain.CHANGESETS, 1); - assertThat(file).exists().isFile(); - BatchReport.Changesets read = Protobuf.read(file, BatchReport.Changesets.PARSER); - assertThat(read.getComponentRef()).isEqualTo(1); - assertThat(read.getChangesetCount()).isEqualTo(1); - assertThat(read.getChangesetList()).hasSize(1); - assertThat(read.getChangeset(0).getDate()).isEqualTo(123_456_789L); - } - - @Test - public void write_duplications() { - assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATIONS, 1)).isFalse(); - - BatchReport.Duplication duplication = BatchReport.Duplication.newBuilder() - .setOriginPosition(BatchReport.TextRange.newBuilder() - .setStartLine(1) - .setEndLine(5) - .build()) - .addDuplicate(BatchReport.Duplicate.newBuilder() - .setOtherFileRef(2) - .setRange(BatchReport.TextRange.newBuilder() - .setStartLine(6) - .setEndLine(10) - .build()) - .build()) - .build(); - underTest.writeComponentDuplications(1, asList(duplication)); - - assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATIONS, 1)).isTrue(); - File file = underTest.getFileStructure().fileFor(FileStructure.Domain.DUPLICATIONS, 1); - assertThat(file).exists().isFile(); - try (CloseableIterator<BatchReport.Duplication> duplications = Protobuf.readStream(file, BatchReport.Duplication.PARSER)) { - BatchReport.Duplication dup = duplications.next(); - assertThat(dup.getOriginPosition()).isNotNull(); - assertThat(dup.getDuplicateList()).hasSize(1); - } - } - - @Test - public void write_duplication_blocks() { - assertThat(underTest.hasComponentData(FileStructure.Domain.CPD_TEXT_BLOCKS, 1)).isFalse(); - - BatchReport.CpdTextBlock duplicationBlock = BatchReport.CpdTextBlock.newBuilder() - .setHash("abcdefghijklmnop") - .setStartLine(1) - .setEndLine(2) - .setStartTokenIndex(10) - .setEndTokenIndex(15) - .build(); - underTest.writeCpdTextBlocks(1, asList(duplicationBlock)); - - assertThat(underTest.hasComponentData(FileStructure.Domain.CPD_TEXT_BLOCKS, 1)).isTrue(); - File file = underTest.getFileStructure().fileFor(FileStructure.Domain.CPD_TEXT_BLOCKS, 1); - assertThat(file).exists().isFile(); - try (CloseableIterator<BatchReport.CpdTextBlock> duplicationBlocks = Protobuf.readStream(file, BatchReport.CpdTextBlock.parser())) { - BatchReport.CpdTextBlock duplicationBlockResult = duplicationBlocks.next(); - assertThat(duplicationBlockResult.getHash()).isEqualTo("abcdefghijklmnop"); - assertThat(duplicationBlockResult.getStartLine()).isEqualTo(1); - assertThat(duplicationBlockResult.getEndLine()).isEqualTo(2); - assertThat(duplicationBlockResult.getStartTokenIndex()).isEqualTo(10); - assertThat(duplicationBlockResult.getEndTokenIndex()).isEqualTo(15); - } - } - - @Test - public void write_symbols() { - // no data yet - assertThat(underTest.hasComponentData(FileStructure.Domain.SYMBOLS, 1)).isFalse(); - - // write data - BatchReport.Symbol symbol = BatchReport.Symbol.newBuilder() - .setDeclaration(BatchReport.TextRange.newBuilder() - .setStartLine(1) - .setStartOffset(3) - .setEndLine(1) - .setEndOffset(5) - .build()) - .addReference(BatchReport.TextRange.newBuilder() - .setStartLine(10) - .setStartOffset(15) - .setEndLine(11) - .setEndOffset(2) - .build()) - .build(); - - underTest.writeComponentSymbols(1, asList(symbol)); - - assertThat(underTest.hasComponentData(FileStructure.Domain.SYMBOLS, 1)).isTrue(); - - File file = underTest.getFileStructure().fileFor(FileStructure.Domain.SYMBOLS, 1); - assertThat(file).exists().isFile(); - try (CloseableIterator<BatchReport.Symbol> read = Protobuf.readStream(file, BatchReport.Symbol.PARSER)) { - assertThat(read).hasSize(1); - } - } - - @Test - public void write_syntax_highlighting() { - // no data yet - assertThat(underTest.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, 1)).isFalse(); - - underTest.writeComponentSyntaxHighlighting(1, asList( - BatchReport.SyntaxHighlighting.newBuilder() - .setRange(BatchReport.TextRange.newBuilder() - .setStartLine(1) - .setEndLine(1) - .build()) - .setType(Constants.HighlightingType.ANNOTATION) - .build())); - - assertThat(underTest.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, 1)).isTrue(); - } - - @Test - public void write_coverage() { - // no data yet - assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isFalse(); - - underTest.writeComponentCoverage(1, asList( - BatchReport.Coverage.newBuilder() - .setLine(1) - .setConditions(1) - .setUtHits(true) - .setItHits(false) - .setUtCoveredConditions(1) - .setItCoveredConditions(1) - .setOverallCoveredConditions(1) - .build())); - - assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isTrue(); - } - - @Test - public void write_tests() { - assertThat(underTest.hasComponentData(FileStructure.Domain.TESTS, 1)).isFalse(); - - underTest.writeTests(1, asList( - BatchReport.Test.getDefaultInstance())); - - assertThat(underTest.hasComponentData(FileStructure.Domain.TESTS, 1)).isTrue(); - - } - - @Test - public void write_coverage_details() { - assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGE_DETAILS, 1)).isFalse(); - - underTest.writeCoverageDetails(1, asList( - BatchReport.CoverageDetail.getDefaultInstance())); - - assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGE_DETAILS, 1)).isTrue(); - } -} diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/FileStructureTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/FileStructureTest.java deleted file mode 100644 index 1692263a17c..00000000000 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/FileStructureTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.batch.protocol.output; - -import org.apache.commons.io.FileUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import java.io.File; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - -public class FileStructureTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void fail_if_dir_does_not_exist() throws Exception { - File dir = temp.newFolder(); - FileUtils.deleteQuietly(dir); - try { - new FileStructure(dir); - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessageContaining("Directory of analysis report does not exist"); - } - } - - @Test - public void fail_if_invalid_dir() throws Exception { - // not a dir but a file - File dir = temp.newFile(); - try { - new FileStructure(dir); - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessageContaining("Directory of analysis report does not exist"); - } - } - - @Test - public void locate_files() throws Exception { - File dir = temp.newFolder(); - FileUtils.write(new File(dir, "metadata.pb"), "metadata content"); - FileUtils.write(new File(dir, "issues-3.pb"), "issues of component 3"); - FileUtils.write(new File(dir, "component-42.pb"), "details of component 42"); - - FileStructure structure = new FileStructure(dir); - assertThat(structure.metadataFile()).exists().isFile(); - assertThat(structure.fileFor(FileStructure.Domain.COMPONENT, 42)).exists().isFile(); - assertThat(structure.fileFor(FileStructure.Domain.ISSUES, 3)).exists().isFile(); - assertThat(structure.fileFor(FileStructure.Domain.ISSUES, 42)).doesNotExist(); - } -} diff --git a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/FileStreamTest/file.txt b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/FileStreamTest/file.txt deleted file mode 100644 index 83db48f84ec..00000000000 --- a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/FileStreamTest/file.txt +++ /dev/null @@ -1,3 +0,0 @@ -line1 -line2 -line3 diff --git a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/GlobalRepositoriesTest/expected.json b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/GlobalRepositoriesTest/expected.json deleted file mode 100644 index de38ae0cb18..00000000000 --- a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/GlobalRepositoriesTest/expected.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "timestamp": 10, - "metrics": [ - { - "id": 1, - "key": "ncloc", - "valueType": "INT", - "description": "Description", - "direction": -1, - "name": "NCLOC", - "qualitative": true, - "userManaged": false, - "worstValue": 2.0, - "bestValue": 1.0, - "optimizedBestValue": true - } - ], - "globalSettings": { - "prop": "value" - } -} diff --git a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/ProjectRepositoriesTest/testToJson.json b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/ProjectRepositoriesTest/testToJson.json deleted file mode 100644 index ba7489143a6..00000000000 --- a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/ProjectRepositoriesTest/testToJson.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "timestamp": 10, - "settingsByModule": { - "foo": { - "prop1": "value1", - "prop2": "value2", - "prop": "value" - } - }, - "fileDataByModuleAndPath": { - "foo": { - "src/main/java/Foo.java": { - "hash": "xyz", - "needBlame": true - }, - "src/main/java/Foo2.java": { - "hash": "xyz", - "needBlame": false - } - } - }, - "lastAnalysisDate": "2014-05-18T15:50:45+0100" -} diff --git a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/RulesSearchTest/empty.json b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/RulesSearchTest/empty.json deleted file mode 100644 index 055fe8b8d63..00000000000 --- a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/RulesSearchTest/empty.json +++ /dev/null @@ -1 +0,0 @@ -{"total":3225,"p":30,"ps":500,"rules":[]}
\ No newline at end of file diff --git a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/RulesSearchTest/expected.json b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/RulesSearchTest/expected.json deleted file mode 100644 index 89350a7e331..00000000000 --- a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/RulesSearchTest/expected.json +++ /dev/null @@ -1 +0,0 @@ -{"total":290,"p":1,"ps":2,"rules":[{"key":"squid:S1194","internalKey":"S1194","repo":"squid","name":"\"java.lang.Error\" should not be extended","severity":"MAJOR","lang":"java"},{"key":"squid:ObjectFinalizeOverridenCallsSuperFinalizeCheck","internalKey":"ObjectFinalizeOverridenCallsSuperFinalizeCheck","repo":"squid","name":"super.finalize() should be called at the end of Object.finalize() implementations","severity":"BLOCKER","lang":"java"}]}
\ No newline at end of file diff --git a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/output/component/ReportComponentsTest/expected.json b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/output/component/ReportComponentsTest/expected.json deleted file mode 100644 index 581bbc5ea23..00000000000 --- a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/output/component/ReportComponentsTest/expected.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "analysisDate": "2012-12-12T00:00:00+0100", - "root": { - "batchId": 1, - "id": 11, - "snapshotId": 111, - "name": "Root project", - "type": "PRJ", - "children": [ - { - "batchId": 2, - "id": 22, - "snapshotId": 222, - "path": "module1", - "name": "Module", - "type": "MOD", - "children": [ - { - "batchId": 3, - "id": 33, - "snapshotId": 333, - "path": "src", - "name": "src", - "type": "DIR", - "children": [ - { - "batchId": 4, - "id": 44, - "snapshotId": 444, - "path": "Foo.java", - "name": "Foo.java", - "type": "FIL", - "languageKey": "java", - "isTest": true, - "children": [] - } - ] - } - ] - } - ] - } -}
\ No newline at end of file |