Search in sources :

Example 1 with AddChatParticipantsResult

use of com.azure.android.communication.chat.models.AddChatParticipantsResult in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method canAddListAndRemoveParticipantsWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canAddListAndRemoveParticipantsWithResponse(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    Iterable<ChatParticipant> participants = addParticipants(this.firstThreadParticipant.getId(), this.secondThreadParticipant.getId());
    Response<AddChatParticipantsResult> addResponse = this.chatThreadClient.addParticipantsWithResponse(participants, null).get();
    assertNotNull(addResponse);
    assertEquals(201, addResponse.getStatusCode());
    PagedAsyncStream<ChatParticipant> participantPagedAsyncStream = this.chatThreadClient.listParticipants(new ListParticipantsOptions(), null);
    CountDownLatch latch = new CountDownLatch(1);
    List<ChatParticipant> returnedParticipants = new ArrayList<ChatParticipant>();
    participantPagedAsyncStream.forEach(new AsyncStreamHandler<ChatParticipant>() {

        @Override
        public void onNext(ChatParticipant participant) {
            returnedParticipants.add(participant);
        }

        @Override
        public void onError(Throwable throwable) {
            latch.countDown();
        }

        @Override
        public void onComplete() {
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "canAddListAndRemoveParticipantsWithResponse");
    assertTrue(returnedParticipants.size() > 0);
    for (ChatParticipant participant : returnedParticipants) {
        assertNotNull(participant);
        assertNotNull(participant.getDisplayName());
        assertNotNull(participant.getShareHistoryTime());
        assertNotNull(participant.getCommunicationIdentifier());
        assertTrue(participant.getCommunicationIdentifier() instanceof CommunicationUserIdentifier);
        assertNotNull(((CommunicationUserIdentifier) participant.getCommunicationIdentifier()).getId());
    }
    if (TEST_MODE != TestMode.PLAYBACK) {
        for (ChatParticipant participant : participants) {
            assertTrue(super.checkParticipantsListContainsParticipantId(returnedParticipants, ((CommunicationUserIdentifier) participant.getCommunicationIdentifier()).getId()));
        }
        for (ChatParticipant participant : participants) {
            final String id = ((CommunicationUserIdentifier) participant.getCommunicationIdentifier()).getId();
            assertNotNull(id);
            if (!id.equals(this.firstThreadParticipant.getId())) {
                this.chatThreadClient.removeParticipant(participant.getCommunicationIdentifier()).get();
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant) CountDownLatch(java.util.concurrent.CountDownLatch) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier) AddChatParticipantsResult(com.azure.android.communication.chat.models.AddChatParticipantsResult) ListParticipantsOptions(com.azure.android.communication.chat.models.ListParticipantsOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

AddChatParticipantsResult (com.azure.android.communication.chat.models.AddChatParticipantsResult)1 ChatParticipant (com.azure.android.communication.chat.models.ChatParticipant)1 ListParticipantsOptions (com.azure.android.communication.chat.models.ListParticipantsOptions)1 CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1