mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
better scala test (UserApi)
This commit is contained in:
parent
8836644d37
commit
cbd1b98bf5
@ -11,21 +11,41 @@ import scala.collection.JavaConverters._
|
|||||||
import scala.beans.BeanProperty
|
import scala.beans.BeanProperty
|
||||||
|
|
||||||
@RunWith(classOf[JUnitRunner])
|
@RunWith(classOf[JUnitRunner])
|
||||||
class UserApiTest extends FlatSpec with Matchers {
|
class UserApiTest extends FlatSpec with Matchers with BeforeAndAfterAll {
|
||||||
behavior of "UserApi"
|
behavior of "UserApi"
|
||||||
val api = new UserApi
|
val api = new UserApi
|
||||||
api.apiInvoker.defaultHeaders += "api_key" -> "special-key"
|
api.apiInvoker.defaultHeaders += "api_key" -> "special-key"
|
||||||
|
|
||||||
|
// preparation before running a test
|
||||||
|
override def beforeAll() {
|
||||||
|
val user = User(
|
||||||
|
11222,
|
||||||
|
"scala-test-username",
|
||||||
|
"scala-test-first",
|
||||||
|
"scala-test-last",
|
||||||
|
"scala_test@fail.com",
|
||||||
|
"SCALATEST",
|
||||||
|
"408-867-5309",
|
||||||
|
1)
|
||||||
|
|
||||||
|
api.createUser(user)
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanup after running a test
|
||||||
|
override def afterAll() {
|
||||||
|
api.deleteUser("scala-test-username")
|
||||||
|
}
|
||||||
|
|
||||||
it should "fetch a user" in {
|
it should "fetch a user" in {
|
||||||
api.getUserByName("user1") match {
|
api.getUserByName("scala-test") match {
|
||||||
case Some(user) => {
|
case Some(user) => {
|
||||||
user.id should be(1)
|
user.id should be(11222)
|
||||||
user.username should be("user1")
|
user.username should be("scala-test-username")
|
||||||
user.password should be("XXXXXXXXXXX")
|
user.password should be("SCALATEST")
|
||||||
user.email should be("email1@test.com")
|
user.email should be("scala_test@fail.com")
|
||||||
user.firstName should be("first name 1")
|
user.firstName should be("scala-test-first")
|
||||||
user.lastName should be("last name 1")
|
user.lastName should be("scala-test-last")
|
||||||
user.phone should be("123-456-7890")
|
user.phone should be("408-867-5309")
|
||||||
user.userStatus should be(1)
|
user.userStatus should be(1)
|
||||||
}
|
}
|
||||||
case None =>
|
case None =>
|
||||||
@ -33,7 +53,7 @@ class UserApiTest extends FlatSpec with Matchers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it should "authenticate a user" in {
|
it should "authenticate a user" in {
|
||||||
api.loginUser("user1", "XXXXXXXXXXX") match {
|
api.loginUser("scala-test-username", "SCALATEST") match {
|
||||||
case Some(status) => status.startsWith("logged in user session") match {
|
case Some(status) => status.startsWith("logged in user session") match {
|
||||||
case true => // success!
|
case true => // success!
|
||||||
case _ => fail("didn't get expected message " + status)
|
case _ => fail("didn't get expected message " + status)
|
||||||
@ -46,28 +66,6 @@ class UserApiTest extends FlatSpec with Matchers {
|
|||||||
api.logoutUser
|
api.logoutUser
|
||||||
}
|
}
|
||||||
|
|
||||||
it should "create a user" in {
|
|
||||||
val user = User(
|
|
||||||
1002,
|
|
||||||
"johnny",
|
|
||||||
"Johnny",
|
|
||||||
"Rocket",
|
|
||||||
"johnny@fail.com",
|
|
||||||
"XXXXXXXXXXX",
|
|
||||||
"408-867-5309",
|
|
||||||
1)
|
|
||||||
|
|
||||||
api.createUser(user)
|
|
||||||
|
|
||||||
api.getUserByName("johnny") match {
|
|
||||||
case Some(user) => {
|
|
||||||
user.id should be(1002)
|
|
||||||
user.username should be("johnny")
|
|
||||||
}
|
|
||||||
case None =>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it should "create 2 users" in {
|
it should "create 2 users" in {
|
||||||
val userArray = (for (i <- (1 to 2)) yield {
|
val userArray = (for (i <- (1 to 2)) yield {
|
||||||
User(
|
User(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user