File tree Expand file tree Collapse file tree 5 files changed +54
-3
lines changed
main/kotlin/org/uqbar/tareas
test/kotlin/org/uqbar/tareas/controller Expand file tree Collapse file tree 5 files changed +54
-3
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ package org.uqbar.tareas.controller
22
33import org.springframework.web.bind.annotation.CrossOrigin
44import org.springframework.web.bind.annotation.GetMapping
5+ import org.springframework.web.bind.annotation.PostMapping
6+ import org.springframework.web.bind.annotation.RequestBody
57import org.springframework.web.bind.annotation.RestController
8+ import org.uqbar.tareas.domain.Usuario
69import org.uqbar.tareas.service.UsuariosService
710
811@RestController
@@ -14,4 +17,6 @@ class UsuariosController(
1417 @GetMapping(" /usuarios" )
1518 fun usuarios () = usuariosService.allInstances()
1619
20+ @PostMapping(" /usuarios" )
21+ fun crear (@RequestBody usuario : Usuario ) = usuariosService.crear(usuario)
1722}
Original file line number Diff line number Diff line change 11package org.uqbar.tareas.domain
22
3- class Usuario (val nombre : String ) : Entity() {
3+ class Usuario (var nombre : String = " " ) : Entity() {
44
55 val tareasAsignadas: MutableList <Tarea > = mutableListOf ()
66
Original file line number Diff line number Diff line change 11package org.uqbar.tareas.service
22
33import org.springframework.stereotype.Service
4+ import org.uqbar.tareas.domain.Usuario
45import org.uqbar.tareas.repository.UsuariosRepository
56
67@Service
78class UsuariosService (
8- val usuariosRepository : UsuariosRepository
9+ val usuariosRepository : UsuariosRepository
910) {
1011
11- fun allInstances () = usuariosRepository.allInstances()
12+ fun allInstances () = usuariosRepository.allInstances()
13+ fun crear (usuario : Usuario ) = usuariosRepository.create(usuario)
1214
1315}
Original file line number Diff line number Diff line change 1+ package org.uqbar.tareas.controller
2+
3+ import org.junit.jupiter.api.DisplayName
4+ import org.junit.jupiter.api.Test
5+ import org.springframework.beans.factory.annotation.Autowired
6+ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
7+ import org.springframework.boot.test.context.SpringBootTest
8+ import org.springframework.test.web.servlet.MockMvc
9+ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
10+ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
11+ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
12+ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
13+
14+ @SpringBootTest
15+ @AutoConfigureMockMvc
16+ @DisplayName(" Dado un controller health" )
17+ class HealthControllerTest {
18+ // region GET /health
19+ @Test
20+ fun `devuelve UP si esta levantado` (@Autowired mockMvc : MockMvc ) {
21+ mockMvc
22+ .perform(MockMvcRequestBuilders .get(" /health" ))
23+ .andExpect(status().isOk)
24+ .andExpect(content().contentType(" application/json" ))
25+ .andExpect(jsonPath(" $.status" ).value(" UP" ))
26+ }
27+ // endregion
28+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test
66import org.springframework.beans.factory.annotation.Autowired
77import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
88import org.springframework.boot.test.context.SpringBootTest
9+ import org.springframework.http.MediaType
910import org.springframework.test.web.servlet.MockMvc
1011import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
1112import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
@@ -44,4 +45,19 @@ class UsuariosControllerTest {
4445 .andExpect(jsonPath(" $.length()" ).value(5 ))
4546 }
4647
48+ @Test
49+ fun `se puede crear un usuarie` () {
50+ mockMvc
51+ .perform(MockMvcRequestBuilders
52+ .post(" /usuarios" )
53+ .contentType(MediaType .APPLICATION_JSON )
54+ .content("""
55+ { "nombre": "Fernando Dodino" }
56+ """ .trimIndent())
57+ )
58+ .andExpect(status().isOk)
59+ .andExpect(content().contentTypeCompatibleWith(MediaType .APPLICATION_JSON ))
60+ .andExpect(jsonPath(" $.nombre" ).value(" Fernando Dodino" ))
61+ }
62+
4763}
You can’t perform that action at this time.
0 commit comments