ingo@0: package de.intevation.flys.client.client; ingo@0: ingo@0: import de.intevation.flys.client.shared.FieldVerifier; ingo@0: import com.google.gwt.core.client.GWT; ingo@0: import com.google.gwt.junit.client.GWTTestCase; ingo@0: import com.google.gwt.user.client.rpc.AsyncCallback; ingo@0: import com.google.gwt.user.client.rpc.ServiceDefTarget; ingo@0: ingo@0: /** ingo@0: * GWT JUnit tests must extend GWTTestCase. ingo@0: */ ingo@0: public class FLYSTest extends GWTTestCase { ingo@0: ingo@0: /** ingo@0: * Must refer to a valid module that sources this class. ingo@0: */ ingo@0: public String getModuleName() { ingo@0: return "de.intevation.flys.client.FLYSJUnit"; ingo@0: } ingo@0: ingo@0: /** ingo@0: * Tests the FieldVerifier. ingo@0: */ ingo@0: public void testFieldVerifier() { ingo@0: assertFalse(FieldVerifier.isValidName(null)); ingo@0: assertFalse(FieldVerifier.isValidName("")); ingo@0: assertFalse(FieldVerifier.isValidName("a")); ingo@0: assertFalse(FieldVerifier.isValidName("ab")); ingo@0: assertFalse(FieldVerifier.isValidName("abc")); ingo@0: assertTrue(FieldVerifier.isValidName("abcd")); ingo@0: } ingo@0: ingo@0: /** ingo@0: * This test will send a request to the server using the greetServer method in ingo@0: * GreetingService and verify the response. ingo@0: */ ingo@0: public void testGreetingService() { ingo@0: // Create the service that we will test. ingo@0: GreetingServiceAsync greetingService = GWT.create(GreetingService.class); ingo@0: ServiceDefTarget target = (ServiceDefTarget) greetingService; ingo@0: target.setServiceEntryPoint(GWT.getModuleBaseURL() + "flys/greet"); ingo@0: ingo@0: // Since RPC calls are asynchronous, we will need to wait for a response ingo@0: // after this test method returns. This line tells the test runner to wait ingo@0: // up to 10 seconds before timing out. ingo@0: delayTestFinish(10000); ingo@0: ingo@0: // Send a request to the server. ingo@0: greetingService.greetServer("GWT User", new AsyncCallback() { ingo@0: public void onFailure(Throwable caught) { ingo@0: // The request resulted in an unexpected error. ingo@0: fail("Request failure: " + caught.getMessage()); ingo@0: } ingo@0: ingo@0: public void onSuccess(String result) { ingo@0: // Verify that the response is correct. ingo@0: assertTrue(result.startsWith("Hello, GWT User!")); ingo@0: ingo@0: // Now that we have received a response, we need to tell the test runner ingo@0: // that the test is complete. You must call finishTest() after an ingo@0: // asynchronous test finishes successfully, or the test will time out. ingo@0: finishTest(); ingo@0: } ingo@0: }); ingo@0: } ingo@0: ingo@0: ingo@0: }