Hello,
I am doing experiments with a simple service QuestionService and I
have a GWTTestCase that calls the QuestionService. All works fine, but
my problem is that in the QuestionServiceImpl constructor I have to
use the LocalServiceTestHelper helper infrastructure in order to make
the whole test case work.
My problem is now that I have to introduce dependencies in my
QuestionServiceImpl on the appengine-testing jar in order to make my
GWTTestCase work! My initial tries were to use the
LocalServiceTestHelper directly in the gwtSetUp and gwtTearDown
methods of the GWTTestCase but that does of course not work, because
those classes are not compatible with the GWT (they obviously cannot
and should not be compiled to java script).
Is there any good way around this that I have to introduce a
dependency on the appengine-testing infrastructure in my service
implementation? Can I somehow detect that I am running in a
GWTTestCase, then I could at least create a if-then-else block that
only instantiates the helper in test mode.
Many thanks for any recommendations!
@RemoteServiceRelativePath("question")
public interface QuestionService extends RemoteService {
public QuestionDefinition createQuestionDefinition(String question);
public void deleteQuestionDefinition(QuestionDefinition qd);
public QuestionDefinition findQuestionDefinitionById(String key);
}
public class QuestionServiceImpl extends RemoteServiceServlet
implements QuestionService {
private final LocalServiceTestHelper helper = new
LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
public QuestionServiceImpl() {
super();
helper.setUp();
}
public QuestionDefinition createQuestionDefinition(String question) {
PersistenceManager pm = PMF.get().getPersistenceManager();
QuestionDefinition qd = new QuestionDefinition(question);
try {
pm.makePersistent(qd);
} finally {
pm.close();
}
return qd;
}
...
}
public class GwtTestQuestionService extends GWTTestCase {
@Override
public String getModuleName() {
return "questionservice";
}
public void testQuestionServiceCreate() {
QuestionServiceAsync questionService =
GWT.create(QuestionService.class);
String question = "Are you happy?";
questionService.createQuestionDefinition(question,
new AsyncCallback<QuestionDefinition>() {
public void onFailure(Throwable caught)
{
Assert.fail();
finishTest();
}
public void
onSuccess(QuestionDefinition result) {
Assert.assertNotNull(result);
finishTest();
}
});
delayTestFinish(5000);
}
}
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" 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-appengine-java?hl=en.