Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sprachschulsystem
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
Jan Pokorný
Sprachschulsystem
Merge requests
!23
An error occurred while fetching the assigned milestone of the selected merge_request.
M2 course tests
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
M2 course tests
M2-course-tests
into
M2
Overview
1
Commits
30
Pipelines
14
Changes
1
Merged
Ester Vilímková
requested to merge
M2-course-tests
into
M2
1 year ago
Overview
1
Commits
30
Pipelines
14
Changes
1
Expand
0
0
Merge request reports
Viewing commit
ad607fa6
Prev
Next
Show latest version
1 file
+
181
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
ad607fa6
Implementing LectureFacadeTest
· ad607fa6
Ester Vilímková
authored
1 year ago
application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/lecture/LectureFacadeTest.java
0 → 100644
+
181
−
0
Options
package
org.fuseri.modulelanguageschool.lecture
;
import
org.fuseri.model.dto.course.LanguageTypeDto
;
import
org.fuseri.model.dto.course.ProficiencyLevelDto
;
import
org.fuseri.model.dto.lecture.LectureCreateDto
;
import
org.fuseri.model.dto.lecture.LectureDto
;
import
org.fuseri.model.dto.user.AddressDto
;
import
org.fuseri.model.dto.user.UserDto
;
import
org.fuseri.modulelanguageschool.course.Language
;
import
org.fuseri.modulelanguageschool.course.ProficiencyLevel
;
import
org.fuseri.modulelanguageschool.user.User
;
import
org.fuseri.modulelanguageschool.user.UserMapper
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@SpringBootTest
@AutoConfigureMockMvc
final
class
LectureFacadeTest
{
private
final
UserDto
USER
=
new
UserDto
(
"novakovat"
,
"novakova@gamil.com"
,
"Tereza"
,
"Nováková"
,
new
AddressDto
());
private
final
LectureCreateDto
lectureCreateDto
=
new
LectureCreateDto
(
LocalDateTime
.
now
().
plusDays
(
2
),
LocalDateTime
.
now
().
plusDays
(
2
).
plusHours
(
2
),
"Learning how to spell deprecated"
,
10
,
0L
);
private
final
LectureDto
lectureDto
=
new
LectureDto
(
LocalDateTime
.
now
().
plusDays
(
2
),
LocalDateTime
.
now
().
plusDays
(
2
).
plusHours
(
2
),
"Learning how to spell deprecated"
,
10
,
0L
,
0L
);
private
final
Lecture
lecture
=
new
Lecture
();
private
final
User
user
=
new
User
();
private
final
List
<
Lecture
>
lectureList
=
List
.
of
(
lecture
);
private
final
List
<
LectureDto
>
lectureDtoList
=
List
.
of
(
lectureDto
);
private
final
LanguageTypeDto
languageTypeDto
=
LanguageTypeDto
.
ENGLISH
;
private
final
ProficiencyLevelDto
proficiencyLevelDto
=
ProficiencyLevelDto
.
B1
;
@Autowired
private
LectureFacade
lectureFacade
;
@MockBean
private
LectureService
lectureService
;
@MockBean
private
LectureMapper
lectureMapper
;
@MockBean
private
UserMapper
userMapper
;
@Test
void
create
()
{
when
(
lectureMapper
.
mapToLecture
(
lectureCreateDto
)).
thenReturn
(
lecture
);
when
(
lectureService
.
save
(
lecture
)).
thenReturn
(
lecture
);
when
(
lectureMapper
.
mapToDto
(
lecture
)).
thenReturn
(
lectureDto
);
LectureDto
actualDto
=
lectureFacade
.
create
(
lectureCreateDto
);
assertEquals
(
lectureDto
,
actualDto
);
}
@Test
void
testFindById
()
{
Long
id
=
0L
;
when
(
lectureService
.
findById
(
id
)).
thenReturn
(
lecture
);
when
(
lectureMapper
.
mapToDto
(
lecture
)).
thenReturn
(
lectureDto
);
LectureDto
actualDto
=
lectureFacade
.
findById
(
id
);
assertNotNull
(
actualDto
);
assertEquals
(
lectureDto
,
actualDto
);
}
@Test
void
testFindAll
()
{
var
id
=
1L
;
when
(
lectureService
.
findAllByCourse
(
anyLong
())).
thenReturn
(
lectureList
);
when
(
lectureMapper
.
mapToList
(
lectureList
)).
thenReturn
(
lectureDtoList
);
List
<
LectureDto
>
actualPageDtos
=
lectureFacade
.
findAll
(
id
);
assertEquals
(
lectureDtoList
,
actualPageDtos
);
}
@Test
void
update
()
{
Long
id
=
1L
;
when
(
lectureMapper
.
mapToLecture
(
lectureCreateDto
)).
thenReturn
(
lecture
);
when
(
lectureService
.
update
(
id
,
lecture
)).
thenReturn
(
lecture
);
when
(
lectureMapper
.
mapToDto
(
lecture
)).
thenReturn
(
lectureDto
);
LectureDto
actualDto
=
lectureFacade
.
update
(
id
,
lectureCreateDto
);
assertEquals
(
lectureDto
,
actualDto
);
}
@Test
void
testDelete
()
{
Long
id
=
1L
;
lectureFacade
.
delete
(
id
);
verify
(
lectureService
).
delete
(
id
);
}
@Test
void
testFindAllByLanguage
()
{
when
(
lectureService
.
findAll
(
any
(
Language
.
class
))).
thenReturn
(
lectureList
);
when
(
lectureMapper
.
mapToList
(
lectureList
)).
thenReturn
(
lectureDtoList
);
List
<
LectureDto
>
actualDtoList
=
lectureFacade
.
findAll
(
languageTypeDto
);
assertNotNull
(
actualDtoList
);
assertEquals
(
lectureDtoList
,
actualDtoList
);
}
@Test
void
testFindAllByLanguageAndProf
()
{
when
(
lectureService
.
findAll
(
any
(
Language
.
class
),
any
(
ProficiencyLevel
.
class
))).
thenReturn
(
lectureList
);
when
(
lectureMapper
.
mapToList
(
lectureList
)).
thenReturn
(
lectureDtoList
);
List
<
LectureDto
>
actualDtoList
=
lectureFacade
.
findAll
(
languageTypeDto
,
proficiencyLevelDto
);
assertNotNull
(
actualDtoList
);
assertEquals
(
lectureDtoList
,
actualDtoList
);
}
@Test
void
testEnrol
()
{
Long
id
=
0L
;
when
(
lectureMapper
.
mapToDto
(
lecture
)).
thenReturn
(
lectureDto
);
when
(
userMapper
.
fromDto
(
USER
)).
thenReturn
(
user
);
when
(
lectureService
.
enrol
(
anyLong
(),
any
(
User
.
class
))).
thenReturn
(
lecture
);
LectureDto
actualDto
=
lectureFacade
.
enrol
(
id
,
USER
);
assertNotNull
(
actualDto
);
assertEquals
(
lectureDto
,
actualDto
);
}
@Test
void
testExpel
()
{
Long
id
=
0L
;
when
(
lectureMapper
.
mapToDto
(
lecture
)).
thenReturn
(
lectureDto
);
when
(
userMapper
.
fromDto
(
USER
)).
thenReturn
(
user
);
when
(
lectureService
.
expel
(
anyLong
(),
any
(
User
.
class
))).
thenReturn
(
lecture
);
LectureDto
actualDto
=
lectureFacade
.
expel
(
id
,
USER
);
assertNotNull
(
actualDto
);
assertEquals
(
lectureDto
,
actualDto
);
}
@Test
void
testSetLecturer
()
{
Long
id
=
0L
;
when
(
lectureMapper
.
mapToDto
(
lecture
)).
thenReturn
(
lectureDto
);
when
(
userMapper
.
fromDto
(
USER
)).
thenReturn
(
user
);
when
(
lectureService
.
setLecturer
(
anyLong
(),
any
(
User
.
class
))).
thenReturn
(
lecture
);
LectureDto
actualDto
=
lectureFacade
.
setLecturer
(
id
,
USER
);
assertNotNull
(
actualDto
);
assertEquals
(
lectureDto
,
actualDto
);
}
}
Loading