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

package com.azure.resourcemanager.machinelearning.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.machinelearning.MachineLearningManager;
import com.azure.resourcemanager.machinelearning.models.ComputeResource;
import com.azure.resourcemanager.machinelearning.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.machinelearning.models.SkuTier;
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 ComputesGetWithResponseMockTests {
    @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 =
            "{\"identity\":{\"principalId\":\"1de443a3-f608-425f-91bd-438d47ec26d7\",\"tenantId\":\"e37f22c1-6b70-4a8c-8d5a-d0815df251d2\",\"type\":\"None\",\"userAssignedIdentities\":{}},\"location\":\"kgd\",\"tags\":{\"qsktxqf\":\"krukizyhgsqt\",\"cgbfzuscstun\":\"jbqggweeiwdhdm\",\"bkl\":\"lhxd\",\"f\":\"iichgjsysmvxodgw\"},\"sku\":{\"name\":\"sifcuvbdujgc\",\"tier\":\"Free\",\"size\":\"cbbwjtrdxriz\",\"family\":\"bbgiarksykpgdqxw\",\"capacity\":230334707},\"properties\":{\"computeType\":\"Compute\",\"computeLocation\":\"qrxhaclcdos\",\"provisioningState\":\"Creating\",\"description\":\"jqgkifmmainwhe\",\"createdOn\":\"2021-07-02T12:23:07Z\",\"modifiedOn\":\"2021-11-29T01:34:21Z\",\"resourceId\":\"wuntobuiz\",\"provisioningErrors\":[],\"isAttachedCompute\":false,\"disableLocalAuth\":true},\"id\":\"vydjufbnk\",\"name\":\"blaxpegj\",\"type\":\"dabalfdxaglzfytl\"}";

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

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

        ComputeResource response =
            manager
                .computes()
                .getWithResponse("xampqcr", "g", "uqxbpiatwfauje", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals(ManagedServiceIdentityType.NONE, response.identity().type());
        Assertions.assertEquals("kgd", response.location());
        Assertions.assertEquals("krukizyhgsqt", response.tags().get("qsktxqf"));
        Assertions.assertEquals("sifcuvbdujgc", response.sku().name());
        Assertions.assertEquals(SkuTier.FREE, response.sku().tier());
        Assertions.assertEquals("cbbwjtrdxriz", response.sku().size());
        Assertions.assertEquals("bbgiarksykpgdqxw", response.sku().family());
        Assertions.assertEquals(230334707, response.sku().capacity());
        Assertions.assertEquals("qrxhaclcdos", response.properties().computeLocation());
        Assertions.assertEquals("jqgkifmmainwhe", response.properties().description());
        Assertions.assertEquals("wuntobuiz", response.properties().resourceId());
        Assertions.assertEquals(true, response.properties().disableLocalAuth());
    }
}
