Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4e8be5e7855f |
---|---|
1 package de.intevation.flys.client.client; | |
2 | |
3 import de.intevation.flys.client.shared.FieldVerifier; | |
4 import com.google.gwt.core.client.GWT; | |
5 import com.google.gwt.junit.client.GWTTestCase; | |
6 import com.google.gwt.user.client.rpc.AsyncCallback; | |
7 import com.google.gwt.user.client.rpc.ServiceDefTarget; | |
8 | |
9 /** | |
10 * GWT JUnit tests must extend GWTTestCase. | |
11 */ | |
12 public class FLYSTest extends GWTTestCase { | |
13 | |
14 /** | |
15 * Must refer to a valid module that sources this class. | |
16 */ | |
17 public String getModuleName() { | |
18 return "de.intevation.flys.client.FLYSJUnit"; | |
19 } | |
20 | |
21 /** | |
22 * Tests the FieldVerifier. | |
23 */ | |
24 public void testFieldVerifier() { | |
25 assertFalse(FieldVerifier.isValidName(null)); | |
26 assertFalse(FieldVerifier.isValidName("")); | |
27 assertFalse(FieldVerifier.isValidName("a")); | |
28 assertFalse(FieldVerifier.isValidName("ab")); | |
29 assertFalse(FieldVerifier.isValidName("abc")); | |
30 assertTrue(FieldVerifier.isValidName("abcd")); | |
31 } | |
32 | |
33 /** | |
34 * This test will send a request to the server using the greetServer method in | |
35 * GreetingService and verify the response. | |
36 */ | |
37 public void testGreetingService() { | |
38 // Create the service that we will test. | |
39 GreetingServiceAsync greetingService = GWT.create(GreetingService.class); | |
40 ServiceDefTarget target = (ServiceDefTarget) greetingService; | |
41 target.setServiceEntryPoint(GWT.getModuleBaseURL() + "flys/greet"); | |
42 | |
43 // Since RPC calls are asynchronous, we will need to wait for a response | |
44 // after this test method returns. This line tells the test runner to wait | |
45 // up to 10 seconds before timing out. | |
46 delayTestFinish(10000); | |
47 | |
48 // Send a request to the server. | |
49 greetingService.greetServer("GWT User", new AsyncCallback<String>() { | |
50 public void onFailure(Throwable caught) { | |
51 // The request resulted in an unexpected error. | |
52 fail("Request failure: " + caught.getMessage()); | |
53 } | |
54 | |
55 public void onSuccess(String result) { | |
56 // Verify that the response is correct. | |
57 assertTrue(result.startsWith("Hello, GWT User!")); | |
58 | |
59 // Now that we have received a response, we need to tell the test runner | |
60 // that the test is complete. You must call finishTest() after an | |
61 // asynchronous test finishes successfully, or the test will time out. | |
62 finishTest(); | |
63 } | |
64 }); | |
65 } | |
66 | |
67 | |
68 } |