Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Smart Energy Management System
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
Marek Skácelík
Smart Energy Management System
Commits
94b814c7
There was an error fetching the commit references. Please try again later.
Commit
94b814c7
authored
2 years ago
by
Anesa Fazlagić
Browse files
Options
Downloads
Patches
Plain Diff
added tests for statistics microservice
parent
074a787a
No related branches found
No related tags found
2 merge requests
!25
Milestone 1
,
!24
Added unit tests for statistics microservice
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
statistics/pom.xml
+5
-0
5 additions, 0 deletions
statistics/pom.xml
statistics/src/test/java/cz/muni/fi/pa165/statistics/UnitTestUserStatisticsJPA.java
+102
-0
102 additions, 0 deletions
...z/muni/fi/pa165/statistics/UnitTestUserStatisticsJPA.java
with
107 additions
and
0 deletions
statistics/pom.xml
+
5
−
0
View file @
94b814c7
...
...
@@ -36,6 +36,11 @@
<version>
1.5.3.Final
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<modelVersion>
4.0.0
</modelVersion>
...
...
This diff is collapsed.
Click to expand it.
statistics/src/test/java/cz/muni/fi/pa165/statistics/UnitTestUserStatisticsJPA.java
0 → 100644
+
102
−
0
View file @
94b814c7
package
cz.muni.fi.pa165.statistics
;
import
cz.muni.fi.pa165.statistics.statistics.StatisticRepository
;
import
cz.muni.fi.pa165.statistics.statistics.UserStatistic
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
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.test.context.junit4.SpringRunner
;
import
java.util.regex.Pattern
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringRunner
.
class
)
@DataJpaTest
public
class
UnitTestUserStatisticsJPA
{
@Autowired
private
TestEntityManager
entityManager
;
@Autowired
private
StatisticRepository
statisticRepository
;
@Test
public
void
createTesting
()
throws
Exception
{
String
userStatistics
=
this
.
entityManager
.
persistAndGetId
(
new
UserStatistic
()).
toString
();
// Regular expression to match UUID format
Pattern
uuidPattern
=
Pattern
.
compile
(
"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
,
Pattern
.
CASE_INSENSITIVE
);
// Check if the string matches the UUID format
boolean
isUUID
=
uuidPattern
.
matcher
(
userStatistics
).
matches
();
assertThat
(
isUUID
).
isTrue
();
}
@Test
public
void
shouldFindNoneIfRepositoryIsEmpty
()
{
Iterable
<
UserStatistic
>
userStatistics
=
statisticRepository
.
findAll
();
assertThat
(
userStatistics
).
isEmpty
();
}
@Test
public
void
shouldStore
()
{
assertThat
(
new
UserStatistic
()).
hasFieldOrProperty
(
"id"
);
}
@Test
public
void
shouldFindAll
()
{
UserStatistic
m
=
new
UserStatistic
();
entityManager
.
persist
(
m
);
UserStatistic
m1
=
new
UserStatistic
();
entityManager
.
persist
(
m1
);
UserStatistic
m2
=
new
UserStatistic
();
entityManager
.
persist
(
m2
);
assertThat
(
statisticRepository
.
findAll
()).
hasSize
(
3
).
contains
(
m
,
m1
,
m2
);
}
@Test
public
void
shouldUpdateById
()
{
UserStatistic
m
=
new
UserStatistic
();
entityManager
.
persist
(
m
);
UserStatistic
m1
=
new
UserStatistic
();
entityManager
.
persist
(
m1
);
UserStatistic
update
=
statisticRepository
.
findById
(
m
.
getId
()).
get
();
update
.
setName
(
"New name"
);
statisticRepository
.
save
(
update
);
UserStatistic
check
=
statisticRepository
.
findById
(
m
.
getId
()).
get
();
assertThat
(
check
.
getId
()).
isEqualTo
(
m
.
getId
());
assertThat
(
check
.
getName
()).
isEqualTo
(
m
.
getName
());
}
@Test
public
void
shouldDeleteById
()
{
UserStatistic
m
=
new
UserStatistic
();
entityManager
.
persist
(
m
);
UserStatistic
m1
=
new
UserStatistic
();
entityManager
.
persist
(
m1
);
statisticRepository
.
deleteById
(
m
.
getId
());
assertThat
(
statisticRepository
.
findAll
()).
hasSize
(
1
).
contains
(
m1
);
assertThat
(
statisticRepository
.
findAll
()).
hasSize
(
1
).
doesNotContain
(
m
);
}
@Test
public
void
shouldDeleteAll
()
{
entityManager
.
persist
(
new
UserStatistic
());
entityManager
.
persist
(
new
UserStatistic
());
statisticRepository
.
deleteAll
();
assertThat
(
statisticRepository
.
findAll
()).
isEmpty
();
}
}
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