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

package com.azure.resourcemanager.hybridcontainerservice.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.hybridcontainerservice.HybridContainerServiceManager;
import com.azure.resourcemanager.hybridcontainerservice.models.LicenseType;
import com.azure.resourcemanager.hybridcontainerservice.models.LoadBalancerSku;
import com.azure.resourcemanager.hybridcontainerservice.models.Mode;
import com.azure.resourcemanager.hybridcontainerservice.models.NetworkPolicy;
import com.azure.resourcemanager.hybridcontainerservice.models.OsType;
import com.azure.resourcemanager.hybridcontainerservice.models.ProvisionedClustersResponse;
import com.azure.resourcemanager.hybridcontainerservice.models.ResourceIdentityType;
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 ProvisionedClustersOperationsListMockTests {
    @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\":[{\"identity\":{\"principalId\":\"lcrpw\",\"tenantId\":\"eznoig\",\"type\":\"None\"},\"properties\":{\"enableRbac\":false,\"linuxProfile\":{\"adminUsername\":\"kpnb\"},\"features\":{},\"addonProfiles\":{},\"controlPlane\":{\"name\":\"gfhsxttaugzxn\",\"count\":1764275997,\"availabilityZones\":[],\"maxCount\":1339153822,\"maxPods\":2134025822,\"minCount\":1884087819,\"mode\":\"LB\",\"nodeLabels\":{},\"nodeTaints\":[],\"osType\":\"Windows\",\"nodeImageVersion\":\"wuenvr\",\"vmSize\":\"yo\"},\"kubernetesVersion\":\"bre\",\"networkProfile\":{\"loadBalancerSku\":\"unmanaged\",\"dnsServiceIP\":\"j\",\"networkPolicy\":\"calico\",\"podCidr\":\"tnqttezlwfffiak\",\"podCidrs\":[],\"serviceCidr\":\"qqmtedltmmji\",\"serviceCidrs\":[]},\"nodeResourceGroup\":\"ozphvwauyqncygu\",\"agentPoolProfiles\":[],\"cloudProviderProfile\":{},\"provisioningState\":\"Failed\",\"status\":{\"addonStatus\":{},\"errorMessage\":\"upev\"},\"aadProfile\":{\"adminGroupObjectIDs\":[],\"clientAppID\":\"otxhojujby\",\"enableAzureRbac\":true,\"managed\":false,\"serverAppID\":\"vhixbjxy\",\"tenantID\":\"n\"},\"windowsProfile\":{\"adminUsername\":\"coolsttpkiwkkb\",\"enableCsiProxy\":true,\"licenseType\":\"None\"},\"httpProxyConfig\":{\"httpProxy\":\"tylbfpncurdoiw\",\"httpsProxy\":\"thtywub\",\"noProxy\":[],\"trustedCa\":\"ihwqknfdntwjchr\",\"username\":\"oihxumwctondzjlu\"}},\"extendedLocation\":{\"type\":\"lwg\",\"name\":\"tsbwtovvtgse\"},\"location\":\"nqfiufxqknpi\",\"tags\":{\"dmqnrojlpij\":\"epttwqmsniff\",\"xfrdd\":\"k\",\"atiz\":\"c\"},\"id\":\"ronasxift\",\"name\":\"zq\",\"type\":\"zh\"}]}";

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

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

        PagedIterable<ProvisionedClustersResponse> response =
            manager.provisionedClustersOperations().list(com.azure.core.util.Context.NONE);

        Assertions.assertEquals("nqfiufxqknpi", response.iterator().next().location());
        Assertions.assertEquals("epttwqmsniff", response.iterator().next().tags().get("dmqnrojlpij"));
        Assertions.assertEquals(ResourceIdentityType.NONE, response.iterator().next().identity().type());
        Assertions.assertEquals("otxhojujby", response.iterator().next().properties().aadProfile().clientAppId());
        Assertions.assertEquals(true, response.iterator().next().properties().aadProfile().enableAzureRbac());
        Assertions.assertEquals(false, response.iterator().next().properties().aadProfile().managed());
        Assertions.assertEquals("vhixbjxy", response.iterator().next().properties().aadProfile().serverAppId());
        Assertions.assertEquals("n", response.iterator().next().properties().aadProfile().tenantId());
        Assertions
            .assertEquals("coolsttpkiwkkb", response.iterator().next().properties().windowsProfile().adminUsername());
        Assertions.assertEquals(true, response.iterator().next().properties().windowsProfile().enableCsiProxy());
        Assertions
            .assertEquals(LicenseType.NONE, response.iterator().next().properties().windowsProfile().licenseType());
        Assertions
            .assertEquals("tylbfpncurdoiw", response.iterator().next().properties().httpProxyConfig().httpProxy());
        Assertions.assertEquals("thtywub", response.iterator().next().properties().httpProxyConfig().httpsProxy());
        Assertions
            .assertEquals("ihwqknfdntwjchr", response.iterator().next().properties().httpProxyConfig().trustedCa());
        Assertions
            .assertEquals("oihxumwctondzjlu", response.iterator().next().properties().httpProxyConfig().username());
        Assertions.assertEquals(false, response.iterator().next().properties().enableRbac());
        Assertions.assertEquals("kpnb", response.iterator().next().properties().linuxProfile().adminUsername());
        Assertions.assertEquals(1764275997, response.iterator().next().properties().controlPlane().count());
        Assertions.assertEquals(1339153822, response.iterator().next().properties().controlPlane().maxCount());
        Assertions.assertEquals(2134025822, response.iterator().next().properties().controlPlane().maxPods());
        Assertions.assertEquals(1884087819, response.iterator().next().properties().controlPlane().minCount());
        Assertions.assertEquals(Mode.LB, response.iterator().next().properties().controlPlane().mode());
        Assertions.assertEquals(OsType.WINDOWS, response.iterator().next().properties().controlPlane().osType());
        Assertions.assertEquals("wuenvr", response.iterator().next().properties().controlPlane().nodeImageVersion());
        Assertions.assertEquals("yo", response.iterator().next().properties().controlPlane().vmSize());
        Assertions.assertEquals("gfhsxttaugzxn", response.iterator().next().properties().controlPlane().name());
        Assertions.assertEquals("bre", response.iterator().next().properties().kubernetesVersion());
        Assertions
            .assertEquals(
                LoadBalancerSku.UNMANAGED, response.iterator().next().properties().networkProfile().loadBalancerSku());
        Assertions.assertEquals("j", response.iterator().next().properties().networkProfile().dnsServiceIp());
        Assertions
            .assertEquals(
                NetworkPolicy.CALICO, response.iterator().next().properties().networkProfile().networkPolicy());
        Assertions.assertEquals("tnqttezlwfffiak", response.iterator().next().properties().networkProfile().podCidr());
        Assertions.assertEquals("qqmtedltmmji", response.iterator().next().properties().networkProfile().serviceCidr());
        Assertions.assertEquals("ozphvwauyqncygu", response.iterator().next().properties().nodeResourceGroup());
        Assertions.assertEquals("lwg", response.iterator().next().extendedLocation().type());
        Assertions.assertEquals("tsbwtovvtgse", response.iterator().next().extendedLocation().name());
    }
}
