Skip to content

Instantly share code, notes, and snippets.

@lucapiccinelli
Last active May 26, 2020 06:39
Show Gist options
  • Save lucapiccinelli/b3b97a9010725df64115c76fe96549a8 to your computer and use it in GitHub Desktop.
Save lucapiccinelli/b3b97a9010725df64115c76fe96549a8 to your computer and use it in GitHub Desktop.
class HelloTests {
@Test
fun `GIVEN springboot in certain state WHEN a restart happens THEN it should preserve the state`(){
val restTemplate = TestRestTemplate()
val webserverPort = Random.nextInt(10000, 10100)
val appContext = SpringApplication.run(MainApplication::class.java, "--server.port=$webserverPort")
restTemplate.getForObject<String>("http://localhost:$webserverPort/hello") shouldBe "Ok 0"
appContext.close()
val newContext = SpringApplication.run(MainApplication::class.java, "--server.port=$webserverPort")
restTemplate.getForObject<String>("http://localhost:$webserverPort/hello") shouldBe "Ok 1"
newContext.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment