Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laboratorio1 SSDD
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jonathan Cavia
laboratorio1 SSDD
Commits
4de34ff6
Commit
4de34ff6
authored
Aug 25, 2022
by
Jonathan Cavia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests
parent
4c44e3c1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
200 additions
and
15 deletions
+200
-15
src/main/java/com/example/test1/SaldoController.java
src/main/java/com/example/test1/SaldoController.java
+0
-6
src/main/java/com/example/test1/TransaccionController.java
src/main/java/com/example/test1/TransaccionController.java
+2
-6
src/test/java/com/example/test1/ApplicationTest1Test2.java
src/test/java/com/example/test1/ApplicationTest1Test2.java
+105
-0
src/test/java/com/example/test1/ApplicationTest1Tests.java
src/test/java/com/example/test1/ApplicationTest1Tests.java
+93
-3
No files found.
src/main/java/com/example/test1/SaldoController.java
View file @
4de34ff6
...
...
@@ -14,12 +14,6 @@ public class SaldoController {
this
.
transaccionService
=
transaccionService
;
}
@GetMapping
(
"/hello"
)
public
String
sayHello
(
@RequestParam
(
value
=
"myName"
,
defaultValue
=
"World"
)
String
name
)
{
return
String
.
format
(
"Hello %s!"
,
name
);
}
@GetMapping
(
"/saldo"
)
public
Saldo
returnSaldo
()
{
return
transaccionService
.
getSaldoActual
();
...
...
src/main/java/com/example/test1/TransaccionController.java
View file @
4de34ff6
...
...
@@ -35,13 +35,9 @@ public class TransaccionController {
}
@PostMapping
(
"/interes"
)
TransaccionModel
nuev
aExtraccion
(
@RequestBody
InteresDTO
extraccion
DTO
)
{
return
transaccionService
.
nuevoInteres
(
extraccion
DTO
.
interes
);
TransaccionModel
nuev
oInteres
(
@RequestBody
InteresDTO
interes
DTO
)
{
return
transaccionService
.
nuevoInteres
(
interes
DTO
.
interes
);
}
}
src/test/java/com/example/test1/ApplicationTest1Test2.java
0 → 100644
View file @
4de34ff6
package
com
.
example
.
test1
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
org.junit.jupiter.api.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.RequestBuilder
;
import
org.springframework.test.web.servlet.request.MockMvcRequestBuilders
;
import
org.springframework.test.web.servlet.result.MockMvcResultHandlers
;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
import
java.util.List
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_UTF8
;
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
@TestMethodOrder
(
MethodOrderer
.
OrderAnnotation
.
class
)
class
ApplicationTest1Test2
{
private
MockMvc
mvc
;
@Autowired
private
WebApplicationContext
webApplicationContext
;
@Autowired
private
TransaccionRepository
transaccionRepository
;
@BeforeEach
void
setUp
()
{
System
.
out
.
println
(
"antes de la prueba"
);
this
.
mvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
webApplicationContext
).
build
();
}
@Test
@Order
(
2
)
public
void
simuladorTest
()
throws
Exception
{
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
SerializationFeature
.
WRAP_ROOT_VALUE
,
false
);
ObjectWriter
ow
=
mapper
.
writer
().
withDefaultPrettyPrinter
();
transaccionRepository
.
deleteAll
();
List
<
TransaccionModel
>
transacciones
=
transaccionRepository
.
findAll
();
assertEquals
(
0
,
transacciones
.
size
());
//transaccion auxiliar
TransaccionModel
transaccionAux
=
new
TransaccionModel
();
transaccionAux
.
monto
=
1000
;
//interes auxiliar
InteresDTO
interesAux
=
new
InteresDTO
();
interesAux
.
interes
=
10
;
//requests
RequestBuilder
requestDeposito
=
MockMvcRequestBuilders
.
post
(
"/deposito"
).
contentType
(
APPLICATION_JSON
).
content
(
ow
.
writeValueAsString
(
transaccionAux
));
RequestBuilder
requestExtraccion
=
MockMvcRequestBuilders
.
post
(
"/extraccion"
).
contentType
(
APPLICATION_JSON
).
content
(
ow
.
writeValueAsString
(
transaccionAux
));
RequestBuilder
requestSaldo
=
MockMvcRequestBuilders
.
get
(
"/saldo"
);
RequestBuilder
requestInteres
=
MockMvcRequestBuilders
.
post
(
"/interes"
).
contentType
(
APPLICATION_JSON
).
content
(
ow
.
writeValueAsString
(
interesAux
));
// Deposito 1, saldo: 1000
this
.
mvc
.
perform
(
requestDeposito
).
andDo
(
MockMvcResultHandlers
.
print
()).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
content
().
contentType
(
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.monto"
).
value
(
1000
));
System
.
out
.
println
(
"durante la prueba"
);
//1er interés, monto esperado: 100, saldo luego: 1100,
this
.
mvc
.
perform
(
requestInteres
).
andDo
(
MockMvcResultHandlers
.
print
()).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
content
().
contentType
(
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.monto"
).
value
(
100
));
// Deposito 1, saldo: 2100
this
.
mvc
.
perform
(
requestDeposito
).
andDo
(
MockMvcResultHandlers
.
print
()).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
content
().
contentType
(
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.monto"
).
value
(
1000
));
System
.
out
.
println
(
"durante la prueba"
);
//1ra consulta de saldo, esperado: 2100
this
.
mvc
.
perform
(
requestSaldo
).
andDo
(
MockMvcResultHandlers
.
print
()).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
content
().
contentType
(
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.saldo"
).
value
(
2100
));
System
.
out
.
println
(
"durante la prueba"
);
}
@AfterEach
void
tearDown
()
{
System
.
out
.
println
(
"prueba terminada"
);
}
}
src/test/java/com/example/test1/ApplicationTest1Tests.java
View file @
4de34ff6
package
com
.
example
.
test1
;
import
org.junit.jupiter.api.Test
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
org.junit.jupiter.api.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.RequestBuilder
;
import
org.springframework.test.web.servlet.request.MockMvcRequestBuilders
;
import
org.springframework.test.web.servlet.result.MockMvcResultHandlers
;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
@SpringBootTest
import
java.util.List
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_UTF8
;
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
@TestMethodOrder
(
MethodOrderer
.
OrderAnnotation
.
class
)
class
ApplicationTest1Tests
{
private
MockMvc
mvc
;
@Autowired
private
WebApplicationContext
webApplicationContext
;
@Autowired
private
TransaccionRepository
transaccionRepository
;
@BeforeEach
void
setUp
()
{
System
.
out
.
println
(
"antes de la prueba"
);
this
.
mvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
webApplicationContext
).
build
();
}
@Test
void
contextLoads
()
{
@Order
(
1
)
public
void
simuladorTest
()
throws
Exception
{
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
SerializationFeature
.
WRAP_ROOT_VALUE
,
false
);
ObjectWriter
ow
=
mapper
.
writer
().
withDefaultPrettyPrinter
();
transaccionRepository
.
deleteAll
();
List
<
TransaccionModel
>
transacciones
=
transaccionRepository
.
findAll
();
assertEquals
(
0
,
transacciones
.
size
());
//transaccion auxiliar
TransaccionModel
transaccionAux
=
new
TransaccionModel
();
transaccionAux
.
monto
=
1000
;
//interes auxiliar
InteresDTO
interesAux
=
new
InteresDTO
();
interesAux
.
interes
=
10
;
//requests
RequestBuilder
requestDeposito
=
MockMvcRequestBuilders
.
post
(
"/deposito"
).
contentType
(
APPLICATION_JSON
).
content
(
ow
.
writeValueAsString
(
transaccionAux
));
RequestBuilder
requestExtraccion
=
MockMvcRequestBuilders
.
post
(
"/extraccion"
).
contentType
(
APPLICATION_JSON
).
content
(
ow
.
writeValueAsString
(
transaccionAux
));
RequestBuilder
requestSaldo
=
MockMvcRequestBuilders
.
get
(
"/saldo"
);
RequestBuilder
requestInteres
=
MockMvcRequestBuilders
.
post
(
"/interes"
).
contentType
(
APPLICATION_JSON
).
content
(
ow
.
writeValueAsString
(
interesAux
));
// Deposito 1, saldo actual: 1000
this
.
mvc
.
perform
(
requestDeposito
).
andDo
(
MockMvcResultHandlers
.
print
()).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
content
().
contentType
(
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.monto"
).
value
(
1000
));
System
.
out
.
println
(
"durante la prueba"
);
//2do deposito, saldo actual: 2000
this
.
mvc
.
perform
(
requestDeposito
).
andDo
(
MockMvcResultHandlers
.
print
()).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
content
().
contentType
(
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.monto"
).
value
(
1000
));
//1er interés, monto esperado: 200, saldo luego: 2200
this
.
mvc
.
perform
(
requestInteres
).
andDo
(
MockMvcResultHandlers
.
print
()).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
content
().
contentType
(
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.monto"
).
value
(
200
));
//1ra consulta de saldo
this
.
mvc
.
perform
(
requestSaldo
).
andDo
(
MockMvcResultHandlers
.
print
()).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
content
().
contentType
(
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.saldo"
).
value
(
2200
));
System
.
out
.
println
(
"durante la prueba"
);
}
@AfterEach
void
tearDown
()
{
System
.
out
.
println
(
"prueba terminada"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment