BAEL-755 - moving kotlin code to spring-5-mvc
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.springbootkotlin
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
class HelloController(val helloService: HelloService) {
|
||||
|
||||
@GetMapping("/hello")
|
||||
fun helloKotlin(): String {
|
||||
return "hello world"
|
||||
}
|
||||
|
||||
@GetMapping("/hello-service")
|
||||
fun helloKotlinService(): String {
|
||||
return helloService.getHello()
|
||||
}
|
||||
|
||||
@GetMapping("/hello-dto")
|
||||
fun helloDto(): HelloDto {
|
||||
return HelloDto("Hello from the dto")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.baeldung.springbootkotlin
|
||||
|
||||
data class HelloDto(val greeting: String)
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.springbootkotlin
|
||||
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class HelloService {
|
||||
|
||||
fun getHello(): String {
|
||||
return "hello service"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.springbootkotlin
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
|
||||
@SpringBootApplication
|
||||
class KotlinDemoApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
SpringApplication.run(KotlinDemoApplication::class.java, *args)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package springbootkotlin
|
||||
|
||||
import com.baeldung.springbootkotlin.HelloDto
|
||||
import com.baeldung.springbootkotlin.KotlinDemoApplication
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate
|
||||
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)
|
||||
class KotlinDemoApplicationIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
val testRestTemplate: TestRestTemplate? = null
|
||||
|
||||
@Test
|
||||
fun contextLoads() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHelloController() {
|
||||
val result = testRestTemplate?.getForEntity("/hello", String::class.java)
|
||||
|
||||
assertNotNull(result)
|
||||
assertEquals(result?.statusCode, HttpStatus.OK)
|
||||
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")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHelloDto() {
|
||||
val result = testRestTemplate?.getForEntity("/hello-dto", HelloDto::class.java)
|
||||
|
||||
assertNotNull(result)
|
||||
assertEquals(result?.statusCode, HttpStatus.OK)
|
||||
assertEquals(result?.body, HelloDto("Hello from the dto"))
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user