Added some tests for GroupSessionController
This commit is contained in:
parent
cb6c15146e
commit
b72060cd2a
@ -0,0 +1,79 @@
|
|||||||
|
package uk.co.neviyn.observationdatabase.controller
|
||||||
|
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.InjectMocks
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner
|
||||||
|
import org.springframework.web.server.ResponseStatusException
|
||||||
|
import uk.co.neviyn.observationdatabase.GroupObservationInit
|
||||||
|
import uk.co.neviyn.observationdatabase.GroupSessionManager
|
||||||
|
import uk.co.neviyn.observationdatabase.ObservationRepository
|
||||||
|
import uk.co.neviyn.observationdatabase.PersonRepository
|
||||||
|
import uk.co.neviyn.observationdatabase.Site
|
||||||
|
import uk.co.neviyn.observationdatabase.SiteRepository
|
||||||
|
import uk.co.neviyn.observationdatabase.TrainingType
|
||||||
|
import uk.co.neviyn.observationdatabase.Tutor
|
||||||
|
import uk.co.neviyn.observationdatabase.TutorRepository
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner::class)
|
||||||
|
class GroupSessionControllerTest{
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
lateinit var controller: GroupSessionController
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var siteRepository: SiteRepository
|
||||||
|
@Mock
|
||||||
|
lateinit var tutorRepository: TutorRepository
|
||||||
|
/**
|
||||||
|
@Mock
|
||||||
|
lateinit var observationRepository: ObservationRepository
|
||||||
|
@Mock
|
||||||
|
lateinit var personRepository: PersonRepository
|
||||||
|
**/
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun tearDown() {
|
||||||
|
GroupSessionManager.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStartSession(){
|
||||||
|
val site = Site(1, "Test site")
|
||||||
|
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||||
|
Mockito.doReturn(listOf(Tutor(1, "Mr X", site))).`when`(tutorRepository).findAllById(listOf(1))
|
||||||
|
controller.startGroupObservation(GroupObservationInit(1, TrainingType.INITIAL, listOf(1), listOf("Sample title")))
|
||||||
|
assertTrue(GroupSessionManager.isValid())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ResponseStatusException::class)
|
||||||
|
fun testStartSession_NoSite(){
|
||||||
|
controller.startGroupObservation(GroupObservationInit(0, TrainingType.INITIAL, listOf(1), listOf("Sample title")))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ResponseStatusException::class)
|
||||||
|
fun testStartSession_NoTutor(){
|
||||||
|
val site = Site(1, "Test site")
|
||||||
|
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||||
|
controller.startGroupObservation(GroupObservationInit(1, TrainingType.INITIAL, listOf(0), listOf("Sample title")))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testRecoverSession(){
|
||||||
|
val site = Site(1, "Test site")
|
||||||
|
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||||
|
Mockito.doReturn(listOf(Tutor(1, "Mr X", site))).`when`(tutorRepository).findAllById(listOf(1))
|
||||||
|
controller.startGroupObservation(GroupObservationInit(1, TrainingType.INITIAL, listOf(1), listOf("Sample title")))
|
||||||
|
assertNotNull(controller.reconnectToGroupObservation())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = ResponseStatusException::class)
|
||||||
|
fun testRecoverSession_NoActiveSession(){
|
||||||
|
controller.reconnectToGroupObservation()
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package uk.co.neviyn.observationdatabase
|
package uk.co.neviyn.observationdatabase.controller
|
||||||
|
|
||||||
import junit.framework.TestCase.*
|
import junit.framework.TestCase.*
|
||||||
import org.joda.time.LocalDate
|
import org.joda.time.LocalDate
|
||||||
@ -8,7 +8,22 @@ import org.mockito.*
|
|||||||
import org.mockito.Mockito.*
|
import org.mockito.Mockito.*
|
||||||
import org.mockito.junit.MockitoJUnitRunner
|
import org.mockito.junit.MockitoJUnitRunner
|
||||||
import org.springframework.web.server.ResponseStatusException
|
import org.springframework.web.server.ResponseStatusException
|
||||||
import uk.co.neviyn.observationdatabase.controller.ObservationsController
|
import uk.co.neviyn.observationdatabase.NameValue
|
||||||
|
import uk.co.neviyn.observationdatabase.NewObservation
|
||||||
|
import uk.co.neviyn.observationdatabase.NewSite
|
||||||
|
import uk.co.neviyn.observationdatabase.NewTutor
|
||||||
|
import uk.co.neviyn.observationdatabase.Observation
|
||||||
|
import uk.co.neviyn.observationdatabase.ObservationRepository
|
||||||
|
import uk.co.neviyn.observationdatabase.ObservationsRequest
|
||||||
|
import uk.co.neviyn.observationdatabase.Person
|
||||||
|
import uk.co.neviyn.observationdatabase.PersonRepository
|
||||||
|
import uk.co.neviyn.observationdatabase.RatingComponent
|
||||||
|
import uk.co.neviyn.observationdatabase.Scenario
|
||||||
|
import uk.co.neviyn.observationdatabase.Site
|
||||||
|
import uk.co.neviyn.observationdatabase.SiteRepository
|
||||||
|
import uk.co.neviyn.observationdatabase.TrainingType
|
||||||
|
import uk.co.neviyn.observationdatabase.Tutor
|
||||||
|
import uk.co.neviyn.observationdatabase.TutorRepository
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner::class)
|
@RunWith(MockitoJUnitRunner::class)
|
Loading…
Reference in New Issue
Block a user