Skip to content

Instantly share code, notes, and snippets.

@nboire
Created May 28, 2012 16:15
Show Gist options
  • Save nboire/2819920 to your computer and use it in GitHub Desktop.
Save nboire/2819920 to your computer and use it in GitHub Desktop.
Playframework play2 EbeanTest Class to Clean Database before each test
package app;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.MySqlPlatform;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.ddl.DdlGenerator;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import play.test.FakeApplication;
import play.test.Helpers;
import java.io.IOException;
public class EbeanTest {
public static FakeApplication app;
@BeforeClass
public static void startApp() throws IOException {
app = Helpers.fakeApplication();
Helpers.start(app);
}
@AfterClass
public static void stopApp() {
Helpers.stop(app);
}
@Before
public void dropCreateDb() throws IOException {
String serverName = "default";
EbeanServer server = Ebean.getServer(serverName);
ServerConfig config = new ServerConfig();
DdlGenerator ddl = new DdlGenerator((SpiEbeanServer) server, new MySqlPlatform(), config);
// Drop
ddl.runScript(false, ddl.generateDropDdl());
// Create
ddl.runScript(false, ddl.generateCreateDdl());
}
}
@pmichna
Copy link

pmichna commented Dec 17, 2013

Hey, I get this error:

[CityGame] $ test
[info] Compiling 2 Java sources to /Users/pmichna/Documents/code/citygame/target/scala-2.10/test-classes...
[error] /Users/pmichna/Documents/code/citygame/test/models/BaseModelTest.java:31: error: constructor DdlGenerator in class DdlGenerator cannot be applied to given types;
[error]         ddl = new DdlGenerator((SpiEbeanServer) server, new MySqlPlatform(), config);
[error]               ^
[error]   required: no arguments
[error]   found: SpiEbeanServer,MySqlPlatform,ServerConfig
[error]   reason: actual and formal argument lists differ in length
[error] 1 error
[error] (test:compile) javac returned nonzero exit code
[error] Total time: 2 s, completed 2013-12-17 00:21:23

Do you have any idea what can be the cause?

@janetruluck
Copy link

For others looking this was solved on SO http://stackoverflow.com/q/20623040/1359888

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment