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
1c62f411
There was an error fetching the commit references. Please try again later.
Commit
1c62f411
authored
1 year ago
by
Filip Bugoš
Browse files
Options
Downloads
Patches
Plain Diff
feat: User service test 16/04/23
parent
7ee41e07
No related branches found
No related tags found
3 merge requests
!79
Final merge to main
,
!44
Testing user
,
!43
Testing user
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/test/java/cz/muni/fi/pa165/core/user/UserServiceTest.java
+79
-0
79 additions, 0 deletions
...test/java/cz/muni/fi/pa165/core/user/UserServiceTest.java
with
79 additions
and
0 deletions
core/src/test/java/cz/muni/fi/pa165/core/user/UserServiceTest.java
+
79
−
0
View file @
1c62f411
...
...
@@ -2,15 +2,27 @@ package cz.muni.fi.pa165.core.user;
import
cz.muni.fi.pa165.core.company.Company
;
import
cz.muni.fi.pa165.core.device.Device
;
import
cz.muni.fi.pa165.core.house.House
;
import
cz.muni.fi.pa165.core.house.HouseService
;
import
cz.muni.fi.pa165.core.metrics.Metrics
;
import
cz.muni.fi.pa165.core.metrics.MetricsService
;
import
cz.muni.fi.pa165.core.smartmeter.SmartMeter
;
import
cz.muni.fi.pa165.core.smartmeter.SmartMeterService
;
import
cz.muni.fi.pa165.core.user.roles.HouseRole
;
import
cz.muni.fi.pa165.core.user.roles.RoleService
;
import
cz.muni.fi.pa165.model.dto.role.enums.HouseRoleEnum
;
import
org.junit.Assert
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.Optional
;
...
...
@@ -25,6 +37,18 @@ public class UserServiceTest {
@InjectMocks
private
UserService
userService
;
@Mock
private
MetricsService
metricsService
;
@Mock
private
SmartMeterService
smartMeterService
;
@Mock
private
HouseService
houseService
;
@Mock
private
RoleService
roleService
;
@Mock
private
UserRepository
userReposiroyMock
;
...
...
@@ -228,4 +252,59 @@ public class UserServiceTest {
assertEquals
(
pageResult
,
result
);
}
@Test
void
shouldReturnUserMonthConsumption
()
{
User
user
=
User
.
builder
()
.
email
(
"test@gmail.com"
)
.
firstName
(
"lol"
)
.
lastName
(
"lol"
)
.
username
(
"lol"
)
.
password
(
"lol"
)
.
userType
(
UserType
.
ADMIN
)
.
build
();
user
.
setId
(
"6a9f853d-59ef-4636-9c0b-bbac44bfd7f4"
);
userService
.
create
(
user
);
House
house
=
House
.
builder
()
.
address
(
"lol"
)
.
city
(
"lol"
)
.
state
(
"lol"
)
.
zipcode
(
"lol"
)
.
build
();
house
.
setId
(
"b256ac78-dc47-11ed-afa1-0242ac120002"
);
houseService
.
create
(
house
);
HouseRole
role
=
HouseRole
.
builder
()
.
houseRole
(
HouseRoleEnum
.
Owner
)
.
house
(
house
)
.
build
();
role
.
setUser
(
user
);
roleService
.
create
(
role
);
SmartMeter
smartMeter
=
SmartMeter
.
builder
()
.
house
(
house
)
.
build
();
smartMeterService
.
create
(
smartMeter
);
LocalDateTime
date
=
LocalDateTime
.
of
(
2023
,
1
,
15
,
0
,
0
,
0
,
0
);
double
consumptionSeed
=
0
;
Metrics
metrics
=
Metrics
.
builder
()
.
consumptionKWH
(
consumptionSeed
)
.
timeStamp
(
date
)
.
smartMeter
(
smartMeter
)
.
build
();
metricsService
.
create
(
metrics
);
double
consumption
=
userService
.
getConsumption
(
user
.
getId
(),
house
.
getId
(),
LocalDateTime
.
of
(
2023
,
1
,
1
,
0
,
0
,
0
,
0
),
LocalDateTime
.
of
(
2023
,
1
,
31
,
0
,
0
,
0
,
0
));
assertEquals
(
consumptionSeed
,
consumption
);
}
}
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