Search in sources :

Example 6 with CommunicationUserIdentifier

use of com.azure.android.communication.common.CommunicationUserIdentifier in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method canAddSingleParticipant.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canAddSingleParticipant(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    this.chatThreadClient.addParticipant(new ChatParticipant().setCommunicationIdentifier(this.firstThreadParticipant)).get();
    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, "canAddSingleParticipant");
    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) {
        assertTrue(super.checkParticipantsListContainsParticipantId(returnedParticipants, this.firstThreadParticipant.getId()));
    }
}
Also used : ArrayList(java.util.ArrayList) ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant) ListParticipantsOptions(com.azure.android.communication.chat.models.ListParticipantsOptions) CountDownLatch(java.util.concurrent.CountDownLatch) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with CommunicationUserIdentifier

use of com.azure.android.communication.common.CommunicationUserIdentifier in project azure-sdk-for-android by Azure.

the class ChatClientTestBase method generateParticipant.

public static ChatParticipant generateParticipant(String id, String displayName) {
    ChatParticipant chatParticipant = new ChatParticipant();
    chatParticipant.setCommunicationIdentifier(new CommunicationUserIdentifier(id));
    chatParticipant.setDisplayName(displayName);
    return chatParticipant;
}
Also used : ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier)

Example 8 with CommunicationUserIdentifier

use of com.azure.android.communication.common.CommunicationUserIdentifier in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method canAddSingleParticipantWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canAddSingleParticipantWithResponse(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    Response<Void> addResponse = this.chatThreadClient.addParticipantWithResponse(new ChatParticipant().setCommunicationIdentifier(this.firstThreadParticipant), 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, "canAddSingleParticipantWithResponse");
    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) {
        assertTrue(super.checkParticipantsListContainsParticipantId(returnedParticipants, this.firstThreadParticipant.getId()));
    }
}
Also used : ArrayList(java.util.ArrayList) ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant) ListParticipantsOptions(com.azure.android.communication.chat.models.ListParticipantsOptions) CountDownLatch(java.util.concurrent.CountDownLatch) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with CommunicationUserIdentifier

use of com.azure.android.communication.common.CommunicationUserIdentifier in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method canAddListAndRemoveParticipants.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canAddListAndRemoveParticipants(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    Iterable<ChatParticipant> participants = addParticipants(this.firstThreadParticipant.getId(), this.secondThreadParticipant.getId());
    this.chatThreadClient.addParticipants(participants).get();
    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, "canAddListAndRemoveParticipants");
    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) ListParticipantsOptions(com.azure.android.communication.chat.models.ListParticipantsOptions) CountDownLatch(java.util.concurrent.CountDownLatch) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with CommunicationUserIdentifier

use of com.azure.android.communication.common.CommunicationUserIdentifier in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method setupTest.

private void setupTest(HttpClient httpClient) throws ExecutionException, InterruptedException {
    this.client = super.getChatClientBuilder(httpClient).buildAsyncClient();
    this.firstThreadParticipant = new CommunicationUserIdentifier(THREAD_PARTICIPANT_1);
    this.secondThreadParticipant = new CommunicationUserIdentifier(THREAD_PARTICIPANT_2);
    CreateChatThreadOptions threadRequest = createThreadOptions(this.firstThreadParticipant.getId(), this.secondThreadParticipant.getId());
    CreateChatThreadResult createChatThreadResult = client.createChatThread(threadRequest).get();
    this.chatThreadClient = client.getChatThreadClient(createChatThreadResult.getChatThreadProperties().getId());
    this.threadId = chatThreadClient.getChatThreadId();
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier)

Aggregations

CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ChatParticipant (com.azure.android.communication.chat.models.ChatParticipant)6 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 ListParticipantsOptions (com.azure.android.communication.chat.models.ListParticipantsOptions)4 CommunicationIdentifier (com.azure.android.communication.common.CommunicationIdentifier)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ExecutionException (java.util.concurrent.ExecutionException)4 ChatErrorResponseException (com.azure.android.communication.chat.models.ChatErrorResponseException)2 CreateChatThreadOptions (com.azure.android.communication.chat.models.CreateChatThreadOptions)2 CreateChatThreadResult (com.azure.android.communication.chat.models.CreateChatThreadResult)2 CommunicationCloudEnvironmentModel (com.azure.android.communication.chat.implementation.models.CommunicationCloudEnvironmentModel)1 CommunicationIdentifierModel (com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel)1 MicrosoftTeamsUserIdentifierModel (com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel)1 PhoneNumberIdentifierModel (com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel)1 AddChatParticipantsResult (com.azure.android.communication.chat.models.AddChatParticipantsResult)1 ChatEvent (com.azure.android.communication.chat.models.ChatEvent)1 ChatMessageDeletedEvent (com.azure.android.communication.chat.models.ChatMessageDeletedEvent)1