Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.baeldung.springbootkotlin
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
@SpringBootApplication(scanBasePackages = arrayOf("com.baeldung.springbootkotlin"))
class KotlinDemoApplication

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,41 @@ import org.springframework.http.HttpStatus
import org.springframework.test.context.junit4.SpringRunner

@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 {

@Autowired
val testRestTemplate: TestRestTemplate? = null
lateinit var testRestTemplate: TestRestTemplate

@Test
fun contextLoads() {
}

@Test
fun testHelloController() {
val result = testRestTemplate?.getForEntity("/hello", String::class.java)
fun whenCalled_thenShouldReturnHello() {
val result = testRestTemplate.withBasicAuth("user", "pass")
.getForEntity("/hello", String::class.java)

assertNotNull(result)
assertEquals(result?.statusCode, HttpStatus.OK)
assertEquals(result?.body, "hello world")
assertEquals(HttpStatus.OK, result?.statusCode)
assertEquals("hello world", result?.body)
}

@Test
fun testHelloService() {
val result = testRestTemplate?.getForEntity("/hello-service", String::class.java)
fun whenCalled_thenShouldReturnHelloService() {
val result = testRestTemplate.withBasicAuth("user", "pass")
.getForEntity("/hello-service", String::class.java)

assertNotNull(result)
assertEquals(result?.statusCode, HttpStatus.OK)
assertEquals(HttpStatus.OK, result?.statusCode)
assertEquals(result?.body, "hello service")
}

@Test
fun testHelloDto() {
val result = testRestTemplate?.getForEntity("/hello-dto", HelloDto::class.java)
fun whenCalled_thenShouldReturnJson() {
val result = testRestTemplate.withBasicAuth("user", "pass")
.getForEntity("/hello-dto", HelloDto::class.java)

assertNotNull(result)
assertEquals(result?.statusCode, HttpStatus.OK)
assertEquals(HttpStatus.OK, result?.statusCode)
assertEquals(result?.body, HelloDto("Hello from the dto"))
}

Expand Down