params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "1", "value", "A"));
ExecutableScript script = factory.newScript(params);
script.setNextVar("ctx", ImmutableMap.of("_source", source));
script.run();
mapFields = (Collection) source.get(listField);
System.out.println("source = " + source);
assertThat(mapFields).hasSize(1);
// Add item to existing list
params = new HashMap<String, Object>();
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "B"));
script = factory.newScript(params);
script.setNextVar("ctx", ImmutableMap.of("_source", source));
script.run();
mapFields = (Collection) source.get(listField);
assertThat(mapFields).hasSize(2);
// updated first item in list
params = new HashMap<String, Object>();
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "1", "value", "a"));
script = factory.newScript(params);
script.setNextVar("ctx", ImmutableMap.of("_source", source));
script.run();
mapFields = (Collection) source.get(listField);
assertThat(mapFields).hasSize(2);
// updated second item in list
params = new HashMap<String, Object>();
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "b"));
script = factory.newScript(params);
script.setNextVar("ctx", ImmutableMap.of("_source", source));
script.run();
mapFields = (Collection) source.get(listField);
assertThat(mapFields).hasSize(2);
// delete first item
params = new HashMap<String, Object>();
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, null);
script = factory.newScript(params);
script.setNextVar("ctx", ImmutableMap.of("_source", source));
script.run();
mapFields = (Collection) source.get(listField);
assertThat(mapFields).hasSize(1);
}