PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/scala/code/snippet/ReminderTest.scala

https://bitbucket.org/ta_jim/lift_userlogin_template
Scala | 185 lines | 154 code | 22 blank | 9 comment | 12 complexity | 20cf9534ae28daca8bceb6961efb15f1 MD5 | raw file
  1. package code.snippet
  2. import org.junit.runner.RunWith
  3. import org.scalatest.junit.JUnitRunner
  4. import org.scalatest.FunSuite
  5. import org.scalatest.BeforeAndAfter
  6. import code.model.User
  7. import com.mongodb.casbah.commons.MongoDBObject
  8. import code.config.MongoConfig
  9. import code.model.Reminder
  10. import java.text.SimpleDateFormat
  11. import code.model.LoginCredentials
  12. import net.liftweb.http.LiftSession
  13. import net.liftweb.util.StringHelpers
  14. import net.liftweb.common.Empty
  15. import net.liftweb.http.S
  16. @RunWith(classOf[JUnitRunner])
  17. class Reminderest extends FunSuite with BeforeAndAfter {
  18. before {
  19. MongoConfig.init()
  20. }
  21. /**
  22. * Test case for creation of Reminder
  23. */
  24. test("Testing for a successful creation of Reminder") {
  25. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  26. val user = User.saveUser("test@test.com", "123456", "test", "test")
  27. val validate = Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "03/12/2013")
  28. assert(validate.isRight == true)
  29. }
  30. test("Testing for a unsuccessful creation of Reminder with blank text") {
  31. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  32. S.initIfUninitted(session) {
  33. val user = User.saveUser("test@test.com", "123456", "test", "test")
  34. User.logUserIn(user, true)
  35. val validate = Reminder.createReminder(user.id.toString, "", "03/12/2013")
  36. assert(validate.isLeft == true)
  37. }
  38. }
  39. test("Testing for a unsuccessful creation of Reminder with a blank date") {
  40. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  41. S.initIfUninitted(session) {
  42. val user = User.saveUser("test@test.com", "123456", "test", "test")
  43. User.logUserIn(user, true)
  44. val validate = Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "")
  45. assert(validate.isLeft == true)
  46. }
  47. }
  48. test("Testing for a unsuccessful creation of Reminder with a blank text and blank date") {
  49. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  50. S.initIfUninitted(session) {
  51. val user = User.saveUser("test@test.com", "123456", "test", "test")
  52. User.logUserIn(user, true)
  53. val validate = Reminder.createReminder(user.id.toString, "", "")
  54. assert(validate.isLeft == true)
  55. }
  56. }
  57. test("Testing for a unsuccessful creation of Reminder with a blank text and incorrect format of date") {
  58. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  59. S.initIfUninitted(session) {
  60. val user = User.saveUser("test@test.com", "123456", "test", "test")
  61. User.logUserIn(user, true)
  62. val validate = Reminder.createReminder(user.id.toString, "", "12 mar 2013")
  63. assert(validate.isLeft == true)
  64. }
  65. }
  66. test("Testing for a unsuccessful creation of Reminder with incorrect format of date") {
  67. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  68. S.initIfUninitted(session) {
  69. val user = User.saveUser("test@test.com", "123456", "test", "test")
  70. User.logUserIn(user, true)
  71. val validate = Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "12 mar 2013")
  72. assert(validate.isLeft == true)
  73. }
  74. }
  75. /**
  76. * Test case for deletion of Reminder
  77. */
  78. test("Testing for a successful deletion of Reminder") {
  79. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  80. S.initIfUninitted(session) {
  81. val user = User.saveUser("test@test.com", "123456", "test", "test")
  82. User.logUserIn(user, true)
  83. Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "03/12/2013")
  84. val reminder = Reminder.find(MongoDBObject("description" -> "Have to play cricket in morning"))
  85. val validate = Reminder.deleteReminder(reminder.open_!)
  86. assert(validate)
  87. }
  88. }
  89. /**
  90. * Test case for updating Reminder
  91. */
  92. test("Testing for a successful updation of Reminder") {
  93. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  94. S.initIfUninitted(session) {
  95. val user = User.saveUser("test@test.com", "123456", "test", "test")
  96. User.logUserIn(user, true)
  97. Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "03/12/2013")
  98. val reminder = Reminder.find(MongoDBObject("description" -> "Have to play cricket in morning"))
  99. val validate = Reminder.updateReminder(reminder.open_!, "Have to play cricket in morning", "03/12/2013")
  100. assert(validate.isRight == true)
  101. }
  102. }
  103. test("Testing for a unsuccessful updation of Reminder with blank text") {
  104. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  105. S.initIfUninitted(session) {
  106. val user = User.saveUser("test@test.com", "123456", "test", "test")
  107. User.logUserIn(user, true)
  108. Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "03/12/2013")
  109. val reminder = Reminder.find(MongoDBObject("description" -> "Have to play cricket in morning"))
  110. val validate = Reminder.updateReminder(reminder.open_!, "", "03/12/2013")
  111. assert(validate.isLeft == true)
  112. }
  113. }
  114. test("Testing for a unsuccessful updation of Reminder with a blank date") {
  115. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  116. S.initIfUninitted(session) {
  117. val user = User.saveUser("test@test.com", "123456", "test", "test")
  118. User.logUserIn(user, true)
  119. Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "03/12/2013")
  120. val reminder = Reminder.find(MongoDBObject("description" -> "Have to play cricket in morning"))
  121. val validate = Reminder.updateReminder(reminder.open_!, "Have to play cricket in morning", "")
  122. assert(validate.isLeft == true)
  123. }
  124. }
  125. test("Testing for a unsuccessful updation of Reminder with a blank text and blank date") {
  126. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  127. S.initIfUninitted(session) {
  128. val user = User.saveUser("test@test.com", "123456", "test", "test")
  129. User.logUserIn(user, true)
  130. Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "03/12/2013")
  131. val reminder = Reminder.find(MongoDBObject("description" -> "Have to play cricket in morning"))
  132. val validate = Reminder.updateReminder(reminder.open_!, "", "")
  133. assert(validate.isLeft == true)
  134. }
  135. }
  136. test("Testing for a unsuccessful updation of Reminder with a blank text and incorrect format of date") {
  137. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  138. S.initIfUninitted(session) {
  139. val user = User.saveUser("test@test.com", "123456", "test", "test")
  140. User.logUserIn(user, true)
  141. Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "03/12/2013")
  142. val reminder = Reminder.find(MongoDBObject("description" -> "Have to play cricket in morning"))
  143. val validate = Reminder.updateReminder(reminder.open_!, "", "12 mar 2013")
  144. assert(validate.isLeft == true)
  145. }
  146. }
  147. test("Testing for a unsuccessful updation of Reminder with incorrect format of date") {
  148. val session: LiftSession = new LiftSession("", StringHelpers.randomString(20), Empty)
  149. S.initIfUninitted(session) {
  150. val user = User.saveUser("test@test.com", "123456", "test", "test")
  151. User.logUserIn(user, true)
  152. Reminder.createReminder(user.id.toString, "Have to play cricket in morning", "03/12/2013")
  153. val reminder = Reminder.find(MongoDBObject("description" -> "Have to play cricket in morning"))
  154. val validate = Reminder.updateReminder(reminder.open_!, "Have to play cricket in morning", "12 mar 2013")
  155. assert(validate.isLeft == true)
  156. }
  157. }
  158. after {
  159. User.delete(MongoDBObject("name" -> "test"))
  160. Reminder.delete(MongoDBObject("description" -> "Have to play cricket in morning"))
  161. Reminder.delete(MongoDBObject("description" -> ""))
  162. }
  163. }