diff flys-client/src/test/java/de/intevation/flys/client/client/FLYSTest.java @ 0:4e8be5e7855f

Start of a GWT based client for FLYS-3.0 flys-client/trunk@1305 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 08 Feb 2011 10:29:49 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/test/java/de/intevation/flys/client/client/FLYSTest.java	Tue Feb 08 10:29:49 2011 +0000
@@ -0,0 +1,68 @@
+package de.intevation.flys.client.client;
+
+import de.intevation.flys.client.shared.FieldVerifier;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.rpc.ServiceDefTarget;
+
+/**
+ * GWT JUnit tests must extend GWTTestCase.
+ */
+public class FLYSTest extends GWTTestCase {
+
+  /**
+   * Must refer to a valid module that sources this class.
+   */
+  public String getModuleName() {
+    return "de.intevation.flys.client.FLYSJUnit";
+  }
+
+  /**
+   * Tests the FieldVerifier.
+   */
+  public void testFieldVerifier() {
+    assertFalse(FieldVerifier.isValidName(null));
+    assertFalse(FieldVerifier.isValidName(""));
+    assertFalse(FieldVerifier.isValidName("a"));
+    assertFalse(FieldVerifier.isValidName("ab"));
+    assertFalse(FieldVerifier.isValidName("abc"));
+    assertTrue(FieldVerifier.isValidName("abcd"));
+  }
+
+  /**
+   * This test will send a request to the server using the greetServer method in
+   * GreetingService and verify the response.
+   */
+  public void testGreetingService() {
+    // Create the service that we will test.
+    GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
+    ServiceDefTarget target = (ServiceDefTarget) greetingService;
+    target.setServiceEntryPoint(GWT.getModuleBaseURL() + "flys/greet");
+
+    // Since RPC calls are asynchronous, we will need to wait for a response
+    // after this test method returns. This line tells the test runner to wait
+    // up to 10 seconds before timing out.
+    delayTestFinish(10000);
+
+    // Send a request to the server.
+    greetingService.greetServer("GWT User", new AsyncCallback<String>() {
+      public void onFailure(Throwable caught) {
+        // The request resulted in an unexpected error.
+        fail("Request failure: " + caught.getMessage());
+      }
+
+      public void onSuccess(String result) {
+        // Verify that the response is correct.
+        assertTrue(result.startsWith("Hello, GWT User!"));
+
+        // Now that we have received a response, we need to tell the test runner
+        // that the test is complete. You must call finishTest() after an
+        // asynchronous test finishes successfully, or the test will time out.
+        finishTest();
+      }
+    });
+  }
+
+
+}

http://dive4elements.wald.intevation.org