-
-
Save lidaling/ba2831b1f33a2517bfac1a9ef3d733b3 to your computer and use it in GitHub Desktop.
Spring-Boot-Application Integration Test in scala
This file contains hidden or 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 hidden or 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 hidden or 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