mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
[headless] make events related to adding contacts available via websocket
This commit is contained in:
@@ -14,6 +14,7 @@ import org.briarproject.bramble.api.sync.Message
|
||||
import org.briarproject.bramble.api.system.Clock
|
||||
import org.briarproject.bramble.test.TestUtils.*
|
||||
import org.briarproject.bramble.util.StringUtils.getRandomString
|
||||
import org.briarproject.briar.headless.event.WebSocketController
|
||||
import org.skyscreamer.jsonassert.JSONAssert.assertEquals
|
||||
import org.skyscreamer.jsonassert.JSONCompareMode.STRICT
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
@@ -26,6 +27,8 @@ abstract class ControllerTest {
|
||||
protected val clock = mockk<Clock>()
|
||||
protected val ctx = mockk<Context>()
|
||||
|
||||
protected val webSocketController = mockk<WebSocketController>()
|
||||
|
||||
private val request = mockk<HttpServletRequest>(relaxed = true)
|
||||
private val response = mockk<HttpServletResponse>(relaxed = true)
|
||||
private val outputCtx = ContextUtil.init(request, response)
|
||||
|
||||
@@ -5,9 +5,14 @@ import io.javalin.json.JavalinJson.toJson
|
||||
import io.mockk.Runs
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.runs
|
||||
import org.briarproject.bramble.api.contact.Contact
|
||||
import org.briarproject.bramble.api.contact.ContactId
|
||||
import org.briarproject.bramble.api.contact.PendingContactId
|
||||
import org.briarproject.bramble.api.contact.PendingContactState.FAILED
|
||||
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent
|
||||
import org.briarproject.bramble.api.db.NoSuchContactException
|
||||
import org.briarproject.bramble.api.db.NoSuchPendingContactException
|
||||
import org.briarproject.bramble.identity.output
|
||||
@@ -20,9 +25,11 @@ import org.junit.jupiter.api.Test
|
||||
|
||||
internal class ContactControllerTest : ControllerTest() {
|
||||
|
||||
private val controller = ContactControllerImpl(contactManager, objectMapper)
|
||||
private val pendingContact = getPendingContact()
|
||||
|
||||
private val controller =
|
||||
ContactControllerImpl(contactManager, objectMapper, webSocketController)
|
||||
|
||||
@Test
|
||||
fun testEmptyContactList() {
|
||||
every { contactManager.contacts } returns emptyList<Contact>()
|
||||
@@ -134,6 +141,48 @@ internal class ContactControllerTest : ControllerTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testContactAddedRemotelyEvent() {
|
||||
val event = ContactAddedRemotelyEvent(contact)
|
||||
|
||||
every {
|
||||
webSocketController.sendEvent(
|
||||
EVENT_CONTACT_ADDED_REMOTELY,
|
||||
event.output()
|
||||
)
|
||||
} just runs
|
||||
|
||||
controller.eventOccurred(event)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPendingContactStateChangedEvent() {
|
||||
val event = PendingContactStateChangedEvent(pendingContact.id, FAILED)
|
||||
|
||||
every {
|
||||
webSocketController.sendEvent(
|
||||
EVENT_PENDING_CONTACT_STATE_CHANGED,
|
||||
event.output()
|
||||
)
|
||||
} just runs
|
||||
|
||||
controller.eventOccurred(event)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPendingContactRemovedEvent() {
|
||||
val event = PendingContactRemovedEvent(pendingContact.id)
|
||||
|
||||
every {
|
||||
webSocketController.sendEvent(
|
||||
EVENT_PENDING_CONTACT_REMOVED,
|
||||
event.output()
|
||||
)
|
||||
} just runs
|
||||
|
||||
controller.eventOccurred(event)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOutputContact() {
|
||||
val json = """
|
||||
@@ -159,6 +208,12 @@ internal class ContactControllerTest : ControllerTest() {
|
||||
assertJsonEquals(json, author.output())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOutputContactAddedRemotelyEvent() {
|
||||
val event = ContactAddedRemotelyEvent(contact)
|
||||
assertJsonEquals(toJson(contact.output()), event.output())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOutputPendingContact() {
|
||||
val json = """
|
||||
@@ -172,4 +227,27 @@ internal class ContactControllerTest : ControllerTest() {
|
||||
assertJsonEquals(json, pendingContact.output())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOutputPendingContactStateChangedEvent() {
|
||||
val event = PendingContactStateChangedEvent(pendingContact.id, FAILED)
|
||||
val json = """
|
||||
{
|
||||
"pendingContactId": ${toJson(pendingContact.id.bytes)},
|
||||
"state": "failed"
|
||||
}
|
||||
"""
|
||||
assertJsonEquals(json, event.output())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOutputPendingContactRemovedEvent() {
|
||||
val event = PendingContactRemovedEvent(pendingContact.id)
|
||||
val json = """
|
||||
{
|
||||
"pendingContactId": ${toJson(pendingContact.id.bytes)}
|
||||
}
|
||||
"""
|
||||
assertJsonEquals(json, event.output())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.briarproject.briar.api.messaging.PrivateMessageFactory
|
||||
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.event.WebSocketController
|
||||
import org.briarproject.briar.headless.event.output
|
||||
import org.briarproject.briar.headless.json.JsonDict
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
@@ -35,7 +34,6 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
private val messagingManager = mockk<MessagingManager>()
|
||||
private val conversationManager = mockk<ConversationManager>()
|
||||
private val privateMessageFactory = mockk<PrivateMessageFactory>()
|
||||
private val webSocketController = mockk<WebSocketController>()
|
||||
private val dbExecutor = ImmediateExecutor()
|
||||
|
||||
private val controller = MessagingControllerImpl(
|
||||
|
||||
Reference in New Issue
Block a user