Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pa165-airport-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review 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
Petr Kabourek
pa165-airport-manager
Commits
5f3cfbd7
There was an error fetching the commit references. Please try again later.
Commit
5f3cfbd7
authored
11 months ago
by
xkromm
Browse files
Options
Downloads
Patches
Plain Diff
added steward controller tests
parent
1b369cef
No related branches found
No related tags found
1 merge request
!12
Controller tests
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
airports-hr-service/src/test/java/cz/muni/fi/pa165/hr/rest/StewardControllerTest.java
+53
-6
53 additions, 6 deletions
.../java/cz/muni/fi/pa165/hr/rest/StewardControllerTest.java
with
53 additions
and
6 deletions
airports-hr-service/src/test/java/cz/muni/fi/pa165/hr/rest/StewardControllerTest.java
+
53
−
6
View file @
5f3cfbd7
package
cz.muni.fi.pa165.hr.rest
;
import
cz.muni.fi.pa165.api.employee.Steward
;
import
cz.muni.fi.pa165.api.employee.requests.StewardRequest
;
import
cz.muni.fi.pa165.hr.excdption.EmployeeNotFoundException
;
import
cz.muni.fi.pa165.hr.facade.EmployeeFacade
;
import
cz.muni.fi.pa165.hr.util.ObjectConverter
;
import
cz.muni.fi.pa165.hr.util.TestApiFactory
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.Mockito
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
java.nio.charset.StandardCharsets
;
import
java.util.UUID
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
put
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
@WebMvcTest
(
controllers
=
{
StewardController
.
class
})
class
StewardControllerTest
{
@Test
void
createSteward
()
{
}
@Autowired
private
MockMvc
mockMvc
;
@MockBean
private
EmployeeFacade
employeeFacade
;
@Test
void
update
()
{
void
updateSteward_stewardFound_returnsSteward
()
throws
Exception
{
UUID
id
=
new
UUID
(
0x1
,
0xf
);
Steward
updatedSteward
=
TestApiFactory
.
getStewardEntity
();
when
(
employeeFacade
.
updateSteward
(
Mockito
.
eq
(
id
),
Mockito
.
any
(
StewardRequest
.
class
))).
thenReturn
(
updatedSteward
);
String
requestJson
=
"{\"id\":\""
+
id
+
"\",\"name\":\"UpdatedName\",\"surname\":\"UpdatedSurname\",\"gender\":false,\"dateOfBirth\":\"1990-01-01\",\"hired\":\"2015-01-01\",\"terminated\":\"2022-01-01\",\"languages\":[\"english\"]}"
;
String
responseJson
=
mockMvc
.
perform
(
put
(
"/employee/steward/{id}"
,
id
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
requestJson
))
.
andExpect
(
status
().
isOk
())
.
andReturn
()
.
getResponse
()
.
getContentAsString
(
StandardCharsets
.
UTF_8
);
Steward
response
=
ObjectConverter
.
convertJsonToObject
(
responseJson
,
Steward
.
class
);
assertThat
(
response
).
isEqualTo
(
updatedSteward
);
Mockito
.
verify
(
employeeFacade
,
Mockito
.
times
(
1
)).
updateSteward
(
Mockito
.
eq
(
id
),
Mockito
.
any
(
StewardRequest
.
class
));
}
@Test
void
getAvailable
()
{
void
updateSteward_stewardNotFound_throws404
()
throws
Exception
{
UUID
id
=
UUID
.
randomUUID
();
when
(
employeeFacade
.
updateSteward
(
Mockito
.
eq
(
id
),
Mockito
.
any
(
StewardRequest
.
class
))).
thenThrow
(
new
EmployeeNotFoundException
());
String
requestJson
=
"{\"id\":\""
+
id
+
"\",\"name\":\"UpdatedName\",\"surname\":\"UpdatedSurname\",\"gender\":false,\"dateOfBirth\":\"1990-01-01\",\"hired\":\"2015-01-01\",\"terminated\":\"2022-01-01\",\"languages\":[\"english\"]}"
;
mockMvc
.
perform
(
put
(
"/employee/steward/{id}"
,
id
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
requestJson
))
.
andExpect
(
status
().
isNotFound
());
Mockito
.
verify
(
employeeFacade
,
Mockito
.
times
(
1
)).
updateSteward
((
Mockito
.
eq
(
id
)),
Mockito
.
any
(
StewardRequest
.
class
));
}
}
\ No newline at end of file
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