Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:24:02+00:00 2026-06-05T19:24:02+00:00

This is for Play! Framework 2.0. I’m trying to write a simple test case

  • 0

This is for Play! Framework 2.0.

I’m trying to write a simple test case to ensure my user model is functioning properly and persisting data in my database. I’d like to run it in memory if possible so I can get a fresh start with every new run.

The issue I have is that my evolutions run(tables are created, data is inserted, but I can’t query it as being there). First, my code.

CREATE TABLE user_data (
id SERIAL PRIMARY KEY,
user_name varchar(256) UNIQUE NOT NULL,
email varchar(256) NOT NULL,
password varchar(256) NOT NULL,
edits int NOT NULL,
reports int NOT NULL,
active BOOLEAN NOT NULL);

INSERT INTO user_data(user_name, email, password, edits, reports, active) VALUES ('user1', 'user1@email.com', '12345678', 0, 0, true);

In application.conf

db.default.driver=org.postgresql.Driver
db.default.url="postgres://user:password@localhost:5432/ME"

In build.scala

val appDependencies = Seq(
  // Add your project dependencies here,
    "postgresql" % "postgresql" % "9.1-901-1.jdbc4"
)

The test code

class User_dataSpec extends Specification {

  "The Database" should {
    "persist data properly" in {
  running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {

      //User_data.findAll().length must beEqualTo(1)
      //Create users
      User_data.create("user1", "password1", "email@test1.com") must beEqualTo(1)
      User_data.create("user2", "password2", "email@test2.com") must beEqualTo(2)
      User_data.create("user1", "password3", "email@test3.com") must beEqualTo(0)

      //Count users
      User_data.findAll().length must beEqualTo(2)

      //Verify users exist
      User_data.exists("user1") must beTrue
      User_data.exists("user2") must beTrue

      //Verify user doesn't exist
      User_data.exists("user3") must beFalse

      //Find users by ID
      User_data.findUser(1).get.user_name must beEqualTo("user1")
      User_data.findUser(2).get.user_name must beEqualTo("user2")

      //Fail to find users by ID
      User_data.findUser(3) must beNone

      //Find users by user_name
      User_data.findUser("user1").get.user_name must beEqualTo("user1")
      User_data.findUser("user2").get.user_name must beEqualTo("user2")

      //Fail to find users by user_name
      User_data.findUser("user3") must beNone

      //Authenticate users
      User_data.authenticate("user1", "password1") must beTrue
      User_data.authenticate("user2", "password2") must beTrue

      //Fail to authenticate users
      User_data.authenticate("user1", "password2") must beFalse
      User_data.authenticate("user3", "passwordX") must beFalse

      //Confirm the user was inserted properly
      val user = User_data.findUser("user1")
      user.get.user_name must beEqualTo("user1")
      user.get.email must beEqualTo("email@test1.com")
      user.get.password must beEqualTo("password1")
      user.get.edits must beEqualTo(0)
      user.get.reports must beEqualTo(0)
      user.get.active must beTrue
      }
    }
  }
}

This code will pass as written, however it shouldn’t. If I uncomment the first test case inside the running block to test that my findAll() function should be a length of 1 it will fail immediately. However, if I change this to use a persisted PostgreSQL DB on my machine, it will still fail immediately, but when I look at the PostgreSQL DB, my user_data table has the single evolution applied insert in it, and the play_evolutions table has the entry for my evolution and is marked as state = “applied” and last problem = “”.

Any help would be appreciated, thanks.

(P.S., I am a first time poster, but will do my best to accept an answer as soon as possible for those willing to lend their help)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:24:03+00:00Added an answer on June 5, 2026 at 7:24 pm

    * UPDATED *

    As Jakob stated, the reason evolutions are failing is probably because the SQL written for MySQL is incompatible with H2DB. You can solve this by using a separate MySQL for testing as per the original answer, or put H2DB into MySQL compatibility mode which may fix the problem (see Fixtures in Play! 2 for Scala).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in scala play framework I seen this code: abstract class AnalyserInfo case class ColumnC(typeName:String,fieldName:String)
I wondering is there an equivalent of this feature from play framework http://www.playframework.org/documentation/2.0/JavaAsync Basicly
I'm following the Play Framework 2.0 tutorial for Java and get this error when
I'm learning using Play Framework and doing a demo app for it. For this
We have recently started to see this exception while running the play framework in
This is my query using entity manager. Trying to join 2 table with play
I'm trying to create a plugin for Play Framework 2.0 (latest code in Github
Am trying to use MSSQL server with Play Framework, In my application.conf db.url=jdbc:microsoft:sqlserver://localhost\SQL2008:1433;DatabaseName=testDB db.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
i am using guice with java play framework. i have a simple command interface,
I've been trying to create a Web Service with play framework. I've searched some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.