1

Am new to play framework and Junit. Have little bit knowledge in java. Based on play framework getting started and documentation am started to write unit tests for play application. When i run the application in normal mode. It works fine with database models.

when i run the application in test mode. it shows jpa query exception and schema not found.

Am attached the test class file for your reference : -

import org.junit.*;
import java.net.*;
import java.util.*;
import play.test.*;
import play.test.FunctionalTest.URL;
import models.*;
import params.*;

public class BasicTest extends UnitTest {



    @Test
    public void testing(){

        //User user = null;
        User user = User.find("byUsernameAndPassword","admin","Y29tcGFzczEyMw==").first();
        assertNotNull(user);
        //assertNotNull("test");
    }

}

Anyone help me to fix this issue.

This is my current application.conf settings in play :

db.url=jdbc:vertica://verticadatabaseurlurl/XXXXXXX
db.driver=com.vertica.Driver
db.user=XXXXX
db.pass=XXXXXX
db.schema=XXXXXX

# JPA Configuration (Hibernate)
# ~~~~~
#
# Specify the custom JPA dialect to use here (default to guess):
 jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
#
# Specify the ddl generation pattern to use. Set to none to disable it 
# (default to update in DEV mode, and none in PROD mode):
 jpa.ddl=none
#
# Debug SQL statements (logged using DEBUG level):
 jpa.debugSQL=true
#
# You can even specify additional hibernate properties here:
# hibernate.use_sql_comments=true
# ...
#
#%test.module.cobertura=${play.path}/modules/cobertura
%test.application.mode=dev
%test.db.url=jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
%test.db=mem
%test.jpa.ddl=create
%test.mail.smtp=mock

am currently using vertica for database. By this settings can able to run the application in normal mode. In test mode it makes that issue.

http://tinypic.com/r/a48zg4/7 -screenshot reference

Mohan Shanmugam
  • 644
  • 1
  • 6
  • 18

1 Answers1

2

What is the JPA configuration you use for the unit tests. More specifc, what's the persistence.xml that you use for unit tests. It might be that you need to add the schema autogeneration config param to the test persistence unit you use, something like:

<persistence-unit name="emApplicationManaged_forTests_h2" transaction-type="RESOURCE_LOCAL">  
    <class>model.Employee</class>  
    <!-- your Entity classes here --> 
    <properties>  
        <!-- your hibernate specific params here -->
        <!-- the below parameter tells hibernate to create the schema when you start your app (test) and to erase it when it finishes: -->
        <property name="hibernate.hbm2ddl.auto" value="create-drop" />    
    </properties>  
</persistence-unit>

The above is for when you use Hibernate JPA implementation. If you use Toplink, try:

<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="todos" transaction-type="RESOURCE_LOCAL">
        <!-- entity classes -->
        <properties>
            <!-- eclipselink specific config-->
            <!-- EclipseLink should create the database schema automatically -->
            <property name="eclipselink.ddl-generation" value="create-tables" />
            <property name="eclipselink.ddl-generation.output-mode" value="database" />
        </properties>
    </persistence-unit>
</persistence>

For Play framework, you have special config params that start with test. prefix. Try this: open your application.conf config file and add the lines that configures the test environment for db schema auto-creation:

%test.db=mem
%test.jpa.ddl=create-drop

Then try your tests from the Play unit test running page (localhost:9090/@tests#)

Also check out this Play cheat-sheet, its pretty useful (I think the chapter called "Multidev Environment" is pertinent to your specific issue):

http://playcheatsheet.appspot.com/show/ArtemMedeu/armed/play-cheatsheets

Shivan Dragon
  • 15,004
  • 9
  • 62
  • 103
  • can you able to explain it for play framework. am using play framework – Mohan Shanmugam Oct 24 '11 at 12:53
  • Check out my answer, I've added an example for Play – Shivan Dragon Oct 24 '11 at 13:20
  • getting same issue after changes in application.conf. Modified the question to shown the current application.conf settings for your reference – Mohan Shanmugam Oct 25 '11 at 08:53
  • Well, there's obviouslly still some issue either with the SQL Query that's generated from your code, or how the schema is created in the db. I see you already have jpa.debugSQL=true set in your .conf file. Execute your unit test, look at the generated SQL, then look in the database and see if that generated SQL is pertinent to what's in the database (maybe use a real db like MYSql instead of the in-memory one, so you can actually access it with a console/GUI tool and explore it). Check if the query doesn't refference tables that don't actually exist in the db, or columns in the same situation. – Shivan Dragon Oct 25 '11 at 09:05
  • Thanks for the quick update. for your reference am attached a screen shot for your reference. – Mohan Shanmugam Oct 25 '11 at 09:13
  • maybe use a real db like MYSql instead of the in-memory one - for this whether i need to modify the test.db.url to our vertica database path – Mohan Shanmugam Oct 25 '11 at 09:20
  • Also, have you set your test.jpa.ddl to create-drop? (test.jpa.ddl=create-drop)? In your example code i still see it set to create, and I think that's an ivalid value (for Hibernate it should be create-drop). – Shivan Dragon Oct 25 '11 at 10:14
  • what is the use of that statement - test.jpa.ddl=create-drop. Whether it afects any table values. want to know where can i get information about application.conf file values – Mohan Shanmugam Oct 25 '11 at 10:33
  • Well normally I'd point you to the Play framework documentation: http://www.playframework.org/documentation/1.2.3/configuration#jpa.ddl but there's not a lot of details there. At any rate, I'm pretty sure that the allowed values for test.jpa.ddl are: create-drop,update,validate and empty (as in no value, as in test.jpa.ddl=). Details on what these do you can infact find here: http://stackoverflow.com/questions/438146/hibernate-question-hbm2ddl-auto-possible-values-and-what-they-do – Shivan Dragon Oct 25 '11 at 11:17
  • At last am configured database with vertica and run the unit test successfully. Thanks for your well support – Mohan Shanmugam Oct 28 '11 at 11:09