From bd9fe1c2531df1fb5682ace03197a1aa8ded2da4 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 12 May 2010 13:47:14 +0000 Subject: Added a module to speed up testing in development mode --- .../com/google/gwt/query/DevTestRunner.gwt.xml | 5 ++ .../com/google/gwt/query/client/DevTestRunner.java | 50 ++++++++++++++++ .../com/google/gwt/query/client/MyTestCase.java | 69 ++++++++++++++++++++++ .../java/com/google/gwt/query/public/test.html | 8 +++ 4 files changed, 132 insertions(+) create mode 100644 devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml create mode 100644 devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java create mode 100644 devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java create mode 100644 devtest/src/main/java/com/google/gwt/query/public/test.html (limited to 'devtest/src/main/java') diff --git a/devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml b/devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml new file mode 100644 index 00000000..537f0c47 --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java b/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java new file mode 100644 index 00000000..046fdf11 --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java @@ -0,0 +1,50 @@ +/* + * Copyright 2009 Google Inc. + * + * 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; + +import static com.google.gwt.query.client.GQuery.$; + +import com.google.gwt.core.client.EntryPoint; + +/** + * This module is thought to emulate a test environment similar to + * GWTTestCase, but running it in development mode. + * + * The main goal of it is to execute tests in a faster way, because you only need + * to push reload in your browser. + * + * @author manolo + * + */ +public class DevTestRunner extends MyTestCase implements EntryPoint { + + public void onModuleLoad() { + gwtSetUp(); + testDomManip(); + } + + public void testDomManip() { + String content = "branchA target" + + "branchB target"; + + $(e).html(""); + $(e).append(content); + assertEquals(4, $("span", e).size()); + assertEquals(2, $("span.target", e).size()); + assertHtmlEquals(content, $(e).html()); + } + +} diff --git a/devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java b/devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java new file mode 100644 index 00000000..e505812a --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java @@ -0,0 +1,69 @@ +/* + * Copyright 2009 Google Inc. + * + * 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; + +import com.google.gwt.dom.client.Element; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.RootPanel; + +/** + * Just a simple class to emulate JUnit TestCase + */ +public class MyTestCase { + + static Element e = null; + static HTML testPanel = null; + + public void gwtSetUp() { + if (e == null) { + testPanel = new HTML(); + RootPanel.get().add(testPanel); + e = testPanel.getElement(); + e.setId("core-tst"); + } else { + e.setInnerHTML(""); + } + } + + public static void assertNotNull(Object a) { + check(a != null, "assertNotNull: actual object is null"); + } + + public static void assertEquals(Object a, Object b) { + check(a.equals(b), "assertEquals: expected=" + a + " actual=" + b); + } + + public static void check(boolean condition, String message) { + if (!condition) { + RuntimeException e = new RuntimeException(message); + e.printStackTrace(); + throw e; + } + } + + protected static void assertHtmlEquals(Object expected, Object actual) { + assertEquals(iExplorerFixHtml(expected), iExplorerFixHtml(actual)); + } + + protected static String iExplorerFixHtml(Object s) { + return s.toString().trim().toLowerCase(). + replaceAll("[\r\n]", ""). + replaceAll(" ([\\w]+)=[\"']([^\"']+)[\"']", " $1=$2"). + replaceAll("\\s+\\$h=\"[^\"]+\"", ""). + replaceAll(" added=[^ >]+", ""); + } + +} diff --git a/devtest/src/main/java/com/google/gwt/query/public/test.html b/devtest/src/main/java/com/google/gwt/query/public/test.html new file mode 100644 index 00000000..1c447858 --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/public/test.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file -- cgit v1.2.3