Skip to content

Commit

Permalink
Watcher: Remove unused hipchat render method (#32211)
Browse files Browse the repository at this point in the history
The HipChatMessage#render is no longer used, and instead the
HipChatAccount#render is used in the ExecutableHipChatAction. Only a
test that validated the HttpProxy used this render method still. This
commit cleans it up.
  • Loading branch information
hub-cap committed Aug 15, 2018
1 parent 0814425 commit a5ec145
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.common.text.TextTemplate;
import org.elasticsearch.xpack.watcher.common.text.TextTemplateEngine;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

public class HipChatMessage implements ToXContentObject {
Expand Down Expand Up @@ -181,26 +179,6 @@ public int hashCode() {
return Objects.hash(body, rooms, users, from, format, color, notify);
}

public HipChatMessage render(TextTemplateEngine engine, Map<String, Object> model) {
String body = engine.render(this.body, model);
String[] rooms = null;
if (this.rooms != null) {
rooms = new String[this.rooms.length];
for (int i = 0; i < this.rooms.length; i++) {
rooms[i] = engine.render(this.rooms[i], model);
}
}
String[] users = null;
if (this.users != null) {
users = new String[this.users.length];
for (int i = 0; i < this.users.length; i++) {
users[i] = engine.render(this.users[i], model);
}
}
Color color = this.color == null ? null : Color.resolve(engine.render(this.color, model), null);
return new HipChatMessage(body, rooms, users, from, format, color, notify);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
import org.elasticsearch.xpack.watcher.common.http.HttpProxy;
import org.elasticsearch.xpack.watcher.common.http.HttpRequest;
import org.elasticsearch.xpack.watcher.common.http.HttpResponse;
import org.elasticsearch.xpack.watcher.common.text.TextTemplate;
import org.elasticsearch.xpack.watcher.test.MockTextTemplateEngine;
import org.junit.Before;
import org.mockito.ArgumentCaptor;

import java.util.HashMap;
import java.util.HashSet;

import static org.hamcrest.Matchers.is;
Expand All @@ -40,11 +37,7 @@ public void testProxy() throws Exception {
new HashSet<>(HipChatService.getSettings())));
HipChatAccount account = service.getAccount("account1");

HipChatMessage.Template template = new HipChatMessage.Template.Builder(new TextTemplate("foo"))
.addRooms(new TextTemplate("room"))
.setFrom("from")
.build();
HipChatMessage hipChatMessage = template.render(new MockTextTemplateEngine(), new HashMap<>());
HipChatMessage hipChatMessage = new HipChatMessage("body", new String[]{"rooms"}, null, "from", null, null, null);

ArgumentCaptor<HttpRequest> argumentCaptor = ArgumentCaptor.forClass(HttpRequest.class);
when(httpClient.execute(argumentCaptor.capture())).thenReturn(new HttpResponse(200));
Expand Down

0 comments on commit a5ec145

Please sign in to comment.