// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.mediaservices.generated;

import com.azure.core.credential.AccessToken;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.mediaservices.MediaServicesManager;
import com.azure.resourcemanager.mediaservices.models.StreamingEndpoint;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public final class StreamingEndpointsListMockTests {
    @Test
    public void testList() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"value\":[{\"properties\":{\"description\":\"lwywae\",\"scaleUnits\":665085676,\"availabilitySetName\":\"gfbukklelss\",\"accessControl\":{},\"maxCacheAge\":2996960351334140021,\"customHostNames\":[\"jks\",\"lsmdesqplpvmjc\",\"oewbid\",\"vteo\"],\"hostName\":\"vgp\",\"cdnEnabled\":false,\"cdnProvider\":\"ugfsxzecpaxwk\",\"cdnProfile\":\"ykhv\",\"provisioningState\":\"xepmrut\",\"resourceState\":\"Scaling\",\"crossSiteAccessPolicies\":{\"clientAccessPolicy\":\"obns\",\"crossDomainPolicy\":\"jdjltymkmvgui\"},\"freeTrialEndTime\":\"2021-11-13T17:45:06Z\",\"created\":\"2021-04-21T11:58:54Z\",\"lastModified\":\"2021-05-15T17:05:47Z\"},\"sku\":{\"name\":\"kixkykxdssjpemm\",\"capacity\":1510283924},\"location\":\"xhikkflrmymyin\",\"tags\":{\"s\":\"hr\",\"iiiovgqcgxuugq\":\"sl\"},\"id\":\"ctotiowlx\",\"name\":\"e\",\"type\":\"dptjgwdtgukranb\"}]}";

        Mockito.when(httpResponse.getStatusCode()).thenReturn(200);
        Mockito.when(httpResponse.getHeaders()).thenReturn(new HttpHeaders());
        Mockito
            .when(httpResponse.getBody())
            .thenReturn(Flux.just(ByteBuffer.wrap(responseStr.getBytes(StandardCharsets.UTF_8))));
        Mockito
            .when(httpResponse.getBodyAsByteArray())
            .thenReturn(Mono.just(responseStr.getBytes(StandardCharsets.UTF_8)));
        Mockito
            .when(httpClient.send(httpRequest.capture(), Mockito.any()))
            .thenReturn(
                Mono
                    .defer(
                        () -> {
                            Mockito.when(httpResponse.getRequest()).thenReturn(httpRequest.getValue());
                            return Mono.just(httpResponse);
                        }));

        MediaServicesManager manager =
            MediaServicesManager
                .configure()
                .withHttpClient(httpClient)
                .authenticate(
                    tokenRequestContext -> Mono.just(new AccessToken("this_is_a_token", OffsetDateTime.MAX)),
                    new AzureProfile("", "", AzureEnvironment.AZURE));

        PagedIterable<StreamingEndpoint> response =
            manager.streamingEndpoints().list("roznnhdrlktgj", "sggux", com.azure.core.util.Context.NONE);

        Assertions.assertEquals("xhikkflrmymyin", response.iterator().next().location());
        Assertions.assertEquals("hr", response.iterator().next().tags().get("s"));
        Assertions.assertEquals(1510283924, response.iterator().next().sku().capacity());
        Assertions.assertEquals("lwywae", response.iterator().next().description());
        Assertions.assertEquals(665085676, response.iterator().next().scaleUnits());
        Assertions.assertEquals("gfbukklelss", response.iterator().next().availabilitySetName());
        Assertions.assertEquals(2996960351334140021L, response.iterator().next().maxCacheAge());
        Assertions.assertEquals("jks", response.iterator().next().customHostNames().get(0));
        Assertions.assertEquals(false, response.iterator().next().cdnEnabled());
        Assertions.assertEquals("ugfsxzecpaxwk", response.iterator().next().cdnProvider());
        Assertions.assertEquals("ykhv", response.iterator().next().cdnProfile());
        Assertions.assertEquals("obns", response.iterator().next().crossSiteAccessPolicies().clientAccessPolicy());
        Assertions
            .assertEquals("jdjltymkmvgui", response.iterator().next().crossSiteAccessPolicies().crossDomainPolicy());
    }
}
