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
a25fafc4
There was an error fetching the commit references. Please try again later.
Commit
a25fafc4
authored
1 year ago
by
xkromm
Browse files
Options
Downloads
Patches
Plain Diff
new dependency
parent
60b3b78d
No related branches found
No related tags found
1 merge request
!8
Rest tests
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
airports-hr-service/src/test/java/cz/muni/fi/pa165/hr/rest/EmployeeControllerTest.java
+73
-37
73 additions, 37 deletions
...java/cz/muni/fi/pa165/hr/rest/EmployeeControllerTest.java
pom.xml
+5
-0
5 additions, 0 deletions
pom.xml
with
78 additions
and
37 deletions
airports-hr-service/src/test/java/cz/muni/fi/pa165/hr/rest/EmployeeControllerTest.java
+
73
−
37
View file @
a25fafc4
//package cz.muni.fi.pa165.hr.rest;
//
//import cz.muni.fi.pa165.api.employee.Employee;
//import cz.muni.fi.pa165.hr.facade.EmployeeFacade;
//import cz.muni.fi.pa165.hr.util.ObjectConverter;
//import cz.muni.fi.pa165.hr.util.TestDaoFactory;
//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.context.ApplicationContext;
//import org.springframework.http.MediaType;
//import org.springframework.test.web.servlet.MockMvc;
//
//import java.nio.charset.StandardCharsets;
//import java.util.UUID;
//
//import static org.assertj.core.api.Assertions.assertThat;
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
//
//
//@WebMvcTest(controllers = {EmployeeController.class})
//class EmployeeControllerTest {
//
// @Autowired
// private ApplicationContext applicationContext;
//
// @Autowired
// private MockMvc mockMvc;
//
// @MockBean
// private EmployeeFacade employeeFacade;
//
package
cz.muni.fi.pa165.hr.rest
;
import
cz.muni.fi.pa165.api.employee.Employee
;
import
cz.muni.fi.pa165.hr.facade.EmployeeFacade
;
import
cz.muni.fi.pa165.hr.util.ObjectConverter
;
import
cz.muni.fi.pa165.hr.util.TestDaoFactory
;
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.context.ApplicationContext
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.request.MockMvcRequestBuilders
;
import
java.nio.charset.StandardCharsets
;
import
java.util.UUID
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
java.util.UUID
;
import
static
org
.
mockito
.
Mockito
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.*;
@WebMvcTest
(
controllers
=
{
EmployeeController
.
class
})
class
EmployeeControllerTest
{
@Autowired
private
ApplicationContext
applicationContext
;
@Autowired
private
MockMvc
mockMvc
;
@MockBean
private
EmployeeFacade
employeeFacade
;
@Test
public
void
testGetEmployeeById
()
throws
Exception
{
UUID
id
=
UUID
.
randomUUID
();
Employee
employee
=
new
Employee
();
employee
.
setId
(
id
);
employee
.
setName
(
"John"
);
employee
.
setSurname
(
"Doe"
);
// Stubbing the behavior of employeeFacade.get(id) to return the employee object
Mockito
.
when
(
employeeFacade
.
get
(
id
)).
thenReturn
(
employee
);
// Perform GET request to /employee/{id}
mockMvc
.
perform
(
get
(
"/employee/{id}"
,
id
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
jsonPath
(
"$.id"
).
value
(
id
.
toString
()))
.
andExpect
(
jsonPath
(
"$.name"
).
value
(
"John"
))
.
andExpect
(
jsonPath
(
"$.surname"
).
value
(
"Doe"
));
// Verify that employeeFacade.get(id) is called exactly once with the correct argument
Mockito
.
verify
(
employeeFacade
,
Mockito
.
times
(
1
)).
get
(
id
);
}
// @Test
// void findById_personFound_returnsPerson() throws Exception {
// // Arrange
...
...
@@ -53,5 +89,5 @@
//
// assertThat(response).isEqualTo(TestDaoFactory.employeeEntity);
// }
//
//}
\ No newline at end of file
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pom.xml
+
5
−
0
View file @
a25fafc4
...
...
@@ -35,6 +35,11 @@
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
<version>
6.1.5
</version>
</dependency>
<dependency>
<groupId>
org.mapstruct
</groupId>
<artifactId>
mapstruct
</artifactId>
...
...
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