Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Queue
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Labrador
Queue
Merge requests
!338
Add tests for LabStatusService
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Add tests for LabStatusService
labstatusservice-test
into
development
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Add tests for LabStatusService
Thijs Nulle
requested to merge
labstatusservice-test
into
development
May 16, 2020
Overview
0
Commits
1
Pipelines
0
Changes
1
This MR adds tests for LabStatusService
0
0
Merge request reports
Compare
development
development (base)
and
latest version
latest version
586b72f2
1 commit,
May 16, 2020
1 file
+
182
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/test/java/nl/tudelft/ewi/queue/service/LabStatusServiceTest.java
0 → 100644
+
182
−
0
View file @ 586b72f2
Edit in single-file editor
Open in Web IDE
/*
* Queue - A Queueing system that can be used to handle labs in higher education
* Copyright (C) 2016-2020 Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package
nl.tudelft.ewi.queue.service
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.TreeSet
;
import
nl.tudelft.ewi.queue.QueueApplication
;
import
nl.tudelft.ewi.queue.model.*
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mockito
;
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.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
QueueApplication
.
class
)
@WebAppConfiguration
@AutoConfigureMockMvc
@DirtiesContext
(
classMode
=
DirtiesContext
.
ClassMode
.
BEFORE_CLASS
)
public
class
LabStatusServiceTest
{
@Autowired
private
LabStatusService
labStatusService
;
private
TreeSet
<
Long
>
buckets
;
@Before
public
void
init
()
{
Lab
lab1
=
new
Lab
();
lab1
.
setSlot
(
new
LabSlot
(
LocalDateTime
.
now
(),
LocalDateTime
.
now
().
plusHours
(
4
)));
Lab
lab2
=
new
Lab
();
lab2
.
setSlot
(
new
LabSlot
(
LocalDateTime
.
now
().
plusHours
(
1
),
LocalDateTime
.
now
().
plusHours
(
5
)));
buckets
=
labStatusService
.
createBucketsOverCourse
(
List
.
of
(
lab1
,
lab2
),
2
);
}
@Test
public
void
countHandledRequestsInBucketsSimple
()
{
Request
handled
=
new
Request
();
handled
.
setStatus
(
Request
.
Status
.
APPROVED
);
handled
.
setApprovedAt
(
LocalDateTime
.
now
());
Request
handledNoTime
=
new
Request
();
handledNoTime
.
setStatus
(
Request
.
Status
.
APPROVED
);
Request
nonHandled
=
new
Request
();
nonHandled
.
setStatus
(
Request
.
Status
.
PENDING
);
List
<
Request
>
requests
=
List
.
of
(
handled
,
handledNoTime
,
nonHandled
);
List
<
Long
>
vals
=
labStatusService
.
countHandledRequestsInBuckets
(
buckets
,
requests
);
assertThat
(
vals
.
get
(
0
)).
isEqualTo
(
1L
);
assertThat
(
vals
.
get
(
1
)).
isEqualTo
(
0L
);
}
@Test
public
void
countOpenRequestsInBucketsSimple
()
{
Request
notArchived
=
new
Request
();
notArchived
.
setCreatedAt
(
LocalDateTime
.
now
());
notArchived
.
setStatus
(
Request
.
Status
.
PENDING
);
Request
earlyCreationTime
=
new
Request
();
earlyCreationTime
.
setStatus
(
Request
.
Status
.
PENDING
);
earlyCreationTime
.
setCreatedAt
(
LocalDateTime
.
now
().
minusMinutes
(
1
));
Request
lateCreationTime
=
new
Request
();
lateCreationTime
.
setStatus
(
Request
.
Status
.
PENDING
);
lateCreationTime
.
setCreatedAt
(
LocalDateTime
.
now
().
minusMinutes
(
1
));
Request
noArchivedTime
=
new
Request
();
noArchivedTime
.
setStatus
(
Request
.
Status
.
APPROVED
);
noArchivedTime
.
setCreatedAt
(
LocalDateTime
.
now
());
Request
archived
=
new
Request
();
archived
.
setStatus
(
Request
.
Status
.
APPROVED
);
archived
.
setCreatedAt
(
LocalDateTime
.
now
());
archived
.
setApprovedAt
(
LocalDateTime
.
now
().
minusMinutes
(
1
));
List
<
Request
>
requests
=
List
.
of
(
notArchived
,
earlyCreationTime
,
lateCreationTime
,
noArchivedTime
,
archived
);
labStatusService
.
countOpenRequestsInBuckets
(
buckets
,
requests
);
}
@Test
public
void
countDistinctAssistants
()
{
User
assistant1
=
Mockito
.
mock
(
User
.
class
);
when
(
assistant1
.
getId
()).
thenReturn
(
1L
);
User
assistant2
=
Mockito
.
mock
(
User
.
class
);
when
(
assistant2
.
getId
()).
thenReturn
(
2L
);
Request
request1
=
new
Request
();
request1
.
setAssistant
(
assistant1
);
Request
request2
=
new
Request
();
request2
.
setAssistant
(
assistant1
);
Request
request3
=
new
Request
();
request3
.
setAssistant
(
assistant2
);
Request
request4
=
new
Request
();
request4
.
setAssistant
(
null
);
List
<
Request
>
requests
=
List
.
of
(
request1
,
request2
,
request3
,
request4
);
assertThat
(
labStatusService
.
countDistinctAssistants
(
requests
)).
isEqualTo
(
2L
);
}
@Test
public
void
averageWaitingTimeSimple
()
{
Request
notProcessingOrHandled
=
new
Request
();
notProcessingOrHandled
.
setStatus
(
Request
.
Status
.
PENDING
);
Request
processing
=
new
Request
();
processing
.
setStatus
(
Request
.
Status
.
PROCESSING
);
Request
handled
=
new
Request
();
handled
.
setStatus
(
Request
.
Status
.
APPROVED
);
Request
handledWithProcessingTimeNoSlot
=
new
Request
();
handledWithProcessingTimeNoSlot
.
setStatus
(
Request
.
Status
.
APPROVED
);
handledWithProcessingTimeNoSlot
.
setProcessingAt
(
LocalDateTime
.
now
());
handledWithProcessingTimeNoSlot
.
setCreatedAt
(
LocalDateTime
.
now
());
Request
handledWithProcessingTimeWithSlot
=
new
Request
();
handledWithProcessingTimeWithSlot
.
setStatus
(
Request
.
Status
.
APPROVED
);
handledWithProcessingTimeWithSlot
.
setSlot
(
new
RequestSlot
(
LocalDateTime
.
of
(
2020
,
1
,
1
,
0
,
0
),
LocalDateTime
.
now
()));
handledWithProcessingTimeWithSlot
.
setProcessingAt
(
LocalDateTime
.
of
(
2020
,
1
,
1
,
1
,
0
));
List
<
Request
>
requests
=
List
.
of
(
notProcessingOrHandled
,
processing
,
handled
,
handledWithProcessingTimeNoSlot
,
handledWithProcessingTimeWithSlot
);
assertThat
(
labStatusService
.
averageWaitingTime
(
requests
)).
isEqualTo
(
1800L
);
}
@Test
public
void
averageProcessingTimeSimple
()
{
Request
notHandled
=
new
Request
();
notHandled
.
setStatus
(
Request
.
Status
.
PENDING
);
Request
noProcessingTime
=
new
Request
();
noProcessingTime
.
setStatus
(
Request
.
Status
.
APPROVED
);
Request
noHandledTime
=
new
Request
();
noHandledTime
.
setStatus
(
Request
.
Status
.
APPROVED
);
noHandledTime
.
setProcessingAt
(
LocalDateTime
.
now
());
Request
processed
=
new
Request
();
processed
.
setStatus
(
Request
.
Status
.
APPROVED
);
processed
.
setProcessingAt
(
LocalDateTime
.
now
());
processed
.
setApprovedAt
(
LocalDateTime
.
now
().
plusSeconds
(
60
));
List
<
Request
>
requests
=
List
.
of
(
notHandled
,
noProcessingTime
,
noHandledTime
,
processed
);
assertThat
(
labStatusService
.
averageProcessingTime
(
requests
)).
isEqualTo
(
60L
);
}
}
Loading