[TEST] fix template comparisons in watcher tests
Original commit: elastic/x-pack-elasticsearch@8edc47089b
This commit is contained in:
parent
acec3c9216
commit
4f1f535937
|
@ -82,10 +82,11 @@ public final class WatcherUtils {
|
|||
// Here we convert watcher template into a ES core templates. Due to the different format we use, we
|
||||
// convert to the template format used in ES core
|
||||
Template template = requestPrototype.template();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.putAll(watcherContextParams);
|
||||
params.putAll(template.getParams());
|
||||
template = new Template(template.getScript(), template.getType(), template.getLang(), template.getContentType(), params);
|
||||
if (template.getParams() != null) {
|
||||
watcherContextParams.putAll(template.getParams());
|
||||
}
|
||||
template = new Template(template.getScript(), template.getType(), template.getLang(), template.getContentType(),
|
||||
watcherContextParams);
|
||||
request.template(template);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.elasticsearch.watcher.watch.Payload;
|
|||
import org.elasticsearch.watcher.watch.Watch;
|
||||
import org.elasticsearch.watcher.watch.WatchStatus;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.chrono.ISOChronology;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -143,21 +144,20 @@ public class SearchInputTests extends ESIntegTestCase {
|
|||
WatchExecutionContext ctx = createContext();
|
||||
|
||||
final String expectedTemplateString = "{\"query\":{\"filtered\":{\"query\":{\"match\":{\"event_type\":{\"query\":\"a\","
|
||||
+
|
||||
"\"type\":\"boolean\"}}},\"filter\":{\"range\":{\"_timestamp\":" +
|
||||
"{\"from\":\"{{ctx.trigger.scheduled_time}}||-{{seconds_param}}\",\"to\":\"{{ctx.trigger.scheduled_time}}\"," +
|
||||
"\"include_lower\":true,\"include_upper\":true}}}}}}";
|
||||
+ "\"type\":\"boolean\"}}},\"filter\":{\"range\":{\"_timestamp\":"
|
||||
+ "{\"from\":\"{{ctx.trigger.scheduled_time}}||-{{seconds_param}}\",\"to\":\"{{ctx.trigger.scheduled_time}}\","
|
||||
+ "\"include_lower\":true,\"include_upper\":true}}}}}}";
|
||||
|
||||
Map<String, Object> triggerParams = new HashMap<String, Object>();
|
||||
triggerParams.put("triggered_time", "1970-01-01T00:01:00.000Z");
|
||||
triggerParams.put("scheduled_time", "1970-01-01T00:01:00.000Z");
|
||||
triggerParams.put("triggered_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC()));
|
||||
triggerParams.put("scheduled_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC()));
|
||||
Map<String, Object> ctxParams = new HashMap<String, Object>();
|
||||
ctxParams.put("id", ctx.id().value());
|
||||
ctxParams.put("metadata", null);
|
||||
ctxParams.put("vars", new HashMap<String, Object>());
|
||||
ctxParams.put("watch_id", "test-watch");
|
||||
ctxParams.put("trigger", triggerParams);
|
||||
ctxParams.put("execution_time", "1970-01-01T00:01:00.000Z");
|
||||
ctxParams.put("execution_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC()));
|
||||
Map<String, Object> expectedParams = new HashMap<String, Object>();
|
||||
expectedParams.put("seconds_param", "30s");
|
||||
expectedParams.put("ctx", ctxParams);
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.elasticsearch.watcher.watch.Payload;
|
|||
import org.elasticsearch.watcher.watch.Watch;
|
||||
import org.elasticsearch.watcher.watch.WatchStatus;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.chrono.ISOChronology;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -266,13 +267,7 @@ public class SearchTransformTests extends ESIntegTestCase {
|
|||
builder.field("template", template);
|
||||
}
|
||||
|
||||
XContentBuilder sourceBuilder = jsonBuilder().startObject()
|
||||
.startObject("query")
|
||||
.startObject("match_all")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject();
|
||||
BytesReference source = sourceBuilder.bytes();
|
||||
SearchSourceBuilder source = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery());
|
||||
|
||||
builder.startObject("body")
|
||||
.startObject("query")
|
||||
|
@ -327,8 +322,8 @@ public class SearchTransformTests extends ESIntegTestCase {
|
|||
+ "\"include_lower\":true,\"include_upper\":true}}}]}}}";
|
||||
|
||||
Map<String, Object> triggerParams = new HashMap<String, Object>();
|
||||
triggerParams.put("triggered_time", "1970-01-01T00:01:00.000Z");
|
||||
triggerParams.put("scheduled_time", "1970-01-01T00:01:00.000Z");
|
||||
triggerParams.put("triggered_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC()));
|
||||
triggerParams.put("scheduled_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC()));
|
||||
Map<String, Object> ctxParams = new HashMap<String, Object>();
|
||||
ctxParams.put("id", ctx.id().value());
|
||||
ctxParams.put("metadata", null);
|
||||
|
@ -336,7 +331,7 @@ public class SearchTransformTests extends ESIntegTestCase {
|
|||
ctxParams.put("watch_id", "test-watch");
|
||||
ctxParams.put("payload", new HashMap<String, Object>());
|
||||
ctxParams.put("trigger", triggerParams);
|
||||
ctxParams.put("execution_time", "1970-01-01T00:01:00.000Z");
|
||||
ctxParams.put("execution_time", new DateTime(1970, 01, 01, 00, 01, 00, 000, ISOChronology.getInstanceUTC()));
|
||||
Map<String, Object> expectedParams = new HashMap<String, Object>();
|
||||
expectedParams.put("seconds_param", "30s");
|
||||
expectedParams.put("ctx", ctxParams);
|
||||
|
|
Loading…
Reference in New Issue