Added support for Glances API and completly reworked API
This commit is contained in:
23
src/test/java/jpushover/JPushoverTest.java
Normal file
23
src/test/java/jpushover/JPushoverTest.java
Normal file
@ -0,0 +1,23 @@
|
||||
package jpushover;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import de.svenkubiak.jpushover.JPushover;
|
||||
import de.svenkubiak.jpushover.apis.Glance;
|
||||
import de.svenkubiak.jpushover.apis.Message;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author svenkubiak
|
||||
*
|
||||
*/
|
||||
public class JPushoverTest {
|
||||
|
||||
public void testNewGlance() {
|
||||
assertTrue(JPushover.newGlance() instanceof Glance);
|
||||
}
|
||||
|
||||
public void testNewMessage() {
|
||||
assertTrue(JPushover.newMessage() instanceof Message);
|
||||
}
|
||||
}
|
29
src/test/java/jpushover/MockServer.java
Normal file
29
src/test/java/jpushover/MockServer.java
Normal file
@ -0,0 +1,29 @@
|
||||
package jpushover;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author svenkubiak
|
||||
*
|
||||
*/
|
||||
public final class MockServer {
|
||||
private static WireMockServer wireMockServer;
|
||||
private static boolean started;
|
||||
|
||||
public MockServer() {
|
||||
}
|
||||
|
||||
public static void start() {
|
||||
if (!started) {
|
||||
System.setProperty("mode", "test");
|
||||
wireMockServer = new WireMockServer(options()
|
||||
.bindAddress("127.0.0.1")
|
||||
);
|
||||
wireMockServer.start();
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
}
|
77
src/test/java/jpushover/apis/GlanceTest.java
Normal file
77
src/test/java/jpushover/apis/GlanceTest.java
Normal file
@ -0,0 +1,77 @@
|
||||
package jpushover.apis;
|
||||
|
||||
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.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.svenkubiak.jpushover.JPushover;
|
||||
import de.svenkubiak.jpushover.http.PushoverResponse;
|
||||
import jpushover.MockServer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author svenkubiak
|
||||
*
|
||||
*/
|
||||
public class GlanceTest {
|
||||
private static final String APPLICATION_JSON = "application/json; charset=utf-8";
|
||||
private static final String CONTENT_TYPE = "Content-Type";
|
||||
|
||||
private GlanceTest () {
|
||||
MockServer.start();
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testTokenRequired() throws IOException, InterruptedException {
|
||||
stubFor(post(urlEqualTo("/1/glances.json"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(400)
|
||||
.withHeader(CONTENT_TYPE, APPLICATION_JSON)));
|
||||
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
JPushover.newGlance().push();
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testUserRequired() throws IOException, InterruptedException {
|
||||
stubFor(post(urlEqualTo("/1/glances.json"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(400)
|
||||
.withHeader(CONTENT_TYPE, APPLICATION_JSON)));
|
||||
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
JPushover.newGlance().withToken("token").push();
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testPushWithoutContent() throws IOException, InterruptedException {
|
||||
stubFor(post(urlEqualTo("/1/glances.json"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(400)
|
||||
.withHeader(CONTENT_TYPE, APPLICATION_JSON)));
|
||||
|
||||
PushoverResponse response = JPushover.newGlance().withToken("token").withUser("user").push();
|
||||
assertFalse(response.isSuccessful());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPush() throws IOException, InterruptedException {
|
||||
stubFor(post(urlEqualTo("/1/glances.json"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(200)
|
||||
.withHeader(CONTENT_TYPE, APPLICATION_JSON)));
|
||||
|
||||
PushoverResponse response = JPushover.newGlance().withToken("foo").withUser("bla").withText("foobar").push();
|
||||
assertTrue(response.isSuccessful());
|
||||
}
|
||||
}
|
89
src/test/java/jpushover/apis/MessageTest.java
Normal file
89
src/test/java/jpushover/apis/MessageTest.java
Normal file
@ -0,0 +1,89 @@
|
||||
package jpushover.apis;
|
||||
|
||||
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.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.svenkubiak.jpushover.JPushover;
|
||||
import de.svenkubiak.jpushover.http.PushoverResponse;
|
||||
import jpushover.MockServer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author svenkubiak
|
||||
*
|
||||
*/
|
||||
public class MessageTest {
|
||||
private static final String APPLICATION_JSON = "application/json; charset=utf-8";
|
||||
private static final String CONTENT_TYPE = "Content-Type";
|
||||
|
||||
private MessageTest () {
|
||||
MockServer.start();
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testTokenRequired() throws IOException, InterruptedException {
|
||||
stubFor(post(urlEqualTo("/1/messages.json"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(400)
|
||||
.withHeader(CONTENT_TYPE, APPLICATION_JSON)));
|
||||
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
JPushover.newMessage().push();
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testUserRequired() throws IOException, InterruptedException {
|
||||
stubFor(post(urlEqualTo("/1/messages.json"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(400)
|
||||
.withHeader(CONTENT_TYPE, APPLICATION_JSON)));
|
||||
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
JPushover.newMessage().withToken("token").push();
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testMessageRequired() throws IOException, InterruptedException {
|
||||
stubFor(post(urlEqualTo("/1/messages.json"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(400)
|
||||
.withHeader(CONTENT_TYPE, APPLICATION_JSON)));
|
||||
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
JPushover.newMessage().withToken("token").withUser("user").push();
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testPushWithoutContent() throws IOException, InterruptedException {
|
||||
stubFor(post(urlEqualTo("/1/messages.json"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(400)
|
||||
.withHeader(CONTENT_TYPE, APPLICATION_JSON)));
|
||||
|
||||
PushoverResponse response = JPushover.newMessage().withToken("token").withUser("user").withMessage("").push();
|
||||
assertFalse(response.isSuccessful());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPush() throws IOException, InterruptedException {
|
||||
stubFor(post(urlEqualTo("/1/messages.json"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(200)
|
||||
.withHeader(CONTENT_TYPE, APPLICATION_JSON)));
|
||||
|
||||
PushoverResponse response = JPushover.newMessage().withToken("foo").withUser("bla").withMessage("foobar").push();
|
||||
assertTrue(response.isSuccessful());
|
||||
}
|
||||
}
|
26
src/test/java/jpushover/utils/ValidateTest.java
Normal file
26
src/test/java/jpushover/utils/ValidateTest.java
Normal file
@ -0,0 +1,26 @@
|
||||
package jpushover.utils;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.svenkubiak.jpushover.utils.Validate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author svenkubiak
|
||||
*
|
||||
*/
|
||||
public class ValidateTest {
|
||||
|
||||
@Test
|
||||
public void testTrue() {
|
||||
Validate.checkArgument(true, "foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFalse() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
Validate.checkArgument(false, "bar");
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user