Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git build.sbt build.sbt
- index 161634d..388c135 100644
- --- build.sbt
- +++ build.sbt
- @@ -15,3 +15,4 @@ libraryDependencies ++= Seq(
- evolutions
- )
- +javaOptions in Test += "-Dconfig.file=conf/application.test.conf"
- diff --git conf/evolutions/default/1.sql conf/evolutions/default/1.sql
- index 556d223..db6e394 100644
- --- conf/evolutions/default/1.sql
- +++ conf/evolutions/default/1.sql
- @@ -1,16 +1,19 @@
- -# --- First database schema
- +# --- Created by Ebean DDL
- +# To stop Ebean DDL generation, remove this comment and start using Evolutions
- +
- +# --- !Ups
- +
- +create table user (
- + id bigint not null,
- + name varchar(255) not null,
- + password_digest varchar(255) not null,
- + constraint pk_user primary key (id)
- +);
- +create sequence user_seq;
- -# --- !Ups
- +
- +# --- !Downs
- +
- +drop table if exists user;
- +drop sequence if exists user_seq;
- -CREATE TABLE article (
- - id INTEGER NOT NULL auto_increment,
- - title VARCHAR(255),
- - text LONGTEXT,
- - create_at DATETIME NOT NULL,
- - primary key(id)
- - );
- -
- -
- -# --- !Downs
- -
- -DROP TABLE article;
- \ No newline at end of file
- diff --git project/plugins.sbt project/plugins.sbt
- index cd985c6..a28db2b 100644
- --- project/plugins.sbt
- +++ project/plugins.sbt
- @@ -18,4 +18,4 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
- // Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
- // enablePlugins(PlayEbean).
- -addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
- +addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0")
- diff --git test/models/UserTest.java test/models/UserTest.java
- index b3ece07..161011a 100644
- --- test/models/UserTest.java
- +++ test/models/UserTest.java
- @@ -7,10 +7,13 @@ import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotNull;
- +import static play.test.Helpers.*;
- +
- /**
- * Created by nonoca on 7/14/16.
- */
- public class UserTest {
- +
- @Before
- public void setUp() throws Exception {
- }
- @@ -20,54 +23,77 @@ public class UserTest {
- }
- @Test
- - public void UserAddTest01() throws Exception {
- - User actual = new User();
- - actual.setName("mayok");
- - actual.setPasswordDigest("hoge");
- - actual.save();
- - assertNotNull(actual.name);
- - assertNotNull(actual.passwordDigest);
- + public void UserAddTest01() {
- + running(fakeApplication(), new Runnable() {
- + public void run() {
- + User actual = new User();
- + actual.setName("mayok");
- + actual.setPasswordDigest("hoge");
- + actual.save();
- + assertNotNull(actual.name);
- + assertNotNull(actual.passwordDigest);
- + }
- + });
- }
- @Test
- public void UserAddTest02() throws Exception{
- - User actual = new User("mayok", "hoge");
- - actual.save();
- - assertNotNull(actual.name);
- - assertNotNull(actual.passwordDigest);
- + running(fakeApplication(), new Runnable() {
- + public void run() {
- + User actual = new User("mayok", "hoge");
- + actual.save();
- + assertNotNull(actual.name);
- + assertNotNull(actual.passwordDigest);
- + }
- + });
- }
- @Test
- public void UserAddTest03() throws Exception{
- - User actual = new User("mayok", null);
- - actual.save();
- - assertNotNull(actual.name);
- - assertNotNull(actual.passwordDigest);
- + running(fakeApplication(), new Runnable() {
- + public void run() {
- + User actual = new User("mayok", null);
- + actual.save();
- + assertNotNull(actual.name);
- + assertNotNull(actual.passwordDigest);
- + }
- + });
- }
- @Test
- public void UserAddTest04() throws Exception{
- - User actual = new User(null, "hoge");
- - actual.save();
- - assertNotNull(actual.name);
- - assertNotNull(actual.passwordDigest);
- + running(fakeApplication(), new Runnable() {
- + public void run() {
- + User actual = new User(null, "hoge");
- + actual.save();
- + assertNotNull(actual.name);
- + assertNotNull(actual.passwordDigest);
- + }
- + });
- }
- @Test
- public void UserAddTest05() throws Exception{
- - User actual = new User(null, null);
- - actual.save();
- - assertNotNull(actual.name);
- - assertNotNull(actual.passwordDigest);
- + running(fakeApplication(), new Runnable() {
- + public void run() {
- + User actual = new User(null, null);
- + actual.save();
- + assertNotNull(actual.name);
- + assertNotNull(actual.passwordDigest);
- + }
- + });
- }
- @Test
- public void UserSelectTest01() throws Exception{
- - User actual = new User("mayok", "hoge");
- - actual.save();
- - User expect = User.finder.where().eq("user", "mayok").findUnique();
- - assertEquals(actual.getName(), expect.getName());
- + running(fakeApplication(), new Runnable() {
- + public void run() {
- + User actual = new User("mayok", "hoge");
- + actual.save();
- + User expect = User.finder.where().eq("user", "mayok").findUnique();
- + assertEquals(actual.getName(), expect.getName());
- + }
- + });
- }
- -
- -}
- \ No newline at end of file
- +}
- diff --git a/conf/application.test.conf b/conf/application.test.conf
- new file mode 100644
- index 0000000..3d4f0b4
- --- /dev/null
- +++ b/conf/application.test.conf
- @@ -0,0 +1,8 @@
- +include "application.conf"
- +
- +play.evolutions.db.default.autoApply=true
- +db.default.driver = org.h2.Driver
- +db.default.url = "jdbc:h2:mem:play;MODE=MYSQL;DB_CLOSE_DELAY=-1"
- +db.default.username = sa
- +db.default.password = ""
- +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement