Added test for REST client

This commit is contained in:
Ziver Koc 2018-06-08 16:22:17 +02:00
parent 93a4c9eca2
commit 1f8d5cfe2a
3 changed files with 35 additions and 50 deletions

View file

@ -31,7 +31,7 @@ import java.util.HashMap;
import java.util.Set; 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 * @author Ziver
*/ */

View file

@ -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"));
}
}

View file

@ -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<String,String> 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<String,String> input = new HashMap<>();
input.put("input", "test input");
String output = rest.execute("echo", input);
assertEquals("\"echo: test input\"", output);
}
}