List of usage examples for org.apache.commons.configuration Configuration getStringArray
String[] getStringArray(String key);
From source file:org.sonar.plugins.php.codesniffer.PhpCodesnifferExecutorTest.java
/** * Test method for {@link org.sonar.plugins.php.codesniffer.PhpCodeSnifferExecutor#getCommandLine()}. *///from w w w. j a v a 2 s . c o m @Test public void testGetCommandLine2() { Configuration configuration = mock(Configuration.class); String[] suffixes = new String[] { "php", "php2" }; when(configuration.getStringArray(FILE_SUFFIXES_KEY)).thenReturn(suffixes); PhpCodeSnifferConfiguration c = mock(PhpCodeSnifferConfiguration.class); Project p = mock(Project.class); when(p.getConfiguration()).thenReturn(configuration); when(c.getProject()).thenReturn(p); when(c.getRuleSet()).thenReturn(new File("C:\\projets\\PHP\\Monkey\\target\\logs\\php")); RulesProfile profile = mock(RulesProfile.class); PhpCodeSnifferProfileExporter e = mock(PhpCodeSnifferProfileExporter.class); PhpCodeSnifferExecutor executor = new PhpCodeSnifferExecutor(c, e, profile); List<String> commandLine = executor.getCommandLine(); String expected = "--extensions=php,php2"; assertThat(commandLine).contains(expected); }
From source file:org.sonar.plugins.php.codesniffer.PhpCodesnifferExecutorTest.java
/** * Test method for {@link org.sonar.plugins.php.codesniffer.PhpCodeSnifferExecutor#getCommandLine()}. *//*from w w w . j a v a2 s. c o m*/ @Test public void testGetCommandLine3() { Configuration configuration = mock(Configuration.class); String[] suffixes = new String[] { "php", "php2" }; when(configuration.getStringArray(FILE_SUFFIXES_KEY)).thenReturn(suffixes); PhpCodeSnifferConfiguration c = mock(PhpCodeSnifferConfiguration.class); Project p = mock(Project.class); when(p.getConfiguration()).thenReturn(configuration); when(c.getProject()).thenReturn(p); when(c.getRuleSet()).thenReturn(new File("C:\\projets\\PHP\\Monkey\\target\\logs\\php")); String modifierKey = PHPCS_SEVERITY_OR_LEVEL_MODIFIER_KEY; when(configuration.getString(modifierKey, PHPCS_SEVERITY_OR_LEVEL_MODIFIER)) .thenReturn(PHPCS_SEVERITY_OR_LEVEL_MODIFIER); when(c.isStringPropertySet(PhpCodeSnifferConfiguration.PHPCS_SEVERITY_KEY)).thenReturn(true); String severityModifier = "--level="; String level = "--level="; when(c.getSeverityModifier()).thenReturn(severityModifier); when(c.getLevel()).thenReturn(level); RulesProfile profile = mock(RulesProfile.class); PhpCodeSnifferProfileExporter e = mock(PhpCodeSnifferProfileExporter.class); PhpCodeSnifferExecutor executor = new PhpCodeSnifferExecutor(c, e, profile); List<String> commandLine = executor.getCommandLine(); String expected = "--extensions=php,php2"; assertThat(commandLine).contains(expected); assertThat(commandLine).contains(severityModifier + level); }
From source file:org.sonar.plugins.php.codesniffer.sensor.PhpCodesnifferViolationsXmlParserTest.java
/** * Parses the./*from w w w . j av a 2 s. co m*/ * * @param context * the context * @param xmlPath * the xml path * * @throws IOException * Signals that an I/O exception has occurred. * @throws URISyntaxException * the URI syntax exception * @throws XMLStreamException * the XML stream exception */ private void parse(SensorContext context, String xmlPath) throws IOException, URISyntaxException, XMLStreamException { DefaultProjectFileSystem fileSystem = mock(DefaultProjectFileSystem.class); when(fileSystem.getSourceDirs()).thenReturn(Arrays.asList(new File("/test/src/main/"))); Project project = mock(Project.class); when(project.getFileSystem()).thenReturn(fileSystem); RulesManager manager = mock(RulesManager.class); when(manager.getPluginRule(anyString(), anyString())).thenAnswer(new Answer<Rule>() { public Rule answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); return new Rule((String) args[1], (String) args[1], null, (String) args[0], ""); } }); Configuration configuration = mock(Configuration.class); Php php = new Php(configuration); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); RulesProfile profile = mock(RulesProfile.class); when(profile.getActiveRule(anyString(), anyString())) .thenReturn(new ActiveRule(null, null, RulePriority.MINOR)); PhpCheckStyleViolationsXmlParser parser = new PhpCheckStyleViolationsXmlParser(project, context, manager); File xmlFile = new File(getClass().getResource(xmlPath).toURI()); parser.parse(xmlFile); }
From source file:org.sonar.plugins.php.core.PhpFileTest.java
/** * Inits the./*from w ww. j av a 2 s . com*/ */ private void init() { project = mock(Project.class); ProjectFileSystem fileSystem = mock(ProjectFileSystem.class); Configuration configuration = mock(Configuration.class); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); when(project.getFileSystem()).thenReturn(fileSystem); when(fileSystem.getSourceDirs()).thenReturn(Arrays.asList(new File("C:/projets/PHP/Monkey/src/main"))); when(fileSystem.getTestDirs()).thenReturn(Arrays.asList(new File("C:/projets/PHP/Monkey/src/test"))); File f1 = new File("C:/projets/PHP/Monkey/src/main/insult/Monkey.php"); File f2 = new File("C:/projets/PHP/Monkey/src/main/animal/Monkey.php"); File f3 = new File("C:/projets/PHP/Monkey/src/main/Monkey.php"); File f4 = new File("C:/projets/PHP/Monkey/src/test/animal/Monkey.php"); File f5 = new File("C:/projets/PHP/Monkey/src/test/animal/Monkey.php"); when(fileSystem.getSourceFiles(Php.PHP)).thenReturn(Arrays.asList(f1, f2, f3)); when(fileSystem.getTestFiles(Php.PHP)).thenReturn(Arrays.asList(f4, f5)); }
From source file:org.sonar.plugins.php.core.PhpSourceImporterTest.java
@Before public void init() throws Exception { tempFolder.create();//from w w w .j a v a 2s. com sources = tempFolder.newFolder("sources"); tests = tempFolder.newFolder("tests"); testsBelowSources = tempFolder.newFolder("sources/tests"); Configuration configuration = mock(Configuration.class); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); when(configuration.getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY, CoreProperties.CORE_IMPORT_SOURCES_DEFAULT_VALUE)).thenReturn(true); context = mock(SensorContext.class); project = mock(Project.class); when(project.getPom()).thenReturn(new MavenProject()); when(project.getConfiguration()).thenReturn(configuration); DefaultProjectFileSystem fileSystem = new DefaultProjectFileSystem(project, new Languages(Php.PHP)); fileSystem.addSourceDir(sources); fileSystem.addTestDir(tests); fileSystem.addTestDir(testsBelowSources); when(project.getFileSystem()).thenReturn(fileSystem); }
From source file:org.sonar.plugins.php.cpd.PhpCpdExecutorTest.java
/** * Test method for {@link org.sonar.plugins.php.codesniffer.PhpCpdExecutor#getPhpcpdCommandLine()} . *//*from www . j ava 2s .c o m*/ @Test public void testGetCommandLine() { Configuration configuration = mock(Configuration.class); when(configuration.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY)).thenReturn(null); PhpCpdConfiguration c = mock(PhpCpdConfiguration.class); when(c.getMinimunNumberOfIdenticalLines()).thenReturn(PHPCPD_DEFAULT_MINIMUM_NUMBER_OF_IDENTICAL_LINES); when(c.getMinimunNumberOfIdenticalTokens()).thenReturn(PHPCPD_DEFAULT_MINIMUM_NUMBER_OF_IDENTICAL_TOKENS); String excludedPackages = "test/*"; when(c.getExcludePackages()).thenReturn(excludedPackages); when(c.isStringPropertySet(PHPCPD_EXCLUDE_PACKAGE_KEY)).thenReturn(true); String reportFile = "C:\\projets\\PHP\\Monkey\\target\\logs\\php-cpd.xml"; when(c.getReportFile()).thenReturn(new File(reportFile)); when(c.isOsWindows()).thenReturn(false); String phpcpdScriptName = "phpcpd"; when(c.getOsDependentToolScriptName()).thenReturn(phpcpdScriptName); Project p = mock(Project.class); when(p.getConfiguration()).thenReturn(configuration); when(c.getProject()).thenReturn(p); PhpCpdExecutor executor = new PhpCpdExecutor(c); List<String> commandLine = executor.getCommandLine(); List<String> expected = new ArrayList<String>(); expected.add(phpcpdScriptName); expected.add(PHPCPD_MINIMUM_NUMBER_OF_IDENTICAL_LINES_MODIFIER); expected.add(PHPCPD_DEFAULT_MINIMUM_NUMBER_OF_IDENTICAL_LINES.toString()); expected.add(PHPCPD_MINIMUM_NUMBER_OF_IDENTICAL_TOKENS_MODIFIER); expected.add(PHPCPD_DEFAULT_MINIMUM_NUMBER_OF_IDENTICAL_TOKENS.toString()); expected.add("--log-pmd"); expected.add(reportFile); expected.add(PHPCPD_EXCLUDE_OPTION); expected.add(excludedPackages); assertEquals(expected, commandLine); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependConfigurationTest.java
@Test public void testGetReportFileNameKeyIsNull() { Project project = getMockProject();/*from w ww . j a v a 2s . c o m*/ PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); String[] excludeDirs = new String[] { "a", "b" }; when(c.getStringArray(PDEPEND_IGNORE_KEY)).thenReturn(excludeDirs); when(c.getStringArray(PDEPEND_REPORT_FILE_NAME_PROPERTY_KEY)).thenReturn(null); assertEquals("a,b", config.getIgnoreDirs()); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependConfigurationTest.java
@Test public void testGetIgnoreDirsWithNotNull() { Project project = getMockProject();/*from www.j av a 2 s. com*/ PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); String[] excludeDirs = new String[] { "a", "b" }; when(c.getStringArray(PDEPEND_IGNORE_KEY)).thenReturn(excludeDirs); assertEquals("a,b", config.getIgnoreDirs()); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependConfigurationTest.java
@Test public void testGetIgnoreDirsWithEmpty() { Project project = getMockProject();//from w ww. ja va 2 s .c o m PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); String[] excludeDirs = new String[] {}; when(c.getStringArray(PDEPEND_IGNORE_KEY)).thenReturn(excludeDirs); assertThat(config.getIgnoreDirs()).isEqualTo(""); }
From source file:org.sonar.plugins.php.phpdepend.PhpDependConfigurationTest.java
@Test public void testGetExcludePackageWithNull() { Project project = getMockProject();// w w w. j a v a 2 s . c om PhpDependConfiguration config = getWindowsConfiguration(project); Configuration c = project.getConfiguration(); when(c.getStringArray(PDEPEND_EXCLUDE_PACKAGE_KEY)).thenReturn(null); assertEquals(null, config.getExcludePackages()); }