java - Persist data in local storage google app engine with Junit + eclipse -


my setup:

win 7 , eclipse , gae sdk 1.8.5 ,objectify 4 , junit4

i trying write junit test cases save 2 car entities , retrieve them. using objectify , works fine.

my problem need persist entities across many runs of test cases, means once save using dosavecar() in 1 run , in next run , should 2 entities when run dolistcar(). how persist local storage across various junit test runs in eclipse environment ?

import org.junit.after; import org.junit.before; import org.junit.test;   import com.google.appengine.tools.development.testing.localdatastoreservicetestconfig; import com.google.appengine.tools.development.testing.localmemcacheservicetestconfig; import com.google.appengine.tools.development.testing.localservicetesthelper;  public class ofytest  {      private final localservicetesthelper helper = new localservicetesthelper(             new localdatastoreservicetestconfig(),             new localmemcacheservicetestconfig());          @before         public void setup() {             helper.setup();          }         @after         public void teardown() {             helper.teardown();         }          @test         public void dosavecar() {              new crudserviceimpl().save(new car("mustang", "green"));             new crudserviceimpl().save(new car("srt", "red"));          }           @test         public void dolistcars(){              new crudserviceimpl().list(abstractentity.class);           }  } 

i keep data 1 run other using objectify, junit, mockito , google-app-engine, setting nostorageflag.

dsservice.setnostorage(false); 

refer below junit test

private final localservicetesthelper helper =           new localservicetesthelper(new localuserservicetestconfig())               .setenvisloggedin(true)               .setenvauthdomain("localhost")               .setenvemail("test@localhost");    @before   public void setupcustomerservlet() {     helper.setup();     localdatastoreservice dsservice = (localdatastoreservice)helper.getlocalservice(localdatastoreservice.package);     dsservice.setnostorage(false);     customerservlet = new customerservlet();   }    @after   public void teardownhelper() {     helper.teardown();   }    @test   public void testdoget() throws ioexception, servletexception {     httpservletrequest request = mock(httpservletrequest.class);     httpservletresponse response = mock(httpservletresponse.class);      // test entry     customer customerin = new customer();     customerin.setname("felix");     customerin.setaddress("kuestahler");     string json = (new gson()).tojson(customerin);      stringwriter stringwriter = new stringwriter();      when(request.getreader()).thenreturn(new bufferedreader(new stringreader(json)));     when(response.getwriter()).thenreturn(new printwriter(stringwriter));      customerservlet.dopost(request, response);      customer customerout =  (new gson()).fromjson(stringwriter.tostring(), customer.class);      assertequals(customerout.getname(), customerin.getname());     assertequals(customerout.get_id() > 0,true);      stringwriter = new stringwriter();      when(request.getreader()).thenreturn(new bufferedreader(new stringreader("")));     when(response.getwriter()).thenreturn(new printwriter(stringwriter));      customerservlet.doget(request, response);      system.out.println("out: "+stringwriter.tostring());    } 

my list of locally stored customers growing after each mvn test run.

imac:~ felix$ ls -l /users/felix/development/workspace-clb/clb-appengine/./web-  inf/appengine-generated/ total 32 -rw-r--r--  1 felix  felix     81 22 okt 22:00 datastore-indexes-auto.xml -rw-r--r--  1 felix  felix  10068 22 okt 22:00 local_db.bin imac:~ felix$ ls -l /users/felix/development/workspace-clb/clb-appengine/./web-inf/appengine-generated/ total 32 -rw-r--r--  1 felix  felix     81 22 okt 22:08 datastore-indexes-auto.xml -rw-r--r--  1 felix  felix  11265 22 okt 22:08 local_db.bin` 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -