Last active
June 10, 2018 10:39
-
-
Save manjotmona/ec9ce256a6ae55844ac4986f047af3a9 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
class RestSpec extends WordSpec with Matchers with ScalatestRouteTest with MockitoSugar { | |
val mockUserImpl = mock[UserImpl] | |
object TestObject extends RestService { | |
val userImpl = mockUserImpl | |
} | |
"The service" should { | |
"return user added as response for a Post request to /adduser" in { | |
when(mockUserImpl.addUser(User(2, "test"))).thenReturn(Future.successful(Done)) | |
val jsonRequest = ByteString( | |
s""" | |
|{ | |
| "id":2, | |
| "name":"test" | |
|} | |
""".stripMargin) | |
val postRequest = HttpRequest( | |
HttpMethods.POST, | |
uri = "/adduser", | |
entity = HttpEntity(MediaTypes.`application/json`, jsonRequest)) | |
postRequest ~> Route.seal(TestObject.route) ~> check { | |
status.isSuccess() shouldEqual true | |
responseAs[String] shouldEqual "user added" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment