#5 Fixed incorrect setting of URL and URL Title
This commit is contained in:
parent
09ec07a249
commit
11c20c21d9
26
pom.xml
26
pom.xml
@ -1,4 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.svenkubiak</groupId>
|
||||
<artifactId>jpushover</artifactId>
|
||||
@ -130,22 +132,6 @@
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>3.6.0.1398</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.owasp</groupId>
|
||||
<artifactId>dependency-check-maven</artifactId>
|
||||
<version>5.0.0-M2</version>
|
||||
<configuration>
|
||||
<cveValidForHours>12</cveValidForHours>
|
||||
<failBuildOnCVSS>1</failBuildOnCVSS>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
@ -314,6 +300,12 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest</artifactId>
|
||||
<version>2.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
@ -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<String, String> 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -20,4 +20,4 @@ public class JPushoverTest {
|
||||
public void testNewMessage() {
|
||||
assertTrue(JPushover.newMessage() instanceof Message);
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user