Skip to content

Instantly share code, notes, and snippets.

@i07
Last active May 8, 2022 20:23
Show Gist options
  • Save i07/0785f765ff25c7f3ce386e7f5b5416e5 to your computer and use it in GitHub Desktop.
Save i07/0785f765ff25c7f3ce386e7f5b5416e5 to your computer and use it in GitHub Desktop.
package donkers.tutorial.medium
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.test.context.junit.jupiter.SpringExtension
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ExtendWith(SpringExtension::class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TutorialRestApiApplicationTests @Autowired constructor(
private val restTemplate: TestRestTemplate
){
@LocalServerPort
private var port: Int = 0
@Test
fun contextLoads() {
}
@Test
fun `status should return message Server Ok!`() {
val response = restTemplate.getForEntity(
"http://localhost:$port/status",
StatusObject::class.java
)
Assertions.assertEquals(200, response.statusCode.value())
Assertions.assertNotNull(response.body)
Assertions.assertEquals("Server Ok!", response.body?.message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment