Search in sources :

Example 96 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-openedge by Riverside-Software.

the class TestProjectSensorContextExtra method createContext.

public static SensorContextTester createContext() throws IOException {
    MapSettings settings = new MapSettings();
    settings.setProperty("sonar.sources", "src");
    settings.setProperty(Constants.PROPATH, new File(BASEDIR).getAbsolutePath());
    settings.setProperty(Constants.BINARIES, "build");
    settings.setProperty(Constants.DATABASES, "src/schema/sp2k.df");
    settings.setProperty(Constants.SKIP_RCODE, true);
    settings.setProperty(Constants.PROPARSE_ERROR_STACKTRACE, false);
    settings.setProperty("sonar.oe.module1.pattern", FILE6);
    settings.setProperty("sonar.oe.module1.databases", "src/schema/extra.df");
    SensorContextTester context = SensorContextTester.create(new File(BASEDIR));
    context.setSettings(settings);
    context.fileSystem().add(new TestInputFileBuilder(BASEDIR, DF1).setLanguage(Constants.DB_LANGUAGE_KEY).setType(Type.MAIN).setCharset(Charset.defaultCharset()).setContents(Files.toString(new File(BASEDIR, DF1), Charset.defaultCharset())).build());
    context.fileSystem().add(new TestInputFileBuilder(BASEDIR, FILE1).setLanguage(Constants.LANGUAGE_KEY).setType(Type.MAIN).setCharset(Charset.defaultCharset()).setContents(Files.toString(new File(BASEDIR, FILE1), Charset.defaultCharset())).build());
    context.fileSystem().add(new TestInputFileBuilder(BASEDIR, FILE2).setLanguage(Constants.LANGUAGE_KEY).setType(Type.MAIN).setCharset(Charset.defaultCharset()).setContents(Files.toString(new File(BASEDIR, FILE2), Charset.defaultCharset())).build());
    context.fileSystem().add(new TestInputFileBuilder(BASEDIR, FILE3).setLanguage(Constants.LANGUAGE_KEY).setType(Type.MAIN).setCharset(Charset.defaultCharset()).setContents(Files.toString(new File(BASEDIR, FILE3), Charset.defaultCharset())).build());
    context.fileSystem().add(new TestInputFileBuilder(BASEDIR, FILE4).setLanguage(Constants.LANGUAGE_KEY).setType(Type.MAIN).setCharset(Charset.defaultCharset()).setContents(Files.toString(new File(BASEDIR, FILE4), Charset.defaultCharset())).build());
    context.fileSystem().add(new TestInputFileBuilder(BASEDIR, FILE5).setLanguage(Constants.LANGUAGE_KEY).setType(Type.MAIN).setCharset(Charset.defaultCharset()).setContents(Files.toString(new File(BASEDIR, FILE5), Charset.defaultCharset())).build());
    context.fileSystem().add(new TestInputFileBuilder(BASEDIR, FILE6).setLanguage(Constants.LANGUAGE_KEY).setType(Type.MAIN).setCharset(Charset.defaultCharset()).setContents(Files.toString(new File(BASEDIR, FILE6), Charset.defaultCharset())).build());
    context.fileSystem().add(new TestInputFileBuilder(BASEDIR, CLASS1).setLanguage(Constants.LANGUAGE_KEY).setType(Type.MAIN).setCharset(Charset.defaultCharset()).setContents(Files.toString(new File(BASEDIR, CLASS1), Charset.defaultCharset())).build());
    return context;
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) MapSettings(org.sonar.api.config.internal.MapSettings) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) File(java.io.File)

Example 97 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-openedge by Riverside-Software.

the class OpenEdgeCPDSensorTest method testCPDSensor.

@Test
public void testCPDSensor() throws Exception {
    MapSettings settings = new MapSettings();
    settings.setProperty(Constants.USE_SIMPLE_CPD, true);
    SensorContextTester context = TestProjectSensorContext.createContext();
    context.setSettings(settings);
    OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER);
    OpenEdgeCPDSensor sensor = new OpenEdgeCPDSensor(oeSettings);
    sensor.execute(context);
    assertNotNull(context.cpdTokens(BASEDIR + ":" + FILE3));
    assertEquals(context.cpdTokens(BASEDIR + ":" + FILE3).size(), 14);
    assertNotNull(context.cpdTokens(BASEDIR + ":" + CLASS1));
    assertEquals(context.cpdTokens(BASEDIR + ":" + CLASS1).size(), 19);
    assertNotNull(context.cpdTokens(BASEDIR + ":" + FILE4));
    assertEquals(context.cpdTokens(BASEDIR + ":" + FILE4).size(), 3);
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) OpenEdgeSettings(org.sonar.plugins.openedge.foundation.OpenEdgeSettings) OpenEdgePluginTest(org.sonar.plugins.openedge.OpenEdgePluginTest) Test(org.testng.annotations.Test)

Example 98 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-openedge by Riverside-Software.

the class OpenEdgeCodeColorizerTest method testSp2k.

@Test
public void testSp2k() throws Exception {
    SensorContextTester context = TestProjectSensorContext.createContext();
    OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER);
    OpenEdgeCodeColorizer sensor = new OpenEdgeCodeColorizer(oeSettings);
    sensor.execute(context);
    // Comments
    Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE1, 1, 10));
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE1, 1, 10).size(), 1);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE1, 1, 10).get(0), TypeOfText.COMMENT);
    // Quoted string
    Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 13));
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 13).size(), 1);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 13).get(0), TypeOfText.STRING);
    // Keyword
    Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 5));
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 5).size(), 1);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 5).get(0), TypeOfText.KEYWORD);
    // Preprocessor
    Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 3, 25));
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 3, 25).size(), 1);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 3, 25).get(0), TypeOfText.PREPROCESS_DIRECTIVE);
    Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 4, 10));
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 4, 10).size(), 1);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 4, 10).get(0), TypeOfText.STRING);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 4, 16).size(), 0);
    // Constants
    Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 14, 9));
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 14, 9).size(), 1);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 14, 9).get(0), TypeOfText.CONSTANT);
    // Include file
    Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 3));
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 3).size(), 1);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 3).get(0), TypeOfText.PREPROCESS_DIRECTIVE);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 20).size(), 1);
    Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 20).get(0), TypeOfText.PREPROCESS_DIRECTIVE);
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) OpenEdgeSettings(org.sonar.plugins.openedge.foundation.OpenEdgeSettings) OpenEdgePluginTest(org.sonar.plugins.openedge.OpenEdgePluginTest) Test(org.testng.annotations.Test)

Example 99 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-openedge by Riverside-Software.

the class OpenEdgeProparseSensorTest method testPreprocessorSettings01.

@Test
public void testPreprocessorSettings01() throws Exception {
    MapSettings settings = new MapSettings();
    settings.setProperty("sonar.oe.preprocessor.window-system", "foobar");
    settings.setProperty("sonar.oe.preprocessor.opsys", "unix");
    settings.setProperty("sonar.oe.preprocessor.batch-mode", "false");
    settings.setProperty("sonar.oe.preprocessor.process-architecture", "32");
    settings.setProperty("sonar.oe.preprocessor.proversion", "12.0");
    SensorContextTester context = TestProjectSensorContext.createContext();
    context.setSettings(settings);
    OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER);
    assertFalse(oeSettings.getProparseSessions().getDefaultSession().getProparseSettings().getBatchMode());
    assertEquals(oeSettings.getProparseSessions().getDefaultSession().getProparseSettings().getWindowSystem(), "foobar");
    assertEquals(oeSettings.getProparseSessions().getDefaultSession().getProparseSettings().getOpSys(), OperatingSystem.UNIX);
    assertEquals(oeSettings.getProparseSessions().getDefaultSession().getProparseSettings().getProcessArchitecture(), Integer.valueOf(32));
    assertEquals(oeSettings.getProparseSessions().getDefaultSession().getProparseSettings().getProversion(), "12.0");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) OpenEdgeSettings(org.sonar.plugins.openedge.foundation.OpenEdgeSettings) Test(org.testng.annotations.Test) OpenEdgePluginTest(org.sonar.plugins.openedge.OpenEdgePluginTest)

Example 100 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-openedge by Riverside-Software.

the class OpenEdgeProparseSensorTest method testProparseErrorSonarLint.

@Test
public void testProparseErrorSonarLint() throws Exception {
    SensorContextTester context = TestProjectSensorContext.createContext();
    context.setRuntime(OpenEdgePluginTest.SONARLINT_RUNTIME);
    OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARLINT_RUNTIME, OpenEdgePluginTest.SERVER);
    OpenEdgeComponents components = new OpenEdgeComponents(OpenEdgePluginTest.SERVER, null, null);
    OpenEdgeProparseSensor sensor = new OpenEdgeProparseSensor(oeSettings, components);
    sensor.execute(context);
    assertEquals(context.allIssues().size(), 0);
    assertEquals(context.allAnalysisErrors().size(), 1);
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) OpenEdgeComponents(org.sonar.plugins.openedge.foundation.OpenEdgeComponents) OpenEdgeSettings(org.sonar.plugins.openedge.foundation.OpenEdgeSettings) Test(org.testng.annotations.Test) OpenEdgePluginTest(org.sonar.plugins.openedge.OpenEdgePluginTest)

Aggregations

SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)224 File (java.io.File)96 Test (org.junit.jupiter.api.Test)94 InputFile (org.sonar.api.batch.fs.InputFile)75 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)63 MapSettings (org.sonar.api.config.internal.MapSettings)60 Test (org.junit.Test)59 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)49 Test (org.testng.annotations.Test)42 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)40 OpenEdgePluginTest (org.sonar.plugins.openedge.OpenEdgePluginTest)37 Path (java.nio.file.Path)35 OpenEdgeSettings (org.sonar.plugins.openedge.foundation.OpenEdgeSettings)30 ClasspathForTest (org.sonar.java.classpath.ClasspathForTest)25 SonarComponents (org.sonar.java.SonarComponents)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 GeneratedFile (org.sonar.java.model.GeneratedFile)18 ArrayList (java.util.ArrayList)15 ExternalIssue (org.sonar.api.batch.sensor.issue.ExternalIssue)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14