hi, i added a unit test to the greet example (please see code below). i get
Starting HTTP on port 0
HTTP listening on port 4889
Starting
http://192.168.1.105:4889/p.R.JUnit/junit.html?gwt.codesvr=192.168.1.105:4887
on browser FF3
Module p.R.JUnit has been loaded
The development shell servlet received a request for 'greet' in
module 'p.R.JUnit.gwt.xml'
[WARN] Resource not found: greet; (could a file be missing from
the public path or a <servlet> tag misconfigured in module p.R.JUnit.gwt.xml ?)
lose: com.google.gwt.user.client.rpc.StatusCodeException: Cannot find
resource 'greet' in the public path of module 'p.R.JUnit'
All clients connected (Limiting future permutations to: gecko1_8)
the :"lose" message is mine, coming from onFailure() in the async callback.
i don't think i changed anything except the on module load file.
seems like it's confused about the module name.
thanks
package p.client;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.Timer;
public class ATestCase extends GWTTestCase {
public ATestCase(String name) {
setName(name);
}
public ATestCase() {
}
protected void gwtSetUp() throws Exception {
super.gwtSetUp();
}
protected void gwrTearDown() throws Exception {
super.gwtTearDown();
}
@Override
public String getModuleName() {
return "p.R";
}
public void testAnRpc() throws Exception {
R module = new R();
final String id="xx";
final Label label=new Label();
module.send2(id, label);
Timer timer = new Timer() {
public void run() {
System.out.println(label.getText());
finishTest();
}
};
timer.schedule(200);
delayTestFinish(500);
}
}
package p.client;
import p.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class R implements EntryPoint {
/**
* The message displayed to the user when the server cannot
be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error
occurred while " + "attempting to contact the server. Please check
your network "
+ "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side
Greeting service.
*/
private final GreetingServiceAsync greetingService =
GWT.create(GreetingService.class);
/**
* This is the entry point method.
*/
public void onModuleLoad() {
final Button sendButton = new Button("Send");
final TextBox nameField = new TextBox();
nameField.setText("GWT User");
final Label errorLabel = new Label();
// We can add style names to widgets
sendButton.addStyleName("sendButton");
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("nameFieldContainer").add(nameField);
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);
// Focus the cursor on the name field when the app loads
nameField.setFocus(true);
nameField.selectAll();
// Create the popup dialog box
final DialogBox dialogBox = new DialogBox();
dialogBox.setText("Remote Procedure Call");
dialogBox.setAnimationEnabled(true);
final Button closeButton = new Button("Close");
// We can set the id of a widget by accessing its Element
closeButton.getElement().setId("closeButton");
final Label textToServerLabel = new Label();
final HTML serverResponseLabel = new HTML();
VerticalPanel dialogVPanel = new VerticalPanel();
dialogVPanel.addStyleName("dialogVPanel");
dialogVPanel.add(new HTML("<b>Sending name to the
server:</b>"));
dialogVPanel.add(textToServerLabel);
dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
dialogVPanel.add(serverResponseLabel);
dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
dialogVPanel.add(closeButton);
dialogBox.setWidget(dialogVPanel);
// Add a handler to close the DialogBox
closeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
dialogBox.hide();
sendButton.setEnabled(true);
sendButton.setFocus(true);
}
});
// Create a handler for the sendButton and nameField
class MyHandler implements ClickHandler, KeyUpHandler {
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
sendNameToServer();
}
/**
* Fired when the user types in the nameField.
*/
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() ==
KeyCodes.KEY_ENTER) {
sendNameToServer();
}
}
/**
* Send the name from the nameField to the
server and wait for a response.
*/
void sendNameToServer() {
// First, we validate the input.
errorLabel.setText("");
String textToServer = nameField.getText();
if
(!FieldVerifier.isValidName(textToServer)) {
errorLabel.setText("Please
enter at least four characters");
return;
}
// Then, we send the input to the server.
sendButton.setEnabled(false);
textToServerLabel.setText(textToServer);
serverResponseLabel.setText("");
send2(textToServer,textToServerLabel);
//send(dialogBox, closeButton,
serverResponseLabel, textToServer);
}
private void send(final DialogBox dialogBox,
final Button closeButton, final HTML serverResponseLabel, String
textToServer) {
greetingService.greetServer(textToServer,
new AsyncCallback<String>() {
public void
onFailure(Throwable caught) {
// Show the RPC
error message to the user
dialogBox.setText("Remote
Procedure Call - Failure");
serverResponseLabel.addStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(SERVER_ERROR);
dialogBox.center();
closeButton.setFocus(true);
}
public void onSuccess(String result) {
dialogBox.setText("Remote
Procedure Call");
serverResponseLabel.removeStyleName("serverResponseLabelError");
serverResponseLabel.setHTML(result);
dialogBox.center();
closeButton.setFocus(true);
}
});
}
}
// Add a handler to send the name to the server
MyHandler handler = new MyHandler();
sendButton.addClickHandler(handler);
nameField.addKeyUpHandler(handler);
}
void send2(final String textToServer,final Label label) {
greetingService.greetServer(textToServer, new
AsyncCallback<String>() {
public void onFailure(Throwable caught) {
label.setText("lose: "+caught);
}
public void onSuccess(String result) {
label.setText("win");
}
});
}
}
---
co-chair http://ocjug.org/
--
You received this message because you are subscribed to the Google Groups "Google
Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.