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;
}
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);
}
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);
}
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");
}
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);
}
Aggregations