@Test
  public void testFactoryWithTransportClient() throws IOException {
    // setup client for testing http connection params
    Path baseDir = Paths.get("target/elasticsearch");
    String dataPath = Files.createTempDirectory(baseDir, null).toAbsolutePath().toString();
    Settings build = ImmutableSettings.builder().put("path.data", dataPath).build();
    Node node = nodeBuilder().settings(build).node();

    assertTrue(new ElasticDataStoreFactory().isAvailable());
    scanForPlugins();

    Map<String, Serializable> map = new HashMap<>();
    map.put(ElasticDataStoreFactory.HOSTNAME.key, "localhost");
    map.put(ElasticDataStoreFactory.HOSTPORT.key, String.valueOf(9300));
    map.put(ElasticDataStoreFactory.INDEX_NAME.key, "sample");

    Iterator<DataStoreFactorySpi> ps = getAvailableDataSources();
    ElasticDataStoreFactory fac;
    while (ps.hasNext()) {
      fac = (ElasticDataStoreFactory) ps.next();

      try {
        if (fac.canProcess(map)) {
          source = fac.createDataStore(map);
        }
      } catch (Throwable t) {
        LOGGER.log(Level.WARNING, "Could not acquire " + fac.getDescription() + ":" + t, t);
      }
    }

    assertNotNull(source);
    assertTrue(source instanceof ElasticDataStore);
    node.close();
  }
  @Test
  public void testFactoryWithSearchIndices() throws IOException {
    assertTrue(new ElasticDataStoreFactory().isAvailable());
    scanForPlugins();

    Map<String, Serializable> map = new HashMap<>();
    map.put(ElasticDataStoreFactory.DATA_PATH.key, dataPath);
    map.put(ElasticDataStoreFactory.INDEX_NAME.key, "sample");
    map.put(ElasticDataStoreFactory.SEARCH_INDICES.key, "sample1,sample2");

    Iterator<DataStoreFactorySpi> ps = getAvailableDataSources();
    ElasticDataStoreFactory fac;
    while (ps.hasNext()) {
      fac = (ElasticDataStoreFactory) ps.next();

      try {
        if (fac.canProcess(map)) {
          source = fac.createDataStore(map);
        }
      } catch (Throwable t) {
        LOGGER.log(Level.WARNING, "Could not acquire " + fac.getDescription() + ":" + t, t);
      }
    }

    assertNotNull(source);
    assertTrue(source instanceof ElasticDataStore);
    assertTrue(((ElasticDataStore) source).getSearchIndices().equals("sample1,sample2"));
  }
 public Iterator<DataStoreFactorySpi> getAvailableDataSources() {
   Set<DataStoreFactorySpi> availableDS = new HashSet<>();
   Iterator<DataStoreFactorySpi> it =
       getServiceRegistry().getServiceProviders(DataStoreFactorySpi.class, null, null);
   ElasticDataStoreFactory dsFactory;
   while (it.hasNext()) {
     Object ds = it.next();
     if (ds instanceof ElasticDataStoreFactory) {
       dsFactory = (ElasticDataStoreFactory) ds;
       if (dsFactory.isAvailable()) {
         availableDS.add(dsFactory);
       }
     }
   }
   return availableDS.iterator();
 }
  @Test
  public void testFactoryWithMissingRequired() throws IOException {
    assertTrue(new ElasticDataStoreFactory().isAvailable());
    scanForPlugins();

    Map<String, Serializable> map = new HashMap<>();
    map.put(ElasticDataStoreFactory.DATA_PATH.key, dataPath);
    map.put(ElasticDataStoreFactory.SEARCH_INDICES.key, "sample1,sample2");

    Iterator<DataStoreFactorySpi> ps = getAvailableDataSources();
    ElasticDataStoreFactory fac;
    while (ps.hasNext()) {
      fac = (ElasticDataStoreFactory) ps.next();
      assertTrue(!fac.canProcess(map));
    }

    assertNull(source);
  }
 @Test
 public void testFactoryDefaults() throws IOException {
   ElasticDataStoreFactory fac = new ElasticDataStoreFactory();
   assertTrue(fac.getDisplayName().equals(ElasticDataStoreFactory.DISPLAY_NAME));
   assertTrue(fac.getDescription().equals(ElasticDataStoreFactory.DESCRIPTION));
   assertTrue(fac.getParametersInfo().equals(ElasticDataStoreFactory.PARAMS));
   assertTrue(fac.getImplementationHints() == null);
   assertTrue(fac.createNewDataStore(null) == null);
 }