Remove custom parsing and toXContent logic from TextTemplate and delegate to the Script as much as possible
Original commit: elastic/x-pack-elasticsearch@6d23549dc1
This commit is contained in:
parent
33cdecd39e
commit
565f50dbe5
|
@ -15,6 +15,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.rest.RestUtils;
|
import org.elasticsearch.rest.RestUtils;
|
||||||
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.xpack.common.http.auth.HttpAuth;
|
import org.elasticsearch.xpack.common.http.auth.HttpAuth;
|
||||||
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
|
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
|
@ -407,11 +408,7 @@ public class HttpRequestTemplate implements ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder path(String path) {
|
public Builder path(String path) {
|
||||||
return path(TextTemplate.inline(path));
|
return path(new TextTemplate(path));
|
||||||
}
|
|
||||||
|
|
||||||
public Builder path(TextTemplate.Builder path) {
|
|
||||||
return path(path.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder path(TextTemplate path) {
|
public Builder path(TextTemplate path) {
|
||||||
|
@ -424,10 +421,6 @@ public class HttpRequestTemplate implements ToXContent {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder putParam(String key, TextTemplate.Builder value) {
|
|
||||||
return putParam(key, value.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder putParam(String key, TextTemplate value) {
|
public Builder putParam(String key, TextTemplate value) {
|
||||||
this.params.put(key, value);
|
this.params.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -438,10 +431,6 @@ public class HttpRequestTemplate implements ToXContent {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder putHeader(String key, TextTemplate.Builder value) {
|
|
||||||
return putHeader(key, value.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder putHeader(String key, TextTemplate value) {
|
public Builder putHeader(String key, TextTemplate value) {
|
||||||
this.headers.put(key, value);
|
this.headers.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -453,11 +442,7 @@ public class HttpRequestTemplate implements ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder body(String body) {
|
public Builder body(String body) {
|
||||||
return body(TextTemplate.inline(body));
|
return body(new TextTemplate(body));
|
||||||
}
|
|
||||||
|
|
||||||
public Builder body(TextTemplate.Builder body) {
|
|
||||||
return body(body.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder body(TextTemplate body) {
|
public Builder body(TextTemplate body) {
|
||||||
|
@ -465,8 +450,8 @@ public class HttpRequestTemplate implements ToXContent {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder body(XContentBuilder content) {
|
public Builder body(XContentBuilder content) throws IOException {
|
||||||
return body(TextTemplate.inline(content));
|
return body(new TextTemplate(content.string(), content.contentType(), ScriptService.ScriptType.INLINE, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder connectionTimeout(TimeValue timeout) {
|
public Builder connectionTimeout(TimeValue timeout) {
|
||||||
|
@ -503,7 +488,7 @@ public class HttpRequestTemplate implements ToXContent {
|
||||||
port = uri.getPort() > 0 ? uri.getPort() : scheme.defaultPort();
|
port = uri.getPort() > 0 ? uri.getPort() : scheme.defaultPort();
|
||||||
host = uri.getHost();
|
host = uri.getHost();
|
||||||
if (Strings.hasLength(uri.getPath())) {
|
if (Strings.hasLength(uri.getPath())) {
|
||||||
path = TextTemplate.inline(uri.getPath()).build();
|
path = new TextTemplate(uri.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
String rawQuery = uri.getRawQuery();
|
String rawQuery = uri.getRawQuery();
|
||||||
|
@ -511,7 +496,7 @@ public class HttpRequestTemplate implements ToXContent {
|
||||||
Map<String, String> stringParams = new HashMap<>();
|
Map<String, String> stringParams = new HashMap<>();
|
||||||
RestUtils.decodeQueryString(rawQuery, 0, stringParams);
|
RestUtils.decodeQueryString(rawQuery, 0, stringParams);
|
||||||
for (Map.Entry<String, String> entry : stringParams.entrySet()) {
|
for (Map.Entry<String, String> entry : stringParams.entrySet()) {
|
||||||
params.put(entry.getKey(), TextTemplate.inline(entry.getValue()).build());
|
params.put(entry.getKey(), new TextTemplate(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
|
|
|
@ -5,58 +5,58 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.common.text;
|
package org.elasticsearch.xpack.common.text;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseField;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
import org.elasticsearch.script.Script;
|
||||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class TextTemplate implements ToXContent {
|
public class TextTemplate implements ToXContent {
|
||||||
|
|
||||||
private final String template;
|
private final Script script;
|
||||||
@Nullable private final XContentType contentType;
|
private final String value;
|
||||||
@Nullable private final ScriptType type;
|
|
||||||
@Nullable private final Map<String, Object> params;
|
|
||||||
|
|
||||||
public TextTemplate(String template) {
|
public TextTemplate(String template) {
|
||||||
this(template, null, null, null);
|
this.script = null;
|
||||||
|
this.value = template;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextTemplate(String template, @Nullable XContentType contentType, @Nullable ScriptType type,
|
public TextTemplate(String template, @Nullable XContentType contentType, ScriptType type,
|
||||||
@Nullable Map<String, Object> params) {
|
@Nullable Map<String, Object> params) {
|
||||||
this.template = template;
|
this.script = new Script(template, type, null, params, contentType);
|
||||||
this.contentType = contentType;
|
this.value = null;
|
||||||
this.type = type;
|
}
|
||||||
this.params = params;
|
|
||||||
|
public TextTemplate(Script script) {
|
||||||
|
this.script = script;
|
||||||
|
this.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Script getScript() {
|
||||||
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTemplate() {
|
public String getTemplate() {
|
||||||
return template;
|
return script != null ? script.getScript() : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XContentType getContentType() {
|
public XContentType getContentType() {
|
||||||
return contentType;
|
return script != null ? script.getContentType() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptType getType() {
|
public ScriptType getType() {
|
||||||
return type != null ? type : ScriptType.INLINE;
|
return script != null ? script.getType(): ScriptType.INLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getParams() {
|
public Map<String, Object> getParams() {
|
||||||
return params != null ? params : Collections.emptyMap();
|
return script != null ? script.getParams(): null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,210 +65,31 @@ public class TextTemplate implements ToXContent {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
TextTemplate template1 = (TextTemplate) o;
|
TextTemplate template1 = (TextTemplate) o;
|
||||||
|
return Objects.equals(script, template1.script) &&
|
||||||
if (!template.equals(template1.template)) return false;
|
Objects.equals(value, template1.value);
|
||||||
if (contentType != template1.contentType) return false;
|
|
||||||
if (type != template1.type) return false;
|
|
||||||
return !(params != null ? !params.equals(template1.params) : template1.params != null);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = template.hashCode();
|
return Objects.hash(script, value);
|
||||||
result = 31 * result + (contentType != null ? contentType.hashCode() : 0);
|
|
||||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
|
||||||
result = 31 * result + (params != null ? params.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (type == null) {
|
if (script != null) {
|
||||||
return builder.value(template);
|
script.toXContent(builder, params);
|
||||||
}
|
|
||||||
builder.startObject();
|
|
||||||
switch (type) {
|
|
||||||
case INLINE:
|
|
||||||
if (contentType != null && builder.contentType() == contentType) {
|
|
||||||
builder.rawField(Field.INLINE.getPreferredName(), new BytesArray(template));
|
|
||||||
} else {
|
} else {
|
||||||
builder.field(Field.INLINE.getPreferredName(), template);
|
builder.value(value);
|
||||||
}
|
}
|
||||||
break;
|
return builder;
|
||||||
case FILE:
|
|
||||||
builder.field(Field.FILE.getPreferredName(), template);
|
|
||||||
break;
|
|
||||||
default: // STORED
|
|
||||||
assert type == ScriptType.STORED : "template type [" + type + "] is not supported";
|
|
||||||
builder.field(Field.ID.getPreferredName(), template);
|
|
||||||
}
|
|
||||||
if (this.params != null) {
|
|
||||||
builder.field(Field.PARAMS.getPreferredName(), this.params);
|
|
||||||
}
|
|
||||||
return builder.endObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextTemplate parse(XContentParser parser) throws IOException {
|
public static TextTemplate parse(XContentParser parser) throws IOException {
|
||||||
XContentParser.Token token = parser.currentToken();
|
if (parser.currentToken() == XContentParser.Token.VALUE_STRING) {
|
||||||
if (token.isValue()) {
|
return new TextTemplate(parser.text());
|
||||||
return new TextTemplate(String.valueOf(parser.objectText()));
|
|
||||||
}
|
|
||||||
if (token != XContentParser.Token.START_OBJECT) {
|
|
||||||
throw new ElasticsearchParseException("expected a string value or an object, but found [{}] instead", token);
|
|
||||||
}
|
|
||||||
|
|
||||||
String template = null;
|
|
||||||
XContentType contentType = null;
|
|
||||||
ScriptType type = null;
|
|
||||||
Map<String, Object> params = null;
|
|
||||||
|
|
||||||
String currentFieldName = null;
|
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
|
||||||
currentFieldName = parser.currentName();
|
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.INLINE)) {
|
|
||||||
type = ScriptType.INLINE;
|
|
||||||
if (token.isValue()) {
|
|
||||||
template = String.valueOf(parser.objectText());
|
|
||||||
} else {
|
} else {
|
||||||
contentType = parser.contentType();
|
return new TextTemplate(Script.parse(parser, ParseFieldMatcher.STRICT, null));
|
||||||
XContentBuilder builder = XContentFactory.contentBuilder(contentType);
|
|
||||||
template = builder.copyCurrentStructure(parser).bytes().utf8ToString();
|
|
||||||
}
|
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.FILE)) {
|
|
||||||
type = ScriptType.FILE;
|
|
||||||
if (token == XContentParser.Token.VALUE_STRING) {
|
|
||||||
template = parser.text();
|
|
||||||
} else {
|
|
||||||
throw new ElasticsearchParseException("expected a string value for field [{}], but found [{}]",
|
|
||||||
currentFieldName, token);
|
|
||||||
}
|
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.ID)) {
|
|
||||||
type = ScriptType.STORED;
|
|
||||||
if (token == XContentParser.Token.VALUE_STRING) {
|
|
||||||
template = parser.text();
|
|
||||||
} else {
|
|
||||||
throw new ElasticsearchParseException("expected a string value for field [{}], but found [{}]",
|
|
||||||
currentFieldName, token);
|
|
||||||
}
|
|
||||||
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.PARAMS)) {
|
|
||||||
if (token == XContentParser.Token.START_OBJECT) {
|
|
||||||
params = parser.map();
|
|
||||||
} else {
|
|
||||||
throw new ElasticsearchParseException("expected an object for field [{}], but found [{}]", currentFieldName, token);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new ElasticsearchParseException("unexpected field [{}]", currentFieldName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (template == null) {
|
|
||||||
throw new ElasticsearchParseException("expected one of [{}], [{}] or [{}] fields, but found none",
|
|
||||||
Field.INLINE.getPreferredName(), Field.FILE.getPreferredName(), Field.ID.getPreferredName());
|
|
||||||
}
|
|
||||||
assert type != null : "if template is not null, type should definitely not be null";
|
|
||||||
return new TextTemplate(template, contentType, type, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder inline(XContentBuilder template) {
|
|
||||||
return new Builder.Inline(template.bytes().utf8ToString()).contentType(template.contentType());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder<Builder.Inline> inline(String text) {
|
|
||||||
return new Builder.Inline(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder<Builder.File> file(String file) {
|
|
||||||
return new Builder.File(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder<Builder.Indexed> indexed(String id) {
|
|
||||||
return new Builder.Indexed(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder.DefaultType defaultType(String text) {
|
|
||||||
return new Builder.DefaultType(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract static class Builder<B extends Builder> {
|
|
||||||
|
|
||||||
protected final ScriptType type;
|
|
||||||
protected final String template;
|
|
||||||
protected Map<String, Object> params;
|
|
||||||
|
|
||||||
protected Builder(String template, ScriptType type) {
|
|
||||||
this.template = template;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public B params(Map<String, Object> params) {
|
|
||||||
this.params = params;
|
|
||||||
return (B) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract TextTemplate build();
|
|
||||||
|
|
||||||
public static class Inline extends Builder<Inline> {
|
|
||||||
|
|
||||||
private XContentType contentType;
|
|
||||||
|
|
||||||
public Inline(String script) {
|
|
||||||
super(script, ScriptType.INLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Inline contentType(XContentType contentType) {
|
|
||||||
this.contentType = contentType;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TextTemplate build() {
|
|
||||||
return new TextTemplate(template, contentType, type, params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class File extends Builder<File> {
|
|
||||||
|
|
||||||
public File(String file) {
|
|
||||||
super(file, ScriptType.FILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TextTemplate build() {
|
|
||||||
return new TextTemplate(template, null, type, params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Indexed extends Builder<Indexed> {
|
|
||||||
|
|
||||||
public Indexed(String id) {
|
|
||||||
super(id, ScriptType.STORED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TextTemplate build() {
|
|
||||||
return new TextTemplate(template, null, type, params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DefaultType extends Builder<DefaultType> {
|
|
||||||
|
|
||||||
public DefaultType(String text) {
|
|
||||||
super(text, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TextTemplate build() {
|
|
||||||
return new TextTemplate(template, null, type, params);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Field {
|
|
||||||
ParseField INLINE = new ParseField("inline");
|
|
||||||
ParseField FILE = new ParseField("file");
|
|
||||||
ParseField ID = new ParseField("id");
|
|
||||||
ParseField PARAMS = new ParseField("params");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -28,18 +28,24 @@ public class TextTemplateEngine extends AbstractComponent {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move over to use o.e.script.Script instead
|
public String render(TextTemplate textTemplate, Map<String, Object> model) {
|
||||||
public String render(TextTemplate template, Map<String, Object> model) {
|
if (textTemplate == null) {
|
||||||
if (template == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String template = textTemplate.getTemplate();
|
||||||
XContentType contentType = detectContentType(template);
|
XContentType contentType = detectContentType(template);
|
||||||
Map<String, String> compileParams = compileParams(contentType);
|
Map<String, String> compileParams = compileParams(contentType);
|
||||||
template = trimContentType(template);
|
template = trimContentType(textTemplate);
|
||||||
|
|
||||||
CompiledScript compiledScript = service.compile(convert(template, model), Watcher.SCRIPT_CONTEXT,
|
Map<String, Object> mergedModel = new HashMap<>();
|
||||||
compileParams);
|
if (textTemplate.getParams() != null) {
|
||||||
|
mergedModel.putAll(textTemplate.getParams());
|
||||||
|
}
|
||||||
|
mergedModel.putAll(model);
|
||||||
|
|
||||||
|
Script script = new Script(template, textTemplate.getType(), "mustache", mergedModel, textTemplate.getContentType());
|
||||||
|
CompiledScript compiledScript = service.compile(script, Watcher.SCRIPT_CONTEXT, compileParams);
|
||||||
ExecutableScript executable = service.executable(compiledScript, model);
|
ExecutableScript executable = service.executable(compiledScript, model);
|
||||||
Object result = executable.run();
|
Object result = executable.run();
|
||||||
if (result instanceof BytesReference) {
|
if (result instanceof BytesReference) {
|
||||||
|
@ -48,10 +54,10 @@ public class TextTemplateEngine extends AbstractComponent {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextTemplate trimContentType(TextTemplate textTemplate) {
|
private String trimContentType(TextTemplate textTemplate) {
|
||||||
String template = textTemplate.getTemplate();
|
String template = textTemplate.getTemplate();
|
||||||
if (!template.startsWith("__")){
|
if (!template.startsWith("__")){
|
||||||
return textTemplate; //Doesn't even start with __ so can't have a content type
|
return template; //Doesn't even start with __ so can't have a content type
|
||||||
}
|
}
|
||||||
// There must be a __<content_type__:: prefix so the minimum length before detecting '__::' is 3
|
// There must be a __<content_type__:: prefix so the minimum length before detecting '__::' is 3
|
||||||
int index = template.indexOf("__::", 3);
|
int index = template.indexOf("__::", 3);
|
||||||
|
@ -64,28 +70,20 @@ public class TextTemplateEngine extends AbstractComponent {
|
||||||
template = template.substring(index + 4);
|
template = template.substring(index + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new TextTemplate(template, textTemplate.getContentType(), textTemplate.getType(), textTemplate.getParams());
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
private XContentType detectContentType(TextTemplate textTemplate) {
|
private XContentType detectContentType(String content) {
|
||||||
String template = textTemplate.getTemplate();
|
if (content.startsWith("__")) {
|
||||||
if (template.startsWith("__")) {
|
|
||||||
//There must be a __<content_type__:: prefix so the minimum length before detecting '__::' is 3
|
//There must be a __<content_type__:: prefix so the minimum length before detecting '__::' is 3
|
||||||
int endOfContentName = template.indexOf("__::", 3);
|
int endOfContentName = content.indexOf("__::", 3);
|
||||||
if (endOfContentName != -1) {
|
if (endOfContentName != -1) {
|
||||||
return XContentType.fromMediaTypeOrFormat(template.substring(2, endOfContentName));
|
return XContentType.fromMediaTypeOrFormat(content.substring(2, endOfContentName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Script convert(TextTemplate textTemplate, Map<String, Object> model) {
|
|
||||||
Map<String, Object> mergedModel = new HashMap<>();
|
|
||||||
mergedModel.putAll(textTemplate.getParams());
|
|
||||||
mergedModel.putAll(model);
|
|
||||||
return new Script(textTemplate.getTemplate(), textTemplate.getType(), "mustache", mergedModel, textTemplate.getContentType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> compileParams(XContentType contentType) {
|
private Map<String, String> compileParams(XContentType contentType) {
|
||||||
if (contentType == XContentType.JSON) {
|
if (contentType == XContentType.JSON) {
|
||||||
return Collections.singletonMap("content_type", "application/json");
|
return Collections.singletonMap("content_type", "application/json");
|
||||||
|
|
|
@ -21,9 +21,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class EmailTemplate implements ToXContent {
|
public class EmailTemplate implements ToXContent {
|
||||||
|
|
||||||
final TextTemplate from;
|
final TextTemplate from;
|
||||||
|
@ -238,11 +235,7 @@ public class EmailTemplate implements ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder from(String from) {
|
public Builder from(String from) {
|
||||||
return from(TextTemplate.inline(from));
|
return from(new TextTemplate(from));
|
||||||
}
|
|
||||||
|
|
||||||
public Builder from(TextTemplate.Builder from) {
|
|
||||||
return from(from.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder from(TextTemplate from) {
|
public Builder from(TextTemplate from) {
|
||||||
|
@ -253,15 +246,7 @@ public class EmailTemplate implements ToXContent {
|
||||||
public Builder replyTo(String... replyTo) {
|
public Builder replyTo(String... replyTo) {
|
||||||
TextTemplate[] templates = new TextTemplate[replyTo.length];
|
TextTemplate[] templates = new TextTemplate[replyTo.length];
|
||||||
for (int i = 0; i < templates.length; i++) {
|
for (int i = 0; i < templates.length; i++) {
|
||||||
templates[i] = TextTemplate.defaultType(replyTo[i]).build();
|
templates[i] = new TextTemplate(replyTo[i]);
|
||||||
}
|
|
||||||
return replyTo(templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder replyTo(TextTemplate.Builder... replyTo) {
|
|
||||||
TextTemplate[] templates = new TextTemplate[replyTo.length];
|
|
||||||
for (int i = 0; i < templates.length; i++) {
|
|
||||||
templates[i] = replyTo[i].build();
|
|
||||||
}
|
}
|
||||||
return replyTo(templates);
|
return replyTo(templates);
|
||||||
}
|
}
|
||||||
|
@ -272,11 +257,7 @@ public class EmailTemplate implements ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder priority(Email.Priority priority) {
|
public Builder priority(Email.Priority priority) {
|
||||||
return priority(TextTemplate.inline(priority.name()));
|
return priority(new TextTemplate(priority.name()));
|
||||||
}
|
|
||||||
|
|
||||||
public Builder priority(TextTemplate.Builder priority) {
|
|
||||||
return priority(priority.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder priority(TextTemplate priority) {
|
public Builder priority(TextTemplate priority) {
|
||||||
|
@ -287,15 +268,7 @@ public class EmailTemplate implements ToXContent {
|
||||||
public Builder to(String... to) {
|
public Builder to(String... to) {
|
||||||
TextTemplate[] templates = new TextTemplate[to.length];
|
TextTemplate[] templates = new TextTemplate[to.length];
|
||||||
for (int i = 0; i < templates.length; i++) {
|
for (int i = 0; i < templates.length; i++) {
|
||||||
templates[i] = TextTemplate.defaultType(to[i]).build();
|
templates[i] = new TextTemplate(to[i]);
|
||||||
}
|
|
||||||
return to(templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder to(TextTemplate.Builder... to) {
|
|
||||||
TextTemplate[] templates = new TextTemplate[to.length];
|
|
||||||
for (int i = 0; i < templates.length; i++) {
|
|
||||||
templates[i] = to[i].build();
|
|
||||||
}
|
}
|
||||||
return to(templates);
|
return to(templates);
|
||||||
}
|
}
|
||||||
|
@ -308,15 +281,7 @@ public class EmailTemplate implements ToXContent {
|
||||||
public Builder cc(String... cc) {
|
public Builder cc(String... cc) {
|
||||||
TextTemplate[] templates = new TextTemplate[cc.length];
|
TextTemplate[] templates = new TextTemplate[cc.length];
|
||||||
for (int i = 0; i < templates.length; i++) {
|
for (int i = 0; i < templates.length; i++) {
|
||||||
templates[i] = TextTemplate.defaultType(cc[i]).build();
|
templates[i] = new TextTemplate(cc[i]);
|
||||||
}
|
|
||||||
return cc(templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder cc(TextTemplate.Builder... cc) {
|
|
||||||
TextTemplate[] templates = new TextTemplate[cc.length];
|
|
||||||
for (int i = 0; i < templates.length; i++) {
|
|
||||||
templates[i] = cc[i].build();
|
|
||||||
}
|
}
|
||||||
return cc(templates);
|
return cc(templates);
|
||||||
}
|
}
|
||||||
|
@ -329,15 +294,7 @@ public class EmailTemplate implements ToXContent {
|
||||||
public Builder bcc(String... bcc) {
|
public Builder bcc(String... bcc) {
|
||||||
TextTemplate[] templates = new TextTemplate[bcc.length];
|
TextTemplate[] templates = new TextTemplate[bcc.length];
|
||||||
for (int i = 0; i < templates.length; i++) {
|
for (int i = 0; i < templates.length; i++) {
|
||||||
templates[i] = TextTemplate.defaultType(bcc[i]).build();
|
templates[i] = new TextTemplate(bcc[i]);
|
||||||
}
|
|
||||||
return bcc(templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder bcc(TextTemplate.Builder... bcc) {
|
|
||||||
TextTemplate[] templates = new TextTemplate[bcc.length];
|
|
||||||
for (int i = 0; i < templates.length; i++) {
|
|
||||||
templates[i] = bcc[i].build();
|
|
||||||
}
|
}
|
||||||
return bcc(templates);
|
return bcc(templates);
|
||||||
}
|
}
|
||||||
|
@ -348,11 +305,7 @@ public class EmailTemplate implements ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder subject(String subject) {
|
public Builder subject(String subject) {
|
||||||
return subject(TextTemplate.defaultType(subject));
|
return subject(new TextTemplate(subject));
|
||||||
}
|
|
||||||
|
|
||||||
public Builder subject(TextTemplate.Builder subject) {
|
|
||||||
return subject(subject.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder subject(TextTemplate subject) {
|
public Builder subject(TextTemplate subject) {
|
||||||
|
@ -361,11 +314,7 @@ public class EmailTemplate implements ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder textBody(String text) {
|
public Builder textBody(String text) {
|
||||||
return textBody(TextTemplate.defaultType(text));
|
return textBody(new TextTemplate(text));
|
||||||
}
|
|
||||||
|
|
||||||
public Builder textBody(TextTemplate.Builder text) {
|
|
||||||
return textBody(text.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder textBody(TextTemplate text) {
|
public Builder textBody(TextTemplate text) {
|
||||||
|
@ -374,11 +323,7 @@ public class EmailTemplate implements ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder htmlBody(String html) {
|
public Builder htmlBody(String html) {
|
||||||
return htmlBody(TextTemplate.defaultType(html));
|
return htmlBody(new TextTemplate(html));
|
||||||
}
|
|
||||||
|
|
||||||
public Builder htmlBody(TextTemplate.Builder html) {
|
|
||||||
return htmlBody(html.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder htmlBody(TextTemplate html) {
|
public Builder htmlBody(TextTemplate html) {
|
||||||
|
|
|
@ -23,9 +23,6 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class HipChatMessage implements ToXContent {
|
public class HipChatMessage implements ToXContent {
|
||||||
|
|
||||||
final String body;
|
final String body;
|
||||||
|
@ -405,7 +402,7 @@ public class HipChatMessage implements ToXContent {
|
||||||
public enum Color implements ToXContent {
|
public enum Color implements ToXContent {
|
||||||
YELLOW, GREEN, RED, PURPLE, GRAY, RANDOM;
|
YELLOW, GREEN, RED, PURPLE, GRAY, RANDOM;
|
||||||
|
|
||||||
private final TextTemplate template = TextTemplate.inline(name()).build();
|
private final TextTemplate template = new TextTemplate(name());
|
||||||
|
|
||||||
public TextTemplate asTemplate() {
|
public TextTemplate asTemplate() {
|
||||||
return template;
|
return template;
|
||||||
|
@ -453,7 +450,7 @@ public class HipChatMessage implements ToXContent {
|
||||||
TEXT,
|
TEXT,
|
||||||
HTML;
|
HTML;
|
||||||
|
|
||||||
private final TextTemplate template = TextTemplate.inline(name()).build();
|
private final TextTemplate template = new TextTemplate(name());
|
||||||
|
|
||||||
public TextTemplate asTemplate() {
|
public TextTemplate asTemplate() {
|
||||||
return template;
|
return template;
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class IncidentEvent implements ToXContent {
|
||||||
return builder.endObject();
|
return builder.endObject();
|
||||||
}
|
}
|
||||||
public static Template.Builder templateBuilder(String description) {
|
public static Template.Builder templateBuilder(String description) {
|
||||||
return templateBuilder(TextTemplate.inline(description).build());
|
return templateBuilder(new TextTemplate(description));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Template.Builder templateBuilder(TextTemplate description) {
|
public static Template.Builder templateBuilder(TextTemplate description) {
|
||||||
|
|
|
@ -21,9 +21,6 @@ import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class IncidentEventContext implements ToXContent {
|
public class IncidentEventContext implements ToXContent {
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
|
|
|
@ -20,9 +20,6 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Attachment implements MessageElement {
|
public class Attachment implements MessageElement {
|
||||||
|
|
||||||
final String fallback;
|
final String fallback;
|
||||||
|
@ -460,12 +457,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setFallback(TextTemplate.Builder fallback) {
|
|
||||||
return setFallback(fallback.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setFallback(String fallback) {
|
public Builder setFallback(String fallback) {
|
||||||
return setFallback(TextTemplate.indexed(fallback));
|
return setFallback(new TextTemplate(fallback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setColor(TextTemplate color) {
|
public Builder setColor(TextTemplate color) {
|
||||||
|
@ -473,12 +466,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setColor(TextTemplate.Builder color) {
|
|
||||||
return setColor(color.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setColor(String color) {
|
public Builder setColor(String color) {
|
||||||
return setColor(TextTemplate.inline(color));
|
return setColor(new TextTemplate(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setPretext(TextTemplate pretext) {
|
public Builder setPretext(TextTemplate pretext) {
|
||||||
|
@ -486,12 +475,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setPretext(TextTemplate.Builder pretext) {
|
|
||||||
return setPretext(pretext.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setPretext(String pretext) {
|
public Builder setPretext(String pretext) {
|
||||||
return setPretext(TextTemplate.inline(pretext));
|
return setPretext(new TextTemplate(pretext));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setAuthorName(TextTemplate authorName) {
|
public Builder setAuthorName(TextTemplate authorName) {
|
||||||
|
@ -499,12 +484,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setAuthorName(TextTemplate.Builder authorName) {
|
|
||||||
return setAuthorName(authorName.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setAuthorName(String authorName) {
|
public Builder setAuthorName(String authorName) {
|
||||||
return setAuthorName(TextTemplate.inline(authorName));
|
return setAuthorName(new TextTemplate(authorName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setAuthorLink(TextTemplate authorLink) {
|
public Builder setAuthorLink(TextTemplate authorLink) {
|
||||||
|
@ -512,12 +493,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setAuthorLink(TextTemplate.Builder authorLink) {
|
|
||||||
return setAuthorLink(authorLink.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setAuthorLink(String authorLink) {
|
public Builder setAuthorLink(String authorLink) {
|
||||||
return setAuthorLink(TextTemplate.inline(authorLink));
|
return setAuthorLink(new TextTemplate(authorLink));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setAuthorIcon(TextTemplate authorIcon) {
|
public Builder setAuthorIcon(TextTemplate authorIcon) {
|
||||||
|
@ -525,12 +502,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setAuthorIcon(TextTemplate.Builder authorIcon) {
|
|
||||||
return setAuthorIcon(authorIcon.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setAuthorIcon(String authorIcon) {
|
public Builder setAuthorIcon(String authorIcon) {
|
||||||
return setAuthorIcon(TextTemplate.inline(authorIcon));
|
return setAuthorIcon(new TextTemplate(authorIcon));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setTitle(TextTemplate title) {
|
public Builder setTitle(TextTemplate title) {
|
||||||
|
@ -538,12 +511,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setTitle(TextTemplate.Builder title) {
|
|
||||||
return setTitle(title.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setTitle(String title) {
|
public Builder setTitle(String title) {
|
||||||
return setTitle(TextTemplate.inline(title));
|
return setTitle(new TextTemplate(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setTitleLink(TextTemplate titleLink) {
|
public Builder setTitleLink(TextTemplate titleLink) {
|
||||||
|
@ -551,12 +520,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setTitleLink(TextTemplate.Builder titleLink) {
|
|
||||||
return setTitleLink(titleLink.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setTitleLink(String titleLink) {
|
public Builder setTitleLink(String titleLink) {
|
||||||
return setTitleLink(TextTemplate.inline(titleLink));
|
return setTitleLink(new TextTemplate(titleLink));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setText(TextTemplate text) {
|
public Builder setText(TextTemplate text) {
|
||||||
|
@ -564,12 +529,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setText(TextTemplate.Builder text) {
|
|
||||||
return setText(text.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setText(String text) {
|
public Builder setText(String text) {
|
||||||
return setText(TextTemplate.inline(text));
|
return setText(new TextTemplate(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addField(TextTemplate title, TextTemplate value, boolean isShort) {
|
public Builder addField(TextTemplate title, TextTemplate value, boolean isShort) {
|
||||||
|
@ -577,12 +538,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addField(TextTemplate.Builder title, TextTemplate.Builder value, boolean isShort) {
|
|
||||||
return addField(title.build(), value.build(), isShort);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder addField(String title, String value, boolean isShort) {
|
public Builder addField(String title, String value, boolean isShort) {
|
||||||
return addField(TextTemplate.inline(title), TextTemplate.inline(value), isShort);
|
return addField(new TextTemplate(title), new TextTemplate(value), isShort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setImageUrl(TextTemplate imageUrl) {
|
public Builder setImageUrl(TextTemplate imageUrl) {
|
||||||
|
@ -590,12 +547,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setImageUrl(TextTemplate.Builder imageUrl) {
|
|
||||||
return setImageUrl(imageUrl.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setImageUrl(String imageUrl) {
|
public Builder setImageUrl(String imageUrl) {
|
||||||
return setImageUrl(TextTemplate.inline(imageUrl));
|
return setImageUrl(new TextTemplate(imageUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setThumbUrl(TextTemplate thumbUrl) {
|
public Builder setThumbUrl(TextTemplate thumbUrl) {
|
||||||
|
@ -603,12 +556,8 @@ public class Attachment implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setThumbUrl(TextTemplate.Builder thumbUrl) {
|
|
||||||
return setThumbUrl(thumbUrl.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setThumbUrl(String thumbUrl) {
|
public Builder setThumbUrl(String thumbUrl) {
|
||||||
return setThumbUrl(TextTemplate.inline(thumbUrl));
|
return setThumbUrl(new TextTemplate(thumbUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Template build() {
|
public Template build() {
|
||||||
|
|
|
@ -17,9 +17,6 @@ import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Field implements MessageElement {
|
class Field implements MessageElement {
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
|
|
|
@ -22,9 +22,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SlackMessage implements MessageElement {
|
public class SlackMessage implements MessageElement {
|
||||||
|
|
||||||
final String from;
|
final String from;
|
||||||
|
@ -350,12 +347,8 @@ public class SlackMessage implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setFrom(TextTemplate.Builder from) {
|
|
||||||
return setFrom(from.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setFrom(String from) {
|
public Builder setFrom(String from) {
|
||||||
return setFrom(TextTemplate.inline(from));
|
return setFrom(new TextTemplate(from));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addTo(TextTemplate... to) {
|
public Builder addTo(TextTemplate... to) {
|
||||||
|
@ -363,16 +356,9 @@ public class SlackMessage implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addTo(TextTemplate.Builder... to) {
|
|
||||||
for (TextTemplate.Builder name : to) {
|
|
||||||
this.to.add(name.build());
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder addTo(String... to) {
|
public Builder addTo(String... to) {
|
||||||
for (String name : to) {
|
for (String name : to) {
|
||||||
this.to.add(TextTemplate.inline(name).build());
|
this.to.add(new TextTemplate(name));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -382,12 +368,8 @@ public class SlackMessage implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setText(TextTemplate.Builder text) {
|
|
||||||
return setText(text.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setText(String text) {
|
public Builder setText(String text) {
|
||||||
return setText(TextTemplate.inline(text));
|
return setText(new TextTemplate(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setIcon(TextTemplate icon) {
|
public Builder setIcon(TextTemplate icon) {
|
||||||
|
@ -395,12 +377,8 @@ public class SlackMessage implements MessageElement {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setIcon(TextTemplate.Builder icon) {
|
|
||||||
return setIcon(icon.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setIcon(String icon) {
|
public Builder setIcon(String icon) {
|
||||||
return setIcon(TextTemplate.inline(icon));
|
return setIcon(new TextTemplate(icon));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addAttachments(Attachment.Template... attachments) {
|
public Builder addAttachments(Attachment.Template... attachments) {
|
||||||
|
|
|
@ -61,10 +61,10 @@ public class HttpRequestTemplateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testRender() {
|
public void testRender() {
|
||||||
HttpRequestTemplate template = HttpRequestTemplate.builder("_host", 1234)
|
HttpRequestTemplate template = HttpRequestTemplate.builder("_host", 1234)
|
||||||
.body(TextTemplate.inline("_body"))
|
.body(new TextTemplate("_body"))
|
||||||
.path(TextTemplate.inline("_path"))
|
.path(new TextTemplate("_path"))
|
||||||
.putParam("_key1", TextTemplate.inline("_value1"))
|
.putParam("_key1", new TextTemplate("_value1"))
|
||||||
.putHeader("_key2", TextTemplate.inline("_value2"))
|
.putHeader("_key2", new TextTemplate("_value2"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpRequest result = template.render(new MockTextTemplateEngine(), Collections.emptyMap());
|
HttpRequest result = template.render(new MockTextTemplateEngine(), Collections.emptyMap());
|
||||||
|
@ -114,10 +114,10 @@ public class HttpRequestTemplateTests extends ESTestCase {
|
||||||
builder.auth(new BasicAuth("_username", "_password".toCharArray()));
|
builder.auth(new BasicAuth("_username", "_password".toCharArray()));
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
builder.putParam("_key", TextTemplate.inline("_value"));
|
builder.putParam("_key", new TextTemplate("_value"));
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
builder.putHeader("_key", TextTemplate.inline("_value"));
|
builder.putHeader("_key", new TextTemplate("_value"));
|
||||||
}
|
}
|
||||||
long connectionTimeout = randomBoolean() ? 0 : randomIntBetween(5, 100000);
|
long connectionTimeout = randomBoolean() ? 0 : randomIntBetween(5, 100000);
|
||||||
if (connectionTimeout > 0) {
|
if (connectionTimeout > 0) {
|
||||||
|
@ -149,7 +149,7 @@ public class HttpRequestTemplateTests extends ESTestCase {
|
||||||
public void testParsingFromUrl() throws Exception {
|
public void testParsingFromUrl() throws Exception {
|
||||||
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("www.example.org", 1234);
|
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("www.example.org", 1234);
|
||||||
builder.path("/foo/bar/org");
|
builder.path("/foo/bar/org");
|
||||||
builder.putParam("param", TextTemplate.inline("test"));
|
builder.putParam("param", new TextTemplate("test"));
|
||||||
builder.scheme(Scheme.HTTPS);
|
builder.scheme(Scheme.HTTPS);
|
||||||
assertThatManualBuilderEqualsParsingFromUrl("https://www.example.org:1234/foo/bar/org?param=test", builder);
|
assertThatManualBuilderEqualsParsingFromUrl("https://www.example.org:1234/foo/bar/org?param=test", builder);
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ public class HttpRequestTemplateTests extends ESTestCase {
|
||||||
assertThatManualBuilderEqualsParsingFromUrl("http://www.example.org", builder);
|
assertThatManualBuilderEqualsParsingFromUrl("http://www.example.org", builder);
|
||||||
|
|
||||||
// encoded values
|
// encoded values
|
||||||
builder = HttpRequestTemplate.builder("www.example.org", 80).putParam("foo", TextTemplate.inline(" white space"));
|
builder = HttpRequestTemplate.builder("www.example.org", 80).putParam("foo", new TextTemplate(" white space"));
|
||||||
assertThatManualBuilderEqualsParsingFromUrl("http://www.example.org?foo=%20white%20space", builder);
|
assertThatManualBuilderEqualsParsingFromUrl("http://www.example.org?foo=%20white%20space", builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Map;
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static java.util.Collections.unmodifiableMap;
|
import static java.util.Collections.unmodifiableMap;
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
@ -64,7 +63,7 @@ public class TextTemplateTests extends ESTestCase {
|
||||||
when(service.executable(compiledScript, model)).thenReturn(script);
|
when(service.executable(compiledScript, model)).thenReturn(script);
|
||||||
when(script.run()).thenReturn("rendered_text");
|
when(script.run()).thenReturn("rendered_text");
|
||||||
|
|
||||||
TextTemplate template = templateBuilder(type, templateText).params(params).build();
|
TextTemplate template = templateBuilder(type, templateText, params);
|
||||||
assertThat(engine.render(template, model), is("rendered_text"));
|
assertThat(engine.render(template, model), is("rendered_text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ public class TextTemplateTests extends ESTestCase {
|
||||||
when(service.executable(compiledScript, model)).thenReturn(script);
|
when(service.executable(compiledScript, model)).thenReturn(script);
|
||||||
when(script.run()).thenReturn("rendered_text");
|
when(script.run()).thenReturn("rendered_text");
|
||||||
|
|
||||||
TextTemplate template = templateBuilder(scriptType, templateText).params(params).build();
|
TextTemplate template = templateBuilder(scriptType, templateText, params);
|
||||||
assertThat(engine.render(template, model), is("rendered_text"));
|
assertThat(engine.render(template, model), is("rendered_text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +99,7 @@ public class TextTemplateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testParser() throws Exception {
|
public void testParser() throws Exception {
|
||||||
ScriptType type = randomScriptType();
|
ScriptType type = randomScriptType();
|
||||||
TextTemplate template = templateBuilder(type, "_template").params(singletonMap("param_key", "param_val")).build();
|
TextTemplate template = templateBuilder(type, "_template", singletonMap("param_key", "param_val"));
|
||||||
XContentBuilder builder = jsonBuilder().startObject();
|
XContentBuilder builder = jsonBuilder().startObject();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case INLINE:
|
case INLINE:
|
||||||
|
@ -123,7 +122,7 @@ public class TextTemplateTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParserParserSelfGenerated() throws Exception {
|
public void testParserParserSelfGenerated() throws Exception {
|
||||||
TextTemplate template = templateBuilder(randomScriptType(), "_template").params(singletonMap("param_key", "param_val")).build();
|
TextTemplate template = templateBuilder(randomScriptType(), "_template", singletonMap("param_key", "param_val"));
|
||||||
|
|
||||||
XContentBuilder builder = jsonBuilder().value(template);
|
XContentBuilder builder = jsonBuilder().value(template);
|
||||||
BytesReference bytes = builder.bytes();
|
BytesReference bytes = builder.bytes();
|
||||||
|
@ -186,14 +185,8 @@ public class TextTemplateTests extends ESTestCase {
|
||||||
assertThat(engine.render(null ,new HashMap<>()), is(nullValue()));
|
assertThat(engine.render(null ,new HashMap<>()), is(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextTemplate.Builder templateBuilder(ScriptType type, String text) {
|
private TextTemplate templateBuilder(ScriptType type, String text, Map<String, Object> params) {
|
||||||
switch (type) {
|
return new TextTemplate(text, null, type, params);
|
||||||
case INLINE: return TextTemplate.inline(text);
|
|
||||||
case FILE: return TextTemplate.file(text);
|
|
||||||
case STORED: return TextTemplate.indexed(text);
|
|
||||||
default:
|
|
||||||
throw illegalArgument("unsupported script type [{}]", type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ScriptType randomScriptType() {
|
private static ScriptType randomScriptType() {
|
||||||
|
|
|
@ -24,29 +24,27 @@ import static org.hamcrest.Matchers.is;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class EmailTemplateTests extends ESTestCase {
|
public class EmailTemplateTests extends ESTestCase {
|
||||||
public void testEmailTemplateParserSelfGenerated() throws Exception {
|
public void testEmailTemplateParserSelfGenerated() throws Exception {
|
||||||
TextTemplate from = randomFrom(TextTemplate.inline("from@from.com").build(), null);
|
TextTemplate from = randomFrom(new TextTemplate("from@from.com"), null);
|
||||||
List<TextTemplate> addresses = new ArrayList<>();
|
List<TextTemplate> addresses = new ArrayList<>();
|
||||||
for( int i = 0; i < randomIntBetween(1, 5); ++i){
|
for( int i = 0; i < randomIntBetween(1, 5); ++i){
|
||||||
addresses.add(TextTemplate.inline("address" + i + "@test.com").build());
|
addresses.add(new TextTemplate("address" + i + "@test.com"));
|
||||||
}
|
}
|
||||||
TextTemplate[] possibleList = addresses.toArray(new TextTemplate[addresses.size()]);
|
TextTemplate[] possibleList = addresses.toArray(new TextTemplate[addresses.size()]);
|
||||||
TextTemplate[] replyTo = randomFrom(possibleList, null);
|
TextTemplate[] replyTo = randomFrom(possibleList, null);
|
||||||
TextTemplate[] to = randomFrom(possibleList, null);
|
TextTemplate[] to = randomFrom(possibleList, null);
|
||||||
TextTemplate[] cc = randomFrom(possibleList, null);
|
TextTemplate[] cc = randomFrom(possibleList, null);
|
||||||
TextTemplate[] bcc = randomFrom(possibleList, null);
|
TextTemplate[] bcc = randomFrom(possibleList, null);
|
||||||
TextTemplate priority = TextTemplate.inline(randomFrom(Email.Priority.values()).name()).build();
|
TextTemplate priority = new TextTemplate(randomFrom(Email.Priority.values()).name());
|
||||||
|
|
||||||
TextTemplate subjectTemplate = TextTemplate.inline("Templated Subject {{foo}}").build();
|
TextTemplate subjectTemplate = new TextTemplate("Templated Subject {{foo}}");
|
||||||
String subject = "Templated Subject bar";
|
String subject = "Templated Subject bar";
|
||||||
|
|
||||||
TextTemplate textBodyTemplate = TextTemplate.inline("Templated Body {{foo}}").build();
|
TextTemplate textBodyTemplate = new TextTemplate("Templated Body {{foo}}");
|
||||||
String textBody = "Templated Body bar";
|
String textBody = "Templated Body bar";
|
||||||
|
|
||||||
TextTemplate htmlBodyTemplate = TextTemplate.inline("Templated Html Body <script>nefarious scripting</script>").build();
|
TextTemplate htmlBodyTemplate = new TextTemplate("Templated Html Body <script>nefarious scripting</script>");
|
||||||
String htmlBody = "Templated Html Body <script>nefarious scripting</script>";
|
String htmlBody = "Templated Html Body <script>nefarious scripting</script>";
|
||||||
String sanitizedHtmlBody = "Templated Html Body";
|
String sanitizedHtmlBody = "Templated Html Body";
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,6 @@ import static org.hamcrest.Matchers.arrayContaining;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class HipChatMessageTests extends ESTestCase {
|
public class HipChatMessageTests extends ESTestCase {
|
||||||
public void testToXContent() throws Exception {
|
public void testToXContent() throws Exception {
|
||||||
String message = randomAsciiOfLength(10);
|
String message = randomAsciiOfLength(10);
|
||||||
|
@ -163,14 +160,14 @@ public class HipChatMessageTests extends ESTestCase {
|
||||||
XContentBuilder jsonBuilder = jsonBuilder();
|
XContentBuilder jsonBuilder = jsonBuilder();
|
||||||
jsonBuilder.startObject();
|
jsonBuilder.startObject();
|
||||||
|
|
||||||
TextTemplate body = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
TextTemplate body = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("body", body, ToXContent.EMPTY_PARAMS);
|
jsonBuilder.field("body", body, ToXContent.EMPTY_PARAMS);
|
||||||
TextTemplate[] rooms = null;
|
TextTemplate[] rooms = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
jsonBuilder.startArray("room");
|
jsonBuilder.startArray("room");
|
||||||
rooms = new TextTemplate[randomIntBetween(1, 3)];
|
rooms = new TextTemplate[randomIntBetween(1, 3)];
|
||||||
for (int i = 0; i < rooms.length; i++) {
|
for (int i = 0; i < rooms.length; i++) {
|
||||||
rooms[i] = TextTemplate.inline(randomAsciiOfLength(10)).build();
|
rooms[i] = new TextTemplate(randomAsciiOfLength(10));
|
||||||
rooms[i].toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
|
rooms[i].toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
|
||||||
}
|
}
|
||||||
jsonBuilder.endArray();
|
jsonBuilder.endArray();
|
||||||
|
@ -180,7 +177,7 @@ public class HipChatMessageTests extends ESTestCase {
|
||||||
jsonBuilder.startArray("user");
|
jsonBuilder.startArray("user");
|
||||||
users = new TextTemplate[randomIntBetween(1, 3)];
|
users = new TextTemplate[randomIntBetween(1, 3)];
|
||||||
for (int i = 0; i < users.length; i++) {
|
for (int i = 0; i < users.length; i++) {
|
||||||
users[i] = TextTemplate.inline(randomAsciiOfLength(10)).build();
|
users[i] = new TextTemplate(randomAsciiOfLength(10));
|
||||||
users[i].toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
|
users[i].toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
|
||||||
}
|
}
|
||||||
jsonBuilder.endArray();
|
jsonBuilder.endArray();
|
||||||
|
@ -192,7 +189,7 @@ public class HipChatMessageTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
TextTemplate color = null;
|
TextTemplate color = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
color = TextTemplate.inline(randomAsciiOfLength(10)).build();
|
color = new TextTemplate(randomAsciiOfLength(10));
|
||||||
jsonBuilder.field("color", color, ToXContent.EMPTY_PARAMS);
|
jsonBuilder.field("color", color, ToXContent.EMPTY_PARAMS);
|
||||||
}
|
}
|
||||||
HipChatMessage.Format format = null;
|
HipChatMessage.Format format = null;
|
||||||
|
@ -231,26 +228,26 @@ public class HipChatMessageTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTemplateParseSelfGenerated() throws Exception {
|
public void testTemplateParseSelfGenerated() throws Exception {
|
||||||
TextTemplate body = TextTemplate.inline(randomAsciiOfLength(10)).build();
|
TextTemplate body = new TextTemplate(randomAsciiOfLength(10));
|
||||||
HipChatMessage.Template.Builder templateBuilder = new HipChatMessage.Template.Builder(body);
|
HipChatMessage.Template.Builder templateBuilder = new HipChatMessage.Template.Builder(body);
|
||||||
|
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
int count = randomIntBetween(1, 3);
|
int count = randomIntBetween(1, 3);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
templateBuilder.addRooms(TextTemplate.inline(randomAsciiOfLength(10)).build());
|
templateBuilder.addRooms(new TextTemplate(randomAsciiOfLength(10)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
int count = randomIntBetween(1, 3);
|
int count = randomIntBetween(1, 3);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
templateBuilder.addUsers(TextTemplate.inline(randomAsciiOfLength(10)).build());
|
templateBuilder.addUsers(new TextTemplate(randomAsciiOfLength(10)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
templateBuilder.setFrom(randomAsciiOfLength(10));
|
templateBuilder.setFrom(randomAsciiOfLength(10));
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
templateBuilder.setColor(TextTemplate.inline(randomAsciiOfLength(5)).build());
|
templateBuilder.setColor(new TextTemplate(randomAsciiOfLength(5)));
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
templateBuilder.setFormat(randomFrom(HipChatMessage.Format.values()));
|
templateBuilder.setFormat(randomFrom(HipChatMessage.Format.values()));
|
||||||
|
|
|
@ -32,9 +32,6 @@ import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class UserAccountTests extends ESTestCase {
|
public class UserAccountTests extends ESTestCase {
|
||||||
|
|
||||||
public void testSettings() throws Exception {
|
public void testSettings() throws Exception {
|
||||||
|
@ -258,8 +255,8 @@ public class UserAccountTests extends ESTestCase {
|
||||||
.build();
|
.build();
|
||||||
UserAccount userAccount = createUserAccount(settings);
|
UserAccount userAccount = createUserAccount(settings);
|
||||||
|
|
||||||
TextTemplate body = TextTemplate.inline("body").build();
|
TextTemplate body = new TextTemplate("body");
|
||||||
TextTemplate[] rooms = new TextTemplate[] { TextTemplate.inline("room").build() };
|
TextTemplate[] rooms = new TextTemplate[] { new TextTemplate("room")};
|
||||||
HipChatMessage.Template template = new HipChatMessage.Template(body, rooms, null, "sender", HipChatMessage.Format.TEXT, null, true);
|
HipChatMessage.Template template = new HipChatMessage.Template(body, rooms, null, "sender", HipChatMessage.Format.TEXT, null, true);
|
||||||
|
|
||||||
HipChatMessage message = userAccount.render("watchId", "actionId", new MockTextTemplateEngine(), template, new HashMap<>());
|
HipChatMessage message = userAccount.render("watchId", "actionId", new MockTextTemplateEngine(), template, new HashMap<>());
|
||||||
|
@ -273,10 +270,10 @@ public class UserAccountTests extends ESTestCase {
|
||||||
.build();
|
.build();
|
||||||
UserAccount userAccount = createUserAccount(settings);
|
UserAccount userAccount = createUserAccount(settings);
|
||||||
|
|
||||||
TextTemplate body = TextTemplate.inline("body").build();
|
TextTemplate body = new TextTemplate("body");
|
||||||
TextTemplate[] rooms = new TextTemplate[] { TextTemplate.inline("room").build() };
|
TextTemplate[] rooms = new TextTemplate[] { new TextTemplate("room") };
|
||||||
HipChatMessage.Template template = new HipChatMessage.Template(body, rooms, null, "sender", null,
|
HipChatMessage.Template template = new HipChatMessage.Template(body, rooms, null, "sender", null,
|
||||||
TextTemplate.inline("yellow").build(), true);
|
new TextTemplate("yellow"), true);
|
||||||
|
|
||||||
HipChatMessage message = userAccount.render("watchId", "actionId", new MockTextTemplateEngine(), template, new HashMap<>());
|
HipChatMessage message = userAccount.render("watchId", "actionId", new MockTextTemplateEngine(), template, new HashMap<>());
|
||||||
assertThat(message.format, is(nullValue()));
|
assertThat(message.format, is(nullValue()));
|
||||||
|
|
|
@ -27,9 +27,6 @@ import static org.hamcrest.Matchers.arrayContaining;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SlackMessageTests extends ESTestCase {
|
public class SlackMessageTests extends ESTestCase {
|
||||||
public void testToXContent() throws Exception {
|
public void testToXContent() throws Exception {
|
||||||
String from = randomBoolean() ? null : randomAsciiOfLength(10);
|
String from = randomBoolean() ? null : randomAsciiOfLength(10);
|
||||||
|
@ -230,7 +227,7 @@ public class SlackMessageTests extends ESTestCase {
|
||||||
|
|
||||||
TextTemplate from = null;
|
TextTemplate from = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
from = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
from = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("from", from, params);
|
jsonBuilder.field("from", from, params);
|
||||||
}
|
}
|
||||||
TextTemplate[] to = null;
|
TextTemplate[] to = null;
|
||||||
|
@ -238,19 +235,19 @@ public class SlackMessageTests extends ESTestCase {
|
||||||
jsonBuilder.startArray("to");
|
jsonBuilder.startArray("to");
|
||||||
to = new TextTemplate[randomIntBetween(1, 3)];
|
to = new TextTemplate[randomIntBetween(1, 3)];
|
||||||
for (int i = 0; i < to.length; i++) {
|
for (int i = 0; i < to.length; i++) {
|
||||||
to[i] = TextTemplate.inline(randomAsciiOfLength(10)).build();
|
to[i] = new TextTemplate(randomAsciiOfLength(10));
|
||||||
to[i].toXContent(jsonBuilder, params);
|
to[i].toXContent(jsonBuilder, params);
|
||||||
}
|
}
|
||||||
jsonBuilder.endArray();
|
jsonBuilder.endArray();
|
||||||
}
|
}
|
||||||
TextTemplate text = null;
|
TextTemplate text = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
text = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
text = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("text", text, params);
|
jsonBuilder.field("text", text, params);
|
||||||
}
|
}
|
||||||
TextTemplate icon = null;
|
TextTemplate icon = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
icon = TextTemplate.inline(randomAsciiOfLength(10)).build();
|
icon = new TextTemplate(randomAsciiOfLength(10));
|
||||||
jsonBuilder.field("icon", icon);
|
jsonBuilder.field("icon", icon);
|
||||||
}
|
}
|
||||||
Attachment.Template[] attachments = null;
|
Attachment.Template[] attachments = null;
|
||||||
|
@ -261,57 +258,57 @@ public class SlackMessageTests extends ESTestCase {
|
||||||
jsonBuilder.startObject();
|
jsonBuilder.startObject();
|
||||||
TextTemplate fallback = null;
|
TextTemplate fallback = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
fallback = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
fallback = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("fallback", fallback, params);
|
jsonBuilder.field("fallback", fallback, params);
|
||||||
}
|
}
|
||||||
TextTemplate color = null;
|
TextTemplate color = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
color = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
color = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("color", color, params);
|
jsonBuilder.field("color", color, params);
|
||||||
}
|
}
|
||||||
TextTemplate pretext = null;
|
TextTemplate pretext = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
pretext = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
pretext = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("pretext", pretext, params);
|
jsonBuilder.field("pretext", pretext, params);
|
||||||
}
|
}
|
||||||
TextTemplate authorName = null;
|
TextTemplate authorName = null;
|
||||||
TextTemplate authorLink = null;
|
TextTemplate authorLink = null;
|
||||||
TextTemplate authorIcon = null;
|
TextTemplate authorIcon = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
authorName = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
authorName = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("author_name", authorName, params);
|
jsonBuilder.field("author_name", authorName, params);
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
authorLink = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
authorLink = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("author_link", authorLink, params);
|
jsonBuilder.field("author_link", authorLink, params);
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
authorIcon = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
authorIcon = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("author_icon", authorIcon, params);
|
jsonBuilder.field("author_icon", authorIcon, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextTemplate title = null;
|
TextTemplate title = null;
|
||||||
TextTemplate titleLink = null;
|
TextTemplate titleLink = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
title = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
title = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("title", title, params);
|
jsonBuilder.field("title", title, params);
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
titleLink = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
titleLink = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("title_link", titleLink, params);
|
jsonBuilder.field("title_link", titleLink, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextTemplate attachmentText = null;
|
TextTemplate attachmentText = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
attachmentText = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
attachmentText = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("text", attachmentText, params);
|
jsonBuilder.field("text", attachmentText, params);
|
||||||
}
|
}
|
||||||
TextTemplate imageUrl = null;
|
TextTemplate imageUrl = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
imageUrl = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
imageUrl = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("image_url", imageUrl, params);
|
jsonBuilder.field("image_url", imageUrl, params);
|
||||||
}
|
}
|
||||||
TextTemplate thumbUrl = null;
|
TextTemplate thumbUrl = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
thumbUrl = TextTemplate.inline(randomAsciiOfLength(200)).build();
|
thumbUrl = new TextTemplate(randomAsciiOfLength(200));
|
||||||
jsonBuilder.field("thumb_url", thumbUrl, params);
|
jsonBuilder.field("thumb_url", thumbUrl, params);
|
||||||
}
|
}
|
||||||
Field.Template[] fields = null;
|
Field.Template[] fields = null;
|
||||||
|
@ -320,9 +317,9 @@ public class SlackMessageTests extends ESTestCase {
|
||||||
fields = new Field.Template[randomIntBetween(1,3)];
|
fields = new Field.Template[randomIntBetween(1,3)];
|
||||||
for (int j = 0; j < fields.length; j++) {
|
for (int j = 0; j < fields.length; j++) {
|
||||||
jsonBuilder.startObject();
|
jsonBuilder.startObject();
|
||||||
TextTemplate fieldTitle = TextTemplate.inline(randomAsciiOfLength(50)).build();
|
TextTemplate fieldTitle = new TextTemplate(randomAsciiOfLength(50));
|
||||||
jsonBuilder.field("title", fieldTitle, params);
|
jsonBuilder.field("title", fieldTitle, params);
|
||||||
TextTemplate fieldValue = TextTemplate.inline(randomAsciiOfLength(50)).build();
|
TextTemplate fieldValue = new TextTemplate(randomAsciiOfLength(50));
|
||||||
jsonBuilder.field("value", fieldValue, params);
|
jsonBuilder.field("value", fieldValue, params);
|
||||||
boolean isShort = randomBoolean();
|
boolean isShort = randomBoolean();
|
||||||
jsonBuilder.field("short", isShort);
|
jsonBuilder.field("short", isShort);
|
||||||
|
|
|
@ -18,9 +18,6 @@ import org.elasticsearch.xpack.watcher.actions.webhook.WebhookAction;
|
||||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public final class ActionBuilders {
|
public final class ActionBuilders {
|
||||||
|
|
||||||
private ActionBuilders() {
|
private ActionBuilders() {
|
||||||
|
@ -47,11 +44,7 @@ public final class ActionBuilders {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LoggingAction.Builder loggingAction(String text) {
|
public static LoggingAction.Builder loggingAction(String text) {
|
||||||
return loggingAction(TextTemplate.inline(text));
|
return loggingAction(new TextTemplate(text));
|
||||||
}
|
|
||||||
|
|
||||||
public static LoggingAction.Builder loggingAction(TextTemplate.Builder text) {
|
|
||||||
return loggingAction(text.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LoggingAction.Builder loggingAction(TextTemplate text) {
|
public static LoggingAction.Builder loggingAction(TextTemplate text) {
|
||||||
|
@ -59,20 +52,13 @@ public final class ActionBuilders {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HipChatAction.Builder hipchatAction(String message) {
|
public static HipChatAction.Builder hipchatAction(String message) {
|
||||||
return hipchatAction(TextTemplate.inline(message));
|
return hipchatAction(new TextTemplate(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HipChatAction.Builder hipchatAction(String account, String body) {
|
public static HipChatAction.Builder hipchatAction(String account, String body) {
|
||||||
return hipchatAction(account, TextTemplate.inline(body));
|
return hipchatAction(account, new TextTemplate(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HipChatAction.Builder hipchatAction(TextTemplate.Builder body) {
|
|
||||||
return hipchatAction(body.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HipChatAction.Builder hipchatAction(String account, TextTemplate.Builder body) {
|
|
||||||
return hipchatAction(account, body.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HipChatAction.Builder hipchatAction(TextTemplate body) {
|
public static HipChatAction.Builder hipchatAction(TextTemplate body) {
|
||||||
return hipchatAction(null, body);
|
return hipchatAction(null, body);
|
||||||
|
|
|
@ -19,9 +19,6 @@ import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class HipChatAction implements Action {
|
public class HipChatAction implements Action {
|
||||||
|
|
||||||
public static final String TYPE = "hipchat";
|
public static final String TYPE = "hipchat";
|
||||||
|
@ -182,18 +179,10 @@ public class HipChatAction implements Action {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addRooms(TextTemplate.Builder... rooms) {
|
|
||||||
TextTemplate[] templates = new TextTemplate[rooms.length];
|
|
||||||
for (int i = 0; i < rooms.length; i++) {
|
|
||||||
templates[i] = rooms[i].build();
|
|
||||||
}
|
|
||||||
return addRooms(templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder addRooms(String... rooms) {
|
public Builder addRooms(String... rooms) {
|
||||||
TextTemplate[] templates = new TextTemplate[rooms.length];
|
TextTemplate[] templates = new TextTemplate[rooms.length];
|
||||||
for (int i = 0; i < rooms.length; i++) {
|
for (int i = 0; i < rooms.length; i++) {
|
||||||
templates[i] = TextTemplate.inline(rooms[i]).build();
|
templates[i] = new TextTemplate(rooms[i]);
|
||||||
}
|
}
|
||||||
return addRooms(templates);
|
return addRooms(templates);
|
||||||
}
|
}
|
||||||
|
@ -204,18 +193,10 @@ public class HipChatAction implements Action {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addUsers(TextTemplate.Builder... users) {
|
|
||||||
TextTemplate[] templates = new TextTemplate[users.length];
|
|
||||||
for (int i = 0; i < users.length; i++) {
|
|
||||||
templates[i] = users[i].build();
|
|
||||||
}
|
|
||||||
return addUsers(templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder addUsers(String... users) {
|
public Builder addUsers(String... users) {
|
||||||
TextTemplate[] templates = new TextTemplate[users.length];
|
TextTemplate[] templates = new TextTemplate[users.length];
|
||||||
for (int i = 0; i < users.length; i++) {
|
for (int i = 0; i < users.length; i++) {
|
||||||
templates[i] = TextTemplate.inline(users[i]).build();
|
templates[i] = new TextTemplate(users[i]);
|
||||||
}
|
}
|
||||||
return addUsers(templates);
|
return addUsers(templates);
|
||||||
}
|
}
|
||||||
|
@ -235,10 +216,6 @@ public class HipChatAction implements Action {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setColor(TextTemplate.Builder color) {
|
|
||||||
return setColor(color.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setColor(HipChatMessage.Color color) {
|
public Builder setColor(HipChatMessage.Color color) {
|
||||||
return setColor(color.asTemplate());
|
return setColor(color.asTemplate());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,6 @@ import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class LoggingAction implements Action {
|
public class LoggingAction implements Action {
|
||||||
|
|
||||||
public static final String TYPE = "logging";
|
public static final String TYPE = "logging";
|
||||||
|
|
|
@ -76,9 +76,6 @@ import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class EmailActionTests extends ESTestCase {
|
public class EmailActionTests extends ESTestCase {
|
||||||
|
|
||||||
private HttpAuthRegistry registry = new HttpAuthRegistry(singletonMap("basic", new BasicAuthFactory(null)));
|
private HttpAuthRegistry registry = new HttpAuthRegistry(singletonMap("basic", new BasicAuthFactory(null)));
|
||||||
|
@ -113,17 +110,17 @@ public class EmailActionTests extends ESTestCase {
|
||||||
EmailTemplate.Builder emailBuilder = EmailTemplate.builder();
|
EmailTemplate.Builder emailBuilder = EmailTemplate.builder();
|
||||||
TextTemplate subject = null;
|
TextTemplate subject = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
subject = TextTemplate.inline("_subject").build();
|
subject = new TextTemplate("_subject");
|
||||||
emailBuilder.subject(subject);
|
emailBuilder.subject(subject);
|
||||||
}
|
}
|
||||||
TextTemplate textBody = null;
|
TextTemplate textBody = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
textBody = TextTemplate.inline("_text_body").build();
|
textBody = new TextTemplate("_text_body");
|
||||||
emailBuilder.textBody(textBody);
|
emailBuilder.textBody(textBody);
|
||||||
}
|
}
|
||||||
TextTemplate htmlBody = null;
|
TextTemplate htmlBody = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
htmlBody = TextTemplate.inline("_html_body").build();
|
htmlBody = new TextTemplate("_html_body");
|
||||||
emailBuilder.htmlBody(htmlBody);
|
emailBuilder.htmlBody(htmlBody);
|
||||||
}
|
}
|
||||||
EmailTemplate email = emailBuilder.build();
|
EmailTemplate email = emailBuilder.build();
|
||||||
|
@ -204,9 +201,9 @@ public class EmailActionTests extends ESTestCase {
|
||||||
randomBoolean() ? "bcc@domain" : "bcc1@domain,bcc2@domain").toArray();
|
randomBoolean() ? "bcc@domain" : "bcc1@domain,bcc2@domain").toArray();
|
||||||
Email.Address[] replyTo = rarely() ? null : Email.AddressList.parse(
|
Email.Address[] replyTo = rarely() ? null : Email.AddressList.parse(
|
||||||
randomBoolean() ? "reply@domain" : "reply1@domain,reply2@domain").toArray();
|
randomBoolean() ? "reply@domain" : "reply1@domain,reply2@domain").toArray();
|
||||||
TextTemplate subject = randomBoolean() ? TextTemplate.inline("_subject").build() : null;
|
TextTemplate subject = randomBoolean() ? new TextTemplate("_subject") : null;
|
||||||
TextTemplate textBody = randomBoolean() ? TextTemplate.inline("_text_body").build() : null;
|
TextTemplate textBody = randomBoolean() ? new TextTemplate("_text_body") : null;
|
||||||
TextTemplate htmlBody = randomBoolean() ? TextTemplate.inline("_text_html").build() : null;
|
TextTemplate htmlBody = randomBoolean() ? new TextTemplate("_text_html") : null;
|
||||||
DataAttachment dataAttachment = randomDataAttachment();
|
DataAttachment dataAttachment = randomDataAttachment();
|
||||||
XContentBuilder builder = jsonBuilder().startObject()
|
XContentBuilder builder = jsonBuilder().startObject()
|
||||||
.field("account", "_account")
|
.field("account", "_account")
|
||||||
|
@ -312,7 +309,7 @@ public class EmailActionTests extends ESTestCase {
|
||||||
assertThat(executable.action().getAuth(), notNullValue());
|
assertThat(executable.action().getAuth(), notNullValue());
|
||||||
assertThat(executable.action().getAuth().user(), is("_user"));
|
assertThat(executable.action().getAuth().user(), is("_user"));
|
||||||
assertThat(executable.action().getAuth().password(), is(new Secret("_passwd".toCharArray())));
|
assertThat(executable.action().getAuth().password(), is(new Secret("_passwd".toCharArray())));
|
||||||
assertThat(executable.action().getEmail().priority(), is(TextTemplate.defaultType(priority.name()).build()));
|
assertThat(executable.action().getEmail().priority(), is(new TextTemplate(priority.name())));
|
||||||
if (to != null) {
|
if (to != null) {
|
||||||
assertThat(executable.action().getEmail().to(), arrayContainingInAnyOrder(addressesToTemplates(to)));
|
assertThat(executable.action().getEmail().to(), arrayContainingInAnyOrder(addressesToTemplates(to)));
|
||||||
} else {
|
} else {
|
||||||
|
@ -338,7 +335,7 @@ public class EmailActionTests extends ESTestCase {
|
||||||
private static TextTemplate[] addressesToTemplates(Email.Address[] addresses) {
|
private static TextTemplate[] addressesToTemplates(Email.Address[] addresses) {
|
||||||
TextTemplate[] templates = new TextTemplate[addresses.length];
|
TextTemplate[] templates = new TextTemplate[addresses.length];
|
||||||
for (int i = 0; i < templates.length; i++) {
|
for (int i = 0; i < templates.length; i++) {
|
||||||
templates[i] = TextTemplate.defaultType(addresses[i].toString()).build();
|
templates[i] = new TextTemplate(addresses[i].toString());
|
||||||
}
|
}
|
||||||
return templates;
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,6 @@ import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class HipChatActionFactoryTests extends ESTestCase {
|
public class HipChatActionFactoryTests extends ESTestCase {
|
||||||
private HipChatActionFactory factory;
|
private HipChatActionFactory factory;
|
||||||
private HipChatService hipchatService;
|
private HipChatService hipchatService;
|
||||||
|
@ -79,20 +76,20 @@ public class HipChatActionFactoryTests extends ESTestCase {
|
||||||
builder.field("account", accountName);
|
builder.field("account", accountName);
|
||||||
builder.startObject("message");
|
builder.startObject("message");
|
||||||
|
|
||||||
TextTemplate body = TextTemplate.inline("_body").build();
|
TextTemplate body = new TextTemplate("_body");
|
||||||
builder.field("body", body);
|
builder.field("body", body);
|
||||||
|
|
||||||
TextTemplate[] rooms = null;
|
TextTemplate[] rooms = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate r1 = TextTemplate.inline("_r1").build();
|
TextTemplate r1 = new TextTemplate("_r1");
|
||||||
TextTemplate r2 = TextTemplate.inline("_r2").build();
|
TextTemplate r2 = new TextTemplate("_r2");
|
||||||
rooms = new TextTemplate[] { r1, r2 };
|
rooms = new TextTemplate[] { r1, r2 };
|
||||||
builder.array("room", r1, r2);
|
builder.array("room", r1, r2);
|
||||||
}
|
}
|
||||||
TextTemplate[] users = null;
|
TextTemplate[] users = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate u1 = TextTemplate.inline("_u1").build();
|
TextTemplate u1 = new TextTemplate("_u1");
|
||||||
TextTemplate u2 = TextTemplate.inline("_u2").build();
|
TextTemplate u2 = new TextTemplate("_u2");
|
||||||
users = new TextTemplate[] { u1, u2 };
|
users = new TextTemplate[] { u1, u2 };
|
||||||
builder.array("user", u1, u2);
|
builder.array("user", u1, u2);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +105,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
TextTemplate color = null;
|
TextTemplate color = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
color = TextTemplate.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
|
color = new TextTemplate(randomFrom(HipChatMessage.Color.values()).value());
|
||||||
builder.field("color", color);
|
builder.field("color", color);
|
||||||
}
|
}
|
||||||
Boolean notify = null;
|
Boolean notify = null;
|
||||||
|
@ -135,7 +132,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
|
||||||
|
|
||||||
public void testParserSelfGenerated() throws Exception {
|
public void testParserSelfGenerated() throws Exception {
|
||||||
String accountName = randomAsciiOfLength(10);
|
String accountName = randomAsciiOfLength(10);
|
||||||
TextTemplate body = TextTemplate.inline("_body").build();
|
TextTemplate body = new TextTemplate("_body");
|
||||||
HipChatMessage.Template.Builder templateBuilder = new HipChatMessage.Template.Builder(body);
|
HipChatMessage.Template.Builder templateBuilder = new HipChatMessage.Template.Builder(body);
|
||||||
|
|
||||||
XContentBuilder builder = jsonBuilder().startObject();
|
XContentBuilder builder = jsonBuilder().startObject();
|
||||||
|
@ -144,14 +141,14 @@ public class HipChatActionFactoryTests extends ESTestCase {
|
||||||
builder.field("body", body);
|
builder.field("body", body);
|
||||||
|
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate r1 = TextTemplate.inline("_r1").build();
|
TextTemplate r1 = new TextTemplate("_r1");
|
||||||
TextTemplate r2 = TextTemplate.inline("_r2").build();
|
TextTemplate r2 = new TextTemplate("_r2");
|
||||||
templateBuilder.addRooms(r1, r2);
|
templateBuilder.addRooms(r1, r2);
|
||||||
builder.array("room", r1, r2);
|
builder.array("room", r1, r2);
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate u1 = TextTemplate.inline("_u1").build();
|
TextTemplate u1 = new TextTemplate("_u1");
|
||||||
TextTemplate u2 = TextTemplate.inline("_u2").build();
|
TextTemplate u2 = new TextTemplate("_u2");
|
||||||
templateBuilder.addUsers(u1, u2);
|
templateBuilder.addUsers(u1, u2);
|
||||||
builder.array("user", u1, u2);
|
builder.array("user", u1, u2);
|
||||||
}
|
}
|
||||||
|
@ -166,7 +163,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
|
||||||
builder.field("format", format.value());
|
builder.field("format", format.value());
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate color = TextTemplate.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
|
TextTemplate color = new TextTemplate(randomFrom(HipChatMessage.Color.values()).value());
|
||||||
templateBuilder.setColor(color);
|
templateBuilder.setColor(color);
|
||||||
builder.field("color", color);
|
builder.field("color", color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,6 @@ import static org.hamcrest.Matchers.sameInstance;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class HipChatActionTests extends ESTestCase {
|
public class HipChatActionTests extends ESTestCase {
|
||||||
private HipChatService service;
|
private HipChatService service;
|
||||||
|
|
||||||
|
@ -61,7 +58,7 @@ public class HipChatActionTests extends ESTestCase {
|
||||||
|
|
||||||
TextTemplateEngine templateEngine = mock(TextTemplateEngine.class);
|
TextTemplateEngine templateEngine = mock(TextTemplateEngine.class);
|
||||||
|
|
||||||
TextTemplate body = TextTemplate.inline("_body").build();
|
TextTemplate body = new TextTemplate("_body");
|
||||||
HipChatMessage.Template.Builder messageBuilder = new HipChatMessage.Template.Builder(body);
|
HipChatMessage.Template.Builder messageBuilder = new HipChatMessage.Template.Builder(body);
|
||||||
|
|
||||||
HipChatMessage.Template messageTemplate = messageBuilder.build();
|
HipChatMessage.Template messageTemplate = messageBuilder.build();
|
||||||
|
@ -129,20 +126,20 @@ public class HipChatActionTests extends ESTestCase {
|
||||||
builder.field("account", accountName);
|
builder.field("account", accountName);
|
||||||
builder.startObject("message");
|
builder.startObject("message");
|
||||||
|
|
||||||
TextTemplate body = TextTemplate.inline("_body").build();
|
TextTemplate body = new TextTemplate("_body");
|
||||||
builder.field("body", body);
|
builder.field("body", body);
|
||||||
|
|
||||||
TextTemplate[] rooms = null;
|
TextTemplate[] rooms = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate r1 = TextTemplate.inline("_r1").build();
|
TextTemplate r1 = new TextTemplate("_r1");
|
||||||
TextTemplate r2 = TextTemplate.inline("_r2").build();
|
TextTemplate r2 = new TextTemplate("_r2");
|
||||||
rooms = new TextTemplate[] { r1, r2 };
|
rooms = new TextTemplate[] { r1, r2 };
|
||||||
builder.array("room", r1, r2);
|
builder.array("room", r1, r2);
|
||||||
}
|
}
|
||||||
TextTemplate[] users = null;
|
TextTemplate[] users = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate u1 = TextTemplate.inline("_u1").build();
|
TextTemplate u1 = new TextTemplate("_u1");
|
||||||
TextTemplate u2 = TextTemplate.inline("_u2").build();
|
TextTemplate u2 = new TextTemplate("_u2");
|
||||||
users = new TextTemplate[] { u1, u2 };
|
users = new TextTemplate[] { u1, u2 };
|
||||||
builder.array("user", u1, u2);
|
builder.array("user", u1, u2);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +155,7 @@ public class HipChatActionTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
TextTemplate color = null;
|
TextTemplate color = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
color = TextTemplate.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
|
color = new TextTemplate(randomFrom(HipChatMessage.Color.values()).value());
|
||||||
builder.field("color", color);
|
builder.field("color", color);
|
||||||
}
|
}
|
||||||
Boolean notify = null;
|
Boolean notify = null;
|
||||||
|
@ -185,7 +182,7 @@ public class HipChatActionTests extends ESTestCase {
|
||||||
|
|
||||||
public void testParserSelfGenerated() throws Exception {
|
public void testParserSelfGenerated() throws Exception {
|
||||||
String accountName = randomAsciiOfLength(10);
|
String accountName = randomAsciiOfLength(10);
|
||||||
TextTemplate body = TextTemplate.inline("_body").build();
|
TextTemplate body = new TextTemplate("_body");
|
||||||
HipChatMessage.Template.Builder templateBuilder = new HipChatMessage.Template.Builder(body);
|
HipChatMessage.Template.Builder templateBuilder = new HipChatMessage.Template.Builder(body);
|
||||||
|
|
||||||
XContentBuilder builder = jsonBuilder().startObject();
|
XContentBuilder builder = jsonBuilder().startObject();
|
||||||
|
@ -194,14 +191,14 @@ public class HipChatActionTests extends ESTestCase {
|
||||||
builder.field("body", body);
|
builder.field("body", body);
|
||||||
|
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate r1 = TextTemplate.inline("_r1").build();
|
TextTemplate r1 = new TextTemplate("_r1");
|
||||||
TextTemplate r2 = TextTemplate.inline("_r2").build();
|
TextTemplate r2 = new TextTemplate("_r2");
|
||||||
templateBuilder.addRooms(r1, r2);
|
templateBuilder.addRooms(r1, r2);
|
||||||
builder.array("room", r1, r2);
|
builder.array("room", r1, r2);
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate u1 = TextTemplate.inline("_u1").build();
|
TextTemplate u1 = new TextTemplate("_u1");
|
||||||
TextTemplate u2 = TextTemplate.inline("_u2").build();
|
TextTemplate u2 = new TextTemplate("_u2");
|
||||||
templateBuilder.addUsers(u1, u2);
|
templateBuilder.addUsers(u1, u2);
|
||||||
builder.array("user", u1, u2);
|
builder.array("user", u1, u2);
|
||||||
}
|
}
|
||||||
|
@ -216,7 +213,7 @@ public class HipChatActionTests extends ESTestCase {
|
||||||
builder.field("format", format.value());
|
builder.field("format", format.value());
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
TextTemplate color = TextTemplate.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
|
TextTemplate color = new TextTemplate(randomFrom(HipChatMessage.Color.values()).value());
|
||||||
templateBuilder.setColor(color);
|
templateBuilder.setColor(color);
|
||||||
builder.field("color", color);
|
builder.field("color", color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class LoggingActionTests extends ESTestCase {
|
||||||
Map<String, Object> expectedModel = singletonMap("ctx", ctxModel);
|
Map<String, Object> expectedModel = singletonMap("ctx", ctxModel);
|
||||||
|
|
||||||
String text = randomAsciiOfLength(10);
|
String text = randomAsciiOfLength(10);
|
||||||
TextTemplate template = TextTemplate.inline(text).build();
|
TextTemplate template = new TextTemplate(text);
|
||||||
LoggingAction action = new LoggingAction(template, level, "_category");
|
LoggingAction action = new LoggingAction(template, level, "_category");
|
||||||
ExecutableLoggingAction executable = new ExecutableLoggingAction(action, logger, actionLogger, engine);
|
ExecutableLoggingAction executable = new ExecutableLoggingAction(action, logger, actionLogger, engine);
|
||||||
when(engine.render(template, expectedModel)).thenReturn(text);
|
when(engine.render(template, expectedModel)).thenReturn(text);
|
||||||
|
@ -97,7 +97,7 @@ public class LoggingActionTests extends ESTestCase {
|
||||||
LoggingActionFactory parser = new LoggingActionFactory(settings, engine);
|
LoggingActionFactory parser = new LoggingActionFactory(settings, engine);
|
||||||
|
|
||||||
String text = randomAsciiOfLength(10);
|
String text = randomAsciiOfLength(10);
|
||||||
TextTemplate template = TextTemplate.inline(text).build();
|
TextTemplate template = new TextTemplate(text);
|
||||||
|
|
||||||
XContentBuilder builder = jsonBuilder().startObject();
|
XContentBuilder builder = jsonBuilder().startObject();
|
||||||
builder.field("text", template);
|
builder.field("text", template);
|
||||||
|
@ -131,7 +131,7 @@ public class LoggingActionTests extends ESTestCase {
|
||||||
LoggingActionFactory parser = new LoggingActionFactory(settings, engine);
|
LoggingActionFactory parser = new LoggingActionFactory(settings, engine);
|
||||||
|
|
||||||
String text = randomAsciiOfLength(10);
|
String text = randomAsciiOfLength(10);
|
||||||
TextTemplate template = TextTemplate.inline(text).build();
|
TextTemplate template = new TextTemplate(text);
|
||||||
String category = randomAsciiOfLength(10);
|
String category = randomAsciiOfLength(10);
|
||||||
LoggingAction action = new LoggingAction(template, level, category);
|
LoggingAction action = new LoggingAction(template, level, category);
|
||||||
ExecutableLoggingAction executable = new ExecutableLoggingAction(action, logger, settings, engine);
|
ExecutableLoggingAction executable = new ExecutableLoggingAction(action, logger, settings, engine);
|
||||||
|
@ -151,7 +151,7 @@ public class LoggingActionTests extends ESTestCase {
|
||||||
LoggingActionFactory parser = new LoggingActionFactory(settings, engine);
|
LoggingActionFactory parser = new LoggingActionFactory(settings, engine);
|
||||||
|
|
||||||
String text = randomAsciiOfLength(10);
|
String text = randomAsciiOfLength(10);
|
||||||
TextTemplate template = TextTemplate.inline(text).build();
|
TextTemplate template = new TextTemplate(text);
|
||||||
LoggingAction.Builder actionBuilder = loggingAction(template);
|
LoggingAction.Builder actionBuilder = loggingAction(template);
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
actionBuilder.setCategory(randomAsciiOfLength(10));
|
actionBuilder.setCategory(randomAsciiOfLength(10));
|
||||||
|
|
|
@ -47,9 +47,6 @@ import static org.hamcrest.Matchers.sameInstance;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class PagerDutyActionTests extends ESTestCase {
|
public class PagerDutyActionTests extends ESTestCase {
|
||||||
|
|
||||||
private PagerDutyService service;
|
private PagerDutyService service;
|
||||||
|
@ -64,7 +61,7 @@ public class PagerDutyActionTests extends ESTestCase {
|
||||||
|
|
||||||
TextTemplateEngine templateEngine = mock(TextTemplateEngine.class);
|
TextTemplateEngine templateEngine = mock(TextTemplateEngine.class);
|
||||||
|
|
||||||
TextTemplate description = TextTemplate.inline("_description").build();
|
TextTemplate description = new TextTemplate("_description");
|
||||||
IncidentEvent.Template.Builder eventBuilder = new IncidentEvent.Template.Builder(description);
|
IncidentEvent.Template.Builder eventBuilder = new IncidentEvent.Template.Builder(description);
|
||||||
boolean attachPayload = randomBoolean();
|
boolean attachPayload = randomBoolean();
|
||||||
eventBuilder.setAttachPayload(attachPayload);
|
eventBuilder.setAttachPayload(attachPayload);
|
||||||
|
@ -133,31 +130,31 @@ public class PagerDutyActionTests extends ESTestCase {
|
||||||
|
|
||||||
TextTemplate incidentKey = null;
|
TextTemplate incidentKey = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
incidentKey = TextTemplate.inline("_incident_key").build();
|
incidentKey = new TextTemplate("_incident_key");
|
||||||
builder.field("incident_key", incidentKey);
|
builder.field("incident_key", incidentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextTemplate description = null;
|
TextTemplate description = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
description = TextTemplate.inline("_description").build();
|
description = new TextTemplate("_description");
|
||||||
builder.field("description", description);
|
builder.field("description", description);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextTemplate client = null;
|
TextTemplate client = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
client = TextTemplate.inline("_client").build();
|
client = new TextTemplate("_client");
|
||||||
builder.field("client", client);
|
builder.field("client", client);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextTemplate clientUrl = null;
|
TextTemplate clientUrl = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
clientUrl = TextTemplate.inline("_client_url").build();
|
clientUrl = new TextTemplate("_client_url");
|
||||||
builder.field("client_url", clientUrl);
|
builder.field("client_url", clientUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextTemplate eventType = null;
|
TextTemplate eventType = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
eventType = TextTemplate.inline(randomFrom("trigger", "resolve", "acknowledge")).build();
|
eventType = new TextTemplate(randomFrom("trigger", "resolve", "acknowledge"));
|
||||||
builder.field("event_type", eventType);
|
builder.field("event_type", eventType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,9 +166,8 @@ public class PagerDutyActionTests extends ESTestCase {
|
||||||
IncidentEventContext.Template[] contexts = null;
|
IncidentEventContext.Template[] contexts = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
contexts = new IncidentEventContext.Template[] {
|
contexts = new IncidentEventContext.Template[] {
|
||||||
IncidentEventContext.Template.link(TextTemplate.inline("_href").build(), TextTemplate.inline("_text").build()),
|
IncidentEventContext.Template.link(new TextTemplate("_href"), new TextTemplate("_text")),
|
||||||
IncidentEventContext.Template.image(TextTemplate.inline("_src").build(), TextTemplate.inline("_href").build(),
|
IncidentEventContext.Template.image(new TextTemplate("_src"), new TextTemplate("_href"), new TextTemplate("_alt"))
|
||||||
TextTemplate.inline("_alt").build())
|
|
||||||
};
|
};
|
||||||
builder.array("context", (Object) contexts);
|
builder.array("context", (Object) contexts);
|
||||||
}
|
}
|
||||||
|
@ -197,27 +193,26 @@ public class PagerDutyActionTests extends ESTestCase {
|
||||||
IncidentEvent.Template.Builder event = IncidentEvent.templateBuilder(randomAsciiOfLength(50));
|
IncidentEvent.Template.Builder event = IncidentEvent.templateBuilder(randomAsciiOfLength(50));
|
||||||
|
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
event.setIncidentKey(TextTemplate.inline(randomAsciiOfLength(50)).build());
|
event.setIncidentKey(new TextTemplate(randomAsciiOfLength(50)));
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
event.setClient(TextTemplate.inline(randomAsciiOfLength(50)).build());
|
event.setClient(new TextTemplate(randomAsciiOfLength(50)));
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
event.setClientUrl(TextTemplate.inline(randomAsciiOfLength(50)).build());
|
event.setClientUrl(new TextTemplate(randomAsciiOfLength(50)));
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
event.setAttachPayload(randomBoolean());
|
event.setAttachPayload(randomBoolean());
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
event.addContext(IncidentEventContext.Template.link(TextTemplate.inline("_href").build(),
|
event.addContext(IncidentEventContext.Template.link(new TextTemplate("_href"), new TextTemplate("_text")));
|
||||||
TextTemplate.inline("_text").build()));
|
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
event.addContext(IncidentEventContext.Template.image(TextTemplate.inline("_src").build(),
|
event.addContext(IncidentEventContext.Template.image(new TextTemplate("_src"), new TextTemplate("_href"),
|
||||||
TextTemplate.inline("_href").build(), TextTemplate.inline("_alt").build()));
|
new TextTemplate("_alt")));
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
event.setEventType(TextTemplate.inline(randomAsciiOfLength(50)).build());
|
event.setEventType(new TextTemplate(randomAsciiOfLength(50)));
|
||||||
}
|
}
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
event.setAccount(randomAsciiOfLength(50)).build();
|
event.setAccount(randomAsciiOfLength(50)).build();
|
||||||
|
|
|
@ -399,8 +399,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase {
|
||||||
LOGGING {
|
LOGGING {
|
||||||
@Override
|
@Override
|
||||||
public Action.Builder action() throws Exception {
|
public Action.Builder action() throws Exception {
|
||||||
TextTemplate.Builder templateBuilder = new TextTemplate.Builder.Inline("_logging");
|
return LoggingAction.builder(new TextTemplate("_logging"));
|
||||||
return LoggingAction.builder(templateBuilder.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -67,9 +67,6 @@ import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class WebhookActionTests extends ESTestCase {
|
public class WebhookActionTests extends ESTestCase {
|
||||||
|
|
||||||
static final String TEST_HOST = "test.com";
|
static final String TEST_HOST = "test.com";
|
||||||
|
@ -87,8 +84,8 @@ public class WebhookActionTests extends ESTestCase {
|
||||||
@Before
|
@Before
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
templateEngine = new MockTextTemplateEngine();
|
templateEngine = new MockTextTemplateEngine();
|
||||||
testBody = TextTemplate.inline(TEST_BODY_STRING).build();
|
testBody = new TextTemplate(TEST_BODY_STRING);
|
||||||
testPath = TextTemplate.inline(TEST_PATH_STRING).build();
|
testPath = new TextTemplate(TEST_PATH_STRING);
|
||||||
authRegistry = new HttpAuthRegistry(singletonMap("basic", new BasicAuthFactory(null)));
|
authRegistry = new HttpAuthRegistry(singletonMap("basic", new BasicAuthFactory(null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,8 +125,8 @@ public class WebhookActionTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParser() throws Exception {
|
public void testParser() throws Exception {
|
||||||
TextTemplate body = randomBoolean() ? TextTemplate.inline("_subject").build() : null;
|
TextTemplate body = randomBoolean() ? new TextTemplate("_subject") : null;
|
||||||
TextTemplate path = TextTemplate.inline("_url").build();
|
TextTemplate path = new TextTemplate("_url");
|
||||||
String host = "test.host";
|
String host = "test.host";
|
||||||
HttpMethod method = randomFrom(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.HEAD, null);
|
HttpMethod method = randomFrom(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.HEAD, null);
|
||||||
HttpRequestTemplate request = getHttpRequestTemplate(method, host, TEST_PORT, path, body, null);
|
HttpRequestTemplate request = getHttpRequestTemplate(method, host, TEST_PORT, path, body, null);
|
||||||
|
@ -148,8 +145,8 @@ public class WebhookActionTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParserSelfGenerated() throws Exception {
|
public void testParserSelfGenerated() throws Exception {
|
||||||
TextTemplate body = randomBoolean() ? TextTemplate.inline("_body").build() : null;
|
TextTemplate body = randomBoolean() ? new TextTemplate("_body") : null;
|
||||||
TextTemplate path = TextTemplate.inline("_url").build();
|
TextTemplate path = new TextTemplate("_url");
|
||||||
String host = "test.host";
|
String host = "test.host";
|
||||||
String watchId = "_watch";
|
String watchId = "_watch";
|
||||||
String actionId = randomAsciiOfLength(5);
|
String actionId = randomAsciiOfLength(5);
|
||||||
|
@ -174,8 +171,8 @@ public class WebhookActionTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParserBuilder() throws Exception {
|
public void testParserBuilder() throws Exception {
|
||||||
TextTemplate body = randomBoolean() ? TextTemplate.inline("_body").build() : null;
|
TextTemplate body = randomBoolean() ? new TextTemplate("_body") : null;
|
||||||
TextTemplate path = TextTemplate.inline("_url").build();
|
TextTemplate path = new TextTemplate("_url");
|
||||||
String host = "test.host";
|
String host = "test.host";
|
||||||
|
|
||||||
String watchId = "_watch";
|
String watchId = "_watch";
|
||||||
|
@ -257,9 +254,9 @@ public class WebhookActionTests extends ESTestCase {
|
||||||
String watchId = "test_url_encode" + randomAsciiOfLength(10);
|
String watchId = "test_url_encode" + randomAsciiOfLength(10);
|
||||||
|
|
||||||
HttpMethod method = HttpMethod.POST;
|
HttpMethod method = HttpMethod.POST;
|
||||||
TextTemplate path = TextTemplate.defaultType("/test_" + watchId).build();
|
TextTemplate path = new TextTemplate("/test_" + watchId);
|
||||||
String host = "test.host";
|
String host = "test.host";
|
||||||
TextTemplate testBody = TextTemplate.inline("ERROR HAPPENED").build();
|
TextTemplate testBody = new TextTemplate("ERROR HAPPENED");
|
||||||
HttpRequestTemplate requestTemplate = getHttpRequestTemplate(method, host, TEST_PORT, path, testBody, null);
|
HttpRequestTemplate requestTemplate = getHttpRequestTemplate(method, host, TEST_PORT, path, testBody, null);
|
||||||
WebhookAction action = new WebhookAction(requestTemplate);
|
WebhookAction action = new WebhookAction(requestTemplate);
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,8 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
|
||||||
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
|
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
|
||||||
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
|
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
|
||||||
.scheme(Scheme.HTTPS)
|
.scheme(Scheme.HTTPS)
|
||||||
.path(TextTemplate.inline("/test/_id").build())
|
.path(new TextTemplate("/test/_id"))
|
||||||
.body(TextTemplate.inline("{key=value}").build());
|
.body(new TextTemplate("{key=value}"));
|
||||||
|
|
||||||
watcherClient().preparePutWatch("_id")
|
watcherClient().preparePutWatch("_id")
|
||||||
.setSource(watchBuilder()
|
.setSource(watchBuilder()
|
||||||
|
@ -127,8 +127,8 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
|
||||||
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
|
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
|
||||||
.scheme(Scheme.HTTPS)
|
.scheme(Scheme.HTTPS)
|
||||||
.auth(new BasicAuth("_username", "_password".toCharArray()))
|
.auth(new BasicAuth("_username", "_password".toCharArray()))
|
||||||
.path(TextTemplate.inline("/test/_id").build())
|
.path(new TextTemplate("/test/_id"))
|
||||||
.body(TextTemplate.inline("{key=value}").build());
|
.body(new TextTemplate("{key=value}"));
|
||||||
|
|
||||||
watcherClient().preparePutWatch("_id")
|
watcherClient().preparePutWatch("_id")
|
||||||
.setSource(watchBuilder()
|
.setSource(watchBuilder()
|
||||||
|
|
|
@ -39,8 +39,6 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class WebhookIntegrationTests extends AbstractWatcherIntegrationTestCase {
|
public class WebhookIntegrationTests extends AbstractWatcherIntegrationTestCase {
|
||||||
private int webPort;
|
private int webPort;
|
||||||
private MockWebServer webServer;
|
private MockWebServer webServer;
|
||||||
|
@ -70,10 +68,10 @@ public class WebhookIntegrationTests extends AbstractWatcherIntegrationTestCase
|
||||||
public void testWebhook() throws Exception {
|
public void testWebhook() throws Exception {
|
||||||
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
|
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
|
||||||
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
|
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
|
||||||
.path(TextTemplate.inline("/test/_id"))
|
.path(new TextTemplate("/test/_id"))
|
||||||
.putParam("param1", TextTemplate.inline("value1"))
|
.putParam("param1", new TextTemplate("value1"))
|
||||||
.putParam("watch_id", TextTemplate.inline("_id"))
|
.putParam("watch_id", new TextTemplate("_id"))
|
||||||
.body(TextTemplate.inline("_body"));
|
.body(new TextTemplate("_body"));
|
||||||
|
|
||||||
watcherClient().preparePutWatch("_id")
|
watcherClient().preparePutWatch("_id")
|
||||||
.setSource(watchBuilder()
|
.setSource(watchBuilder()
|
||||||
|
@ -115,10 +113,10 @@ public class WebhookIntegrationTests extends AbstractWatcherIntegrationTestCase
|
||||||
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
|
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
|
||||||
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
|
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
|
||||||
.auth(new BasicAuth("_username", "_password".toCharArray()))
|
.auth(new BasicAuth("_username", "_password".toCharArray()))
|
||||||
.path(TextTemplate.inline("/test/_id").build())
|
.path(new TextTemplate("/test/_id"))
|
||||||
.putParam("param1", TextTemplate.inline("value1").build())
|
.putParam("param1", new TextTemplate("value1"))
|
||||||
.putParam("watch_id", TextTemplate.inline("_id").build())
|
.putParam("watch_id", new TextTemplate("_id"))
|
||||||
.body(TextTemplate.inline("_body").build());
|
.body(new TextTemplate("_body"));
|
||||||
|
|
||||||
watcherClient().preparePutWatch("_id")
|
watcherClient().preparePutWatch("_id")
|
||||||
.setSource(watchBuilder()
|
.setSource(watchBuilder()
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class ChainInputTests extends ESTestCase {
|
||||||
|
|
||||||
HttpInput.Builder httpInputBuilder = httpInput(HttpRequestTemplate.builder("theHost", 1234)
|
HttpInput.Builder httpInputBuilder = httpInput(HttpRequestTemplate.builder("theHost", 1234)
|
||||||
.path("/index/_search")
|
.path("/index/_search")
|
||||||
.body(jsonBuilder().startObject().field("size", 1).endObject())
|
.body(jsonBuilder().startObject().field("size", 1).endObject().string())
|
||||||
.auth(new BasicAuth("test", "changeme".toCharArray())));
|
.auth(new BasicAuth("test", "changeme".toCharArray())));
|
||||||
|
|
||||||
ChainInput.Builder chainedInputBuilder = chainInput()
|
ChainInput.Builder chainedInputBuilder = chainInput()
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class ChainIntegrationTests extends AbstractWatcherIntegrationTestCase {
|
||||||
InetSocketAddress address = internalCluster().httpAddresses()[0];
|
InetSocketAddress address = internalCluster().httpAddresses()[0];
|
||||||
HttpInput.Builder httpInputBuilder = httpInput(HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
HttpInput.Builder httpInputBuilder = httpInput(HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
||||||
.path("/" + index + "/_search")
|
.path("/" + index + "/_search")
|
||||||
.body(jsonBuilder().startObject().field("size", 1).endObject())
|
.body(jsonBuilder().startObject().field("size", 1).endObject().string())
|
||||||
.auth(securityEnabled() ? new BasicAuth("test", "changeme".toCharArray()) : null));
|
.auth(securityEnabled() ? new BasicAuth("test", "changeme".toCharArray()) : null));
|
||||||
|
|
||||||
ChainInput.Builder chainedInputBuilder = chainInput()
|
ChainInput.Builder chainedInputBuilder = chainInput()
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
||||||
.trigger(schedule(interval("5s")))
|
.trigger(schedule(interval("5s")))
|
||||||
.input(httpInput(HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
.input(httpInput(HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
||||||
.path("/index/_search")
|
.path("/index/_search")
|
||||||
.body(jsonBuilder().startObject().field("size", 1).endObject())
|
.body(jsonBuilder().startObject().field("size", 1).endObject().string())
|
||||||
.auth(securityEnabled() ? new BasicAuth("test", "changeme".toCharArray()) : null)))
|
.auth(securityEnabled() ? new BasicAuth("test", "changeme".toCharArray()) : null)))
|
||||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||||
.addAction("_id", loggingAction("watch [{{ctx.watch_id}}] matched")))
|
.addAction("_id", loggingAction("watch [{{ctx.watch_id}}] matched")))
|
||||||
|
@ -117,8 +117,8 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
||||||
.field("query").value(termQuery("field", "value"))
|
.field("query").value(termQuery("field", "value"))
|
||||||
.endObject();
|
.endObject();
|
||||||
HttpRequestTemplate.Builder requestBuilder = HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
HttpRequestTemplate.Builder requestBuilder = HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
||||||
.path(TextTemplate.inline("/idx/_search"))
|
.path(new TextTemplate("/idx/_search"))
|
||||||
.body(body);
|
.body(body.string());
|
||||||
if (securityEnabled()) {
|
if (securityEnabled()) {
|
||||||
requestBuilder.auth(new BasicAuth("test", "changeme".toCharArray()));
|
requestBuilder.auth(new BasicAuth("test", "changeme".toCharArray()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,6 @@ import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class HttpInputTests extends ESTestCase {
|
public class HttpInputTests extends ESTestCase {
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
private HttpInputFactory httpParser;
|
private HttpInputFactory httpParser;
|
||||||
|
@ -123,7 +121,7 @@ public class HttpInputTests extends ESTestCase {
|
||||||
|
|
||||||
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine);
|
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine);
|
||||||
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
|
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
|
||||||
when(templateEngine.render(eq(TextTemplate.inline("_body").build()), any(Map.class))).thenReturn("_body");
|
when(templateEngine.render(eq(new TextTemplate("_body")), any(Map.class))).thenReturn("_body");
|
||||||
|
|
||||||
WatchExecutionContext ctx = createWatchExecutionContext();
|
WatchExecutionContext ctx = createWatchExecutionContext();
|
||||||
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
|
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
|
||||||
|
@ -142,7 +140,7 @@ public class HttpInputTests extends ESTestCase {
|
||||||
String notJson = "This is not json";
|
String notJson = "This is not json";
|
||||||
HttpResponse response = new HttpResponse(123, notJson.getBytes(StandardCharsets.UTF_8));
|
HttpResponse response = new HttpResponse(123, notJson.getBytes(StandardCharsets.UTF_8));
|
||||||
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
|
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
|
||||||
when(templateEngine.render(eq(TextTemplate.inline("_body").build()), any(Map.class))).thenReturn("_body");
|
when(templateEngine.render(eq(new TextTemplate("_body")), any(Map.class))).thenReturn("_body");
|
||||||
|
|
||||||
WatchExecutionContext ctx = createWatchExecutionContext();
|
WatchExecutionContext ctx = createWatchExecutionContext();
|
||||||
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
|
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
|
||||||
|
@ -156,18 +154,18 @@ public class HttpInputTests extends ESTestCase {
|
||||||
String host = randomAsciiOfLength(3);
|
String host = randomAsciiOfLength(3);
|
||||||
int port = randomIntBetween(8000, 9000);
|
int port = randomIntBetween(8000, 9000);
|
||||||
String path = randomAsciiOfLength(3);
|
String path = randomAsciiOfLength(3);
|
||||||
TextTemplate pathTemplate = TextTemplate.inline(path).build();
|
TextTemplate pathTemplate = new TextTemplate(path);
|
||||||
String body = randomBoolean() ? randomAsciiOfLength(3) : null;
|
String body = randomBoolean() ? randomAsciiOfLength(3) : null;
|
||||||
Map<String, TextTemplate> params =
|
Map<String, TextTemplate> params =
|
||||||
randomBoolean() ? new MapBuilder<String, TextTemplate>().put("a", TextTemplate.inline("b").build()).map() : null;
|
randomBoolean() ? new MapBuilder<String, TextTemplate>().put("a", new TextTemplate("b")).map() : null;
|
||||||
Map<String, TextTemplate> headers =
|
Map<String, TextTemplate> headers =
|
||||||
randomBoolean() ? new MapBuilder<String, TextTemplate>().put("c", TextTemplate.inline("d").build()).map() : null;
|
randomBoolean() ? new MapBuilder<String, TextTemplate>().put("c", new TextTemplate("d")).map() : null;
|
||||||
HttpAuth auth = randomBoolean() ? new BasicAuth("username", "password".toCharArray()) : null;
|
HttpAuth auth = randomBoolean() ? new BasicAuth("username", "password".toCharArray()) : null;
|
||||||
HttpRequestTemplate.Builder requestBuilder = HttpRequestTemplate.builder(host, port)
|
HttpRequestTemplate.Builder requestBuilder = HttpRequestTemplate.builder(host, port)
|
||||||
.scheme(scheme)
|
.scheme(scheme)
|
||||||
.method(httpMethod)
|
.method(httpMethod)
|
||||||
.path(pathTemplate)
|
.path(pathTemplate)
|
||||||
.body(body != null ? TextTemplate.inline(body).build() : null)
|
.body(body != null ? new TextTemplate(body) : null)
|
||||||
.auth(auth);
|
.auth(auth);
|
||||||
|
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
|
@ -197,7 +195,7 @@ public class HttpInputTests extends ESTestCase {
|
||||||
assertThat(result.getRequest().method(), equalTo(httpMethod != null ? httpMethod : HttpMethod.GET)); // get is the default
|
assertThat(result.getRequest().method(), equalTo(httpMethod != null ? httpMethod : HttpMethod.GET)); // get is the default
|
||||||
assertThat(result.getRequest().host(), equalTo(host));
|
assertThat(result.getRequest().host(), equalTo(host));
|
||||||
assertThat(result.getRequest().port(), equalTo(port));
|
assertThat(result.getRequest().port(), equalTo(port));
|
||||||
assertThat(result.getRequest().path(), is(TextTemplate.inline(path).build()));
|
assertThat(result.getRequest().path(), is(new TextTemplate(path)));
|
||||||
assertThat(result.getExpectedResponseXContentType(), equalTo(expectedResponseXContentType));
|
assertThat(result.getExpectedResponseXContentType(), equalTo(expectedResponseXContentType));
|
||||||
if (expectedResponseXContentType != HttpContentType.TEXT && extractKeys != null) {
|
if (expectedResponseXContentType != HttpContentType.TEXT && extractKeys != null) {
|
||||||
for (String key : extractKeys) {
|
for (String key : extractKeys) {
|
||||||
|
@ -205,14 +203,14 @@ public class HttpInputTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
assertThat(result.getRequest().params(), hasEntry(is("a"), is(TextTemplate.inline("b").build())));
|
assertThat(result.getRequest().params(), hasEntry(is("a"), is(new TextTemplate("b"))));
|
||||||
}
|
}
|
||||||
if (headers != null) {
|
if (headers != null) {
|
||||||
assertThat(result.getRequest().headers(), hasEntry(is("c"), is(TextTemplate.inline("d").build())));
|
assertThat(result.getRequest().headers(), hasEntry(is("c"), is(new TextTemplate("d"))));
|
||||||
}
|
}
|
||||||
assertThat(result.getRequest().auth(), equalTo(auth));
|
assertThat(result.getRequest().auth(), equalTo(auth));
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
assertThat(result.getRequest().body(), is(TextTemplate.inline(body).build()));
|
assertThat(result.getRequest().body(), is(new TextTemplate(body)));
|
||||||
} else {
|
} else {
|
||||||
assertThat(result.getRequest().body(), nullValue());
|
assertThat(result.getRequest().body(), nullValue());
|
||||||
}
|
}
|
||||||
|
@ -256,7 +254,7 @@ public class HttpInputTests extends ESTestCase {
|
||||||
|
|
||||||
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
|
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
|
||||||
|
|
||||||
when(templateEngine.render(eq(TextTemplate.inline("_body").build()), any(Map.class))).thenReturn("_body");
|
when(templateEngine.render(eq(new TextTemplate("_body")), any(Map.class))).thenReturn("_body");
|
||||||
|
|
||||||
WatchExecutionContext ctx = createWatchExecutionContext();
|
WatchExecutionContext ctx = createWatchExecutionContext();
|
||||||
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
|
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
|
||||||
|
|
|
@ -17,11 +17,11 @@ public class MockTextTemplateEngine extends TextTemplateEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String render(TextTemplate template, Map<String, Object> model) {
|
public String render(TextTemplate textTemplate, Map<String, Object> model) {
|
||||||
if (template == null ) {
|
if (textTemplate == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return template.getTemplate();
|
return textTemplate.getTemplate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
import org.elasticsearch.watcher.ResourceWatcherService;
|
||||||
import org.elasticsearch.xpack.XPackPlugin;
|
|
||||||
import org.elasticsearch.xpack.common.http.HttpClient;
|
import org.elasticsearch.xpack.common.http.HttpClient;
|
||||||
import org.elasticsearch.xpack.common.http.HttpMethod;
|
import org.elasticsearch.xpack.common.http.HttpMethod;
|
||||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||||
|
@ -191,9 +190,9 @@ public final class WatcherTestUtils {
|
||||||
HttpRequestTemplate.Builder httpRequest = HttpRequestTemplate.builder("localhost", 80);
|
HttpRequestTemplate.Builder httpRequest = HttpRequestTemplate.builder("localhost", 80);
|
||||||
httpRequest.method(HttpMethod.POST);
|
httpRequest.method(HttpMethod.POST);
|
||||||
|
|
||||||
TextTemplate path = TextTemplate.inline("/foobarbaz/{{ctx.watch_id}}").build();
|
TextTemplate path = new TextTemplate("/foobarbaz/{{ctx.watch_id}}");
|
||||||
httpRequest.path(path);
|
httpRequest.path(path);
|
||||||
TextTemplate body = TextTemplate.inline("{{ctx.watch_id}} executed with {{ctx.payload.response.hits.total_hits}} hits").build();
|
TextTemplate body = new TextTemplate("{{ctx.watch_id}} executed with {{ctx.payload.response.hits.total_hits}} hits");
|
||||||
httpRequest.body(body);
|
httpRequest.body(body);
|
||||||
|
|
||||||
TextTemplateEngine engine = new MockTextTemplateEngine();
|
TextTemplateEngine engine = new MockTextTemplateEngine();
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class SearchTransformTests extends ESIntegTestCase {
|
||||||
builder.field("search_type", searchType.name());
|
builder.field("search_type", searchType.name());
|
||||||
}
|
}
|
||||||
if (templateName != null) {
|
if (templateName != null) {
|
||||||
TextTemplate template = TextTemplate.file(templateName).build();
|
TextTemplate template = new TextTemplate(templateName, null, ScriptService.ScriptType.FILE, null);
|
||||||
builder.field("template", template);
|
builder.field("template", template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class WatchMetadataTests extends AbstractWatcherIntegrationTestCase {
|
||||||
metadata.put("foo", "bar");
|
metadata.put("foo", "bar");
|
||||||
metadata.put("logtext", "This is a test");
|
metadata.put("logtext", "This is a test");
|
||||||
|
|
||||||
LoggingAction.Builder loggingAction = loggingAction(TextTemplate.inline("_logging"))
|
LoggingAction.Builder loggingAction = loggingAction(new TextTemplate("_logging"))
|
||||||
.setLevel(LoggingLevel.DEBUG)
|
.setLevel(LoggingLevel.DEBUG)
|
||||||
.setCategory("test");
|
.setCategory("test");
|
||||||
|
|
||||||
|
|
|
@ -440,7 +440,7 @@ public class WatchTests extends ESTestCase {
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
HttpRequestTemplate httpRequest = HttpRequestTemplate.builder("test.host", randomIntBetween(8000, 9000))
|
HttpRequestTemplate httpRequest = HttpRequestTemplate.builder("test.host", randomIntBetween(8000, 9000))
|
||||||
.method(randomFrom(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT))
|
.method(randomFrom(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT))
|
||||||
.path(TextTemplate.inline("_url").build())
|
.path(new TextTemplate("_url"))
|
||||||
.build();
|
.build();
|
||||||
WebhookAction action = new WebhookAction(httpRequest);
|
WebhookAction action = new WebhookAction(httpRequest);
|
||||||
list.add(new ActionWrapper("_webhook_" + randomAsciiOfLength(8), randomThrottler(), randomCondition(), randomTransform(),
|
list.add(new ActionWrapper("_webhook_" + randomAsciiOfLength(8), randomThrottler(), randomCondition(), randomTransform(),
|
||||||
|
|
Loading…
Reference in New Issue