Created
February 20, 2012 03:19
-
-
Save jackganzha/1867549 to your computer and use it in GitHub Desktop.
A super class for model tests in play 2.0
This file contains hidden or 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 models; | |
import java.util.Map; | |
import java.util.List; | |
import java.util.ArrayList; | |
import org.junit.Test; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Assert; | |
import org.junit.AfterClass; | |
import org.junit.BeforeClass; | |
import play.test.Helpers; | |
import play.db.ebean.Model; | |
import play.test.FakeApplication; | |
import com.avaje.ebean.Ebean; | |
public class ModelTest<T extends Model> { | |
public static FakeApplication app; | |
@BeforeClass | |
public static void startApp() { | |
app = Helpers.fakeApplication(/*Helpers.inMemoryDatabase()*/); | |
Helpers.start(app); | |
} | |
@Before | |
public void beforeEachTest() { | |
Ebean.save(fixturesToLoad()); | |
} | |
@After | |
public void afterEachTest() { | |
Ebean.delete(fixturesToUnload()); | |
} | |
// template methods to load/unload fixtures | |
public List<T> fixturesToLoad() { return new ArrayList<T>(); } | |
public List<T> fixturesToUnload() { return new ArrayList<T>();} | |
@AfterClass | |
public static void stopApp() { | |
Helpers.stop(app); | |
} | |
} |
This file contains hidden or 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
public class TaskTest extends ModelTest<Task> { | |
@Test | |
public void test() { | |
Task task = new Task(); | |
task.label = "foo"; | |
task.save(); | |
Finder<Long, Task> find = new Finder<Long, Task>(Long.class, Task.class); | |
task = find.where().eq("label", "foo").findUnique(); | |
assertEquals("foo", task.label); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment