Created
December 9, 2010 00:08
-
-
Save dwursteisen/734144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.bitbucket.dwursteisen.stripes; | |
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; | |
import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | |
import org.bitbucket.dwursteisen.model.Pics; | |
import org.bitbucket.dwursteisen.model.Spot; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
import static org.junit.Assert.assertEquals; | |
/** | |
* User: david | |
* Date: 9 déc. 2010 | |
* Time: 00:20:05 | |
*/ | |
public class AppEngineContextTest { | |
private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()); | |
private ApplicationContext context; | |
@Before | |
public void setUp() throws Exception { | |
helper.setUp(); | |
context = new ApplicationContext(); | |
} | |
@After | |
public void tearDown() throws Exception { | |
helper.tearDown(); | |
} | |
@Test | |
public void testPersit() { | |
Spot newSpot = new Spot(); | |
newSpot.setName("newSpot"); | |
Pics newPics = new Pics(); | |
newPics.setComment("newPicsComment"); | |
newSpot.setPics(newPics); | |
// the persist method start a transaction, call persist on the EM, then commit the transaction (or rollback it if an error occur) | |
context.persist(newSpot); | |
Spot dbSpot = context.list(Spot.class).get(0); | |
assertEquals("newSpot", dbSpot.getName()); | |
assertEquals("newPicsComment", dbSpot.getPics().getComment()); | |
Pics newDbPics = new Pics(); | |
newDbPics.setComment("newDbPics"); | |
dbSpot.setPics(newDbPics); | |
context.persist(dbSpot); | |
Spot newDbSpot = context.list(Spot.class).get(0); | |
assertEquals("newSpot", newDbSpot.getName()); | |
assertEquals("newDbPics", newDbSpot.getPics().getComment()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment