aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>2013-12-28 23:29:16 +0100
committerManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>2013-12-28 23:29:16 +0100
commit93b8d5792dfe60014cfbaaaec0a17ed0111ebccd (patch)
treef1b25f806ede2c94d0e5ba639460712699e02e8a
parent1e3810ad25a55a3f17be29e2627f89ec51bab07c (diff)
downloadgwtquery-93b8d5792dfe60014cfbaaaec0a17ed0111ebccd.tar.gz
gwtquery-93b8d5792dfe60014cfbaaaec0a17ed0111ebccd.zip
Adding first stuff to implement ajax in js and jvm
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java44
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java8
-rw-r--r--gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTest.java54
-rw-r--r--gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTestGwt.java29
4 files changed, 135 insertions, 0 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java
new file mode 100644
index 00000000..bc7a72ef
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java
@@ -0,0 +1,44 @@
+package com.google.gwt.query.client.plugins.ajax;
+
+import com.google.gwt.core.client.Callback;
+import com.google.gwt.core.client.ScriptInjector;
+import com.google.gwt.dom.client.ScriptElement;
+import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.GQuery;
+import com.google.gwt.query.client.Promise;
+import com.google.gwt.query.client.plugins.ajax.Ajax.Settings;
+import com.google.gwt.query.client.plugins.deferred.PromiseFunction;
+import com.google.gwt.query.client.plugins.deferred.PromiseReqBuilderJSONP;
+
+/**
+ * Ajax transport for Client side.
+ */
+public class AjaxTransportJs {
+
+
+ public Promise getJsonP(Settings settings) {
+ return new PromiseReqBuilderJSONP(settings.getUrl(), settings.getTimeout());
+ }
+
+ public Promise getLoadScript(final Settings settings) {
+ return new PromiseFunction() {
+ private ScriptElement scriptElement;
+ public void f(final Deferred dfd) {
+ scriptElement = ScriptInjector.fromUrl(settings.getUrl()).setWindow(GQuery.window)
+ .setCallback(new Callback<Void, Exception>() {
+ public void onSuccess(Void result) {
+ GQuery.$(GQuery.window).delay(0, new Function(){
+ public void f() {
+ dfd.resolve(scriptElement);
+ }
+ });
+ }
+ public void onFailure(Exception reason) {
+ dfd.reject(reason);
+ }
+ }).inject().cast();
+ }
+ };
+ }
+
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java
new file mode 100644
index 00000000..7e882d62
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java
@@ -0,0 +1,8 @@
+package com.google.gwt.query.vm;
+
+
+/**
+ */
+public class AjaxTransportJre {
+
+}
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTest.java
new file mode 100644
index 00000000..a21ec648
--- /dev/null
+++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2013, The gwtquery team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client.ajax;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.GQ;
+import com.google.gwt.query.client.Properties;
+import com.google.gwt.query.client.builders.JsonBuilder;
+import com.google.gwt.query.client.builders.Name;
+import com.google.gwt.query.client.plugins.ajax.Ajax;
+
+/**
+ * Tests for Deferred which can run either in JVM and GWT
+ */
+public class AjaxTest extends GWTTestCase {
+
+ public String getModuleName() {
+ return null;
+ }
+
+ public void testJsonValidService() {
+ delayTestFinish(5000);
+ // Use a public json service
+ String testJsonpUrl = "https://www.googleapis.com/blogger/v2/blogs/user_id/posts/post_id?callback=?&key=NO-KEY";
+ Ajax.getJSONP(testJsonpUrl, new Function(){
+ public void f() {
+ Properties p = getDataProperties();
+ // It should return error since we do not use a valid key
+ // {"error":{"errors":[{"domain":"usageLimits","reason":"keyInvalid","message":"Bad Request"}],"code":400,"message":"Bad Request"}}
+ assertEquals(400, p.getJavaScriptObject("error").<Properties>cast().getInt("code"));
+ finishTest();
+ }
+ }, null, 0);
+ }
+
+} \ No newline at end of file
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTestGwt.java
new file mode 100644
index 00000000..b30d53d6
--- /dev/null
+++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/ajax/AjaxTestGwt.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2013, The gwtquery team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client.ajax;
+
+
+/**
+ * Test for data binding shared code run in gwt
+ */
+public class AjaxTestGwt extends AjaxTest {
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.query.Query";
+ }
+
+}