FsCrawlerValidator { public static boolean validateSettings(Logger logger, FsSettings settings, boolean rest) { if (settings.getFs() == null || settings.getFs().getUrl() == null) { logger.warn("`url` is not set. Please define it. Falling back to default: [{}].", Fs.DEFAULT_DIR); if (settings.getFs() == null) { settings.setFs(Fs.DEFAULT); } else { settings.getFs().setUrl(Fs.DEFAULT_DIR); } } if (settings.getElasticsearch() == null) { settings.setElasticsearch(Elasticsearch.DEFAULT()); } if (settings.getElasticsearch().getIndex() == null) { settings.getElasticsearch().setIndex(settings.getName()); } if (settings.getElasticsearch().getIndexFolder() == null) { settings.getElasticsearch().setIndexFolder(settings.getName() + INDEX_SUFFIX_FOLDER); } if (settings.getServer() != null) { if (!Server.PROTOCOL.LOCAL.equals(settings.getServer().getProtocol()) && !Server.PROTOCOL.SSH.equals(settings.getServer().getProtocol())) { logger.error(settings.getServer().getProtocol() + " is not supported yet. Please use " + Server.PROTOCOL.LOCAL + " or " + Server.PROTOCOL.SSH + ". Disabling crawler"); return true; } if (Server.PROTOCOL.SSH.equals(settings.getServer().getProtocol()) && FsCrawlerUtil.isNullOrEmpty(settings.getServer().getUsername())) { logger.error("When using SSH, you need to set a username and probably a password or a pem file. Disabling crawler"); return true; } } if (settings.getFs().getChecksum() != null) { try { MessageDigest.getInstance(settings.getFs().getChecksum()); } catch (NoSuchAlgorithmException e) { logger.error("Algorithm [{}] not found. Disabling crawler", settings.getFs().getChecksum()); return true; } } if (settings.getFs().isJsonSupport() && settings.getFs().isXmlSupport()) { logger.error("Can not support both xml and json parsing. Disabling crawler"); return true; } if ((settings.getFs().isJsonSupport() || settings.getFs().isXmlSupport()) && !settings.getFs().isIndexContent()) { logger.error("Json or Xml indexation is activated but you disabled indexing content which does not make sense. Disabling crawler"); return true; } if (OsValidator.WINDOWS && settings.getFs().isAttributesSupport()) { logger.info("attributes_support is set to true but getting group is not available on [{}].", OsValidator.OS); } if (rest && settings.getRest() == null) { logger.warn("`rest` settings are not defined. Falling back to default: [{}].", Rest.URL_DEFAULT); settings.setRest(Rest.DEFAULT); } return false; }  static boolean validateSettings(Logger logger, FsSettings settings, boolean rest);  }
@Test public void testSettingsValidation() { FsSettings settings = buildSettings(Fs.builder().build(), null, null, null); assertThat(settings.getFs().getUrl(), nullValue()); assertThat(FsCrawlerValidator.validateSettings(logger, settings, false), is(false)); assertThat(settings.getFs().getUrl(), is(Fs.DEFAULT_DIR)); assertThat(settings.getElasticsearch().getNodes(), hasItem(Elasticsearch.NODE_DEFAULT)); assertThat(settings.getElasticsearch().getIndex(), is(getCurrentTestName())); assertThat(settings.getElasticsearch().getIndexFolder(), is(getCurrentTestName() + INDEX_SUFFIX_FOLDER)); assertThat(settings.getServer(), nullValue()); assertThat(settings.getRest(), nullValue()); settings = buildSettings(null, null, null, null); assertThat(settings.getFs().getUrl(), is(Fs.DEFAULT_DIR)); assertThat(FsCrawlerValidator.validateSettings(logger, settings, false), is(false)); assertThat(settings.getElasticsearch().getNodes(), hasItem(Elasticsearch.NODE_DEFAULT)); assertThat(settings.getElasticsearch().getIndex(), is(getCurrentTestName())); assertThat(settings.getElasticsearch().getIndexFolder(), is(getCurrentTestName() + INDEX_SUFFIX_FOLDER)); assertThat(settings.getServer(), nullValue()); assertThat(settings.getRest(), nullValue()); settings = buildSettings(Fs.builder().setChecksum("FSCRAWLER").build(), null, null, null); assertThat(FsCrawlerValidator.validateSettings(logger, settings, false), is(true)); settings = buildSettings(null, null, Server.builder().setProtocol("FSCRAWLER").build(), null); assertThat(FsCrawlerValidator.validateSettings(logger, settings, false), is(true)); settings = buildSettings(null, null, Server.builder().setProtocol(Server.PROTOCOL.SSH).build(), null); assertThat(FsCrawlerValidator.validateSettings(logger, settings, false), is(true)); settings = buildSettings(Fs.builder().setJsonSupport(true).setXmlSupport(true).build(), null, null, null); assertThat(FsCrawlerValidator.validateSettings(logger, settings, false), is(true)); settings = buildSettings(Fs.builder().setIndexContent(false).setXmlSupport(true).build(), null, null, null); assertThat(FsCrawlerValidator.validateSettings(logger, settings, false), is(true)); settings = buildSettings(Fs.builder().setIndexContent(false).setJsonSupport(true).build(), null, null, null); assertThat(FsCrawlerValidator.validateSettings(logger, settings, false), is(true)); settings = buildSettings(null, null, null, null); assertThat(FsCrawlerValidator.validateSettings(logger, settings, true), is(false)); assertThat(settings.getRest(), notNullValue()); }