Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PA165 Formula One Team
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
Diana Gulčíková
PA165 Formula One Team
Commits
f8d5c37a
There was an error fetching the commit references. Please try again later.
Commit
f8d5c37a
authored
1 year ago
by
Andrej Šimurka
Browse files
Options
Downloads
Patches
Plain Diff
Test fixed
parent
6112fe8a
No related branches found
No related tags found
2 merge requests
!60
Docker
,
!51
19 car tests
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java
+23
-53
23 additions, 53 deletions
...z/muni/pa165/car/rest/CarComponentPairControllerTest.java
with
23 additions
and
53 deletions
car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java
+
23
−
53
View file @
f8d5c37a
package
cz.muni.pa165.car.rest
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
put
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
cz.muni.pa165.car.rest.CarDriverPairController
;
import
cz.muni.pa165.car.restemplate.DbGetter
;
import
cz.muni.pa165.car.service.CarComponentPairService
;
import
cz.muni.pa165.car.service.CarDriverPairService
;
import
cz.muni.pa165.common_library.dtos.CarComponentResponseDto
;
import
cz.muni.pa165.common_library.dtos.CarResponseDto
;
import
cz.muni.pa165.common_library.dtos.DriverDto
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
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.annotation.Bean
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
put
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.List
;
@WebMvcTest
(
CarComponentPairController
.
class
)
@Import
(
TestConfig
.
class
)
public
class
CarComponentPairControllerTest
{
private
static
CarResponseDto
carResponseDto
;
private
static
CarResponseDto
carResponseDto2
;
private
static
CarComponentResponseDto
carComponentResponseDto
;
private
static
CarComponentResponseDto
carComponentResponseDto2
;
@Autowired
private
MockMvc
mockMvc
;
@MockBean
private
CarComponentPairService
carComponentPairServiceMock
;
@Autowired
private
ObjectMapper
objectMapper
;
private
static
CarResponseDto
carResponseDto
;
private
static
CarResponseDto
carResponseDto2
;
// private static CarComponentRequestDto carComponentRequestDto;
// private static CarComponentRequestDto carComponentRequestDto2;
private
static
CarComponentResponseDto
carComponentResponseDto
;
private
static
CarComponentResponseDto
carComponentResponseDto2
;
@BeforeEach
void
initializeTestObjects
()
{
...
...
@@ -69,20 +53,6 @@ public class CarComponentPairControllerTest {
.
mainDriverId
(
1L
)
.
build
();
// carComponentRequestDto = CarComponentRequestDto.builder()
// .name("")
// .weight(BigDecimal.TEN)
// .manufacturer("")
// .price(BigDecimal.TEN)
// .build();
//
// carComponentRequestDto2 = CarComponentRequestDto.builder()
// .name("")
// .manufacturer("")
// .price(BigDecimal.TEN)
// .weight(BigDecimal.TEN)
// .build();
carComponentResponseDto
=
CarComponentResponseDto
.
builder
()
.
id
(
1L
)
.
name
(
""
)
...
...
@@ -106,10 +76,10 @@ public class CarComponentPairControllerTest {
given
(
carComponentPairServiceMock
.
addComponent
(
1L
,
1L
)).
willReturn
(
carResponseDto
);
String
response
=
mockMvc
.
perform
(
put
(
"/carcomponent/addcomponent"
)
.
param
(
"componentId"
,
String
.
valueOf
(
1L
))
.
param
(
"carId"
,
String
.
valueOf
(
1L
))
.
contentType
(
MediaType
.
APPLICATION_JSON
)
)
.
param
(
"componentId"
,
String
.
valueOf
(
1L
))
.
param
(
"carId"
,
String
.
valueOf
(
1L
))
.
contentType
(
MediaType
.
APPLICATION_JSON
)
)
.
andExpect
(
status
().
isOk
()).
andReturn
().
getResponse
().
getContentAsString
();
CarResponseDto
carResponseDto
=
objectMapper
.
readValue
(
response
,
CarResponseDto
.
class
);
...
...
@@ -122,10 +92,10 @@ public class CarComponentPairControllerTest {
given
(
carComponentPairServiceMock
.
removeComponent
(
1L
,
1L
)).
willReturn
(
carResponseDto2
);
String
response
=
mockMvc
.
perform
(
put
(
"/carcomponent/removecomponent"
)
.
param
(
"componentId"
,
String
.
valueOf
(
1L
))
.
param
(
"carId"
,
String
.
valueOf
(
1L
))
.
contentType
(
MediaType
.
APPLICATION_JSON
)
)
.
param
(
"componentId"
,
String
.
valueOf
(
1L
))
.
param
(
"carId"
,
String
.
valueOf
(
1L
))
.
contentType
(
MediaType
.
APPLICATION_JSON
)
)
.
andExpect
(
status
().
isOk
()).
andReturn
().
getResponse
().
getContentAsString
();
CarResponseDto
carResponseDto
=
objectMapper
.
readValue
(
response
,
CarResponseDto
.
class
);
Assertions
.
assertEquals
(
1L
,
carResponseDto
.
getId
());
...
...
@@ -136,10 +106,10 @@ public class CarComponentPairControllerTest {
void
getAllComponentsOfCar
()
throws
Exception
{
given
(
carComponentPairServiceMock
.
getAllComponentsOfCar
(
1L
)).
willReturn
(
List
.
of
(
carComponentResponseDto
,
carComponentResponseDto2
));
String
response
=
mockMvc
.
perform
(
pu
t
(
"/carcomponent/getcomponents"
)
.
param
(
"carId"
,
String
.
valueOf
(
1L
))
.
contentType
(
MediaType
.
APPLICATION_JSON
)
)
String
response
=
mockMvc
.
perform
(
ge
t
(
"/carcomponent/getcomponents"
)
.
param
(
"carId"
,
String
.
valueOf
(
1L
))
.
contentType
(
MediaType
.
APPLICATION_JSON
)
)
.
andExpect
(
status
().
isOk
()).
andReturn
().
getResponse
().
getContentAsString
();
List
<
CarComponentResponseDto
>
carComponentListResponse
=
List
.
of
(
objectMapper
.
readValue
(
response
,
CarComponentResponseDto
[].
class
));
Assertions
.
assertEquals
(
List
.
of
(
carComponentResponseDto
,
carComponentResponseDto2
),
carComponentListResponse
);
...
...
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