Reputation: 53521
I am struggling with running my first Play! 2.1.x app and I always get this error (this is from running the test
cases) :
Test models.TestModel.testCreate failed: The default EbeanServer has not been defined? This is normally set via the ebean.datasource.default property. Otherwise it should be registered programatically via registerServer()
I have read the official manual, many SO questions, and even some blogs and I still can't figure out why I keep on getting this.
Note: I specify the test.conf
file from this SO question, in Build.scala
.
Here is the content of test.conf
:
include "application.conf"
application.version=${application.major}.${application.minor}.${application.revision}-TEST
db.default.driver=org.h2.Driver
db.default.jndiName=DefaultDS
db.default.url="jdbc:h2:mem:play;MODE=PostgreSQL;DB_CLOSE_DELAY=-1"
db.default.user=sa
db.default.password=""
ebean.default="models.*"
ebean.datasource.factory=jndi
ebean.datasource.default=DefaultDS
Note: the same keys are also specified in application.conf
, but with the "prod" values.
What am I missing? Thanks!
The test case is very straight forward. I am using a base class, copy-pasted as-is from this blog :
public class TestSomeModel extends BaseModelTest {
@Test
public void myModelCreate() {
SomeModel model = new SomeModel();
model.someStringAttribute = "some value";
assertThat(model.id).isNull();
model.save(); // <--- this is the line that gives the error
assertThat(model.id).isPositive();
}
}
... and if anyone insist on seeing the model class....
@Entity
public class SomeModel extends Model {
@Id
public Long id;
public String someStringAttribute;
}
Upvotes: 3
Views: 1749
Reputation: 46
add @Entity before the model
@Entity public class SomeModel extends Model {
Upvotes: 3
Reputation: 21564
Try running your test code inside a fakeApplication()
:
import ...
import play.test.Helpers.*;
public class TestSomeModel extends BaseModelTest {
@Test
public void myModelCreate() {
running(fakeApplication(), new Runnable() {
public void run() {
SomeModel model = new SomeModel();
model.someStringAttribute = "some value";
assertThat(model.id).isNull();
model.save();
assertThat(model.id).isPositive();
}
}
}
}
Upvotes: 2