BAEL-755 changing the name of the POKO to a DTO and removing the use of @Autowired in the constructor as it is not needed.

This commit is contained in:
tschiman 2017-05-31 16:31:02 -06:00
parent 7eb0eafe94
commit ea302a5f33
4 changed files with 10 additions and 11 deletions

View File

@ -1,11 +1,10 @@
package com.baeldung.springbootkotlin
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
@RestController
class HelloController @Autowired constructor(val helloService: HelloService) {
class HelloController constructor(val helloService: HelloService) {
@GetMapping("/hello")
fun helloKotlin(): String {
@ -17,8 +16,8 @@ class HelloController @Autowired constructor(val helloService: HelloService) {
return helloService.getHello()
}
@GetMapping("/hello-poko")
fun helloPoko(): HelloPoko {
return HelloPoko("Hello from the poko")
@GetMapping("/hello-dto")
fun helloDto(): HelloDto {
return HelloDto("Hello from the dto")
}
}

View File

@ -0,0 +1,3 @@
package com.baeldung.springbootkotlin
data class HelloDto constructor(val greeting: String)

View File

@ -1,3 +0,0 @@
package com.baeldung.springbootkotlin
data class HelloPoko constructor(val greeting: String)

View File

@ -1,6 +1,6 @@
package com.example.kotlindemo
import com.baeldung.springbootkotlin.HelloPoko
import com.baeldung.springbootkotlin.HelloDto
import com.baeldung.springbootkotlin.KotlinDemoApplication
import org.junit.Assert
import org.junit.Test
@ -42,11 +42,11 @@ class KotlinDemoApplicationTests {
@Test
fun testHelloPoko() {
var result = testRestTemplate?.getForEntity("/hello-poko", HelloPoko::class.java)
var result = testRestTemplate?.getForEntity("/hello-dto", HelloDto::class.java)
Assert.assertNotNull(result)
Assert.assertEquals(result?.statusCode, HttpStatus.OK)
Assert.assertEquals(result?.body, HelloPoko("Hello from the poko"))
Assert.assertEquals(result?.body, HelloDto("Hello from the dto"))
}
}