Search in sources :

Example 86 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class GenericTestExecutionMediumTest method twoReports.

@Test
public void twoReports() throws IOException {
    File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-test-exec");
    TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).property("sonar.testExecutionReportPaths", "unittest.xml,unittest2.xml").start();
    InputFile testFile = result.inputFile("testx/ClassOneTest.xoo");
    ScannerReport.Test success = result.firstTestExecutionForName(testFile, "test1");
    assertThat(success.getDurationInMs()).isEqualTo(5);
    assertThat(success.getStatus()).isEqualTo(TestStatus.OK);
    ScannerReport.Test success2 = result.firstTestExecutionForName(testFile, "test1b");
    assertThat(success2.getDurationInMs()).isEqualTo(5);
    assertThat(success2.getStatus()).isEqualTo(TestStatus.OK);
    ScannerReport.Test skipped = result.firstTestExecutionForName(testFile, "test2");
    assertThat(skipped.getDurationInMs()).isEqualTo(500);
    assertThat(skipped.getStatus()).isEqualTo(TestStatus.SKIPPED);
    assertThat(skipped.getMsg()).isEqualTo("short message");
    assertThat(skipped.getStacktrace()).isEqualTo("other");
    ScannerReport.Test failed = result.firstTestExecutionForName(testFile, "test3");
    assertThat(failed.getDurationInMs()).isEqualTo(100);
    assertThat(failed.getStatus()).isEqualTo(TestStatus.FAILURE);
    assertThat(failed.getMsg()).isEqualTo("short");
    assertThat(failed.getStacktrace()).isEqualTo("stacktrace");
    ScannerReport.Test error = result.firstTestExecutionForName(testFile, "test4");
    assertThat(error.getDurationInMs()).isEqualTo(500);
    assertThat(error.getStatus()).isEqualTo(TestStatus.ERROR);
    assertThat(error.getMsg()).isEqualTo("short");
    assertThat(error.getStacktrace()).isEqualTo("stacktrace");
    assertThat(result.allMeasures().get(testFile.key())).extracting("metricKey", "intValue.value", "longValue.value").containsOnly(tuple(CoreMetrics.TESTS_KEY, 4, 0L), tuple(CoreMetrics.SKIPPED_TESTS_KEY, 2, 0L), tuple(CoreMetrics.TEST_ERRORS_KEY, 1, 0L), tuple(CoreMetrics.TEST_EXECUTION_TIME_KEY, 0, 1610L), tuple(CoreMetrics.TEST_FAILURES_KEY, 1, 0L));
}
Also used : ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 87 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class DefaultBlameOutputTest method shouldFailIfNotExpectedFile.

@Test
public void shouldFailIfNotExpectedFile() {
    InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").build();
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("It was not expected to blame file src/main/java/Foo.java");
    new DefaultBlameOutput(null, Arrays.<InputFile>asList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build())).blameResult(file, Arrays.asList(new BlameLine().revision("1").author("guy")));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultBlameOutput(org.sonar.scanner.scm.DefaultBlameOutput) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 88 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class DefaultBlameOutputTest method shouldFailIfNullDate.

@Test
public void shouldFailIfNullDate() {
    InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build();
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Blame date is null for file src/main/java/Foo.java at line 1");
    new DefaultBlameOutput(null, Arrays.<InputFile>asList(file)).blameResult(file, Arrays.asList(new BlameLine().revision("1").author("guy")));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultBlameOutput(org.sonar.scanner.scm.DefaultBlameOutput) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 89 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class DefaultSensorStorageTest method duplicateHighlighting.

@Test(expected = UnsupportedOperationException.class)
public void duplicateHighlighting() throws Exception {
    InputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.java").setModuleBaseDir(temp.newFolder().toPath()).build();
    DefaultHighlighting h = new DefaultHighlighting(null).onFile(inputFile);
    underTest.store(h);
    underTest.store(h);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultHighlighting(org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 90 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class DefaultSensorStorageTest method shouldValidateMaxLine.

@Test
public void shouldValidateMaxLine() throws Exception {
    InputFile file = new TestInputFileBuilder("module", "testfile").setModuleBaseDir(temp.newFolder().toPath()).build();
    Map<Integer, Integer> map = ImmutableMap.of(11, 3);
    String data = KeyValueFormat.format(map);
    thrown.expect(IllegalStateException.class);
    underTest.validateCoverageMeasure(data, file);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Aggregations

InputFile (org.sonar.api.batch.fs.InputFile)98 Test (org.junit.Test)60 File (java.io.File)44 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)39 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)19 TaskResult (org.sonar.scanner.mediumtest.TaskResult)19 IOException (java.io.IOException)10 FilePredicates (org.sonar.api.batch.fs.FilePredicates)7 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)7 List (java.util.List)6 BlameLine (org.sonar.api.batch.scm.BlameLine)6 FileSystem (org.sonar.api.batch.fs.FileSystem)5 ArrayList (java.util.ArrayList)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 DefaultBlameOutput (org.sonar.scanner.scm.DefaultBlameOutput)4 FilePredicate (org.sonar.api.batch.fs.FilePredicate)3 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)3 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)3 MutableTestPlan (org.sonar.api.test.MutableTestPlan)3 Block (org.sonar.duplications.block.Block)3