Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / communicate-dev / src / test / java / com / vayunmathur / communicate / rcs / RcsSlice3SessionFocusTest.kt
RcsSlice3SessionFocusTest.kt131 lines · 5.9 KiBRaw
| 1 | package com.vayunmathur.communicate.rcs |
| 2 | |
| 3 | import com.vayunmathur.communicate.data.rcs.RcsSessionManager |
| 4 | import com.vayunmathur.communicate.data.rcs.destroyHostedFocus |
| 5 | import com.vayunmathur.communicate.data.rcs.focusMembers |
| 6 | import com.vayunmathur.communicate.data.rcs.hostedFocusFor |
| 7 | import com.vayunmathur.communicate.data.rcs.noteFocusJoin |
| 8 | import com.vayunmathur.communicate.data.rcs.noteFocusLeave |
| 9 | import com.vayunmathur.communicate.data.rcs.hostGroupFocus |
| 10 | import com.vayunmathur.communicate.data.rcs.inviteFocusMember |
| 11 | import com.vayunmathur.communicate.data.rcs.noteFocusSubscriber |
| 12 | import com.vayunmathur.communicate.data.rcs.dropFocusSubscriber |
| 13 | import com.vayunmathur.communicate.data.rcs.publishConferenceInfo |
| 14 | import com.vayunmathur.communicate.data.rcs.refreshEventSubscriptions |
| 15 | import com.vayunmathur.communicate.data.rcs.removeFocusMember |
| 16 | import com.vayunmathur.communicate.data.rcs.subscribeConferenceEvents |
| 17 | import com.vayunmathur.communicate.data.rcs.onConferenceNotify |
| 18 | import kotlin.test.Test |
| 19 | import kotlin.test.assertEquals |
| 20 | import kotlin.test.assertFalse |
| 21 | import kotlin.test.assertNull |
| 22 | import kotlin.test.assertTrue |
| 23 | import kotlinx.coroutines.test.runTest |
| 24 | import org.junit.runner.RunWith |
| 25 | import org.robolectric.RobolectricTestRunner |
| 26 | |
| 27 | /** |
| 28 | * Slice-3 tests for the conference focus management |
| 29 | * (`RcsSessionFocus.kt` extensions on [RcsSessionManager]): join/leave |
| 30 | * bookkeeping, hosted-focus lookup, conference-info NOTIFY reconciliation |
| 31 | * (added/removed + stale-version filtering), and transport-gated publishes. |
| 32 | */ |
| 33 | @RunWith(RobolectricTestRunner::class) |
| 34 | class RcsSlice3SessionFocusTest { |
| 35 | |
| 36 | private fun conferenceInfo(version: Int, vararg members: String, deleted: String? = null): String = |
| 37 | buildString { |
| 38 | append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") |
| 39 | append("<conference-info xmlns=\"urn:ietf:params:xml:ns:conference-info\"\n") |
| 40 | append(" entity=\"conf:slice3-${version}@rcs.local\" version=\"$version\" state=\"full\">\n") |
| 41 | append(" <users>\n") |
| 42 | for (member in members) { |
| 43 | append(" <user entity=\"$member\" state=\"full\">\n") |
| 44 | append(" <endpoint entity=\"$member\"><state>connected</state></endpoint>\n") |
| 45 | append(" </user>\n") |
| 46 | } |
| 47 | if (deleted != null) { |
| 48 | append(" <user entity=\"$deleted\" state=\"deleted\">\n") |
| 49 | append(" <endpoint entity=\"$deleted\"><state>disconnected</state></endpoint>\n") |
| 50 | append(" </user>\n") |
| 51 | } |
| 52 | append(" </users>\n") |
| 53 | append("</conference-info>") |
| 54 | } |
| 55 | |
| 56 | @Test |
| 57 | fun joinAndLeaveOnUnknownFocusAreNoOps() { |
| 58 | RcsSessionManager.noteFocusJoin("conf:[email protected]", "+15550001111") |
| 59 | assertNull(RcsSessionManager.focusMembers("conf:[email protected]")) |
| 60 | RcsSessionManager.noteFocusLeave("conf:[email protected]", "+15550001111") |
| 61 | assertNull(RcsSessionManager.hostedFocusFor("slice3-conv-unknown")) |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | fun conferenceNotifyReconcilesAddedAndRemoved() { |
| 66 | val (added, removed) = RcsSessionManager.onConferenceNotify( |
| 67 | "slice3-conv-notify", |
| 68 | conferenceInfo(1, "sip:+15550002121@rcs", "sip:+15550002222@rcs", deleted = "sip:+15550002323@rcs"), |
| 69 | ) |
| 70 | assertEquals(listOf("sip:+15550002121@rcs", "sip:+15550002222@rcs"), added) |
| 71 | assertEquals(listOf("sip:+15550002323@rcs"), removed) |
| 72 | } |
| 73 | |
| 74 | @Test |
| 75 | fun conferenceNotifyRejectsNonConference() { |
| 76 | val (added, removed) = RcsSessionManager.onConferenceNotify("slice3-conv-x", "hello plain text") |
| 77 | assertTrue(added.isEmpty()) |
| 78 | assertTrue(removed.isEmpty()) |
| 79 | } |
| 80 | |
| 81 | @Test |
| 82 | fun conferenceNotifyStaleVersionIgnoredAfterSubscribe() = runTest { |
| 83 | // Without transport, subscribe fails closed but must not crash. |
| 84 | assertFalse( |
| 85 | RcsSessionManager.subscribeConferenceEvents("conf:[email protected]", "slice3-conv-sub"), |
| 86 | ) |
| 87 | // Plain NOTIFY path still reconciles (no subscription tracked for this conv). |
| 88 | val first = RcsSessionManager.onConferenceNotify( |
| 89 | "slice3-conv-sub2", |
| 90 | conferenceInfo(5, "sip:+15550003131@rcs"), |
| 91 | ) |
| 92 | assertEquals(listOf("sip:+15550003131@rcs"), first.first) |
| 93 | val second = RcsSessionManager.onConferenceNotify( |
| 94 | "slice3-conv-sub2", |
| 95 | conferenceInfo(7, "sip:+15550003232@rcs"), |
| 96 | ) |
| 97 | assertEquals(listOf("sip:+15550003232@rcs"), second.first) |
| 98 | } |
| 99 | |
| 100 | @Test |
| 101 | fun subscriberBookkeepingIsIdempotent() { |
| 102 | RcsSessionManager.noteFocusSubscriber("slice3-sub-call-1", "conf:[email protected]") |
| 103 | RcsSessionManager.noteFocusSubscriber("slice3-sub-call-1", "conf:[email protected]") |
| 104 | RcsSessionManager.dropFocusSubscriber("slice3-sub-call-1") |
| 105 | // Dropping twice is safe. |
| 106 | RcsSessionManager.dropFocusSubscriber("slice3-sub-call-1") |
| 107 | } |
| 108 | |
| 109 | @Test |
| 110 | fun publishConferenceInfoFailsClosedWithoutTransport() = runTest { |
| 111 | // No subscribers + no transport: returns quietly. |
| 112 | RcsSessionManager.publishConferenceInfo("conf:[email protected]") |
| 113 | RcsSessionManager.refreshEventSubscriptions() |
| 114 | } |
| 115 | |
| 116 | @Test |
| 117 | fun inviteAndRemoveFocusMemberFailClosedWithoutTransport() = runTest { |
| 118 | assertFalse(RcsSessionManager.inviteFocusMember("slice3-conv-nofocus", "+15550004141")) |
| 119 | assertFalse(RcsSessionManager.removeFocusMember("slice3-conv-nofocus", "+15550004141")) |
| 120 | assertFalse(RcsSessionManager.subscribeConferenceEvents("conf:[email protected]", "slice3-conv-nofocus")) |
| 121 | } |
| 122 | |
| 123 | @Test |
| 124 | fun hostFocusFailsClosedWithoutTransport() = runTest { |
| 125 | assertNull( |
| 126 | RcsSessionManager.hostGroupFocus("slice3-conv-host", "subject", listOf("+15550005151")), |
| 127 | ) |
| 128 | assertNull(RcsSessionManager.hostGroupFocus("slice3-conv-host2", "subject", emptyList())) |
| 129 | assertTrue(RcsSessionManager.destroyHostedFocus("slice3-conv-never-hosted")) |
| 130 | } |
| 131 | } |