Note that there are some explanatory texts on larger screens.

plurals
  1. POPlay Java Guide application nr. 2 testing
    primarykey
    data
    text
    <p>I'm trying to walk through this guide: <a href="http://www.playframework.com/documentation/2.2.x/JavaGuide2" rel="nofollow">http://www.playframework.com/documentation/2.2.x/JavaGuide2</a> , but it lacks some explanations which make me lost. More preciesly: a)at the end of "Starting with the User class" paragraph, I should have got error. I didn't. I thought "whatever" and moved along, which, in retrospect might have been a mistake. b) I progressed to the "first test" , but it did not write where am I supposed to put my test. So, I put it in ApplicationTest.java. It failed my tests however, saying ebean was not defined. So, after googling a bit I tried to add <code>ebean.default="models.*"</code> in application.conf. It worked, but now I have </p> <pre><code>[error] Test ApplicationTest.createAndRetrieveUser failed: javax.persistence.PersistenceException: java.sql.SQLException: Attempting to obtain a connection from a pool that has already been shutdown. </code></pre> <p>I don't understand what's wrong.</p> <p>my application test</p> <pre><code>import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.fasterxml.jackson.databind.JsonNode; import models.User; import org.junit.*; import play.mvc.*; import play.test.*; import play.data.DynamicForm; import play.data.validation.ValidationError; import play.data.validation.Constraints.RequiredValidator; import play.i18n.Lang; import play.libs.F; import play.libs.F.*; import static play.test.Helpers.*; import static org.fest.assertions.Assertions.*; import static org.junit.Assert.*; import play.libs.*; import com.avaje.ebean.Ebean; public class ApplicationTest { @Test public void simpleCheck() { int a = 1 + 1; assertThat(a).isEqualTo(2); } @Test public void renderTemplate() { Content html = views.html.index.render("Your new application is ready."); assertThat(contentType(html)).isEqualTo("text/html"); assertThat(contentAsString(html)).contains("Your new application is ready."); } @Test public void createAndRetrieveUser() { new User("bob@gmail.com", "Bob", "secret").save(); User bob = User.find.where().eq("email", "bob@gmail.com").findUnique(); assertNotNull(bob); assertEquals("Bob", bob.name); } } </code></pre> <p>User class</p> <pre><code>package models; import javax.persistence.*; import play.db.ebean.*; import com.avaje.ebean.*; @Entity public class User extends Model { @Id public String email; public String name; public String password; public User(String email, String name, String password) { this.email = email; this.name = name; this.password = password; } public static Finder&lt;String,User&gt; find = new Finder&lt;String,User&gt;( String.class, User.class ); } </code></pre> <p>application.conf</p> <pre><code>#tried with 'db.*' uncommented as well as with commented db.default.driver=org.h2.Driver db.default.url="jdbc:h2:mem:play" db.default.user=sa db.default.password="" db.default.jndiName=DefaultDS # end of 'db.*' ebean.default="models.*" # Root logger: logger.root=ERROR # Logger used by the framework: logger.play=INFO # Logger provided to your application: logger.application=DEBUG </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload