// 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.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 PrivateCloudsGetWithResponseMockTests {
    @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 =
            "{\"id\":\"ukuv\",\"location\":\"cswsmystul\",\"name\":\"ypfcvlerchpqbmf\",\"properties\":{\"availabilityZoneId\":\"abwidfcxsspuun\",\"availabilityZoneName\":\"xyh\",\"clustersNumber\":14245290,\"createdBy\":\"ddrihpf\",\"createdOn\":\"2021-09-06T08:29:10Z\",\"dnsServers\":[\"a\",\"wdaomdjvlpjxxkzb\",\"msgeivsiykzk\"],\"expires\":\"cjdx\",\"nsxType\":\"bzo\",\"placementGroupId\":\"culapzwyrpgogtq\",\"placementGroupName\":\"pnylb\",\"privateCloudId\":\"41ad4685-a085-4e9c-8612-f189ccb00afe\",\"resourcePools\":[],\"state\":\"yjt\",\"totalCpuCores\":279762954,\"totalNodes\":839049702,\"totalRam\":746925062,\"totalStorage\":82.7803,\"type\":\"ibyfmo\",\"vSphereVersion\":\"xrkjpvdw\",\"vcenterFqdn\":\"zwiivwzjbhyzs\",\"vcenterRefid\":\"rkambt\",\"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));

        PrivateCloud response =
            manager
                .privateClouds()
                .getWithResponse("memfnczdwvvbalxl", "lchpodbzevwrdn", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("ukuv", response.id());
        Assertions.assertEquals("cswsmystul", response.location());
        Assertions.assertEquals("ypfcvlerchpqbmf", response.name());
        Assertions.assertEquals(PrivateCloudResourceType.MICROSOFT_VMWARE_CLOUD_SIMPLE_PRIVATE_CLOUDS, response.type());
        Assertions.assertEquals("abwidfcxsspuun", response.availabilityZoneId());
        Assertions.assertEquals("xyh", response.availabilityZoneName());
        Assertions.assertEquals(14245290, response.clustersNumber());
        Assertions.assertEquals("ddrihpf", response.createdBy());
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-06T08:29:10Z"), response.createdOn());
        Assertions.assertEquals("a", response.dnsServers().get(0));
        Assertions.assertEquals("cjdx", response.expires());
        Assertions.assertEquals("bzo", response.nsxType());
        Assertions.assertEquals("culapzwyrpgogtq", response.placementGroupId());
        Assertions.assertEquals("pnylb", response.placementGroupName());
        Assertions.assertEquals(UUID.fromString("41ad4685-a085-4e9c-8612-f189ccb00afe"), response.privateCloudId());
        Assertions.assertEquals("yjt", response.state());
        Assertions.assertEquals(279762954, response.totalCpuCores());
        Assertions.assertEquals(839049702, response.totalNodes());
        Assertions.assertEquals(746925062, response.totalRam());
        Assertions.assertEquals(82.7803F, response.totalStorage());
        Assertions.assertEquals("ibyfmo", response.typePropertiesType());
        Assertions.assertEquals("xrkjpvdw", response.vSphereVersion());
        Assertions.assertEquals("zwiivwzjbhyzs", response.vcenterFqdn());
        Assertions.assertEquals("rkambt", response.vcenterRefid());
        Assertions.assertEquals(true, response.vrOpsEnabled());
    }
}
