Created
September 6, 2019 03:17
-
-
Save mtrojahn/7ccd93fa75b8b3a0b3c137032d9a3ef0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.marcelustrojahn.models | |
import io.ebean.Ebean | |
import io.kotlintest.matchers.shouldBe | |
import io.kotlintest.matchers.shouldNotBe | |
import io.kotlintest.specs.FreeSpec | |
class BaseEntityTests: FreeSpec() { | |
init { | |
// remember the database will always be empty in the beggining of tests | |
// so the id will be 1 | |
"should be able to save a Person" { | |
val person = Person().apply { name = "John" } | |
Ebean.save(person) | |
person.id shouldNotBe null // id is filled on save | |
} | |
"should be able to select the Person from the database" { | |
val person = Ebean.find(Person::class.java).where().idEq(1).findOne() | |
person shouldNotBe null | |
} | |
"should be able to update the Person" { | |
val person = Ebean.find(Person::class.java).where().idEq(1).findOne() | |
person?.name = "Jack" | |
Ebean.save(person) | |
Ebean.find(Person::class.java).where().idEq(1).findOne()?.name shouldBe "Jack" | |
} | |
"should be able to delete the Person" { | |
Ebean.delete(Person::class.java, 1) | |
Ebean.find(Person::class.java).where().idEq(1).findOne() shouldBe null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment