diff --git a/src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java b/src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java index b3b6cb6..a442a16 100644 --- a/src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java +++ b/src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java @@ -142,8 +142,7 @@ public BuildStepMonitor getRequiredMonitorService() { } public HipChatService newHipChatService() { - return new StandardHipChatService(getServer(), getAuthToken(), getRoom(), - StringUtils.isBlank(getSendAs()) ? "Build Server" : getSendAs()); + return new StandardHipChatService(getServer(), getAuthToken(), getRoom(), getSendAs()); } @Override @@ -166,10 +165,10 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen @Extension public static class DescriptorImpl extends BuildStepDescriptor { - private String server; + private String server = "api.hipchat.com"; private String token; private String room; - private String sendAs; + private String sendAs = "Jenkins"; private static int testNotificationCount = 0; public DescriptorImpl() { diff --git a/src/main/java/jenkins/plugins/hipchat/StandardHipChatService.java b/src/main/java/jenkins/plugins/hipchat/StandardHipChatService.java index f85402a..cfb850f 100644 --- a/src/main/java/jenkins/plugins/hipchat/StandardHipChatService.java +++ b/src/main/java/jenkins/plugins/hipchat/StandardHipChatService.java @@ -12,21 +12,19 @@ public class StandardHipChatService implements HipChatService { private static final Logger logger = Logger.getLogger(StandardHipChatService.class.getName()); - private static final String DEFAULT_HOST = "api.hipchat.com"; private static final String[] DEFAULT_ROOMS = new String[0]; - private static final String DEFAULT_FROM = "Build Server"; - private final String host; + private final String server; private final String token; private final String[] roomIds; - private final String from; + private final String sendAs; - public StandardHipChatService(String host, String token, String roomIds, String from) { + public StandardHipChatService(String server, String token, String roomIds, String sendAs) { super(); - this.host = host == null ? DEFAULT_HOST : host; + this.server = server; this.token = token; this.roomIds = roomIds == null ? DEFAULT_ROOMS : roomIds.split("\\s*,\\s*"); - this.from = from == null ? DEFAULT_FROM : from; + this.sendAs = sendAs; } public void publish(String message) { @@ -35,13 +33,13 @@ public void publish(String message) { public void publish(String message, String color) { for (String roomId : roomIds) { - logger.log(Level.INFO, "Posting: {0} to {1}: {2} {3}", new Object[]{from, roomId, message, color}); + logger.log(Level.INFO, "Posting: {0} to {1}: {2} {3}", new Object[]{sendAs, roomId, message, color}); HttpClient client = getHttpClient(); - String url = "https://" + host + "/v1/rooms/message?auth_token=" + token; + String url = "https://" + server + "/v1/rooms/message?auth_token=" + token; PostMethod post = new PostMethod(url); try { - post.addParameter("from", from); + post.addParameter("from", sendAs); post.addParameter("room_id", roomId); post.addParameter("message", message); post.addParameter("color", color); @@ -78,15 +76,15 @@ private String shouldNotify(String color) { return color.equalsIgnoreCase("green") ? "0" : "1"; } - public String getHost() { - return host; + public String getServer() { + return server; } public String[] getRoomIds() { return roomIds; } - public String getFrom() { - return from; + public String getSendAs() { + return sendAs; } } diff --git a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly index 6cbcd6c..7de976e 100644 --- a/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly +++ b/src/main/resources/jenkins/plugins/hipchat/HipChatNotifier/global.jelly @@ -10,7 +10,7 @@ - + diff --git a/src/test/java/jenkins/plugins/hipchat/StandardHipChatServiceTest.java b/src/test/java/jenkins/plugins/hipchat/StandardHipChatServiceTest.java index 3e89617..96cbb4d 100644 --- a/src/test/java/jenkins/plugins/hipchat/StandardHipChatServiceTest.java +++ b/src/test/java/jenkins/plugins/hipchat/StandardHipChatServiceTest.java @@ -12,16 +12,10 @@ public void publishWithBadHostShouldNotRethrowExceptions() { service.publish("message"); } - @Test - public void shouldSetADefaultHost() { - StandardHipChatService service = new StandardHipChatService(null, "token", "room", "from"); - assertEquals("api.hipchat.com", service.getHost()); - } - @Test public void shouldBeAbleToOverrideHost() { StandardHipChatService service = new StandardHipChatService("some.other.host", "token", "room", "from"); - assertEquals("some.other.host", service.getHost()); + assertEquals("some.other.host", service.getServer()); } @Test @@ -42,15 +36,9 @@ public void shouldNotSplitTheRoomsIfNullIsPassed() { assertArrayEquals(new String[0], service.getRoomIds()); } - @Test - public void shouldProvideADefaultFrom() { - StandardHipChatService service = new StandardHipChatService(null, "token", "room", null); - assertEquals("Build Server", service.getFrom()); - } - @Test public void shouldBeAbleToOverrideFrom() { StandardHipChatService service = new StandardHipChatService(null, "token", "room", "from"); - assertEquals("from", service.getFrom()); + assertEquals("from", service.getSendAs()); } }