You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2012/05/08 15:23:48 UTC
[1/2] git commit: WICKET-4540: testcases for callback function
generation
Updated Branches:
refs/heads/master af443acb5 -> 7dba094c1
WICKET-4540: testcases for callback function generation
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/7dba094c
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/7dba094c
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/7dba094c
Branch: refs/heads/master
Commit: 7dba094c1e0c3261eab12c0a3e44d7af0a9eb956
Parents: 3c19f06
Author: Emond Papegaaij <pa...@apache.org>
Authored: Tue May 8 15:23:25 2012 +0200
Committer: Emond Papegaaij <pa...@apache.org>
Committed: Tue May 8 15:23:32 2012 +0200
----------------------------------------------------------------------
.../wicket/ajax/AjaxCallbackFunctionTest.java | 143 +++++++++++++++
.../org/apache/wicket/ajax/AjaxCallbackPage.html | 9 +
.../org/apache/wicket/ajax/AjaxCallbackPage.java | 42 +++++
3 files changed, 194 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/7dba094c/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackFunctionTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackFunctionTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackFunctionTest.java
new file mode 100644
index 0000000..2487c9e
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackFunctionTest.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.wicket.ajax;
+
+import static org.apache.wicket.ajax.attributes.CallbackParameter.context;
+import static org.apache.wicket.ajax.attributes.CallbackParameter.converted;
+import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;
+import static org.apache.wicket.ajax.attributes.CallbackParameter.resolved;
+
+import org.apache.wicket.WicketTestCase;
+import org.junit.Test;
+
+
+public class AjaxCallbackFunctionTest extends WicketTestCase
+{
+ @Test
+ public void testDefaultCallbackFunction()
+ {
+ AjaxCallbackPage page = tester.startPage(AjaxCallbackPage.class);
+ assertEquals(//
+ "function () {\n" //
+ + "var attrs = {\"u\":\"./wicket/page?0-1.IBehaviorListener.0-\"};\n" //
+ + "var params = {};\n" //
+ + "attrs.ep = params;\n" //
+ + "Wicket.Ajax.ajax(attrs);\n" //
+ + "}\n", //
+ page.getBehavior().getCallbackFunction().toString());
+ }
+
+ @Test
+ public void testCallbackFunctionWithContext()
+ {
+ AjaxCallbackPage page = tester.startPage(AjaxCallbackPage.class);
+ assertEquals(//
+ "function (context) {\n" //
+ + "var attrs = {\"u\":\"./wicket/page?0-1.IBehaviorListener.0-\"};\n" //
+ + "var params = {};\n" //
+ + "attrs.ep = params;\n" //
+ + "Wicket.Ajax.ajax(attrs);\n" //
+ + "}\n", //
+ page.getBehavior().getCallbackFunction(context("context")).toString());
+ }
+
+ @Test
+ public void testCallbackFunctionWithExplicit()
+ {
+ AjaxCallbackPage page = tester.startPage(AjaxCallbackPage.class);
+ assertEquals(//
+ "function (explicit) {\n" //
+ + "var attrs = {\"u\":\"./wicket/page?0-1.IBehaviorListener.0-\"};\n" //
+ + "var params = {'explicit': explicit};\n" //
+ + "attrs.ep = params;\n" //
+ + "Wicket.Ajax.ajax(attrs);\n" //
+ + "}\n", //
+ page.getBehavior().getCallbackFunction(explicit("explicit")).toString());
+ }
+
+ @Test
+ public void testCallbackFunctionWithResolved()
+ {
+ AjaxCallbackPage page = tester.startPage(AjaxCallbackPage.class);
+ assertEquals(//
+ "function () {\n" //
+ + "var attrs = {\"u\":\"./wicket/page?0-1.IBehaviorListener.0-\"};\n" //
+ + "var params = {'resolved': window.location.href};\n" //
+ + "attrs.ep = params;\n" //
+ + "Wicket.Ajax.ajax(attrs);\n" //
+ + "}\n", //
+ page.getBehavior()
+ .getCallbackFunction(resolved("resolved", "window.location.href"))
+ .toString());
+ }
+
+ @Test
+ public void testCallbackFunctionWithConverted()
+ {
+ AjaxCallbackPage page = tester.startPage(AjaxCallbackPage.class);
+ assertEquals(
+ //
+ "function (converted) {\n" //
+ + "var attrs = {\"u\":\"./wicket/page?0-1.IBehaviorListener.0-\"};\n" //
+ + "var params = {'converted': converted.substring(0, 3)};\n" //
+ + "attrs.ep = params;\n" //
+ + "Wicket.Ajax.ajax(attrs);\n" //
+ + "}\n", //
+ page.getBehavior()
+ .getCallbackFunction(converted("converted", "converted.substring(0, 3)"))
+ .toString());
+ }
+
+ @Test
+ public void testCallbackFunctionWithAll()
+ {
+ AjaxCallbackPage page = tester.startPage(AjaxCallbackPage.class);
+ assertEquals(
+ //
+ "function (context,explicit,converted) {\n" //
+ + "var attrs = {\"u\":\"./wicket/page?0-1.IBehaviorListener.0-\"};\n" //
+ + "var params = {'explicit': explicit,'resolved': window.location.href,'converted': converted.substring(0, 3)};\n" //
+ + "attrs.ep = params;\n" //
+ + "Wicket.Ajax.ajax(attrs);\n" //
+ + "}\n", //
+ page.getBehavior()
+ .getCallbackFunction(context("context"), explicit("explicit"),
+ resolved("resolved", "window.location.href"),
+ converted("converted", "converted.substring(0, 3)"))
+ .toString());
+ }
+
+ @Test
+ public void testJQueryUIEvent()
+ {
+ AjaxCallbackPage page = tester.startPage(AjaxCallbackPage.class);
+ assertEquals(
+ //
+ "function (event,ui) {\n" //
+ + "var attrs = {\"u\":\"./wicket/page?0-1.IBehaviorListener.0-\"};\n" //
+ + "var params = {'sortIndex': $(this).find(':data(sortable-item)').index(ui.item),'sortItemId': $(ui.item).attr('id'),'sortSenderId': $(ui.sender).attr('id')};\n" //
+ + "attrs.ep = params;\n" //
+ + "Wicket.Ajax.ajax(attrs);\n" //
+ + "}\n", //
+ page.getBehavior()
+ .getCallbackFunction(context("event"), context("ui"),
+ resolved("sortIndex", "$(this).find(':data(sortable-item)').index(ui.item)"),
+ resolved("sortItemId", "$(ui.item).attr('id')"),
+ resolved("sortSenderId", "$(ui.sender).attr('id')"))
+ .toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/7dba094c/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackPage.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackPage.html b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackPage.html
new file mode 100644
index 0000000..f834fa8
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackPage.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Insert title here</title>
+</head>
+<body>
+</body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/7dba094c/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackPage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackPage.java b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackPage.java
new file mode 100644
index 0000000..34e8029
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxCallbackPage.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.wicket.ajax;
+
+import org.apache.wicket.markup.html.WebPage;
+
+public class AjaxCallbackPage extends WebPage
+{
+ private AbstractDefaultAjaxBehavior behavior;
+
+ public AjaxCallbackPage()
+ {
+ add(behavior = new AbstractDefaultAjaxBehavior()
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void respond(AjaxRequestTarget target)
+ {
+ }
+ });
+ }
+
+ public AbstractDefaultAjaxBehavior getBehavior()
+ {
+ return behavior;
+ }
+}