From 1f8d5cfe2a6ceb3f1cc21e6b33a9f7a020fe2657 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Fri, 8 Jun 2018 16:22:17 +0200 Subject: [PATCH] Added test for REST client --- src/zutil/net/ws/WebServiceDef.java | 2 +- test/zutil/net/ws/rest/RESTClientTest.java | 34 ++++++++++++++ test/zutil/net/ws/rest/RestHttpPageTest.java | 49 -------------------- 3 files changed, 35 insertions(+), 50 deletions(-) create mode 100755 test/zutil/net/ws/rest/RESTClientTest.java delete mode 100755 test/zutil/net/ws/rest/RestHttpPageTest.java diff --git a/src/zutil/net/ws/WebServiceDef.java b/src/zutil/net/ws/WebServiceDef.java index fc1b450..656b659 100755 --- a/src/zutil/net/ws/WebServiceDef.java +++ b/src/zutil/net/ws/WebServiceDef.java @@ -31,7 +31,7 @@ import java.util.HashMap; import java.util.Set; /** - * Defines a web service from a class implementing the {@link zutil.net.ws.WSInterface} + * Defines a web service (Server side) from a class implementing the {@link zutil.net.ws.WSInterface} * * @author Ziver */ diff --git a/test/zutil/net/ws/rest/RESTClientTest.java b/test/zutil/net/ws/rest/RESTClientTest.java new file mode 100755 index 0000000..9b94fed --- /dev/null +++ b/test/zutil/net/ws/rest/RESTClientTest.java @@ -0,0 +1,34 @@ +package zutil.net.ws.rest; + +import org.junit.Test; +import zutil.net.ws.WSInterface; +import zutil.net.ws.WebServiceDef; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * Created by Ziver on 2016-09-27. + */ +public class RESTClientTest { + + public interface OpenWeartherMap extends WSInterface { + + int weather(@WSParamName("q") String city); + } + + + //@Test + public void testREST() throws MalformedURLException { + OpenWeartherMap restObj = RESTClientFactory.createClient( + new URL("http://samples.openweathermap.org/data/2.5/"), + OpenWeartherMap.class); + + assertNotNull(restObj.weather("London,uk")); + } + +} \ No newline at end of file diff --git a/test/zutil/net/ws/rest/RestHttpPageTest.java b/test/zutil/net/ws/rest/RestHttpPageTest.java deleted file mode 100755 index 547ee22..0000000 --- a/test/zutil/net/ws/rest/RestHttpPageTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package zutil.net.ws.rest; - -import org.junit.Test; -import zutil.net.ws.WSInterface; - -import java.util.HashMap; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Ziver on 2016-09-27. - */ -public class RestHttpPageTest { - - public static class TestClass implements WSInterface{ - public String hello(){ - return "hello world"; - } - } - - @Test - public void noInput() throws Throwable { - RestHttpPage rest = new RestHttpPage(new TestClass()); - - HashMap input = new HashMap<>(); - String output = rest.execute("hello", input); - assertEquals("\"hello world\"", output); - } - - - - - public static class TestEchoClass implements WSInterface{ - public String echo(@WSParamName("input") String input){ - return "echo: "+input; - } - } - - @Test - public void oneInput() throws Throwable { - RestHttpPage rest = new RestHttpPage(new TestEchoClass()); - - HashMap input = new HashMap<>(); - input.put("input", "test input"); - String output = rest.execute("echo", input); - assertEquals("\"echo: test input\"", output); - } - -} \ No newline at end of file