Last active
December 7, 2016 01:51
-
-
Save Lobedan/c74048dd1c17703847b1 to your computer and use it in GitHub Desktop.
Spring-Boot-Application Integration Test in scala
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
object Application { | |
def main(args: Array[String]) : Unit = SpringApplication.run(classOf[ApplicationConfig], args :_ *) | |
} |
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
@SpringBootApplication //annotation added in Spring-Boot 1.2.0.RELEASE | |
/* | |
@Configuration | |
@ComponentScan | |
@EnableAutoConfiguration | |
*/ | |
class ApplicationConfig |
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
@SpringApplicationConfiguration(classes = Array(classOf[ApplicationConfig])) | |
@WebAppConfiguration | |
@IntegrationTest(value = Array("server.port:0")) | |
@DirtiesContext | |
class ApplicationTest extends AssertionsForJUnit { | |
@Value("${local.server.port}") var port: Int = _ | |
new TestContextManager(classOf[ApplicationTest]).prepareTestInstance(this) | |
@Test def integrationTest: Unit = { | |
val entity = new TestRestTemplate().getForEntity("http://localhost:" + port + "/health", classOf[String]); | |
Assert.assertThat(entity.getStatusCode, CoreMatchers.is(HttpStatus.OK)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment