Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TJV Semestralka - Server
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
Model registry
Monitor
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Petr Seidl
TJV Semestralka - Server
Commits
b557acc9
Commit
b557acc9
authored
4 years ago
by
Petr Seidl
Browse files
Options
Downloads
Patches
Plain Diff
Update added support for DTO
parent
3bf47297
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/cz/cvut/fit/tjv/seidlpet/semestralka/controller/SubjectControllerTest.java
+4
-14
4 additions, 14 deletions
...eidlpet/semestralka/controller/SubjectControllerTest.java
with
4 additions
and
14 deletions
src/test/java/cz/cvut/fit/tjv/seidlpet/semestralka/controller/SubjectControllerTest.java
+
4
−
14
View file @
b557acc9
...
...
@@ -7,7 +7,6 @@ import cz.cvut.fit.tjv.seidlpet.semestralka.data.entity.Student;
import
cz.cvut.fit.tjv.seidlpet.semestralka.data.entity.Subject
;
import
cz.cvut.fit.tjv.seidlpet.semestralka.data.entity.Teacher
;
import
org.hamcrest.CoreMatchers
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.BDDMockito
;
import
org.mockito.Mockito
;
...
...
@@ -25,10 +24,6 @@ import java.util.*;
@SpringBootTest
@AutoConfigureMockMvc
public
class
SubjectControllerTest
{
@Autowired
private
SubjectController
subjectController
;
@Autowired
private
MockMvc
mvc
;
...
...
@@ -56,17 +51,14 @@ public class SubjectControllerTest {
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.id"
).
exists
())
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.name"
,
CoreMatchers
.
is
(
subject
.
getName
())))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.lang"
,
CoreMatchers
.
is
(
subject
.
getLang
())))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.teacher.id"
).
exists
())
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.teacher.firstName"
,
CoreMatchers
.
is
(
teacher
.
getFirstName
())))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.teacher.lastName"
,
CoreMatchers
.
is
(
teacher
.
getLastName
())))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.teacherId"
,
CoreMatchers
.
is
(
teacher
.
getId
())))
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.students"
).
isEmpty
());
Assertions
.
assertEquals
(
subject
,
subjectController
.
findById
(
subject
.
getId
()));
Mockito
.
verify
(
subjectService
,
Mockito
.
atLeastOnce
()).
findById
(
subject
.
getId
());
}
@Test
void
findAll
()
throws
Exception
{
Teacher
teacher
=
new
Teacher
(
"Black"
,
"John"
);
Teacher
teacher
=
new
Teacher
(
1
,
"Black"
,
"John"
);
List
<
Subject
>
subjects
=
Arrays
.
asList
(
new
Subject
(
1
,
"Java"
,
"CZ"
,
teacher
,
new
ArrayList
<>()),
new
Subject
(
2
,
"C++"
,
"EN"
,
teacher
,
Collections
.
singletonList
(
...
...
@@ -78,7 +70,6 @@ public class SubjectControllerTest {
.
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.*.id"
).
exists
());
Assertions
.
assertEquals
(
subjects
,
subjectController
.
findAll
(
null
));
List
<
Subject
>
subject
=
Collections
.
singletonList
(
new
Subject
(
2
,
"C++"
,
"EN"
,
teacher
,
Collections
.
singletonList
(
new
Student
(
1
,
"Teo"
,
"Smith"
,
1.2
)
...
...
@@ -88,17 +79,16 @@ public class SubjectControllerTest {
.
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
MockMvcResultMatchers
.
jsonPath
(
"$.*.id"
,
CoreMatchers
.
equalTo
(
Collections
.
singletonList
(
2
))));
Assertions
.
assertEquals
(
subject
,
subjectController
.
findAll
(
2
));
Mockito
.
verify
(
subjectService
,
Mockito
.
atLeastOnce
()).
findAll
();
}
@Test
void
update
()
throws
Exception
{
Teacher
teacher
=
new
Teacher
(
1
,
"Johny"
,
"Black"
);
Subject
newSubject
=
new
Subject
(
1
,
"Ted
"
,
"
SK
"
,
teacher
,
new
ArrayList
<>(
));
Subject
CreateDTO
subjectCreateDTO
=
new
SubjectCreateDTO
(
"Java
"
,
"
CZ
"
,
teacher
.
getId
(),
Arrays
.
asList
(
1
,
2
,
3
));
mvc
.
perform
(
MockMvcRequestBuilders
.
put
(
"/api/v1/subject/1"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
asJsonString
(
newS
ubject
)))
.
content
(
asJsonString
(
s
ubject
CreateDTO
)))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
...
...
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