Reindex extends GenericResultAbstractAction { @Override public String getData(Gson gson) { if (this.source != null) { if (this.source instanceof String) { this.body.put("source", gson.fromJson((String) this.source, Map.class)); } else if (this.source instanceof Map) { Map<String, Object> source = new HashMap<String, Object>((Map) this.source); Object query = source.get("query"); if (query instanceof String) { Map queryMap = gson.fromJson((String) query, Map.class); source.put("query", queryMap); body.put("source", source); } else { body.put("source", this.source); } } } if (this.destination != null) { if (this.destination instanceof String) { this.body.put("dest", gson.fromJson((String) this.destination, Map.class)); } else { body.put("dest", this.destination); } } if (this.script != null) { if (this.script instanceof String) { this.body.put("script", gson.fromJson((String) this.script, Map.class)); } else if (this.script instanceof Map) { Map<String, Object> script = new HashMap<String, Object>((Map) this.script); Object params = script.get("params"); if (params instanceof String) { Map paramMap = gson.fromJson((String) params, Map.class); script.put("params", paramMap); body.put("script", script); } else { body.put("script", this.script); } } } return gson.toJson(this.body); } Reindex(Builder builder); @Override String getData(Gson gson); @Override String getRestMethodName();  }
@Test public void testDataGeneration() throws Exception { Reindex reindex = new Reindex.Builder(source,dest) .conflicts("proceed") .build(); String generatedData = reindex.getData(new GsonBuilder().create()); String expectedData = "{\"conflicts\":\"proceed\",\"dest\":{\"index\":\"destIndex\"},\"source\":{\"index\":\"sourceIndex\"}}"; JSONAssert.assertEquals(expectedData, generatedData,false); }