Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PA165 Banking System
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Filip Piták
PA165 Banking System
Commits
7be59138
There was an error fetching the commit references. Please try again later.
Commit
7be59138
authored
11 months ago
by
Martin Mojžiš
Browse files
Options
Downloads
Patches
Plain Diff
fix: mock database in integration tests and allow them to run
parent
111aaef1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
account-query/pom.xml
+0
-3
0 additions, 3 deletions
account-query/pom.xml
account-query/src/test/java/cz/muni/pa165/banking/application/controller/BalanceControllerIT.java
+57
-27
57 additions, 27 deletions
...5/banking/application/controller/BalanceControllerIT.java
with
57 additions
and
30 deletions
account-query/pom.xml
+
0
−
3
View file @
7be59138
...
...
@@ -93,9 +93,6 @@
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-failsafe-plugin
</artifactId>
<configuration>
<skipITs>
true
</skipITs>
</configuration>
</plugin>
</plugins>
</build>
...
...
This diff is collapsed.
Click to expand it.
account-query/src/test/java/cz/muni/pa165/banking/application/controller/BalanceControllerIT.java
+
57
−
27
View file @
7be59138
...
...
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
com.fasterxml.jackson.databind.PropertyNamingStrategies
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
cz.muni.pa165.banking.account.query.dto.Transaction
;
import
cz.muni.pa165.banking.application.exception.RestApiExceptionHandler
;
import
cz.muni.pa165.banking.application.facade.BalanceFacade
;
import
cz.muni.pa165.banking.application.mapper.BalanceMapperImpl
;
import
cz.muni.pa165.banking.application.service.BalanceServiceImpl
;
...
...
@@ -13,6 +14,7 @@ import cz.muni.pa165.banking.domain.balance.Balance;
import
cz.muni.pa165.banking.domain.balance.repository.BalancesRepository
;
import
cz.muni.pa165.banking.domain.balance.repository.TransactionRepository
;
import
cz.muni.pa165.banking.domain.balance.service.BalanceService
;
import
cz.muni.pa165.banking.domain.transaction.TransactionType
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
@@ -30,10 +32,7 @@ import org.springframework.test.web.servlet.MockMvc;
import
java.math.BigDecimal
;
import
java.nio.charset.StandardCharsets
;
import
java.time.OffsetDateTime
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.UUID
;
import
java.util.*
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.*;
...
...
@@ -58,6 +57,9 @@ public class BalanceControllerIT {
@Autowired
private
BalanceFacade
facade
;
@Autowired
private
RestApiExceptionHandler
exceptionHandler
;
// disable connecting to database
...
...
@@ -78,6 +80,11 @@ public class BalanceControllerIT {
public
BalanceFacade
facade
(
BalanceService
service
)
{
return
new
BalanceFacade
(
service
,
new
BalanceMapperImpl
());
}
@Bean
public
RestApiExceptionHandler
restApiExceptionHandler
(
BalanceService
service
)
{
return
new
RestApiExceptionHandler
();
}
}
...
...
@@ -120,9 +127,10 @@ public class BalanceControllerIT {
@Test
void
addToBalance_accountNotExists_returnsNOK_IT
()
throws
Exception
{
// Arrange
mockMvc
.
perform
(
post
(
"/balance/new?id=id"
));
String
id
=
"badid"
;
when
(
balancesRepository
.
findById
(
id
)).
thenReturn
(
Optional
.
empty
());
// Act
String
id
=
"id"
;
String
responseJson
=
mockMvc
.
perform
(
post
(
"/balance/add?id=badid&amount=20&processId=5612b08f-27c2-42ca-9f23-0c9aff6ad877&type=WITHDRAW"
)
.
accept
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
status
().
is
(
400
))
...
...
@@ -136,9 +144,11 @@ public class BalanceControllerIT {
@Test
void
getStatus_personExists_returnsBalanceStatus_IT
()
throws
Exception
{
// Arrange
mockMvc
.
perform
(
post
(
"/balance/new?id=id"
));
// Act
String
id
=
"id"
;
Balance
mockBalance
=
new
Balance
(
id
);
when
(
balancesRepository
.
findById
(
id
)).
thenReturn
(
Optional
.
of
(
mockBalance
));
when
(
transactionRepository
.
findByBalance
(
mockBalance
)).
thenReturn
(
mockBalance
.
getTransactions
());
// Act
String
responseJson
=
mockMvc
.
perform
(
get
(
"/balance/status?id=id"
)
.
accept
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andReturn
()
...
...
@@ -169,21 +179,29 @@ public class BalanceControllerIT {
@Test
void
getTransactions_personExists_returnsTransactions_IT
()
throws
Exception
{
// Arrange
mockMvc
.
perform
(
post
(
"/balance/new?id=id"
));
mockMvc
.
perform
(
post
(
"/balance/add?id=id&amount=20&processId=5612b08f-27c2-42ca-9f23-0c9aff6ad877&type=WITHDRAW"
));
String
id
=
"id"
;
Balance
mockBalance
=
new
Balance
(
id
);
when
(
balancesRepository
.
findById
(
id
)).
thenReturn
(
Optional
.
of
(
mockBalance
));
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
Transaction
transaction
=
new
Transaction
();
transaction
.
setDate
(
OffsetDateTime
.
now
());
transaction
.
setAmount
(
BigDecimal
.
valueOf
(
20.00
));
transaction
.
setProcessId
(
UUID
.
fromString
(
"5612b08f-27c2-42ca-9f23-0c9aff6ad877"
));
transaction
.
setTransactionType
(
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
TransactionType
.
WITHDRAW
);
mockBalance
.
addTransaction
(
BigDecimal
.
valueOf
(
20
),
TransactionType
.
WITHDRAW
,
UUID
.
fromString
(
"5612b08f-27c2-42ca-9f23-0c9aff6ad877"
));
when
(
balancesRepository
.
findById
(
id
)).
thenReturn
(
Optional
.
of
(
mockBalance
));
when
(
transactionRepository
.
findByBalance
(
mockBalance
)).
thenReturn
(
mockBalance
.
getTransactions
());
// Act
String
id
=
"id"
;
String
responseJson
=
mockMvc
.
perform
(
get
(
"/balance/transactions?id=id&beginning=2020-02-02&end=2025-02-02"
)
.
accept
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andReturn
()
.
getResponse
()
.
getContentAsString
(
StandardCharsets
.
UTF_8
);
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
Transaction
[]
response
=
OBJECT_MAPPER
.
readValue
(
responseJson
,
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
Transaction
[].
class
);
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
Transaction
[]
response
=
OBJECT_MAPPER
.
readValue
(
responseJson
,
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
Transaction
[].
class
);
// Assert
assertThat
(
response
[
0
].
getAmount
().
byteValueExact
()).
isEqualTo
(
transaction
.
getAmount
().
byteValueExact
());
...
...
@@ -207,10 +225,11 @@ public class BalanceControllerIT {
void
getAllTransactions_returnsAllTransactions_IT
()
throws
Exception
{
// Arrange
mockMvc
.
perform
(
post
(
"/balance/new?id=idddd"
));
mockMvc
.
perform
(
post
(
"/balance/add?id=idddd&amount=20&processId=5612b08f-27c2-42ca-9f23-0c9aff6ad847&type=WITHDRAW"
));
mockMvc
.
perform
(
post
(
"/balance/new?id=idd"
));
mockMvc
.
perform
(
post
(
"/balance/add?id=idd&amount=40&processId=5612b08f-27c2-42ca-9f23-0c9aff64d874&type=WITHDRAW"
));
String
id1
=
"idddd"
;
String
id2
=
"idd"
;
Balance
mockBalance1
=
new
Balance
(
id1
);
Balance
mockBalance2
=
new
Balance
(
id2
);
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
Transaction
transaction
=
new
Transaction
();
transaction
.
setDate
(
OffsetDateTime
.
now
());
transaction
.
setAmount
(
BigDecimal
.
valueOf
(
20
));
...
...
@@ -221,6 +240,16 @@ public class BalanceControllerIT {
transaction2
.
setAmount
(
BigDecimal
.
valueOf
(
40
));
transaction2
.
setProcessId
(
UUID
.
fromString
(
"5612b08f-27c2-42ca-9f23-0c9aff64d874"
));
transaction2
.
setTransactionType
(
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
TransactionType
.
WITHDRAW
);
mockBalance1
.
addTransaction
(
BigDecimal
.
valueOf
(
20
),
TransactionType
.
WITHDRAW
,
UUID
.
fromString
(
"5612b08f-27c2-42ca-9f23-0c9aff6ad847"
));
when
(
balancesRepository
.
findById
(
id1
)).
thenReturn
(
Optional
.
of
(
mockBalance1
));
mockBalance2
.
addTransaction
(
BigDecimal
.
valueOf
(
40
),
TransactionType
.
WITHDRAW
,
UUID
.
fromString
(
"5612b08f-27c2-42ca-9f23-0c9aff64d874"
));
when
(
balancesRepository
.
findById
(
id2
)).
thenReturn
(
Optional
.
of
(
mockBalance2
));
when
(
transactionRepository
.
findByBalance
(
mockBalance1
)).
thenReturn
(
mockBalance1
.
getTransactions
());
when
(
transactionRepository
.
findByBalance
(
mockBalance2
)).
thenReturn
(
mockBalance2
.
getTransactions
());
when
(
balancesRepository
.
getAllIds
()).
thenReturn
(
List
.
of
(
id1
,
id2
));
// Act
String
id
=
"id"
;
String
responseJson
=
mockMvc
.
perform
(
get
(
"/balance/alltransactions?beginning=2020-02-02&end=2025-02-02"
)
...
...
@@ -234,28 +263,29 @@ public class BalanceControllerIT {
mockMvc
.
perform
(
delete
(
"/balance?id=idd"
));
// Assert
assertThat
(
response
.
stream
().
filter
(
a
->
a
.
getProcessId
().
equals
(
transaction2
.
getProcessId
())).
findFirst
().
get
()
.
getAmount
().
byteValueExact
()).
isEqualTo
(
transaction2
.
getAmount
().
byteValueExact
());
assertThat
(
response
.
stream
().
filter
(
a
->
a
.
getProcessId
().
equals
(
transaction2
.
getProcessId
())).
findFirst
().
get
()
.
getTransactionType
()).
isEqualTo
(
transaction2
.
getTransactionType
());
assertThat
(
response
.
stream
().
filter
(
a
->
a
.
getProcessId
().
equals
(
transaction
.
getProcessId
())).
findFirst
().
get
()
.
getAmount
().
byteValueExact
()).
isEqualTo
(
transaction
.
getAmount
().
byteValueExact
());
assertThat
(
response
.
stream
().
filter
(
a
->
a
.
getProcessId
().
equals
(
transaction
.
getProcessId
())).
findFirst
().
get
()
.
getTransactionType
()).
isEqualTo
(
transaction
.
getTransactionType
());
assertThat
(
response
.
get
(
1
).
getAmount
()).
isEqualTo
(
transaction2
.
getAmount
());
assertThat
(
response
.
get
(
1
).
getTransactionType
()).
isEqualTo
(
transaction2
.
getTransactionType
());
assertThat
(
response
.
get
(
0
).
getAmount
().
byteValueExact
()).
isEqualTo
(
transaction
.
getAmount
().
byteValueExact
());
assertThat
(
response
.
get
(
0
).
getTransactionType
()).
isEqualTo
(
transaction
.
getTransactionType
());
}
@Test
void
getReport_personExists_returnsReport_IT
()
throws
Exception
{
// Arrange
mockMvc
.
perform
(
post
(
"/balance/new?id=iddd"
));
mockMvc
.
perform
(
post
(
"/balance/add?id=iddd&amount=20&processId=5612b08f-27c2-42ca-9f26-0c9aff6ad877&type=WITHDRAW"
));
String
id
=
"iddd"
;
Balance
mockBalance
=
new
Balance
(
id
);
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
Transaction
transaction
=
new
Transaction
();
transaction
.
setDate
(
OffsetDateTime
.
now
());
transaction
.
setAmount
(
BigDecimal
.
valueOf
(
20
));
transaction
.
setProcessId
(
UUID
.
fromString
(
"5612b08f-27c2-42ca-9f26-0c9aff6ad877"
));
transaction
.
setTransactionType
(
cz
.
muni
.
pa165
.
banking
.
account
.
query
.
dto
.
TransactionType
.
WITHDRAW
);
mockBalance
.
addTransaction
(
BigDecimal
.
valueOf
(
20
),
TransactionType
.
WITHDRAW
,
UUID
.
fromString
(
"5612b08f-27c2-42ca-9f26-0c9aff6ad877"
));
when
(
balancesRepository
.
findById
(
id
)).
thenReturn
(
Optional
.
of
(
mockBalance
));
when
(
transactionRepository
.
findByBalance
(
mockBalance
)).
thenReturn
(
mockBalance
.
getTransactions
());
// Act
String
id
=
"id"
;
String
responseJson
=
mockMvc
.
perform
(
get
(
"/balance/account/report?id=iddd&beginning=2020-02-02&end=2024-05-05"
)
.
accept
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
status
().
is
(
200
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment