Added better error handling for spring environment issues
This commit is contained in:
parent
b72060cd2a
commit
707b8a1b26
@ -176,8 +176,15 @@ class GroupSessionController {
|
|||||||
retryCount++
|
retryCount++
|
||||||
Thread.sleep(1_000) // Sleep for 1 second
|
Thread.sleep(1_000) // Sleep for 1 second
|
||||||
}
|
}
|
||||||
if (ipv4 != null)
|
if (ipv4 != null && this::environment.isInitialized)
|
||||||
return mapOf("ip" to ipv4, "port" to environment["local.server.port"])
|
return mapOf("ip" to ipv4, "port" to environment["local.server.port"])
|
||||||
|
else if(ipv4 == null) {
|
||||||
|
logger.error("IP Address could not be determined")
|
||||||
return mapOf("error" to "Could not determine IP Address")
|
return mapOf("error" to "Could not determine IP Address")
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
logger.error("Port could not be determined, environment not initialised")
|
||||||
|
return mapOf("error" to "Could not determine port")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ import uk.co.neviyn.observationdatabase.TutorRepository
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner::class)
|
@RunWith(MockitoJUnitRunner::class)
|
||||||
class GroupSessionControllerTest{
|
class GroupSessionControllerTest {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
lateinit var controller: GroupSessionController
|
lateinit var controller: GroupSessionController
|
||||||
@ -30,12 +30,10 @@ class GroupSessionControllerTest{
|
|||||||
lateinit var siteRepository: SiteRepository
|
lateinit var siteRepository: SiteRepository
|
||||||
@Mock
|
@Mock
|
||||||
lateinit var tutorRepository: TutorRepository
|
lateinit var tutorRepository: TutorRepository
|
||||||
/**
|
|
||||||
@Mock
|
@Mock
|
||||||
lateinit var observationRepository: ObservationRepository
|
lateinit var observationRepository: ObservationRepository
|
||||||
@Mock
|
@Mock
|
||||||
lateinit var personRepository: PersonRepository
|
lateinit var personRepository: PersonRepository
|
||||||
**/
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
@ -43,7 +41,7 @@ class GroupSessionControllerTest{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testStartSession(){
|
fun testStartSession() {
|
||||||
val site = Site(1, "Test site")
|
val site = Site(1, "Test site")
|
||||||
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||||
Mockito.doReturn(listOf(Tutor(1, "Mr X", site))).`when`(tutorRepository).findAllById(listOf(1))
|
Mockito.doReturn(listOf(Tutor(1, "Mr X", site))).`when`(tutorRepository).findAllById(listOf(1))
|
||||||
@ -52,19 +50,19 @@ class GroupSessionControllerTest{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResponseStatusException::class)
|
@Test(expected = ResponseStatusException::class)
|
||||||
fun testStartSession_NoSite(){
|
fun testStartSession_NoSite() {
|
||||||
controller.startGroupObservation(GroupObservationInit(0, TrainingType.INITIAL, listOf(1), listOf("Sample title")))
|
controller.startGroupObservation(GroupObservationInit(0, TrainingType.INITIAL, listOf(1), listOf("Sample title")))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResponseStatusException::class)
|
@Test(expected = ResponseStatusException::class)
|
||||||
fun testStartSession_NoTutor(){
|
fun testStartSession_NoTutor() {
|
||||||
val site = Site(1, "Test site")
|
val site = Site(1, "Test site")
|
||||||
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||||
controller.startGroupObservation(GroupObservationInit(1, TrainingType.INITIAL, listOf(0), listOf("Sample title")))
|
controller.startGroupObservation(GroupObservationInit(1, TrainingType.INITIAL, listOf(0), listOf("Sample title")))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testRecoverSession(){
|
fun testRecoverSession() {
|
||||||
val site = Site(1, "Test site")
|
val site = Site(1, "Test site")
|
||||||
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
Mockito.doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||||
Mockito.doReturn(listOf(Tutor(1, "Mr X", site))).`when`(tutorRepository).findAllById(listOf(1))
|
Mockito.doReturn(listOf(Tutor(1, "Mr X", site))).`when`(tutorRepository).findAllById(listOf(1))
|
||||||
@ -73,7 +71,7 @@ class GroupSessionControllerTest{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResponseStatusException::class)
|
@Test(expected = ResponseStatusException::class)
|
||||||
fun testRecoverSession_NoActiveSession(){
|
fun testRecoverSession_NoActiveSession() {
|
||||||
controller.reconnectToGroupObservation()
|
controller.reconnectToGroupObservation()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user