|
10 | 10 | import io.github.hikingc.matrixsdk.api.MatrixClient; |
11 | 11 | import io.github.hikingc.matrixsdk.api.events.*; |
12 | 12 | import io.github.hikingc.matrixsdk.api.events.matrix.StateEventContent; |
13 | | -import io.github.hikingc.matrixsdk.api.events.matrix.room.RoomJoinRules; |
14 | | -import io.github.hikingc.matrixsdk.api.events.matrix.room.RoomMessage; |
| 13 | +import io.github.hikingc.matrixsdk.api.events.matrix.room.*; |
15 | 14 | import io.github.hikingc.matrixsdk.api.events.matrix.room.messages.FileContent; |
16 | 15 | import io.github.hikingc.matrixsdk.api.events.matrix.room.messages.TextContent; |
| 16 | +import io.github.hikingc.matrixsdk.api.events.matrix.room.messages.ThumbnailInfo; |
| 17 | +import io.github.hikingc.matrixsdk.api.events.matrix.space.SpaceChild; |
| 18 | +import io.github.hikingc.matrixsdk.api.events.matrix.space.SpaceParent; |
17 | 19 | import io.github.hikingc.matrixsdk.api.events.queries.ChronologicalDirection; |
18 | 20 | import io.github.hikingc.matrixsdk.api.events.queries.Membership; |
19 | 21 | import io.github.hikingc.matrixsdk.api.events.queries.QueryParametersMessages; |
|
32 | 34 | import java.util.Map; |
33 | 35 | import java.util.Random; |
34 | 36 | import java.util.UUID; |
| 37 | +import java.util.stream.Stream; |
35 | 38 | import org.junit.jupiter.api.BeforeAll; |
36 | 39 | import org.junit.jupiter.api.BeforeEach; |
37 | 40 | import org.junit.jupiter.api.Test; |
38 | 41 | import org.junit.jupiter.api.io.TempDir; |
| 42 | +import org.junit.jupiter.params.ParameterizedTest; |
| 43 | +import org.junit.jupiter.params.provider.Arguments; |
| 44 | +import org.junit.jupiter.params.provider.MethodSource; |
39 | 45 |
|
40 | 46 | @WireMockTest |
41 | 47 | class EventServiceTest { |
@@ -168,12 +174,13 @@ void getMembers_WithACorrectPayload_thenReturnAListOfClientEvent() { |
168 | 174 | assertThat(response.getFirst().content().avatarUrl()) |
169 | 175 | .isEqualTo(URI.create("mxc://example.org/SEsfnsuifSDFSSEF")); |
170 | 176 | assertThat(response.getFirst().content().displayname()).isEqualTo("Alice Margatroid"); |
171 | | - assertThat(response.getFirst().content().membership()).isEqualTo("join"); |
| 177 | + assertThat(response.getFirst().content().membership()).isEqualTo(Membership.JOIN); |
172 | 178 | assertThat(response.getFirst().content().reason()).isEqualTo("Looking for support"); |
173 | 179 | assertThat(response.getFirst().eventId()) |
174 | 180 | .isEqualTo(EventID.parse("$143273582443PhrSn:example.org")); |
175 | | - assertThat(response.getFirst().originServerTs()).isEqualTo(1234); |
176 | | - assertThat(response.getFirst().eventId()).isEqualTo("$143273582443PhrSn:example.org"); |
| 181 | + assertThat(response.getFirst().originServerTs()).isEqualTo(1432735824653L); |
| 182 | + assertThat(response.getFirst().eventId()) |
| 183 | + .isEqualTo(EventID.parse("$143273582443PhrSn:example.org")); |
177 | 184 | } |
178 | 185 |
|
179 | 186 | @Test |
@@ -548,13 +555,105 @@ void getInitialSync_WithACorrectPayload_ThenReturnRoomInfo() { |
548 | 555 | assertThat(response).isNotNull(); |
549 | 556 | } |
550 | 557 |
|
551 | | - @Test |
552 | | - void sendStateEvent_WithACorrectPayload_ThenReturnAString() { |
553 | | - StateEventContent content = |
554 | | - new RoomJoinRules( |
555 | | - new RoomJoinRules.AllowCondition(ROOM_ID, "TYPE"), "JOINRULE"); |
556 | | - var response = client.events().sendStateEvent(ROOM_ID, "", content); |
557 | | - assertThat(response).isNotNull(); |
| 558 | + private static Stream<Arguments> provideEventsForsenStateEvent() { |
| 559 | + return Stream.of( |
| 560 | + Arguments.of( |
| 561 | + new RoomAvatar( |
| 562 | + new RoomAvatar.AvatarInfo( |
| 563 | + 480, |
| 564 | + "image/png", |
| 565 | + 102400, |
| 566 | + new ThumbnailInfo(150, 150, 8192, "image/png"), |
| 567 | + URI.create("mxc://example.org/thumbnailavataruri"), |
| 568 | + 480), |
| 569 | + URI.create("mxc://example.org/avataruri")), |
| 570 | + ""), |
| 571 | + Arguments.of(new RoomCanonicalAlias("#room:example.org", List.of("#alt:example.org")), ""), |
| 572 | + Arguments.of( |
| 573 | + new RoomCreate( |
| 574 | + List.of("@alice:example.org"), |
| 575 | + true, |
| 576 | + new RoomCreate.PreviousRoom( |
| 577 | + EventID.parse("$oldevent:example.org"), RoomID.parse("!oldroom:example.org")), |
| 578 | + "13", |
| 579 | + "m.space"), |
| 580 | + ""), |
| 581 | + Arguments.of(new RoomEncryption("m.megolm.v1.aes-sha2", 10, 10), ""), |
| 582 | + Arguments.of(new RoomGuestAccess(GuestAccessType.CAN_JOIN), ""), |
| 583 | + Arguments.of(new RoomHistoryVisibility(HistoryVisibilityType.SHARED), ""), |
| 584 | + Arguments.of( |
| 585 | + new RoomJoinRules( |
| 586 | + List.of( |
| 587 | + new RoomJoinRules.AllowCondition( |
| 588 | + RoomID.parse("!spaceroom:example.org"), "m.room_membership")), |
| 589 | + "restricted"), |
| 590 | + ""), |
| 591 | + Arguments.of( |
| 592 | + new RoomMember( |
| 593 | + URI.create("mxc://example.org/avataruri"), |
| 594 | + "Alice", |
| 595 | + Boolean.TRUE, |
| 596 | + null, |
| 597 | + Membership.JOIN, |
| 598 | + null, |
| 599 | + null), |
| 600 | + "@alice:example.org"), |
| 601 | + Arguments.of(new RoomName("Test Room"), ""), |
| 602 | + Arguments.of(new RoomPinnedEvents(List.of("$event1:example.org")), ""), |
| 603 | + Arguments.of( |
| 604 | + new RoomPowerLevels( |
| 605 | + 50, |
| 606 | + Map.of("m.room.name", 50, "m.room.power_levels", 100), |
| 607 | + 0, |
| 608 | + 0, |
| 609 | + 50, |
| 610 | + RoomPowerLevels.Notifications.of(Map.of("room", 50)), |
| 611 | + 50, |
| 612 | + 0, |
| 613 | + Map.of("@alice:example.org", 100), |
| 614 | + 0), |
| 615 | + ""), |
| 616 | + Arguments.of( |
| 617 | + new RoomTopic( |
| 618 | + new RoomTopic.TopicContentBlock( |
| 619 | + new RoomTopic.TopicContentBlock.TextualRepresentation( |
| 620 | + "Test topic", "mimetype"))), |
| 621 | + ""), |
| 622 | + Arguments.of(new ServerACL(List.of("*"), true, List.of()), ""), |
| 623 | + Arguments.of( |
| 624 | + new RoomThirdPartyInvite( |
| 625 | + "Alice", |
| 626 | + URI.create("https://identity.example.org/_matrix/identity/v2/pubkey/isvalid"), |
| 627 | + "publicKeyBase64Here", |
| 628 | + List.of( |
| 629 | + new RoomThirdPartyInvite.PublicKeys( |
| 630 | + "https://identity.example.org/_matrix/identity/v2/pubkey/isvalid", |
| 631 | + "anotherPublicKeyBase64Here"))), |
| 632 | + "token123"), |
| 633 | + Arguments.of(new Tombstone("Upgraded", "!newroom:example.org"), ""), |
| 634 | + Arguments.of( |
| 635 | + new SpaceChild("lexicographically_compare_me", false, List.of("example.org")), |
| 636 | + "!child:example.org"), |
| 637 | + Arguments.of(new SpaceParent(true, List.of("example.org")), "!parent:example.org")); |
| 638 | + } |
| 639 | + |
| 640 | + @ParameterizedTest |
| 641 | + @MethodSource("provideEventsForsenStateEvent") |
| 642 | + void sendStateEvent_WithACorrectPayload_ThenReturnAString( |
| 643 | + StateEventContent stateEvent, String stateKey) { |
| 644 | + String eventId = "$abc123def456:example.org"; |
| 645 | + |
| 646 | + stubFor( |
| 647 | + put(urlPathMatching("/_matrix/client/v3/rooms/.*/state/.*")) |
| 648 | + .willReturn( |
| 649 | + aResponse() |
| 650 | + .withStatus(200) |
| 651 | + .withHeader("Content-Type", "application/json") |
| 652 | + .withBody("{\"event_id\":\"" + eventId + "\"}"))); |
| 653 | + |
| 654 | + var response = client.events().sendStateEvent(ROOM_ID, stateKey, stateEvent); |
| 655 | + |
| 656 | + assertThat(response).isEqualTo(eventId); |
558 | 657 | } |
559 | 658 |
|
560 | 659 | @Test |
|
0 commit comments