Merge branch 'master' into migrate_to_strict_settings

Original commit: elastic/x-pack-elasticsearch@608c37fa4c
This commit is contained in:
Simon Willnauer 2016-02-03 13:22:27 +01:00
commit 610bd8c820
7 changed files with 123 additions and 23 deletions

View File

@ -3,16 +3,26 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with 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.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings; 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.Network;
import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.watcher.actions.hipchat.HipChatAction; 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.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; 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.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
@ -42,6 +52,20 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
return false; 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 @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
@ -65,7 +89,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
public void testSendMessageV1Account() throws Exception { public void testSendMessageV1Account() throws Exception {
HipChatService service = getInstanceFromMaster(HipChatService.class); HipChatService service = getInstanceFromMaster(HipChatService.class);
HipChatMessage hipChatMessage = new HipChatMessage( HipChatMessage hipChatMessage = new HipChatMessage(
"/code HipChatServiceIT#testSendMessage_V1Account", "/code HipChatServiceTests#testSendMessage_V1Account",
new String[] { "test-watcher", "test-watcher-2" }, new String[] { "test-watcher", "test-watcher-2" },
null, // users are unsupported in v1 null, // users are unsupported in v1
"watcher-tests", "watcher-tests",
@ -83,7 +107,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
HipChatService service = getInstanceFromMaster(HipChatService.class); HipChatService service = getInstanceFromMaster(HipChatService.class);
HipChatMessage.Color color = randomFrom(HipChatMessage.Color.values()); HipChatMessage.Color color = randomFrom(HipChatMessage.Color.values());
HipChatMessage hipChatMessage = new HipChatMessage( 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, // custom rooms are unsupported by integration profiles
null, // users are unsupported by integration profiles null, // users are unsupported by integration profiles
null, // custom "from" is not supported 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); HipChatService service = getInstanceFromMaster(HipChatService.class);
HipChatMessage.Color color = randomFrom(HipChatMessage.Color.values()); HipChatMessage.Color color = randomFrom(HipChatMessage.Color.values());
HipChatMessage hipChatMessage = new HipChatMessage( 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[] { "test-watcher", "test-watcher-2" },
new String[] { "watcher@elastic.co" }, new String[] { "watcher@elastic.co" },
null, // custom "from" is not supported by integration profiles null, // custom "from" is not supported by integration profiles
@ -123,7 +147,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
switch (profile) { switch (profile) {
case USER: case USER:
account = "user_account"; account = "user_account";
actionBuilder = hipchatAction(account, "/code HipChatServiceIT#testWatchWithHipChatAction") actionBuilder = hipchatAction(account, "/code {{ctx.payload.ref}}")
.addRooms("test-watcher", "test-watcher-2") .addRooms("test-watcher", "test-watcher-2")
.addUsers("watcher@elastic.co") .addUsers("watcher@elastic.co")
.setFormat(HipChatMessage.Format.TEXT) .setFormat(HipChatMessage.Format.TEXT)
@ -133,7 +157,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
case INTEGRATION: case INTEGRATION:
account = "integration_account"; account = "integration_account";
actionBuilder = hipchatAction(account, "/code HipChatServiceIT#testWatchWithHipChatAction") actionBuilder = hipchatAction(account, "/code {{ctx.payload.ref}}")
.setFormat(HipChatMessage.Format.TEXT) .setFormat(HipChatMessage.Format.TEXT)
.setColor(color) .setColor(color)
.setNotify(false); .setNotify(false);
@ -142,7 +166,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
default: default:
assertThat(profile, is(HipChatAccount.Profile.V1)); assertThat(profile, is(HipChatAccount.Profile.V1));
account = "v1_account"; account = "v1_account";
actionBuilder = hipchatAction(account, "/code HipChatServiceIT#testWatchWithHipChatAction") actionBuilder = hipchatAction(account, "/code {{ctx.payload.ref}}")
.addRooms("test-watcher", "test-watcher-2") .addRooms("test-watcher", "test-watcher-2")
.setFrom("watcher-test") .setFrom("watcher-test")
.setFormat(HipChatMessage.Format.TEXT) .setFormat(HipChatMessage.Format.TEXT)
@ -152,7 +176,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder() PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder()
.trigger(schedule(interval("10m"))) .trigger(schedule(interval("10m")))
.input(simpleInput("ref", "HipChatServiceIT#testWatchWithHipChatAction")) .input(simpleInput("ref", "HipChatServiceTests#testWatchWithHipChatAction"))
.condition(alwaysCondition()) .condition(alwaysCondition())
.addAction("hipchat", actionBuilder)) .addAction("hipchat", actionBuilder))
.execute().get(); .execute().get();
@ -179,10 +203,10 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
private void assertSentMessagesAreValid(int expectedMessageSize, SentMessages messages) { private void assertSentMessagesAreValid(int expectedMessageSize, SentMessages messages) {
assertThat(messages.count(), is(expectedMessageSize)); assertThat(messages.count(), is(expectedMessageSize));
for (SentMessages.SentMessage message : messages) { for (SentMessages.SentMessage message : messages) {
assertThat("Expected no failures, but got [" + message.failureReason + "]", message.successful(), is(true)); assertThat("Expected no failures, but got [" + message.getFailureReason() + "]", message.successful(), is(true));
assertThat(message.request, notNullValue()); assertThat(message.getRequest(), notNullValue());
assertThat(message.response, notNullValue()); assertThat(message.getResponse(), notNullValue());
assertThat(message.response.status(), lessThan(300)); assertThat(message.getResponse().status(), lessThan(300));
} }
} }
} }

View File

@ -3,16 +3,27 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with 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.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings; 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.Network;
import org.elasticsearch.watcher.actions.pagerduty.PagerDutyAction; 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.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
import org.elasticsearch.watcher.watch.Payload; 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.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
@ -43,6 +54,20 @@ public class PagerDutyServiceTests extends AbstractWatcherIntegrationTestCase {
return false; 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 @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
@ -66,15 +91,15 @@ public class PagerDutyServiceTests extends AbstractWatcherIntegrationTestCase {
SentEvent sentEvent = account.send(event, payload); SentEvent sentEvent = account.send(event, payload);
assertThat(sentEvent, notNullValue()); assertThat(sentEvent, notNullValue());
assertThat(sentEvent.successful(), is(true)); assertThat(sentEvent.successful(), is(true));
assertThat(sentEvent.request, notNullValue()); assertThat(sentEvent.getRequest(), notNullValue());
assertThat(sentEvent.response, notNullValue()); assertThat(sentEvent.getResponse(), notNullValue());
assertThat(sentEvent.response.status(), lessThan(300)); assertThat(sentEvent.getResponse().status(), lessThan(300));
} }
public void testWatchWithPagerDutyAction() throws Exception { public void testWatchWithPagerDutyAction() throws Exception {
String account = "test_account"; String account = "test_account";
PagerDutyAction.Builder actionBuilder = pagerDutyAction(IncidentEvent 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() PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder()
.trigger(schedule(interval("10m"))) .trigger(schedule(interval("10m")))

View File

@ -3,17 +3,26 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with 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.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings; 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.Network;
import org.elasticsearch.watcher.actions.slack.SlackAction; 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.Attachment;
import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage; import org.elasticsearch.watcher.actions.slack.service.message.SlackMessage;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; 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.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
@ -42,6 +51,20 @@ public class SlackServiceTests extends AbstractWatcherIntegrationTestCase {
return false; 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 @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
@ -69,16 +92,16 @@ public class SlackServiceTests extends AbstractWatcherIntegrationTestCase {
assertThat(messages.count(), is(2)); assertThat(messages.count(), is(2));
for (SentMessages.SentMessage sentMessage : messages) { for (SentMessages.SentMessage sentMessage : messages) {
assertThat(sentMessage.successful(), is(true)); assertThat(sentMessage.successful(), is(true));
assertThat(sentMessage.request, notNullValue()); assertThat(sentMessage.getRequest(), notNullValue());
assertThat(sentMessage.response, notNullValue()); assertThat(sentMessage.getResponse(), notNullValue());
assertThat(sentMessage.response.status(), lessThan(300)); assertThat(sentMessage.getResponse().status(), lessThan(300));
} }
} }
public void testWatchWithSlackAction() throws Exception { public void testWatchWithSlackAction() throws Exception {
String account = "test_account"; String account = "test_account";
SlackAction.Builder actionBuilder = slackAction(account, SlackMessage.Template.builder() 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")); .addTo("#watcher-test", "#watcher-test-2"));
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder() PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder()

View File

@ -59,7 +59,7 @@ public abstract class HipChatAccount {
public abstract SentMessages send(HipChatMessage message); public abstract SentMessages send(HipChatMessage message);
enum Profile implements ToXContent { public enum Profile implements ToXContent {
V1() { V1() {
@Override @Override

View File

@ -97,6 +97,18 @@ public class SentMessages implements ToXContent, Iterable<SentMessages.SentMessa
return failureReason == null; return failureReason == null;
} }
public HttpRequest getRequest() {
return request;
}
public HttpResponse getResponse() {
return response;
}
public String getFailureReason() {
return failureReason;
}
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(); builder.startObject();

View File

@ -52,6 +52,14 @@ public class SentEvent implements ToXContent {
return failureReason == null; return failureReason == null;
} }
public HttpRequest getRequest() {
return request;
}
public HttpResponse getResponse() {
return response;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -89,6 +89,14 @@ public class SentMessages implements ToXContent, Iterable<SentMessages.SentMessa
return failureReason == null; return failureReason == null;
} }
public HttpRequest getRequest() {
return request;
}
public HttpResponse getResponse() {
return response;
}
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(); builder.startObject();