Search in sources :

Example 1 with PagedResponse

use of com.azure.android.core.rest.util.paging.PagedResponse in project azure-sdk-for-android by Azure.

the class ChatAsyncClientTest method canListChatThreadsWithMaxPage.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListChatThreadsWithMaxPage(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
    CompletableFuture<CreateChatThreadResult> completableFuture1 = this.client.createChatThread(threadRequest);
    assertNotNull(completableFuture1);
    CreateChatThreadResult result1 = completableFuture1.get();
    assertNotNull(result1);
    assertNotNull(result1.getChatThreadProperties());
    assertNotNull(result1.getChatThreadProperties().getId());
    CompletableFuture<CreateChatThreadResult> completableFuture2 = this.client.createChatThread(threadRequest);
    assertNotNull(completableFuture2);
    CreateChatThreadResult result2 = completableFuture1.get();
    assertNotNull(result2);
    assertNotNull(result2.getChatThreadProperties());
    assertNotNull(result2.getChatThreadProperties().getId());
    PagedAsyncStream<ChatThreadItem> chatAsyncStream = this.client.listChatThreads(new ListChatThreadsOptions().setMaxPageSize(2), null);
    CountDownLatch latch = new CountDownLatch(1);
    AtomicBoolean gotNullResponse = new AtomicBoolean();
    AtomicBoolean gotNullList = new AtomicBoolean();
    List<ChatThreadItem> returnedThreads = new ArrayList<ChatThreadItem>();
    chatAsyncStream.byPage().forEach(new AsyncStreamHandler<PagedResponse<ChatThreadItem>>() {

        @Override
        public void onNext(PagedResponse<ChatThreadItem> response) {
            if (!gotNullResponse.get()) {
                gotNullResponse.set(response == null);
            }
            if (response != null) {
                List<ChatThreadItem> threadsInPage = response.getValue();
                if (!gotNullList.get()) {
                    gotNullResponse.set(threadsInPage == null);
                }
                if (threadsInPage != null) {
                    for (ChatThreadItem thread : threadsInPage) {
                        returnedThreads.add(thread);
                    }
                }
            }
        }

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

        @Override
        public void onComplete() {
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "canListChatThreads");
    Assertions.assertFalse(gotNullResponse.get());
    Assertions.assertFalse(gotNullList.get());
// REVISIT: Unreliable assert
// assertTrue(returnedThreads.size() > 0);
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) ArrayList(java.util.ArrayList) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) CountDownLatch(java.util.concurrent.CountDownLatch) ListChatThreadsOptions(com.azure.android.communication.chat.models.ListChatThreadsOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ChatThreadItem(com.azure.android.communication.chat.models.ChatThreadItem) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) ArrayList(java.util.ArrayList) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with PagedResponse

use of com.azure.android.core.rest.util.paging.PagedResponse in project azure-sdk-for-android by Azure.

the class ChatAsyncClientTest method canListChatThreads.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListChatThreads(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
    CompletableFuture<CreateChatThreadResult> completableFuture1 = this.client.createChatThread(threadRequest);
    assertNotNull(completableFuture1);
    CreateChatThreadResult result1 = completableFuture1.get();
    assertNotNull(result1);
    assertNotNull(result1.getChatThreadProperties());
    assertNotNull(result1.getChatThreadProperties().getId());
    CompletableFuture<CreateChatThreadResult> completableFuture2 = this.client.createChatThread(threadRequest);
    assertNotNull(completableFuture2);
    CreateChatThreadResult result2 = completableFuture1.get();
    assertNotNull(result2);
    assertNotNull(result2.getChatThreadProperties());
    assertNotNull(result2.getChatThreadProperties().getId());
    PagedAsyncStream<ChatThreadItem> chatAsyncStream = this.client.listChatThreads(new ListChatThreadsOptions(), null);
    CountDownLatch latch = new CountDownLatch(1);
    AtomicBoolean gotNullResponse = new AtomicBoolean();
    AtomicBoolean gotNullList = new AtomicBoolean();
    List<ChatThreadItem> returnedThreads = new ArrayList<ChatThreadItem>();
    chatAsyncStream.byPage().forEach(new AsyncStreamHandler<PagedResponse<ChatThreadItem>>() {

        @Override
        public void onNext(PagedResponse<ChatThreadItem> response) {
            if (!gotNullResponse.get()) {
                gotNullResponse.set(response == null);
            }
            if (response != null) {
                List<ChatThreadItem> threadsInPage = response.getValue();
                if (!gotNullList.get()) {
                    gotNullResponse.set(threadsInPage == null);
                }
                if (threadsInPage != null) {
                    for (ChatThreadItem thread : threadsInPage) {
                        returnedThreads.add(thread);
                    }
                }
            }
        }

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

        @Override
        public void onComplete() {
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "canListChatThreads");
    Assertions.assertFalse(gotNullResponse.get());
    Assertions.assertFalse(gotNullList.get());
// REVISIT: Unreliable assert
// assertTrue(returnedThreads.size() > 0);
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) ArrayList(java.util.ArrayList) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) CountDownLatch(java.util.concurrent.CountDownLatch) ListChatThreadsOptions(com.azure.android.communication.chat.models.ListChatThreadsOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ChatThreadItem(com.azure.android.communication.chat.models.ChatThreadItem) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) ArrayList(java.util.ArrayList) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with PagedResponse

use of com.azure.android.core.rest.util.paging.PagedResponse in project azure-sdk-for-android by Azure.

the class ChatAsyncImplClientTest method canListChatThreadsWithMaxPage.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListChatThreadsWithMaxPage(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadMember.getId(), secondThreadMember.getId());
    CompletableFuture<CreateChatThreadResult> completableFuture1 = this.client.getChatClient().createChatThreadAsync(threadRequest);
    assertNotNull(completableFuture1);
    CreateChatThreadResult result1 = completableFuture1.get();
    assertNotNull(result1);
    assertNotNull(result1.getChatThread());
    assertNotNull(result1.getChatThread().getId());
    CompletableFuture<CreateChatThreadResult> completableFuture2 = this.client.getChatClient().createChatThreadAsync(threadRequest);
    assertNotNull(completableFuture2);
    CreateChatThreadResult result2 = completableFuture1.get();
    assertNotNull(result2);
    assertNotNull(result2.getChatThread());
    assertNotNull(result2.getChatThread().getId());
    CompletableFuture<PagedResponse<ChatThreadItem>> completableFuture = this.client.getChatClient().listChatThreadsSinglePageAsync(2, null);
    String nextLink;
    List<ChatThreadItem> returnedThreads = new ArrayList<ChatThreadItem>();
    do {
        PagedResponse<ChatThreadItem> response = completableFuture.get();
        assertNotNull(response);
        List<ChatThreadItem> threadsInPage = response.getValue();
        assertNotNull(threadsInPage);
        for (ChatThreadItem thread : threadsInPage) {
            returnedThreads.add(thread);
        }
        nextLink = response.getContinuationToken();
        if (nextLink != null) {
            completableFuture = this.client.getChatClient().listChatThreadsNextSinglePageAsync(nextLink);
        }
    } while (nextLink != null);
// REVISIT: Unreliable assertion
// assertTrue(returnedThreads.size() > 0);
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.implementation.models.CreateChatThreadResult) ChatThreadItem(com.azure.android.communication.chat.models.ChatThreadItem) ArrayList(java.util.ArrayList) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) CreateChatThreadOptions(com.azure.android.communication.chat.implementation.models.CreateChatThreadOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with PagedResponse

use of com.azure.android.core.rest.util.paging.PagedResponse in project azure-sdk-for-android by Azure.

the class ChatAsyncImplClientTest method canListChatThreads.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListChatThreads(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadMember.getId(), secondThreadMember.getId());
    CompletableFuture<CreateChatThreadResult> completableFuture1 = this.client.getChatClient().createChatThreadAsync(threadRequest);
    assertNotNull(completableFuture1);
    CreateChatThreadResult result1 = completableFuture1.get();
    assertNotNull(result1);
    assertNotNull(result1.getChatThread());
    assertNotNull(result1.getChatThread().getId());
    CompletableFuture<CreateChatThreadResult> completableFuture2 = this.client.getChatClient().createChatThreadAsync(threadRequest);
    assertNotNull(completableFuture2);
    CreateChatThreadResult result2 = completableFuture1.get();
    assertNotNull(result2);
    assertNotNull(result2.getChatThread());
    assertNotNull(result2.getChatThread().getId());
    CompletableFuture<PagedResponse<ChatThreadItem>> completableFuture = this.client.getChatClient().listChatThreadsSinglePageAsync(null, null);
    String nextLink;
    List<ChatThreadItem> returnedThreads = new ArrayList<ChatThreadItem>();
    do {
        PagedResponse<ChatThreadItem> response = completableFuture.get();
        assertNotNull(response);
        List<ChatThreadItem> threadsInPage = response.getValue();
        assertNotNull(threadsInPage);
        for (ChatThreadItem thread : threadsInPage) {
            returnedThreads.add(thread);
        }
        nextLink = response.getContinuationToken();
        if (nextLink != null) {
            completableFuture = this.client.getChatClient().listChatThreadsNextSinglePageAsync(nextLink);
        }
    } while (nextLink != null);
// REVISIT: Unreliable assertion
// assertTrue(returnedThreads.size() > 0);
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.implementation.models.CreateChatThreadResult) ChatThreadItem(com.azure.android.communication.chat.models.ChatThreadItem) ArrayList(java.util.ArrayList) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) CreateChatThreadOptions(com.azure.android.communication.chat.implementation.models.CreateChatThreadOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with PagedResponse

use of com.azure.android.core.rest.util.paging.PagedResponse in project azure-sdk-for-android by Azure.

the class HttpResponseMapper method extractContentAndHeaderDecodeType.

private Pair<Type, Type> extractContentAndHeaderDecodeType(Type callbackType, String swaggerMethodName) {
    final Type callbackTypeArgument = TypeUtil.getTypeArgument(callbackType);
    // Pair<Type:HeaderDecodeType, Type:ContentDecodeType>
    Pair<Type, Type> decodeTypes;
    decodeTypes = tryExtractContentAndHeaderDecodeType(callbackTypeArgument, ResponseBase.class, swaggerMethodName);
    if (decodeTypes != null) {
        return decodeTypes;
    }
    decodeTypes = tryExtractContentAndHeaderDecodeType(callbackTypeArgument, PagedResponseBase.class, swaggerMethodName);
    if (decodeTypes != null) {
        return decodeTypes;
    }
    Type decodeType;
    decodeType = tryExtractContentDecodeType(callbackTypeArgument, PagedResponse.class, swaggerMethodName);
    if (decodeType != null) {
        return Pair.create(null, decodeType);
    }
    decodeType = tryExtractContentDecodeType(callbackTypeArgument, Response.class, swaggerMethodName);
    if (decodeType != null) {
        return Pair.create(null, decodeType);
    }
    throw logger.logExceptionAsError(new IllegalStateException("The type argument of " + Callback.class.getName() + " in the method " + swaggerMethodName + " must either ResponseBase<H, C>, PagedResponseBase<H, C>, PagedResponse<C> or Response<C>"));
}
Also used : HttpResponse(com.azure.android.core.http.HttpResponse) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) UnexpectedResponseExceptionType(com.azure.android.core.rest.annotation.UnexpectedResponseExceptionType) ReturnValueWireType(com.azure.android.core.rest.annotation.ReturnValueWireType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) PagedResponseBase(com.azure.android.core.rest.util.paging.PagedResponseBase) PagedResponseBase(com.azure.android.core.rest.util.paging.PagedResponseBase) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse)

Aggregations

PagedResponse (com.azure.android.core.rest.util.paging.PagedResponse)5 ChatThreadItem (com.azure.android.communication.chat.models.ChatThreadItem)4 ArrayList (java.util.ArrayList)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 CreateChatThreadOptions (com.azure.android.communication.chat.implementation.models.CreateChatThreadOptions)2 CreateChatThreadResult (com.azure.android.communication.chat.implementation.models.CreateChatThreadResult)2 CreateChatThreadOptions (com.azure.android.communication.chat.models.CreateChatThreadOptions)2 CreateChatThreadResult (com.azure.android.communication.chat.models.CreateChatThreadResult)2 ListChatThreadsOptions (com.azure.android.communication.chat.models.ListChatThreadsOptions)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 HttpResponse (com.azure.android.core.http.HttpResponse)1 ReturnValueWireType (com.azure.android.core.rest.annotation.ReturnValueWireType)1 UnexpectedResponseExceptionType (com.azure.android.core.rest.annotation.UnexpectedResponseExceptionType)1 PagedResponseBase (com.azure.android.core.rest.util.paging.PagedResponseBase)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1