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
2d4032f6
Prev
Next
Show latest version
1 file
+
92
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
2d4032f6
Implementing CourseRepositoryTest
· 2d4032f6
Ester Vilímková
authored
1 year ago
application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/course/CourseRepositoryTest.java
0 → 100644
+
92
−
0
Options
package
org.fuseri.modulelanguageschool.course
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
;
import
org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.List
;
@DataJpaTest
public
class
CourseRepositoryTest
{
@Autowired
private
TestEntityManager
entityManager
;
@Autowired
private
CourseRepository
courseRepository
;
private
final
Course
course
=
new
Course
(
"AJ1"
,
10
,
Language
.
ENGLISH
,
ProficiencyLevel
.
A1
,
new
HashSet
<>());
@Test
void
saveCourse
()
{
Course
saved
=
courseRepository
.
save
(
course
);
Assertions
.
assertNotNull
(
saved
);
Assertions
.
assertEquals
(
course
,
saved
);
}
@Test
void
findById
()
{
entityManager
.
persist
(
course
);
entityManager
.
flush
();
Course
found
=
courseRepository
.
findById
(
course
.
getId
()).
orElse
(
null
);
Assertions
.
assertNotNull
(
found
);
Assertions
.
assertEquals
(
found
,
course
);
}
@Test
void
findAllByLang
()
{
entityManager
.
persist
(
course
);
entityManager
.
flush
();
List
<
Course
>
found
=
courseRepository
.
findAllByLang
(
course
.
getLanguage
());
Assertions
.
assertEquals
(
1
,
found
.
size
());
Assertions
.
assertEquals
(
found
.
get
(
0
),
course
);
}
@Test
void
findAllByLangProf
()
{
entityManager
.
persist
(
course
);
entityManager
.
flush
();
List
<
Course
>
found
=
courseRepository
.
findAllByLangProf
(
course
.
getLanguage
(),
course
.
getProficiency
());
Assertions
.
assertEquals
(
1
,
found
.
size
());
Assertions
.
assertEquals
(
found
.
get
(
0
),
course
);
}
@Test
public
void
testFindAllCourses
()
{
Course
course1
=
new
Course
();
Course
course2
=
new
Course
();
courseRepository
.
save
(
course1
);
courseRepository
.
save
(
course2
);
Page
<
Course
>
coursePage
=
courseRepository
.
findAll
(
PageRequest
.
of
(
0
,
42
));
Assertions
.
assertEquals
(
2
,
coursePage
.
getTotalElements
());
Assertions
.
assertEquals
(
coursePage
.
getContent
(),
Arrays
.
asList
(
course1
,
course2
));
}
@Test
public
void
testDeleteCourse
()
{
Long
courseId
=
entityManager
.
persist
(
new
Course
()).
getId
();
entityManager
.
flush
();
courseRepository
.
deleteById
(
courseId
);
Assertions
.
assertTrue
(
courseRepository
.
findById
(
courseId
).
isEmpty
());
}
}
Loading