Skip to content
Browse files

[#925] Adding a test which was not added in last commit

  • Loading branch information...
1 parent fab3d73 commit 5a5d77ed9c3d08b75b52db7e3e3d67861c7d8043 @mbknor mbknor committed
Showing with 66 additions and 0 deletions.
  1. +66 −0 samples-and-tests/just-test-cases/test/WSUrlFetchTest.java
View
66 samples-and-tests/just-test-cases/test/WSUrlFetchTest.java
@@ -0,0 +1,66 @@
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import play.libs.WS;
+import play.libs.ws.WSUrlFetch;
+import play.test.UnitTest;
+
+import java.lang.reflect.Field;
+
+
+public class WSUrlFetchTest extends UnitTest {
+
+ private static WS.WSImpl orgWsImpl;
+ private static Field field;
+
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // make sure we use WSUrlFetch as WS impl
+
+ // store org impl
+ // call WS.url() to make sure it is initialized by default
+ WS.url("");
+ field = WS.class.getDeclaredField("wsImpl");
+ field.setAccessible(true);
+ orgWsImpl = (WS.WSImpl)field.get(null);
+
+ // set WSUrlFetch impl
+ field.set(null, new WSUrlFetch());
+
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ // Restore to default WS impl
+ field.set(null, orgWsImpl);
+ }
+
+
+ @Test
+ public void test() throws Exception {
+ final String url = "http://localhost:9003/Rest/echoHttpMethod";
+ assertEquals("GET", WS.url(url).get().getString());
+ assertEquals("GET", WS.url(url).setParameter("name", "value").get().getString());
+ assertEquals("GET a=1 b=2", WS.url(url+"?a=1&b=2").get().getString());
+ assertEquals("GET a=1 b=2", WS.url(url+"?a=1").setParameter("b", "2").get().getString());
+
+ assertEquals("POST", WS.url(url).post().getString());
+ assertEquals("POST", WS.url(url).setParameter("name", "value").post().getString());
+ assertEquals("POST a=1 b=2", WS.url(url+"?a=1&b=2").post().getString());
+ assertEquals("POST a=1 b=2", WS.url(url+"?a=1").setParameter("b", "2").post().getString());
+
+ assertEquals("DELETE", WS.url(url).delete().getString());
+ assertEquals("DELETE", WS.url(url).setParameter("name", "value").delete().getString());
+ assertEquals("DELETE a=1 b=2", WS.url(url+"?a=1&b=2").delete().getString());
+ assertEquals("DELETE a=1 b=2", WS.url(url+"?a=1").setParameter("b", "2").delete().getString());
+
+ assertEquals("PUT", WS.url(url).put().getString());
+ assertEquals("PUT", WS.url(url).setParameter("name", "value").put().getString());
+ assertEquals("PUT a=1 b=2", WS.url(url+"?a=1&b=2").put().getString());
+ assertEquals("PUT a=1 b=2", WS.url(url+"?a=1").setParameter("b", "2").put().getString());
+
+ // Head does not appear to work with UrlFetch
+ // assertEquals("HEAD", WS.url(url).head().getString());
+ }
+}

0 comments on commit 5a5d77e

Please sign in to comment.
Something went wrong with that request. Please try again.