Merge branch 'master' into migrate_to_strict_settings
Original commit: elastic/x-pack-elasticsearch@608c37fa4c
This commit is contained in:
commit
610bd8c820
|
@ -3,16 +3,26 @@
|
|||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.watcher.actions.hipchat.service;
|
||||
package org.elasticsearch.messy.tests;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockMustacheScriptEngine;
|
||||
import org.elasticsearch.script.mustache.MustachePlugin;
|
||||
import org.elasticsearch.test.junit.annotations.Network;
|
||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||
import org.elasticsearch.watcher.actions.hipchat.HipChatAction;
|
||||
import org.elasticsearch.watcher.actions.hipchat.service.HipChatAccount;
|
||||
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage;
|
||||
import org.elasticsearch.watcher.actions.hipchat.service.HipChatService;
|
||||
import org.elasticsearch.watcher.actions.hipchat.service.SentMessages;
|
||||
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
|
@ -42,6 +52,20 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> getMockPlugins() {
|
||||
Collection<Class<? extends Plugin>> mockPlugins = super.getMockPlugins();
|
||||
mockPlugins.remove(MockMustacheScriptEngine.TestPlugin.class);
|
||||
return mockPlugins;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Class<? extends Plugin>> pluginTypes() {
|
||||
List<Class<? extends Plugin>> types = super.pluginTypes();
|
||||
types.add(MustachePlugin.class);
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.builder()
|
||||
|
@ -65,7 +89,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
public void testSendMessageV1Account() throws Exception {
|
||||
HipChatService service = getInstanceFromMaster(HipChatService.class);
|
||||
HipChatMessage hipChatMessage = new HipChatMessage(
|
||||
"/code HipChatServiceIT#testSendMessage_V1Account",
|
||||
"/code HipChatServiceTests#testSendMessage_V1Account",
|
||||
new String[] { "test-watcher", "test-watcher-2" },
|
||||
null, // users are unsupported in v1
|
||||
"watcher-tests",
|
||||
|
@ -83,7 +107,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
HipChatService service = getInstanceFromMaster(HipChatService.class);
|
||||
HipChatMessage.Color color = randomFrom(HipChatMessage.Color.values());
|
||||
HipChatMessage hipChatMessage = new HipChatMessage(
|
||||
"/code HipChatServiceIT#testSendMessage_IntegrationAccount colored " + color.value(),
|
||||
"/code HipChatServiceTests#testSendMessage_IntegrationAccount colored " + color.value(),
|
||||
null, // custom rooms are unsupported by integration profiles
|
||||
null, // users are unsupported by integration profiles
|
||||
null, // custom "from" is not supported by integration profiles
|
||||
|
@ -101,7 +125,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
HipChatService service = getInstanceFromMaster(HipChatService.class);
|
||||
HipChatMessage.Color color = randomFrom(HipChatMessage.Color.values());
|
||||
HipChatMessage hipChatMessage = new HipChatMessage(
|
||||
"/code HipChatServiceIT#testSendMessage_UserAccount colored " + color.value(),
|
||||
"/code HipChatServiceTests#testSendMessage_UserAccount colored " + color.value(),
|
||||
new String[] { "test-watcher", "test-watcher-2" },
|
||||
new String[] { "watcher@elastic.co" },
|
||||
null, // custom "from" is not supported by integration profiles
|
||||
|
@ -123,7 +147,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
switch (profile) {
|
||||
case USER:
|
||||
account = "user_account";
|
||||
actionBuilder = hipchatAction(account, "/code HipChatServiceIT#testWatchWithHipChatAction")
|
||||
actionBuilder = hipchatAction(account, "/code {{ctx.payload.ref}}")
|
||||
.addRooms("test-watcher", "test-watcher-2")
|
||||
.addUsers("watcher@elastic.co")
|
||||
.setFormat(HipChatMessage.Format.TEXT)
|
||||
|
@ -133,7 +157,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
|
||||
case INTEGRATION:
|
||||
account = "integration_account";
|
||||
actionBuilder = hipchatAction(account, "/code HipChatServiceIT#testWatchWithHipChatAction")
|
||||
actionBuilder = hipchatAction(account, "/code {{ctx.payload.ref}}")
|
||||
.setFormat(HipChatMessage.Format.TEXT)
|
||||
.setColor(color)
|
||||
.setNotify(false);
|
||||
|
@ -142,7 +166,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
default:
|
||||
assertThat(profile, is(HipChatAccount.Profile.V1));
|
||||
account = "v1_account";
|
||||
actionBuilder = hipchatAction(account, "/code HipChatServiceIT#testWatchWithHipChatAction")
|
||||
actionBuilder = hipchatAction(account, "/code {{ctx.payload.ref}}")
|
||||
.addRooms("test-watcher", "test-watcher-2")
|
||||
.setFrom("watcher-test")
|
||||
.setFormat(HipChatMessage.Format.TEXT)
|
||||
|
@ -152,7 +176,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
|
||||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("10m")))
|
||||
.input(simpleInput("ref", "HipChatServiceIT#testWatchWithHipChatAction"))
|
||||
.input(simpleInput("ref", "HipChatServiceTests#testWatchWithHipChatAction"))
|
||||
.condition(alwaysCondition())
|
||||
.addAction("hipchat", actionBuilder))
|
||||
.execute().get();
|
||||
|
@ -179,10 +203,10 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
private void assertSentMessagesAreValid(int expectedMessageSize, SentMessages messages) {
|
||||
assertThat(messages.count(), is(expectedMessageSize));
|
||||
for (SentMessages.SentMessage message : messages) {
|
||||
assertThat("Expected no failures, but got [" + message.failureReason + "]", message.successful(), is(true));
|
||||
assertThat(message.request, notNullValue());
|
||||
assertThat(message.response, notNullValue());
|
||||
assertThat(message.response.status(), lessThan(300));
|
||||
assertThat("Expected no failures, but got [" + message.getFailureReason() + "]", message.successful(), is(true));
|
||||
assertThat(message.getRequest(), notNullValue());
|
||||
assertThat(message.getResponse(), notNullValue());
|
||||
assertThat(message.getResponse().status(), lessThan(300));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,16 +3,27 @@
|
|||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.watcher.actions.pagerduty.service;
|
||||
package org.elasticsearch.messy.tests;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockMustacheScriptEngine;
|
||||
import org.elasticsearch.script.mustache.MustachePlugin;
|
||||
import org.elasticsearch.test.junit.annotations.Network;
|
||||
import org.elasticsearch.watcher.actions.pagerduty.PagerDutyAction;
|
||||
import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEvent;
|
||||
import org.elasticsearch.watcher.actions.pagerduty.service.IncidentEventContext;
|
||||
import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyAccount;
|
||||
import org.elasticsearch.watcher.actions.pagerduty.service.PagerDutyService;
|
||||
import org.elasticsearch.watcher.actions.pagerduty.service.SentEvent;
|
||||
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
|
||||
import org.elasticsearch.watcher.watch.Payload;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
|
@ -43,6 +54,20 @@ public class PagerDutyServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> getMockPlugins() {
|
||||
Collection<Class<? extends Plugin>> mockPlugins = super.getMockPlugins();
|
||||
mockPlugins.remove(MockMustacheScriptEngine.TestPlugin.class);
|
||||
return mockPlugins;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Class<? extends Plugin>> pluginTypes() {
|
||||
List<Class<? extends Plugin>> types = super.pluginTypes();
|
||||
types.add(MustachePlugin.class);
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.builder()
|
||||
|
@ -66,15 +91,15 @@ public class PagerDutyServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
SentEvent sentEvent = account.send(event, payload);
|
||||
assertThat(sentEvent, notNullValue());
|
||||
assertThat(sentEvent.successful(), is(true));
|
||||
assertThat(sentEvent.request, notNullValue());
|
||||
assertThat(sentEvent.response, notNullValue());
|
||||
assertThat(sentEvent.response.status(), lessThan(300));
|
||||
assertThat(sentEvent.getRequest(), notNullValue());
|
||||
assertThat(sentEvent.getResponse(), notNullValue());
|
||||
assertThat(sentEvent.getResponse().status(), lessThan(300));
|
||||
}
|
||||
|
||||
public void testWatchWithPagerDutyAction() throws Exception {
|
||||
String account = "test_account";
|
||||
PagerDutyAction.Builder actionBuilder = pagerDutyAction(IncidentEvent
|
||||
.templateBuilder("pager duty integration test `testWatchWithPagerDutyAction()`").setAccount(account));
|
||||
.templateBuilder("pager duty integration test `{{ctx.payload.ref}}`").setAccount(account));
|
||||
|
||||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("10m")))
|
|
@ -3,17 +3,26 @@
|
|||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.watcher.actions.slack.service;
|
||||
package org.elasticsearch.messy.tests;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockMustacheScriptEngine;
|
||||
import org.elasticsearch.script.mustache.MustachePlugin;
|
||||
import org.elasticsearch.test.junit.annotations.Network;
|
||||
import org.elasticsearch.watcher.actions.slack.SlackAction;
|
||||
import org.elasticsearch.watcher.actions.slack.service.SentMessages;
|
||||
import org.elasticsearch.watcher.actions.slack.service.SlackAccount;
|
||||
import org.elasticsearch.watcher.actions.slack.service.SlackService;
|
||||
import org.elasticsearch.watcher.actions.slack.service.message.Attachment;
|
||||
import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage;
|
||||
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
|
@ -42,6 +51,20 @@ public class SlackServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> getMockPlugins() {
|
||||
Collection<Class<? extends Plugin>> mockPlugins = super.getMockPlugins();
|
||||
mockPlugins.remove(MockMustacheScriptEngine.TestPlugin.class);
|
||||
return mockPlugins;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Class<? extends Plugin>> pluginTypes() {
|
||||
List<Class<? extends Plugin>> types = super.pluginTypes();
|
||||
types.add(MustachePlugin.class);
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.builder()
|
||||
|
@ -69,16 +92,16 @@ public class SlackServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
assertThat(messages.count(), is(2));
|
||||
for (SentMessages.SentMessage sentMessage : messages) {
|
||||
assertThat(sentMessage.successful(), is(true));
|
||||
assertThat(sentMessage.request, notNullValue());
|
||||
assertThat(sentMessage.response, notNullValue());
|
||||
assertThat(sentMessage.response.status(), lessThan(300));
|
||||
assertThat(sentMessage.getRequest(), notNullValue());
|
||||
assertThat(sentMessage.getResponse(), notNullValue());
|
||||
assertThat(sentMessage.getResponse().status(), lessThan(300));
|
||||
}
|
||||
}
|
||||
|
||||
public void testWatchWithSlackAction() throws Exception {
|
||||
String account = "test_account";
|
||||
SlackAction.Builder actionBuilder = slackAction(account, SlackMessage.Template.builder()
|
||||
.setText("slack integration test `testWatchWithSlackAction()`")
|
||||
.setText("slack integration test `{{ctx.payload.ref}}`")
|
||||
.addTo("#watcher-test", "#watcher-test-2"));
|
||||
|
||||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder()
|
|
@ -59,7 +59,7 @@ public abstract class HipChatAccount {
|
|||
|
||||
public abstract SentMessages send(HipChatMessage message);
|
||||
|
||||
enum Profile implements ToXContent {
|
||||
public enum Profile implements ToXContent {
|
||||
|
||||
V1() {
|
||||
@Override
|
||||
|
|
|
@ -97,6 +97,18 @@ public class SentMessages implements ToXContent, Iterable<SentMessages.SentMessa
|
|||
return failureReason == null;
|
||||
}
|
||||
|
||||
public HttpRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public HttpResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public String getFailureReason() {
|
||||
return failureReason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
|
|
|
@ -52,6 +52,14 @@ public class SentEvent implements ToXContent {
|
|||
return failureReason == null;
|
||||
}
|
||||
|
||||
public HttpRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public HttpResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -89,6 +89,14 @@ public class SentMessages implements ToXContent, Iterable<SentMessages.SentMessa
|
|||
return failureReason == null;
|
||||
}
|
||||
|
||||
public HttpRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public HttpResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
|
|
Loading…
Reference in New Issue