Advertisement
Guest User

Untitled

a guest
Jul 19th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. diff --git build.sbt build.sbt
  2. index 161634d..388c135 100644
  3. --- build.sbt
  4. +++ build.sbt
  5. @@ -15,3 +15,4 @@ libraryDependencies ++= Seq(
  6. evolutions
  7. )
  8.  
  9. +javaOptions in Test += "-Dconfig.file=conf/application.test.conf"
  10. diff --git conf/evolutions/default/1.sql conf/evolutions/default/1.sql
  11. index 556d223..db6e394 100644
  12. --- conf/evolutions/default/1.sql
  13. +++ conf/evolutions/default/1.sql
  14. @@ -1,16 +1,19 @@
  15. -# --- First database schema
  16. +# --- Created by Ebean DDL
  17. +# To stop Ebean DDL generation, remove this comment and start using Evolutions
  18. +
  19. +# --- !Ups
  20. +
  21. +create table user (
  22. + id bigint not null,
  23. + name varchar(255) not null,
  24. + password_digest varchar(255) not null,
  25. + constraint pk_user primary key (id)
  26. +);
  27. +create sequence user_seq;
  28.  
  29. -# --- !Ups
  30. +
  31. +# --- !Downs
  32. +
  33. +drop table if exists user;
  34. +drop sequence if exists user_seq;
  35.  
  36. -CREATE TABLE article (
  37. - id INTEGER NOT NULL auto_increment,
  38. - title VARCHAR(255),
  39. - text LONGTEXT,
  40. - create_at DATETIME NOT NULL,
  41. - primary key(id)
  42. - );
  43. -
  44. -
  45. -# --- !Downs
  46. -
  47. -DROP TABLE article;
  48. \ No newline at end of file
  49. diff --git project/plugins.sbt project/plugins.sbt
  50. index cd985c6..a28db2b 100644
  51. --- project/plugins.sbt
  52. +++ project/plugins.sbt
  53. @@ -18,4 +18,4 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
  54.  
  55. // Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
  56. // enablePlugins(PlayEbean).
  57. -addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
  58. +addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0")
  59. diff --git test/models/UserTest.java test/models/UserTest.java
  60. index b3ece07..161011a 100644
  61. --- test/models/UserTest.java
  62. +++ test/models/UserTest.java
  63. @@ -7,10 +7,13 @@ import org.junit.Test;
  64. import static org.junit.Assert.assertEquals;
  65. import static org.junit.Assert.assertNotNull;
  66.  
  67. +import static play.test.Helpers.*;
  68. +
  69. /**
  70. * Created by nonoca on 7/14/16.
  71. */
  72. public class UserTest {
  73. +
  74. @Before
  75. public void setUp() throws Exception {
  76. }
  77. @@ -20,54 +23,77 @@ public class UserTest {
  78. }
  79.  
  80. @Test
  81. - public void UserAddTest01() throws Exception {
  82. - User actual = new User();
  83. - actual.setName("mayok");
  84. - actual.setPasswordDigest("hoge");
  85. - actual.save();
  86. - assertNotNull(actual.name);
  87. - assertNotNull(actual.passwordDigest);
  88. + public void UserAddTest01() {
  89. + running(fakeApplication(), new Runnable() {
  90. + public void run() {
  91. + User actual = new User();
  92. + actual.setName("mayok");
  93. + actual.setPasswordDigest("hoge");
  94. + actual.save();
  95. + assertNotNull(actual.name);
  96. + assertNotNull(actual.passwordDigest);
  97. + }
  98. + });
  99. }
  100.  
  101. @Test
  102. public void UserAddTest02() throws Exception{
  103. - User actual = new User("mayok", "hoge");
  104. - actual.save();
  105. - assertNotNull(actual.name);
  106. - assertNotNull(actual.passwordDigest);
  107. + running(fakeApplication(), new Runnable() {
  108. + public void run() {
  109. + User actual = new User("mayok", "hoge");
  110. + actual.save();
  111. + assertNotNull(actual.name);
  112. + assertNotNull(actual.passwordDigest);
  113. + }
  114. + });
  115. }
  116.  
  117. @Test
  118. public void UserAddTest03() throws Exception{
  119. - User actual = new User("mayok", null);
  120. - actual.save();
  121. - assertNotNull(actual.name);
  122. - assertNotNull(actual.passwordDigest);
  123. + running(fakeApplication(), new Runnable() {
  124. + public void run() {
  125. + User actual = new User("mayok", null);
  126. + actual.save();
  127. + assertNotNull(actual.name);
  128. + assertNotNull(actual.passwordDigest);
  129. + }
  130. + });
  131. }
  132.  
  133. @Test
  134. public void UserAddTest04() throws Exception{
  135. - User actual = new User(null, "hoge");
  136. - actual.save();
  137. - assertNotNull(actual.name);
  138. - assertNotNull(actual.passwordDigest);
  139. + running(fakeApplication(), new Runnable() {
  140. + public void run() {
  141. + User actual = new User(null, "hoge");
  142. + actual.save();
  143. + assertNotNull(actual.name);
  144. + assertNotNull(actual.passwordDigest);
  145. + }
  146. + });
  147. }
  148.  
  149. @Test
  150. public void UserAddTest05() throws Exception{
  151. - User actual = new User(null, null);
  152. - actual.save();
  153. - assertNotNull(actual.name);
  154. - assertNotNull(actual.passwordDigest);
  155. + running(fakeApplication(), new Runnable() {
  156. + public void run() {
  157. + User actual = new User(null, null);
  158. + actual.save();
  159. + assertNotNull(actual.name);
  160. + assertNotNull(actual.passwordDigest);
  161. + }
  162. + });
  163. }
  164.  
  165. @Test
  166. public void UserSelectTest01() throws Exception{
  167. - User actual = new User("mayok", "hoge");
  168. - actual.save();
  169. - User expect = User.finder.where().eq("user", "mayok").findUnique();
  170. - assertEquals(actual.getName(), expect.getName());
  171. + running(fakeApplication(), new Runnable() {
  172. + public void run() {
  173. + User actual = new User("mayok", "hoge");
  174. + actual.save();
  175. + User expect = User.finder.where().eq("user", "mayok").findUnique();
  176. + assertEquals(actual.getName(), expect.getName());
  177. + }
  178. + });
  179. }
  180.  
  181. -
  182. -}
  183. \ No newline at end of file
  184. +}
  185. diff --git a/conf/application.test.conf b/conf/application.test.conf
  186. new file mode 100644
  187. index 0000000..3d4f0b4
  188. --- /dev/null
  189. +++ b/conf/application.test.conf
  190. @@ -0,0 +1,8 @@
  191. +include "application.conf"
  192. +
  193. +play.evolutions.db.default.autoApply=true
  194. +db.default.driver = org.h2.Driver
  195. +db.default.url = "jdbc:h2:mem:play;MODE=MYSQL;DB_CLOSE_DELAY=-1"
  196. +db.default.username = sa
  197. +db.default.password = ""
  198. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement