org.sonar.api.batch.sensor.internal.SensorContextTester Java Examples
The following examples show how to use
org.sonar.api.batch.sensor.internal.SensorContextTester.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClojureSensorTest.java From sonar-clojure with MIT License | 6 votes |
private SensorContextTester prepareContext() { DefaultFileSystem fileSystem = new DefaultFileSystem(temporaryFolder.getRoot()); SensorContextTester context = SensorContextTester.create(temporaryFolder.getRoot()); context.setFileSystem(fileSystem); DefaultInputFile inputFile1 = TestInputFileBuilder.create("module", "foo.clj") .setLanguage(Clojure.KEY) .initMetadata("firstLine\nsecondLine") .build(); DefaultInputFile inputFile2 = TestInputFileBuilder.create("module", "bar.clj") .setLanguage(Clojure.KEY) .initMetadata("firstLine\nsecondLine\nthirdLine") .build(); context.fileSystem().add(inputFile1).add(inputFile2); return context; }
Example #2
Source File: SimpleCovSensorTest.java From sonar-ruby-plugin with MIT License | 6 votes |
@Before public void setUp() throws URISyntaxException { URL filePath = SimpleCovSensorTest.class.getClassLoader().getResource("./test_controller.rb"); rubyFile = new File(filePath.toURI()); context = SensorContextTester.create(rubyFile.getParentFile()); context.settings().setProperty(RubyPlugin.TEST_FRAMEWORK, "RSpec"); context.fileSystem().add(new DefaultInputFile("myProjectKey", "test_controller.rb") .setLanguage("rb") .setLines(15)); context.fileSystem().add(new DefaultInputFile("myProjectKey", "unknown_file.rb") .setLanguage("rb") .setLines(10)); TestUtils.buildResultSetFile(rubyFile); }
Example #3
Source File: PathResolverTest.java From sonar-ruby-plugin with MIT License | 6 votes |
@Before public void setUp() throws Exception { URL filePath = PathResolverTest.class.getClassLoader().getResource("./test_controller.rb"); existingFile = new File(filePath.toURI()); String parentPath = existingFile.getParent(); this.sensorContext = SensorContextTester.create(new File(parentPath)); this.sensorContext.settings().setProperty("path key", "test_controller.rb"); DefaultInputFile file = new DefaultInputFile("", "test_controller.rb") .setLanguage(Ruby.LANGUAGE_KEY); this.sensorContext.fileSystem().add(file); this.resolver = new PathResolver(); }
Example #4
Source File: RubocopSensorTest.java From sonar-ruby-plugin with MIT License | 6 votes |
@Before public void setUp() throws URISyntaxException { MockitoAnnotations.initMocks(this); URL filePath = RubocopSensorTest.class.getClassLoader().getResource("./test_controller.rb"); rubyFile = new File(filePath.toURI()); context = SensorContextTester.create(rubyFile.getParentFile()); context.fileSystem().add(new DefaultInputFile("myProjectKey", "test_controller.rb") .setLanguage("rb") .setOriginalLineOffsets(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}) .setLines(15)); context.fileSystem().add(new DefaultInputFile("myProjectKey", "unknown_file.rb") .setLanguage("rb") .setOriginalLineOffsets(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) .setLines(10)); }
Example #5
Source File: CpdVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("css") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); cpdVisitor = new CpdVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #6
Source File: ScssMetricsVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void setUp(String fileName) { File moduleBaseDir = new File("src/test/resources/metrics/"); context = SensorContextTester.create(moduleBaseDir); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName) .setModuleBaseDir(moduleBaseDir.toPath()) .setLanguage("scss") .setType(InputFile.Type.MAIN); context.fileSystem().add(inputFile); context.fileSystem().setEncoding(Charsets.UTF_8); ScssMetricsVisitor metricsVisitor = new ScssMetricsVisitor(context, mock(NoSonarFilter.class)); TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class); when(treeVisitorContext.getFile()).thenReturn(inputFile.file()); when(treeVisitorContext.getTopTree()).thenReturn(ScssParser.createParser(Charsets.UTF_8).parse(inputFile.file())); metricsVisitor.scanTree(treeVisitorContext); }
Example #7
Source File: LessMetricsVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void setUp(String fileName) { File moduleBaseDir = new File("src/test/resources/metrics/"); context = SensorContextTester.create(moduleBaseDir); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName) .setModuleBaseDir(moduleBaseDir.toPath()) .setLanguage("less") .setType(InputFile.Type.MAIN); context.fileSystem().add(inputFile); context.fileSystem().setEncoding(Charsets.UTF_8); LessMetricsVisitor metricsVisitor = new LessMetricsVisitor(context, mock(NoSonarFilter.class)); TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class); when(treeVisitorContext.getFile()).thenReturn(inputFile.file()); when(treeVisitorContext.getTopTree()).thenReturn(LessParser.createParser(Charsets.UTF_8).parse(inputFile.file())); metricsVisitor.scanTree(treeVisitorContext); }
Example #8
Source File: CssMetricsVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
private void setUp(String fileName) { File moduleBaseDir = new File("src/test/resources/metrics/"); context = SensorContextTester.create(moduleBaseDir); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName) .setModuleBaseDir(moduleBaseDir.toPath()) .setLanguage("css") .setType(InputFile.Type.MAIN); context.fileSystem().add(inputFile); context.fileSystem().setEncoding(Charsets.UTF_8); CssMetricsVisitor metricsVisitor = new CssMetricsVisitor(context, mock(NoSonarFilter.class)); TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class); when(treeVisitorContext.getFile()).thenReturn(inputFile.file()); when(treeVisitorContext.getTopTree()).thenReturn(CssParser.createParser(Charsets.UTF_8).parse(inputFile.file())); metricsVisitor.scanTree(treeVisitorContext); }
Example #9
Source File: CssSyntaxHighlighterVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("css") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); highlighterVisitor = new CssSyntaxHighlighterVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #10
Source File: ScssSyntaxHighlighterVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("scss") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); highlighterVisitor = new ScssSyntaxHighlighterVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #11
Source File: LessSyntaxHighlighterVisitorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("less") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); highlighterVisitor = new LessSyntaxHighlighterVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #12
Source File: AnsibleSensorTest.java From sonar-ansible with Apache License 2.0 | 6 votes |
@Before public void init() throws Exception { Path baseDir = Paths.get("src/test/resources"); context = SensorContextTester.create(baseDir); DefaultFileSystem fs = new DefaultFileSystem(baseDir); fs.setWorkDir(temporaryFolder.newFolder("temp").toPath()); context.setFileSystem(fs); ActiveRules activeRules = new ActiveRulesBuilder() .create(ruleKey1) .activate() .create(ruleKey2) .activate() .create(ruleKey3) .activate() .build(); context.setActiveRules(activeRules); FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); sensor = new AnsibleSensor(fs); }
Example #13
Source File: CloverageSensorTest.java From sonar-clojure with MIT License | 6 votes |
@Test public void shouldExecuteCloverage() throws IOException { SensorContextTester context = prepareContext(); cloverageSensor.execute(context); String fooKey = MODULE_KEY + ":" + FOO_PATH; assertThat(context.lineHits(fooKey, 1), is(1)); assertThat(context.lineHits(fooKey, 3), is(1)); assertThat(context.lineHits(fooKey, 5), is(0)); assertThat(context.lineHits(fooKey, 6), is(1)); String barKey = MODULE_KEY + ":" + BAR_PATH; assertThat(context.lineHits(barKey, 1), is(1)); assertThat(logTester.logs(), hasItems("Running Cloverage")); verify(commandRunner).run(300L, "lein", "cloverage", "--codecov"); }
Example #14
Source File: AbstractAnsibleSensorNoRuleTest.java From sonar-ansible with Apache License 2.0 | 6 votes |
@Test public void testNoActiveRule() throws IOException { SensorContextTester context = Utils.getSensorContext(); DefaultFileSystem fs = Utils.getFileSystem(); fs.setWorkDir(temporaryFolder.newFolder("temp").toPath()); context.setFileSystem(fs); FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); InputFile playbook1 = Utils.getInputFile("playbooks/playbook1.yml"); InputFile playbook2 = Utils.getInputFile("playbooks/playbook2.yml"); InputFile playbook3 = Utils.getInputFile("playbooks/playbook3.yml"); context.fileSystem().add(playbook1).add(playbook2).add(playbook3); MySensor sensor = new MySensor(fs); sensor.executeWithAnsibleLint(context, null); assertEquals(1, logTester.logs(LoggerLevel.INFO).size()); assertEquals("No active rules found for this plugin, skipping.", logTester.logs(LoggerLevel.INFO).get(0)); assertEquals(0, context.allIssues().size()); }
Example #15
Source File: SyntaxHighlighterVisitorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot()); fileSystem.setEncoding(Charsets.UTF_8); file = tempFolder.newFile(); inputFile = new DefaultInputFile("moduleKey", file.getName()) .setLanguage("gherkin") .setType(InputFile.Type.MAIN); fileSystem.add(inputFile); sensorContext = SensorContextTester.create(tempFolder.getRoot()); sensorContext.setFileSystem(fileSystem); visitorContext = mock(TreeVisitorContext.class); highlighterVisitor = new SyntaxHighlighterVisitor(sensorContext); when(visitorContext.getFile()).thenReturn(file); }
Example #16
Source File: KibitSensorTest.java From sonar-clojure with MIT License | 6 votes |
@Test public void shouldExecuteKibit() throws IOException { SensorContextTester context = prepareContext(); CommandStreamConsumer stdOut = new CommandStreamConsumer(); stdOut.consumeLine("----"); stdOut.consumeLine("At kibit.clj:5:"); stdOut.consumeLine("Kibit will say that there is pos? function available"); when(commandRunner.run(300L, "lein", "kibit")).thenReturn(stdOut); kibitSensor.execute(context); List<Issue> issuesList = new ArrayList<>(context.allIssues()); assertThat(issuesList.size(), is(1)); assertThat(issuesList.get(0).ruleKey().rule(), is("kibit")); }
Example #17
Source File: LeinNvdSensorTest.java From sonar-clojure with MIT License | 6 votes |
private SensorContextTester prepareContext() throws IOException { SensorContextTester context = SensorContextTester.create(new File("/")); context.settings().appendProperty(NvdProperties.REPORT_LOCATION_PROPERTY, "src/test/resources/nvd-report.json"); File baseDir = new File("src/test/resources/"); File project = new File(baseDir, "project.clj"); DefaultInputFile projectFile = TestInputFileBuilder.create("", "project.clj") .setLanguage(Clojure.KEY) .initMetadata(new String(Files.readAllBytes(project.toPath()), StandardCharsets.UTF_8)) .setContents(new String(Files.readAllBytes(project.toPath()), StandardCharsets.UTF_8)) .build(); context.fileSystem().add(projectFile); return context; }
Example #18
Source File: LeinNvdSensorTest.java From sonar-clojure with MIT License | 6 votes |
@Test public void shouldExecuteLeinNvd() throws IOException { SensorContextTester context = prepareContext(); CommandStreamConsumer stdOut = new CommandStreamConsumer(); stdOut.consumeLine("We are not really interested of std out"); leinNvdSensor.execute(context); List<Issue> issuesList = new ArrayList<>(context.allIssues()); assertThat(issuesList.size(), is(2)); assertThat(issuesList.get(0).ruleKey().rule(), is("nvd-high")); assertThat(issuesList.get(0).primaryLocation().message(), is("CVE-2018-5968;CWE-502,CWE-184;jackson-databind-2.9.3.jar")); assertThat(issuesList.get(1).ruleKey().rule(), is("nvd-critical")); assertThat(issuesList.get(1).primaryLocation().message(), is("CVE-2018-19362;CWE-502;jackson-databind-2.9.3.jar")); }
Example #19
Source File: CoverageSensorTest.java From sonar-tsql-plugin with GNU General Public License v3.0 | 6 votes |
@Test public void test() throws Throwable { TemporaryFolder folder = new TemporaryFolder(); folder.create(); SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); String tempName = "GetStatusMessage.sql"; String covReport = "test.xml"; File f = folder.newFile(tempName); File coverage = folder.newFile(covReport); FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/coverage/Coverage.opencoverxml"), coverage); FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/coverage/TestCode.sql"), f); DefaultInputFile file1 = new TestInputFileBuilder(folder.getRoot().getAbsolutePath(), tempName) .initMetadata(new String(Files.readAllBytes(f.toPath()))).setLanguage(TSQLLanguage.KEY).build(); ctxTester.fileSystem().add(file1); ctxTester.settings().setProperty(Constants.COVERAGE_FILE, coverage.getAbsolutePath()); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_COVERAGE, false); CoverageSensor sut = new CoverageSensor(new SqlCoverCoverageProvider(ctxTester.settings(), ctxTester.fileSystem())); sut.execute(ctxTester); Assert.assertEquals((int) 2, (int) ctxTester.lineHits(file1.key(), 7)); }
Example #20
Source File: AncientSensorTest.java From sonar-clojure with MIT License | 6 votes |
@Test public void shouldExecuteAncient() throws IOException { SensorContextTester context = prepareContext(); CommandStreamConsumer stdOut = new CommandStreamConsumer(); stdOut.consumeLine("This is some non related line which should not end to report"); stdOut.consumeLine("[metosin/reitit \"0.2.10\"] is available but we use \"0.2.1\""); stdOut.consumeLine("[metosin/ring-http-response \"0.9.1\"] is available but we use \"0.9.0\""); when(commandRunner.run(any(), eq("lein"), eq("ancient"))).thenReturn(stdOut); ancientSensor.execute(context); List<Issue> issuesList = new ArrayList<>(context.allIssues()); assertThat(issuesList.size(), is(2)); assertThat(issuesList.get(0).ruleKey().rule(), is("ancient-clj-dependency")); assertThat(issuesList.get(0).primaryLocation().message(), is("metosin/reitit is using version: 0.2.1 but version: 0.2.10 is available.")); assertThat(issuesList.get(1).ruleKey().rule(), is("ancient-clj-dependency")); assertThat(issuesList.get(1).primaryLocation().message(), is("metosin/ring-http-response is using version: 0.9.0 but version: 0.9.1 is available.")); }
Example #21
Source File: TraceSensorTest.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
@Before public void init() throws FileNotFoundException { settings = new MapSettings(); settings.setProperty("sonar.esql.trace.reportPaths", "TraceSensorTest/trace.txt"); context = SensorContextTester.create(moduleBaseDir); context.setSettings(settings); InputFile inputFile1 = inputFile("file1.esql", Type.MAIN); InputFile inputFile2 = inputFile("file2.esql", Type.MAIN); InputFile inputFile3 = inputFile("file3.esql", Type.MAIN); // inputFile("tests/file1.esql", Type.TEST); linesOfCode = new HashMap<>(); linesOfCode.put(inputFile1, ImmutableSet.of(1, 2, 3, 4)); linesOfCode.put(inputFile2, null); linesOfCode.put(inputFile3, ImmutableSet.of(1, 2, 3, 4)); sensor = new TraceSensor(); }
Example #22
Source File: EastwoodSensorTest.java From sonar-clojure with MIT License | 6 votes |
@Test public void shouldExecuteEastwood() throws IOException { SensorContextTester context = prepareContext(); CommandStreamConsumer stdOut = new CommandStreamConsumer(); stdOut.consumeLine("file.clj:1:0:issue-1:description-1"); stdOut.consumeLine("file.clj:2:0:issue-2:description-2"); String options = "eastwood-option"; when(commandRunner.run(300L, "lein", "eastwood", options)) .thenReturn(stdOut); eastwoodSensor.execute(context); List<Issue> issuesList = new ArrayList<>(context.allIssues()); assertThat(issuesList.size(), is(2)); assertThat(issuesList.get(0).ruleKey().rule(), is("issue-1")); assertThat(issuesList.get(0).primaryLocation().message(), is("description-1")); assertThat(issuesList.get(1).ruleKey().rule(), is("issue-2")); assertThat(issuesList.get(1).primaryLocation().message(), is("description-2")); }
Example #23
Source File: TsCoverageSensorImplTest.java From SonarTsPlugin with MIT License | 6 votes |
@Before public void setUp() throws Exception { this.file = new DefaultInputFile("", "src/test/existing.ts").setLanguage(TypeScriptLanguage.LANGUAGE_KEY); this.file.setLines(5); this.settings = mock(Settings.class); when(this.settings.getString(TypeScriptPlugin.SETTING_LCOV_REPORT_PATH)).thenReturn("lcovpath"); this.parser = mock(LCOVParser.class); this.sensor = spy(new TsCoverageSensorImpl()); this.context = SensorContextTester.create(new File("")); this.context.fileSystem().add(this.file); this.context.setSettings(this.settings); this.lcovFile = mock(File.class); when(this.lcovFile.isFile()).thenReturn(true); doReturn(this.lcovFile).when(this.sensor).getIOFile(any(File.class), eq("lcovpath")); doReturn(this.parser).when(this.sensor).getParser(eq(this.context), any(File[].class)); }
Example #24
Source File: PathResolverImplTest.java From SonarTsPlugin with MIT License | 6 votes |
@Before public void setUp() throws Exception { URL filePath = PathResolverImplTest.class.getClassLoader().getResource("./existing.ts"); existingFile = new File(filePath.toURI()); String parentPath = existingFile.getParent(); this.sensorContext = SensorContextTester.create(new File(parentPath)); this.sensorContext.settings().setProperty("path key", "existing.ts"); DefaultInputFile file = new DefaultInputFile("", "existing.ts") .setLanguage(TypeScriptLanguage.LANGUAGE_KEY); this.sensorContext.fileSystem().add(file); this.resolver = new PathResolverImpl(); }
Example #25
Source File: BaseTsqlSensorTest.java From sonar-tsql-plugin with GNU General Public License v3.0 | 5 votes |
public void testSkipPlugin() throws Throwable { SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); File baseFile = folder.newFile("test.sql"); FileUtils.copyURLToFile(getClass().getResource("/testFiles/TestTable.sql"), baseFile); InputFile ti = new TestInputFileBuilder("test", "test.sql") .initMetadata(new String(Files.readAllBytes(baseFile.toPath()))).build(); ctxTester.fileSystem().add(ti); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP, true); final TsqlIssue issue = new TsqlIssue(); issue.setFilePath(ti.absolutePath()); issue.setLine(1); issue.setType("test"); IIssuesProvider provider = new IIssuesProvider() { @Override public TsqlIssue[] getIssues(String baseDir) { return new TsqlIssue[] { issue }; } }; BaseTsqlExternalSensor sensor = new BaseTsqlExternalSensor(provider, "test", "test"); sensor.execute(ctxTester); Assert.assertEquals(0, ctxTester.allIssues().size()); }
Example #26
Source File: CustomChecksSensorTest.java From sonar-tsql-plugin with GNU General Public License v3.0 | 5 votes |
@Test public void testTSQLGrammarFiles() throws IOException { TemporaryFolder folder = new TemporaryFolder(); folder.create(); SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP, false); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM_RULES, false); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM, false); ctxTester.settings().setProperty(Constants.PLUGIN_MAX_FILE_SIZE, 100); String dirPath = "..\\grammars\\tsql"; File dir = new File(dirPath); Collection<File> files = FileUtils.listFiles(dir, new String[] { "sql" }, true); for (File f : files) { String tempName = f.getName() + System.nanoTime(); File dest = folder.newFile(tempName); FileUtils.copyFile(f, dest); DefaultInputFile file1 = new TestInputFileBuilder(folder.getRoot().getAbsolutePath(), tempName) .initMetadata(new String(Files.readAllBytes(f.toPath()))).setLanguage(TSQLLanguage.KEY).build(); ctxTester.fileSystem().add(file1); } CustomChecksSensor sensor = new CustomChecksSensor(); sensor.execute(ctxTester); Collection<Issue> issues = ctxTester.allIssues(); Assert.assertEquals(183, issues.size()); }
Example #27
Source File: CustomChecksSensorTest.java From sonar-tsql-plugin with GNU General Public License v3.0 | 5 votes |
@Test public void testSingleFile() throws IOException { TemporaryFolder folder = new TemporaryFolder(); folder.create(); SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP, false); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM_RULES, false); ctxTester.settings().setProperty(Constants.PLUGIN_SKIP_CUSTOM, false); ctxTester.settings().setProperty(Constants.PLUGIN_MAX_FILE_SIZE, 100); String tempName = "test.sql"; File f = folder.newFile(tempName); FileUtils.write(f, "select * from dbo.test;\r\n--test", Charset.defaultCharset()); DefaultInputFile file1 = new TestInputFileBuilder(folder.getRoot().getAbsolutePath(), tempName) .initMetadata(new String(Files.readAllBytes(f.toPath()))).setLanguage(TSQLLanguage.KEY).build(); ctxTester.fileSystem().add(file1); CustomChecksSensor sensor = new CustomChecksSensor(); sensor.execute(ctxTester); Collection<Issue> issues = ctxTester.allIssues(); for (Issue i : issues) { System.out.println(i.ruleKey() + " " + i.primaryLocation()); } Assert.assertEquals(1, issues.size()); Assert.assertEquals(2, ctxTester.cpdTokens(file1.key()).size()); Assert.assertEquals(1, ctxTester.highlightingTypeAt(file1.key(), 2, 1).size()); Assert.assertEquals(4, ctxTester.measures(file1.key()).size()); }
Example #28
Source File: HtlSensorTest.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Before public void setUp() { RulesDefinition rulesDefinition = new AemRulesRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); RulesDefinition.Repository htlRepository = context.repository(HtlCheckClasses.REPOSITORY_KEY); FileLinesContextFactory fileLinesContextFactory = getMockedFileLinesContextFactory(); Configuration configuration = getMockedConfiguration(); CheckFactory checkFactory = getCheckFactory(htlRepository); sensor = new HtlSensor(fileLinesContextFactory, configuration, checkFactory); tester = SensorContextTester.create(TEST_DIR); }
Example #29
Source File: SimpleCovParserTest.java From sonar-ruby-plugin with MIT License | 5 votes |
@Before public void setUp() throws URISyntaxException { URL filePath = SimpleCovParserTest.class.getClassLoader().getResource("./test_controller.rb"); rubyFile = new File(filePath.toURI()); context = SensorContextTester.create(rubyFile.getParentFile()); context.settings().setProperty(RubyPlugin.TEST_FRAMEWORK, "RSpec"); context.fileSystem().add(new DefaultInputFile("myProjectKey", "test_controller.rb") .setLanguage("rb") .setLines(15)); TestUtils.buildResultSetFile(rubyFile); }
Example #30
Source File: LuaSquidSensorTest.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void setUp() throws Exception { NewActiveRule ar = new ActiveRulesBuilder().create(RuleKey.of("lua", "S1125")).setSeverity("BLOCKER"); ActiveRules activeRules = new DefaultActiveRules(Collections.singletonList(ar)); CheckFactory checkFactory = new CheckFactory(activeRules); FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); sensor = new LuaSquidSensor(checkFactory, fileLinesContextFactory); tester = SensorContextTester.create(TEST_DIR); }