Reputation: 1
I am using Spring MVC in eclipse and running junit test in local dev server. Junit test not able to access the datastore of GAE. Is there any connection or settings required to access the GAE dev server while test Junit locally . // code as follows
private LocalServiceTestHelper helper;
@Before
public void setUp()
{
File dbContents = new File("war/WEB-INF/appengine-generated/local_db.bin");
helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
.setBackingStoreLocation(dbContents.getAbsolutePath())
.setStoreDelayMs(4000)
.setNoStorage(true)
) {
};
this.helper.setUp();
LocalDatastoreService dsService = (LocalDatastoreService)LocalServiceTestHelper.getLocalService(LocalDatastoreService.PACKAGE);
dsService.setNoStorage(false);
CustomerPageJDO CustomerPageJDO = new CustomerPageJDO();
CustomerPageJDO.setCUID("fac54bca-d593-44c6-8c84-6b4d765eb35f");
accountJDO.setKey("fac54bca-d593-44c6-8c84-6b4d765eb35f");
accountJDO.setCompanyKey("fac54bca-d593-44c6-8c84-6b4d765eb35f");
accountJDO.setCurrentplanType("freePlan_v3");
planJDO.setPlanId("freePlan_v3");
planJDO.setPlanName("Free Plan");
pm = PMF.get().getPersistenceManager();
pm.makePersistent(CustomerPageJDO);
pm.makePersistent(accountJDO);
pm.makePersistent(planJDO);
}
public void testPersistaccountJDOs1()
{
List<AccountJDO> accountJDOList = null;
PersistenceManager pm;
//Ensure the accountJDO does not already exist in datasource
pm = PMF.get().getPersistenceManager();
boolean notFound = false;
try
{
accountJDO=pm.getObjectById(AccountJDO.class, "fac54bca-d593-44c6-8c84-6b4d765eb35f");
planJDO= pm.getObjectById(PlanJDO.class,accountJDO.getCurrentplanType());
System.out.println("accountJDO"+gson.toJson(accountJDO));
} catch (Exception e)
{
notFound = true;
System.out.println("error");
e.printStackTrace();
}
finally
{
pm.close();
}
}
@Test
public void testInsert2() {
testPersistaccountJDOs1();
}
@After
public void tearDown11()
{
this.helper.tearDown();
}
Upvotes: 0
Views: 535
Reputation: 2143
if you need do test datastore (GAE) you should follow the steps (here) add jars
then you can test for example:
public class DatastoreTest {
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void queryTest(){
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Entity directoty = new Entity("Directory");
directoty.setProperty("email", "test@localhost");
directoty.setProperty("name", "edy");
ds.put(directoty);
assertEquals(1,ds.prepare(new Query("Directoty")).countEntities(withLimit(10)));
}
}
Upvotes: 4