mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
briar-headless: Address second round of review comments
This commit is contained in:
@@ -23,7 +23,7 @@ internal class BlogControllerTest : ControllerTest() {
|
||||
private val blogPostFactory = mockk<BlogPostFactory>()
|
||||
|
||||
private val controller =
|
||||
BlogController(blogManager, blogPostFactory, identityManager, clock)
|
||||
BlogControllerImpl(blogManager, blogPostFactory, identityManager, clock)
|
||||
|
||||
private val blog = Blog(group, author, false)
|
||||
private val parentId: MessageId? = null
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test
|
||||
|
||||
internal class ContactControllerTest : ControllerTest() {
|
||||
|
||||
private val controller = ContactController(contactManager)
|
||||
private val controller = ContactControllerImpl(contactManager)
|
||||
|
||||
@Test
|
||||
fun testEmptyContactList() {
|
||||
|
||||
@@ -3,17 +3,22 @@ package org.briarproject.briar.headless.event
|
||||
import io.javalin.json.JavalinJson.toJson
|
||||
import io.javalin.websocket.WsSession
|
||||
import io.mockk.*
|
||||
import org.briarproject.bramble.test.ImmediateExecutor
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader
|
||||
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
|
||||
import org.briarproject.briar.headless.ControllerTest
|
||||
import org.briarproject.briar.headless.messaging.EVENT_PRIVATE_MESSAGE
|
||||
import org.briarproject.briar.headless.messaging.output
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.IOException
|
||||
|
||||
internal class WebSocketControllerTest : ControllerTest() {
|
||||
|
||||
private val session = mockk<WsSession>()
|
||||
private val controller = WebSocketControllerImpl()
|
||||
private val session1 = mockk<WsSession>()
|
||||
private val session2 = mockk<WsSession>()
|
||||
|
||||
private val controller = WebSocketControllerImpl(ImmediateExecutor())
|
||||
|
||||
private val header =
|
||||
PrivateMessageHeader(message.id, group.id, timestamp, true, true, true, true)
|
||||
@@ -21,17 +26,40 @@ internal class WebSocketControllerTest : ControllerTest() {
|
||||
private val outputEvent = OutputEvent(EVENT_PRIVATE_MESSAGE, event.output(body))
|
||||
|
||||
@Test
|
||||
fun testSessionSend() {
|
||||
fun testSendEvent() {
|
||||
val slot = CapturingSlot<String>()
|
||||
|
||||
every { session.send(capture(slot)) } just Runs
|
||||
every { session1.send(capture(slot)) } just Runs
|
||||
|
||||
controller.sessions.add(session)
|
||||
controller.sessions.add(session1)
|
||||
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(body))
|
||||
|
||||
assertJsonEquals(slot.captured, outputEvent)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSendEventIOException() {
|
||||
testSendEventException(IOException())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSendEventWebSocketException() {
|
||||
testSendEventException(WebSocketException())
|
||||
}
|
||||
|
||||
private fun testSendEventException(throwable: Throwable) {
|
||||
val slot = CapturingSlot<String>()
|
||||
|
||||
every { session1.send(capture(slot)) } throws throwable
|
||||
every { session2.send(capture(slot)) } just Runs
|
||||
|
||||
controller.sessions.add(session1)
|
||||
controller.sessions.add(session2)
|
||||
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(body))
|
||||
|
||||
verify { session2.send(slot.captured) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOutputPrivateMessageReceivedEvent() {
|
||||
val json = """
|
||||
|
||||
@@ -16,7 +16,7 @@ internal class ForumControllerTest : ControllerTest() {
|
||||
|
||||
private val forumManager = mockk<ForumManager>()
|
||||
|
||||
private val controller = ForumController(forumManager)
|
||||
private val controller = ForumControllerImpl(forumManager)
|
||||
|
||||
private val forum = Forum(group, getRandomString(5), getRandomBytes(5))
|
||||
|
||||
@@ -30,7 +30,7 @@ internal class ForumControllerTest : ControllerTest() {
|
||||
|
||||
@Test
|
||||
fun create() {
|
||||
every { ctx.formParam("name") } returns forum.name
|
||||
every { ctx.formParam("text") } returns forum.name
|
||||
every { forumManager.addForum(forum.name) } returns forum
|
||||
every { ctx.json(forum.output()) } returns ctx
|
||||
|
||||
@@ -39,21 +39,21 @@ internal class ForumControllerTest : ControllerTest() {
|
||||
|
||||
@Test
|
||||
fun createNoName() {
|
||||
every { ctx.formParam("name") } returns null
|
||||
every { ctx.formParam("text") } returns null
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createEmptyName() {
|
||||
every { ctx.formParam("name") } returns ""
|
||||
every { ctx.formParam("text") } returns ""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createTooLongName() {
|
||||
every { ctx.formParam("name") } returns getRandomString(MAX_FORUM_NAME_LENGTH + 1)
|
||||
every { ctx.formParam("text") } returns getRandomString(MAX_FORUM_NAME_LENGTH + 1)
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.create(ctx) }
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
val slot = CapturingSlot<OutputPrivateMessageHeader>()
|
||||
|
||||
expectGetContact()
|
||||
every { ctx.formParam("message") } returns body
|
||||
every { ctx.formParam("text") } returns body
|
||||
every { messagingManager.getContactGroup(contact) } returns group
|
||||
every { clock.currentTimeMillis() } returns timestamp
|
||||
every {
|
||||
@@ -110,7 +110,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
@Test
|
||||
fun writeNonexistentBody() {
|
||||
expectGetContact()
|
||||
every { ctx.formParam("message") } returns null
|
||||
every { ctx.formParam("text") } returns null
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.write(ctx) }
|
||||
}
|
||||
@@ -118,7 +118,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
@Test
|
||||
fun writeEmptyBody() {
|
||||
expectGetContact()
|
||||
every { ctx.formParam("message") } returns ""
|
||||
every { ctx.formParam("text") } returns ""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.write(ctx) }
|
||||
}
|
||||
@@ -126,7 +126,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
@Test
|
||||
fun writeTooLongBody() {
|
||||
expectGetContact()
|
||||
every { ctx.formParam("message") } returns getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH + 1)
|
||||
every { ctx.formParam("text") } returns getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH + 1)
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.write(ctx) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user