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

package com.azure.resourcemanager.vmwarecloudsimple.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.vmwarecloudsimple.VMwareCloudSimpleManager;
import com.azure.resourcemanager.vmwarecloudsimple.models.PrivateCloud;
import com.azure.resourcemanager.vmwarecloudsimple.models.PrivateCloudResourceType;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.util.UUID;
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 PrivateCloudsListMockTests {
    @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\":[{\"id\":\"n\",\"location\":\"xcpjuisavokqdzf\",\"name\":\"zivj\",\"properties\":{\"availabilityZoneId\":\"qttbaj\",\"availabilityZoneName\":\"atnwxyiopi\",\"clustersNumber\":1442492241,\"createdBy\":\"fku\",\"createdOn\":\"2021-02-24T16:53:48Z\",\"dnsServers\":[\"dmligovibrxk\",\"mloazuru\",\"cbgoor\"],\"expires\":\"eoybfhjxakvvjgs\",\"nsxType\":\"r\",\"placementGroupId\":\"lmywwtkgkxnyed\",\"placementGroupName\":\"gyvudtjuewbc\",\"privateCloudId\":\"23f531d0-c01a-437b-b46f-c61b5b733be9\",\"resourcePools\":[],\"state\":\"whcjyxcc\",\"totalCpuCores\":970870399,\"totalNodes\":436827826,\"totalRam\":1093154656,\"totalStorage\":54.286934,\"type\":\"dzpxgwjpl\",\"vSphereVersion\":\"gstcyohpf\",\"vcenterFqdn\":\"rkdbdgiogsjkmnwq\",\"vcenterRefid\":\"obaiyhddviaceg\",\"virtualMachineTemplates\":[],\"virtualNetworks\":[],\"vrOpsEnabled\":true},\"type\":\"Microsoft.VMwareCloudSimple/privateClouds\"}]}";

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

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

        PagedIterable<PrivateCloud> response = manager.privateClouds().list("x", com.azure.core.util.Context.NONE);

        Assertions.assertEquals("n", response.iterator().next().id());
        Assertions.assertEquals("xcpjuisavokqdzf", response.iterator().next().location());
        Assertions.assertEquals("zivj", response.iterator().next().name());
        Assertions
            .assertEquals(
                PrivateCloudResourceType.MICROSOFT_VMWARE_CLOUD_SIMPLE_PRIVATE_CLOUDS,
                response.iterator().next().type());
        Assertions.assertEquals("qttbaj", response.iterator().next().availabilityZoneId());
        Assertions.assertEquals("atnwxyiopi", response.iterator().next().availabilityZoneName());
        Assertions.assertEquals(1442492241, response.iterator().next().clustersNumber());
        Assertions.assertEquals("fku", response.iterator().next().createdBy());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-24T16:53:48Z"), response.iterator().next().createdOn());
        Assertions.assertEquals("dmligovibrxk", response.iterator().next().dnsServers().get(0));
        Assertions.assertEquals("eoybfhjxakvvjgs", response.iterator().next().expires());
        Assertions.assertEquals("r", response.iterator().next().nsxType());
        Assertions.assertEquals("lmywwtkgkxnyed", response.iterator().next().placementGroupId());
        Assertions.assertEquals("gyvudtjuewbc", response.iterator().next().placementGroupName());
        Assertions
            .assertEquals(
                UUID.fromString("23f531d0-c01a-437b-b46f-c61b5b733be9"), response.iterator().next().privateCloudId());
        Assertions.assertEquals("whcjyxcc", response.iterator().next().state());
        Assertions.assertEquals(970870399, response.iterator().next().totalCpuCores());
        Assertions.assertEquals(436827826, response.iterator().next().totalNodes());
        Assertions.assertEquals(1093154656, response.iterator().next().totalRam());
        Assertions.assertEquals(54.286934F, response.iterator().next().totalStorage());
        Assertions.assertEquals("dzpxgwjpl", response.iterator().next().typePropertiesType());
        Assertions.assertEquals("gstcyohpf", response.iterator().next().vSphereVersion());
        Assertions.assertEquals("rkdbdgiogsjkmnwq", response.iterator().next().vcenterFqdn());
        Assertions.assertEquals("obaiyhddviaceg", response.iterator().next().vcenterRefid());
        Assertions.assertEquals(true, response.iterator().next().vrOpsEnabled());
    }
}
