ElasticsearchStoreFactory implements SailFactory { @Override public Sail getSail(SailImplConfig sailImplConfig) throws SailConfigException { if (!SAIL_TYPE.equals(sailImplConfig.getType())) { throw new SailConfigException("Invalid Sail type: " + sailImplConfig.getType()); } if (sailImplConfig instanceof ElasticsearchStoreConfig) { ElasticsearchStoreConfig config = (ElasticsearchStoreConfig) sailImplConfig; config.assertRequiredValuesPresent(); ElasticsearchStore elasticsearchStore = new ElasticsearchStore(config.getHostname(), config.getPort(), config.getClusterName(), config.getIndex()); EvaluationStrategyFactory evalStratFactory = config.getEvaluationStrategyFactory(); if (evalStratFactory != null) { elasticsearchStore.setEvaluationStrategyFactory(evalStratFactory); } return elasticsearchStore; } return null; }  @Override String getSailType(); @Override SailImplConfig getConfig(); @Override Sail getSail(SailImplConfig sailImplConfig); static final String SAIL_TYPE; }
@Test(expected = SailConfigException.class) public void getSailWithDefaultConfigFails() { ElasticsearchStoreConfig config = new ElasticsearchStoreConfig(); ElasticsearchStore sail = (ElasticsearchStore) subject.getSail(config); }
@Test public void getSailWithCustomConfigSetsConfigurationCorrectly() { ElasticsearchStoreConfig config = new ElasticsearchStoreConfig(); config.setHostname("localhost"); config.setClusterName("elasticsearch"); config.setIndex("index1"); config.setPort(9300); ElasticsearchStore sail = (ElasticsearchStore) subject.getSail(config); assertMatchesConfig(sail, config); }