Fix kotlin tests (#1995)

This commit is contained in:
Grzegorz Piwowarek 2017-06-05 12:09:37 +02:00 committed by GitHub
parent ef7264c53b
commit ecc91a6108
2 changed files with 20 additions and 19 deletions

View File

@ -3,7 +3,7 @@ package com.baeldung.springbootkotlin
import org.springframework.boot.SpringApplication import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication @SpringBootApplication(scanBasePackages = arrayOf("com.baeldung.springbootkotlin"))
class KotlinDemoApplication class KotlinDemoApplication
fun main(args: Array<String>) { fun main(args: Array<String>) {

View File

@ -13,40 +13,41 @@ import org.springframework.http.HttpStatus
import org.springframework.test.context.junit4.SpringRunner import org.springframework.test.context.junit4.SpringRunner
@RunWith(SpringRunner::class) @RunWith(SpringRunner::class)
@SpringBootTest(classes = arrayOf(KotlinDemoApplication::class), webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(
classes = arrayOf(KotlinDemoApplication::class),
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class KotlinDemoApplicationIntegrationTest { class KotlinDemoApplicationIntegrationTest {
@Autowired @Autowired
val testRestTemplate: TestRestTemplate? = null lateinit var testRestTemplate: TestRestTemplate
@Test @Test
fun contextLoads() { fun whenCalled_thenShouldReturnHello() {
val result = testRestTemplate.withBasicAuth("user", "pass")
.getForEntity("/hello", String::class.java)
assertNotNull(result)
assertEquals(HttpStatus.OK, result?.statusCode)
assertEquals("hello world", result?.body)
} }
@Test @Test
fun testHelloController() { fun whenCalled_thenShouldReturnHelloService() {
val result = testRestTemplate?.getForEntity("/hello", String::class.java) val result = testRestTemplate.withBasicAuth("user", "pass")
.getForEntity("/hello-service", String::class.java)
assertNotNull(result) assertNotNull(result)
assertEquals(result?.statusCode, HttpStatus.OK) assertEquals(HttpStatus.OK, result?.statusCode)
assertEquals(result?.body, "hello world")
}
@Test
fun testHelloService() {
val result = testRestTemplate?.getForEntity("/hello-service", String::class.java)
assertNotNull(result)
assertEquals(result?.statusCode, HttpStatus.OK)
assertEquals(result?.body, "hello service") assertEquals(result?.body, "hello service")
} }
@Test @Test
fun testHelloDto() { fun whenCalled_thenShouldReturnJson() {
val result = testRestTemplate?.getForEntity("/hello-dto", HelloDto::class.java) val result = testRestTemplate.withBasicAuth("user", "pass")
.getForEntity("/hello-dto", HelloDto::class.java)
assertNotNull(result) assertNotNull(result)
assertEquals(result?.statusCode, HttpStatus.OK) assertEquals(HttpStatus.OK, result?.statusCode)
assertEquals(result?.body, HelloDto("Hello from the dto")) assertEquals(result?.body, HelloDto("Hello from the dto"))
} }