[appengine-java] Re: How to best run GWTTestCase tests that involve persistence?

2011-06-23 Thread esorf
   

I have a pretty good solution for you, Christian, and anyone else trying to 
do this, ie GwtTestCase plus GAE test fixtures.


First, create a myapptest.gwt.xml module file.




  

  


  

  

  


  

  




The key here is that you're pointing services to a new class.  Thankfully, 
the class is a simple subclass of the original service implementation that 
adds AppEngine test fixture initialization in the init() method.


public class AccountServiceTestImpl extends AccountServiceImpl {

private final LocalServiceTestHelper helper = new LocalServiceTestHelper(

 new LocalDatastoreServiceTestConfig(), newLocalUserServiceTestConfig())

 .setEnvIsLoggedIn(true)

 .setEnvAuthDomain("test.com")

 .setEnvEmail("t...@test.com");


 @Override

public void init() throws ServletException {

 super.init();

 helper.setUp();

}

}


All these files sit in subdirectories of /test so you're not introducing 
fixture dependencies in your /src code.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/AELb4qfT9VkJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: How to best run GWTTestCase tests that involve persistence?

2010-03-17 Thread Christian Schuhegger
The reason why I thought such tests would be beneficial is that there
exist projects like gilead:
http://noon.gilead.free.fr/gilead/index.php?page=gwt
that only deal with the aspect of mapping between enhanced and
unenhanced objects.

When communicating over the network the object graph of the arguments
and return values needs to be serialized back and forth and normally
on the server side you have the enhanced objects that are "richer"
than the unenhanced objects on the client side. I would have guessed
that incompatibilities could result from the fact that the
serialization mechanism (which is a feature of the remoting framework
that normally knows nothing about ORM frameworks) cannot serialize
enhanced objects to java script.

Where is my mistake in my line of argumentation?

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: How to best run GWTTestCase tests that involve persistence?

2010-03-15 Thread datanucleus
DataNucleus enhances the classes when you tell it to; compile time,
post-compile, or runtime. You can use unenhanced classes on client,
and enhanced on server without issues

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: How to best run GWTTestCase tests that involve persistence?

2010-03-15 Thread Christian Schuhegger
Hi,

I already have two types of tests. One type of test that separately
tests the server side logic and the client side logic separately and
independently and the second type of test that verifies the
integration of both sides. I am also already using SyncProxy for some
tests.

The reason why I would like to have integration tests using
GWTTestCase is that I would like to have them automatically execute
from a continuous integration server. I want to verify with those
tests that any additional layer of infrastructure like Hibernate or
DataNucleus does not introduce any incompatibilities in my data
objects. As Hibernate or DataNucleus enhance the objects at runtime it
is important for me to verify that these enhanced objects are still
compatible when transferring them over the network to the client. A
QuestionDefinition object that I create via the Java new operator may
not be the same object that exists at runtime after being enhanced
(byte code manipulation) by Hibernate or DataNucleus.

Do you have any suggestions for that use case for me?

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: How to best run GWTTestCase tests that involve persistence?

2010-03-14 Thread Trung
Hi,

1. I think the proper way is separating the test from
QuestionServiceImpl.

2. For testing QuestionServiceImpl, you should run two separate parts:
server side and client side.
a) In your case, there are no special in the server side.
b) In the client side, you can use GWTTestcase. Your test logic is on
the client side.
However, testing with GWTTestcase are slow. SyncProxy can be used on
the client side to invoke your remote service.
See http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/
and 
http://www.gdevelop.com/w/blog/2010/03/13/invoke-gwt-rpc-services-deployed-on-google-app-engine/
for how to use SyncProxy.



On Mar 14, 8:34 pm, Christian Schuhegger
 wrote:
> 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() {
>                                         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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.