// 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.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 StreamingEndpointsGetWithResponseMockTests {
    @Test
    public void testGetWithResponse() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"description\":\"ufypiv\",\"scaleUnits\":1886525962,\"availabilitySetName\":\"bjpmcubk\",\"accessControl\":{},\"maxCacheAge\":9135623978527949819,\"customHostNames\":[\"v\",\"havpmhbrbqgvg\"],\"hostName\":\"pbbttefjoknss\",\"cdnEnabled\":true,\"cdnProvider\":\"edikdfrdbiq\",\"cdnProfile\":\"jgeihfqlggwfi\",\"provisioningState\":\"cxmjpbyephmg\",\"resourceState\":\"Stopping\",\"crossSiteAccessPolicies\":{\"clientAccessPolicy\":\"rc\",\"crossDomainPolicy\":\"fqip\"},\"freeTrialEndTime\":\"2020-12-22T02:20:11Z\",\"created\":\"2021-09-18T18:40:03Z\",\"lastModified\":\"2021-04-01T06:59Z\"},\"sku\":{\"name\":\"cabvnuil\",\"capacity\":637099772},\"location\":\"aswlp\",\"tags\":{\"xwtoaukhfkvc\":\"mrmfjl\"},\"id\":\"sizmoae\",\"name\":\"sx\",\"type\":\"wuived\"}";

        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));

        StreamingEndpoint response =
            manager
                .streamingEndpoints()
                .getWithResponse("wphqlkccuzgygqw", "hoi", "lwgniiprglvawu", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("aswlp", response.location());
        Assertions.assertEquals("mrmfjl", response.tags().get("xwtoaukhfkvc"));
        Assertions.assertEquals(637099772, response.sku().capacity());
        Assertions.assertEquals("ufypiv", response.description());
        Assertions.assertEquals(1886525962, response.scaleUnits());
        Assertions.assertEquals("bjpmcubk", response.availabilitySetName());
        Assertions.assertEquals(9135623978527949819L, response.maxCacheAge());
        Assertions.assertEquals("v", response.customHostNames().get(0));
        Assertions.assertEquals(true, response.cdnEnabled());
        Assertions.assertEquals("edikdfrdbiq", response.cdnProvider());
        Assertions.assertEquals("jgeihfqlggwfi", response.cdnProfile());
        Assertions.assertEquals("rc", response.crossSiteAccessPolicies().clientAccessPolicy());
        Assertions.assertEquals("fqip", response.crossSiteAccessPolicies().crossDomainPolicy());
    }
}
