use of com.azure.android.communication.chat.models.ListChatThreadsOptions 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);
}
use of com.azure.android.communication.chat.models.ListChatThreadsOptions 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);
}
Aggregations