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

package com.azure.resourcemanager.batch.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.core.util.Context;
import com.azure.resourcemanager.batch.BatchManager;
import com.azure.resourcemanager.batch.models.ComputeNodeFillType;
import com.azure.resourcemanager.batch.models.DynamicVNetAssignmentScope;
import com.azure.resourcemanager.batch.models.InterNodeCommunicationState;
import com.azure.resourcemanager.batch.models.NodeCommunicationMode;
import com.azure.resourcemanager.batch.models.Pool;
import com.azure.resourcemanager.batch.models.PoolIdentityType;
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 PoolsDisableAutoScaleWithResponseMockTests {
    @Test
    public void testDisableAutoScaleWithResponse() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"displayName\":\"wmd\",\"lastModified\":\"2021-09-16T09:36:53Z\",\"creationTime\":\"2020-12-31T05:30:07Z\",\"provisioningState\":\"Succeeded\",\"provisioningStateTransitionTime\":\"2021-06-30T21:52:17Z\",\"allocationState\":\"Steady\",\"allocationStateTransitionTime\":\"2021-01-18T09:11:28Z\",\"vmSize\":\"pgpqchiszepnnb\",\"deploymentConfiguration\":{},\"currentDedicatedNodes\":1194186280,\"currentLowPriorityNodes\":2110316602,\"scaleSettings\":{},\"autoScaleRun\":{\"evaluationTime\":\"2021-11-29T17:23:44Z\",\"results\":\"fozauorsuk\"},\"interNodeCommunication\":\"Enabled\",\"networkConfiguration\":{\"subnetId\":\"lhlv\",\"dynamicVnetAssignmentScope\":\"none\"},\"taskSlotsPerNode\":647520979,\"taskSchedulingPolicy\":{\"nodeFillType\":\"Pack\"},\"userAccounts\":[],\"metadata\":[],\"startTask\":{\"commandLine\":\"dweyuqdunv\",\"resourceFiles\":[],\"environmentSettings\":[],\"maxTaskRetryCount\":1205325724,\"waitForSuccess\":false},\"certificates\":[],\"applicationPackages\":[],\"applicationLicenses\":[\"wjhhgdnhxmsivf\",\"miloxggdufiqndie\",\"zaofjchvcyy\"],\"resizeOperationStatus\":{\"targetDedicatedNodes\":1812829551,\"targetLowPriorityNodes\":1377717439,\"resizeTimeout\":\"PT123H17M23S\",\"nodeDeallocationOption\":\"Terminate\",\"startTime\":\"2021-10-22T10:52:16Z\",\"errors\":[]},\"mountConfiguration\":[],\"targetNodeCommunicationMode\":\"Classic\",\"currentNodeCommunicationMode\":\"Simplified\"},\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"etag\":\"jeknizshq\",\"id\":\"cimpevfg\",\"name\":\"b\",\"type\":\"rrilbywdxsmic\"}";

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

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

        Pool response =
            manager.pools().disableAutoScaleWithResponse("d", "utujba", "pjuohminyfl", Context.NONE).getValue();

        Assertions.assertEquals(PoolIdentityType.USER_ASSIGNED, response.identity().type());
        Assertions.assertEquals("wmd", response.displayName());
        Assertions.assertEquals("pgpqchiszepnnb", response.vmSize());
        Assertions.assertEquals(InterNodeCommunicationState.ENABLED, response.interNodeCommunication());
        Assertions.assertEquals("lhlv", response.networkConfiguration().subnetId());
        Assertions
            .assertEquals(
                DynamicVNetAssignmentScope.NONE, response.networkConfiguration().dynamicVnetAssignmentScope());
        Assertions.assertEquals(647520979, response.taskSlotsPerNode());
        Assertions.assertEquals(ComputeNodeFillType.PACK, response.taskSchedulingPolicy().nodeFillType());
        Assertions.assertEquals("dweyuqdunv", response.startTask().commandLine());
        Assertions.assertEquals(1205325724, response.startTask().maxTaskRetryCount());
        Assertions.assertEquals(false, response.startTask().waitForSuccess());
        Assertions.assertEquals("wjhhgdnhxmsivf", response.applicationLicenses().get(0));
        Assertions.assertEquals(NodeCommunicationMode.CLASSIC, response.targetNodeCommunicationMode());
    }
}
