@Test public void testConfigWithIgnoreUsingInputSource() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration(new InputSource( new File(getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml")) .toURI().toString()), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); }
@Test public void testLoadConfigurationDeprecated() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( Files.newInputStream(Paths.get( getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"))), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); }
@Test public void testRemoveChild() { final DefaultConfiguration config = new DefaultConfiguration("MyConfig"); final DefaultConfiguration configChild = new DefaultConfiguration("childConfig"); assertEquals("Invalid children count", 0, config.getChildren().length); config.addChild(configChild); assertEquals("Invalid children count", 1, config.getChildren().length); config.removeChild(configChild); assertEquals("Invalid children count", 0, config.getChildren().length); }
@Test public void testCustomMessages() throws Exception { final Properties props = new Properties(); props.setProperty("checkstyle.basedir", "basedir"); final DefaultConfiguration config = (DefaultConfiguration) loadConfiguration( "InputConfigurationLoaderCustomMessages.xml", props); final Configuration[] children = config.getChildren(); final Configuration[] grandchildren = children[0].getChildren(); final String expectedKey = "name.invalidPattern"; assertTrue("Messages should contain key: " + expectedKey, grandchildren[0].getMessages() .containsKey(expectedKey)); }
@Test public void testConfigCheckerWithIgnore() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( getPath("InputConfigurationLoaderCheckerIgnoreSeverity.xml"), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children.length); }
@Test public void testConfigWithIgnore() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); }
@Test public void testLoadConfigurationFromClassPath() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); }
@Test public void testConstructors() throws Exception { final Properties props = new Properties(); props.setProperty("checkstyle.basedir", "basedir"); final String fName = getPath("InputConfigurationLoaderChecks.xml"); final Configuration configuration = ConfigurationLoader.loadConfiguration(fName, new PropertiesExpander(props), ConfigurationLoader.IgnoredModulesOptions.OMIT); assertEquals("Name is not expected", "Checker", configuration.getName()); final DefaultConfiguration configuration1 = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( new InputSource(Files.newInputStream(Paths.get( getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml")))), new PropertiesExpander(new Properties()), ConfigurationLoader.IgnoredModulesOptions.EXECUTE); final Configuration[] children = configuration1.getChildren(); assertEquals("Unexpected children size", 1, children[0].getChildren().length); }
final Configuration[] children = config.getChildren(); atts.clear(); verifyConfigNode(
private static void verifyConfigNode( DefaultConfiguration config, String name, int childrenLength, Properties atts) throws Exception { assertEquals("name.", name, config.getName()); assertEquals( "children.length.", childrenLength, config.getChildren().length); final String[] attNames = config.getAttributeNames(); assertEquals("attributes.length", atts.size(), attNames.length); for (String attName : attNames) { assertEquals( "attribute[" + attName + "]", atts.getProperty(attName), config.getAttribute(attName)); } }
@Test public void testLoadConfigurationWrongUrl() { try { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( ";InputConfigurationLoaderModuleIgnoreSeverity.xml", new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); fail("Exception is expected"); } catch (CheckstyleException ex) { assertEquals("Invalid exception message", "Unable to find: ;InputConfigurationLoaderModuleIgnoreSeverity.xml", ex.getMessage()); } }
@Test public void testModuleNameInSingleThreadMode() throws Exception { TestRootModuleChecker.reset(); exit.checkAssertionAfterwards(() -> { assertEquals("Unexpected output log", "", systemOut.getLog()); assertEquals("Unexpected system error log", "", systemErr.getLog()); assertTrue("Invalid checker state", TestRootModuleChecker.isProcessed()); final DefaultConfiguration config = (DefaultConfiguration) TestRootModuleChecker.getConfig(); final ThreadModeSettings multiThreadModeSettings = config.getThreadModeSettings(); assertEquals("Invalid checker thread number", 1, multiThreadModeSettings.getCheckerThreadsNumber()); assertEquals("Invalid checker thread number", 1, multiThreadModeSettings.getTreeWalkerThreadsNumber()); final Configuration checkerConfiguration = config .getChildren()[0]; assertEquals("Invalid checker name", "Checker", checkerConfiguration.getName()); final Configuration treeWalkerConfig = checkerConfiguration.getChildren()[0]; assertEquals("Invalid checker children name", "TreeWalker", treeWalkerConfig.getName()); }); Main.main("-C", "1", "-W", "1", "-c", getPath("InputMainConfig-multi-thread-mode.xml"), getPath("InputMain.java")); }