From 11c20c21d919f3a449f40945ee10aad907ef31b5 Mon Sep 17 00:00:00 2001 From: Sven Kubiak Date: Wed, 4 Mar 2020 12:58:30 +0100 Subject: [PATCH] #5 Fixed incorrect setting of URL and URL Title --- pom.xml | 26 +++--- .../de/svenkubiak/jpushover/apis/Message.java | 79 ++++++++++++++++++- .../de/svenkubiak/jpushover/enums/Param.java | 3 +- src/test/java/jpushover/JPushoverTest.java | 2 +- src/test/java/jpushover/apis/MessageTest.java | 70 ++++++++++++++++ 5 files changed, 156 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 3ffd433..ab0397d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,6 @@ - + 4.0.0 de.svenkubiak jpushover @@ -130,22 +132,6 @@ sonar-maven-plugin 3.6.0.1398 - - org.owasp - dependency-check-maven - 5.0.0-M2 - - 12 - 1 - - - - - check - - - - org.apache.maven.plugins maven-release-plugin @@ -314,6 +300,12 @@ + + org.hamcrest + hamcrest + 2.2 + test + org.slf4j slf4j-api diff --git a/src/main/java/de/svenkubiak/jpushover/apis/Message.java b/src/main/java/de/svenkubiak/jpushover/apis/Message.java index 8a24d05..2efe77f 100644 --- a/src/main/java/de/svenkubiak/jpushover/apis/Message.java +++ b/src/main/java/de/svenkubiak/jpushover/apis/Message.java @@ -140,6 +140,7 @@ public class Message { */ public final Message withUrl(final String url) { this.url = url; + this.urlTitle = url; return this; } @@ -151,7 +152,8 @@ public class Message { * @return Message instance */ public final Message enableMonospace() { - this.monospace = (this.html) ? false : true; + this.monospace = true; + this.html = false; return this; } @@ -163,7 +165,8 @@ public class Message { * @return Message instance */ public final Message enableHtml() { - this.html = (this.monospace) ? false : true; + this.monospace = false; + this.html = true; return this; } @@ -293,7 +296,7 @@ public class Message { Objects.requireNonNull(this.retry, "Retry is required on priority emergency"); Objects.requireNonNull(this.expire, "Expire is required on priority emergency"); } - + NavigableMap body = new TreeMap<>(); body.put(Param.TOKEN.toString(), this.token); body.put(Param.USER.toString(), this.user); @@ -304,7 +307,7 @@ public class Message { body.put(Param.RETRY.toString(), this.retry); body.put(Param.EXPIRE.toString(), this.expire); body.put(Param.CALLBACK.toString(), this.callback); - body.put(Param.URLTITLE.toString(), this.urlTitle); + body.put(Param.URL_TITLE.toString(), this.urlTitle); body.put(Param.PRIORITY.toString(), this.priority.toString()); body.put(Param.TIMESTAMP.toString(), this.timestamp); body.put(Param.SOUND.toString(), this.sound.toString()); @@ -313,4 +316,72 @@ public class Message { return new PushoverRequest().push(MESSAGE_URL, body, this.proxyHost, this.proxyPort); } + + public Priority getPriority() { + return priority; + } + + public Sound getSound() { + return sound; + } + + public String getToken() { + return token; + } + + public String getUser() { + return user; + } + + public String getMessage() { + return message; + } + + public String getDevice() { + return device; + } + + public String getTitle() { + return title; + } + + public String getUrl() { + return url; + } + + public String getUrlTitle() { + return urlTitle; + } + + public String getTimestamp() { + return timestamp; + } + + public String getRetry() { + return retry; + } + + public String getExpire() { + return expire; + } + + public String getCallback() { + return callback; + } + + public String getProxyHost() { + return proxyHost; + } + + public int getProxyPort() { + return proxyPort; + } + + public boolean isHtml() { + return html; + } + + public boolean isMonospace() { + return monospace; + } } \ No newline at end of file diff --git a/src/main/java/de/svenkubiak/jpushover/enums/Param.java b/src/main/java/de/svenkubiak/jpushover/enums/Param.java index 688dd5c..2e7e516 100644 --- a/src/main/java/de/svenkubiak/jpushover/enums/Param.java +++ b/src/main/java/de/svenkubiak/jpushover/enums/Param.java @@ -6,7 +6,6 @@ package de.svenkubiak.jpushover.enums; * */ public enum Param { - ATTACHMENT("attachment"), CALLBACK("callback"), COUNT("count"), DEVICE("device"), @@ -24,7 +23,7 @@ public enum Param { TITLE("title"), TOKEN("token"), URL("url"), - URLTITLE("urltitle"), + URL_TITLE("url_title"), USER("user"); private final String value; diff --git a/src/test/java/jpushover/JPushoverTest.java b/src/test/java/jpushover/JPushoverTest.java index 8011634..d61e982 100644 --- a/src/test/java/jpushover/JPushoverTest.java +++ b/src/test/java/jpushover/JPushoverTest.java @@ -20,4 +20,4 @@ public class JPushoverTest { public void testNewMessage() { assertTrue(JPushover.newMessage() instanceof Message); } -} +} \ No newline at end of file diff --git a/src/test/java/jpushover/apis/MessageTest.java b/src/test/java/jpushover/apis/MessageTest.java index b23f870..416feb5 100644 --- a/src/test/java/jpushover/apis/MessageTest.java +++ b/src/test/java/jpushover/apis/MessageTest.java @@ -4,6 +4,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -13,6 +15,9 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import de.svenkubiak.jpushover.JPushover; +import de.svenkubiak.jpushover.apis.Message; +import de.svenkubiak.jpushover.enums.Priority; +import de.svenkubiak.jpushover.enums.Sound; import de.svenkubiak.jpushover.http.PushoverResponse; import jpushover.MockServer; @@ -86,4 +91,69 @@ public class MessageTest { PushoverResponse response = JPushover.newMessage().withToken("foo").withUser("bla").withMessage("foobar").push(); assertTrue(response.isSuccessful()); } + + @Test + public void testConstruct() throws IOException, InterruptedException { + //given + String callback = "callback"; + String device = "device"; + String expire = "expire"; + String message = "message"; + String retry = "retry"; + String user = "user"; + String urlTitle = "urlTitle"; + String timestamp = "timestamp"; + String proxyHost = "proxyhost"; + String title = "tile"; + String token = "token"; + String url = "https://www.url.url"; + int proxyPort = 8080; + Priority priority = Priority.HIGH; + Sound sound = Sound.BUGLE; + + //when + Message m = JPushover.newMessage() + .enableHtml() + .withCallback(callback) + .withDevice(device) + .withExpire(expire) + .withMessage(message) + .withPriority(priority) + .withProxy(proxyHost, proxyPort) + .withRetry(retry) + .withSound(sound) + .withTimestamp(timestamp) + .withTitle(title) + .withToken(token) + .withUrl(url) + .withUser(user); + + //then + assertThat(m.isHtml(), equalTo(true)); + assertThat(m.isMonospace(), equalTo(false)); + assertThat(m.getCallback(), equalTo(callback)); + assertThat(m.getDevice(), equalTo(device)); + assertThat(m.getExpire(), equalTo(expire)); + assertThat(m.getMessage(), equalTo(message)); + assertThat(m.getPriority(), equalTo(Priority.HIGH)); + assertThat(m.getProxyHost(), equalTo(proxyHost)); + assertThat(m.getProxyPort(), equalTo(proxyPort)); + assertThat(m.getRetry(), equalTo(retry)); + assertThat(m.getSound(), equalTo(Sound.BUGLE)); + assertThat(m.getTimestamp(), equalTo(timestamp)); + assertThat(m.getTitle(), equalTo(title)); + assertThat(m.getToken(), equalTo(token)); + assertThat(m.getUrl(), equalTo(url)); + assertThat(m.getUrlTitle(), equalTo(url)); + assertThat(m.getUser(), equalTo(user)); + + //when + m.withUrlTitle(urlTitle); + m.enableMonospace(); + + //then + assertThat(m.getUrlTitle(), equalTo(urlTitle)); + assertThat(m.isHtml(), equalTo(false)); + assertThat(m.isMonospace(), equalTo(true)); + } }