// 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 PoolsGetWithResponseMockTests {
    @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 =
            "{\"properties\":{\"displayName\":\"jb\",\"lastModified\":\"2021-03-17T22:00:43Z\",\"creationTime\":\"2021-04-28T23:02:30Z\",\"provisioningState\":\"Succeeded\",\"provisioningStateTransitionTime\":\"2021-07-07T02:32:57Z\",\"allocationState\":\"Resizing\",\"allocationStateTransitionTime\":\"2021-06-03T05:33:27Z\",\"vmSize\":\"fa\",\"deploymentConfiguration\":{},\"currentDedicatedNodes\":141630952,\"currentLowPriorityNodes\":764858532,\"scaleSettings\":{},\"autoScaleRun\":{\"evaluationTime\":\"2021-06-21T23:29Z\",\"results\":\"yjkqabqgzslesjcb\"},\"interNodeCommunication\":\"Enabled\",\"networkConfiguration\":{\"subnetId\":\"iew\",\"dynamicVnetAssignmentScope\":\"none\"},\"taskSlotsPerNode\":730948461,\"taskSchedulingPolicy\":{\"nodeFillType\":\"Spread\"},\"userAccounts\":[],\"metadata\":[],\"startTask\":{\"commandLine\":\"o\",\"resourceFiles\":[],\"environmentSettings\":[],\"maxTaskRetryCount\":569382071,\"waitForSuccess\":true},\"certificates\":[],\"applicationPackages\":[],\"applicationLicenses\":[\"xtdr\"],\"resizeOperationStatus\":{\"targetDedicatedNodes\":647279453,\"targetLowPriorityNodes\":730644177,\"resizeTimeout\":\"PT238H13M32S\",\"nodeDeallocationOption\":\"RetainedData\",\"startTime\":\"2021-06-12T20:57:35Z\",\"errors\":[]},\"mountConfiguration\":[],\"targetNodeCommunicationMode\":\"Default\",\"currentNodeCommunicationMode\":\"Classic\"},\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{}},\"etag\":\"uaadraufactkahzo\",\"id\":\"ajjziuxxpshne\",\"name\":\"kulfg\",\"type\":\"lqubkwdlen\"}";

        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().getWithResponse("skh", "dyg", "ookk", Context.NONE).getValue();

        Assertions.assertEquals(PoolIdentityType.NONE, response.identity().type());
        Assertions.assertEquals("jb", response.displayName());
        Assertions.assertEquals("fa", response.vmSize());
        Assertions.assertEquals(InterNodeCommunicationState.ENABLED, response.interNodeCommunication());
        Assertions.assertEquals("iew", response.networkConfiguration().subnetId());
        Assertions
            .assertEquals(
                DynamicVNetAssignmentScope.NONE, response.networkConfiguration().dynamicVnetAssignmentScope());
        Assertions.assertEquals(730948461, response.taskSlotsPerNode());
        Assertions.assertEquals(ComputeNodeFillType.SPREAD, response.taskSchedulingPolicy().nodeFillType());
        Assertions.assertEquals("o", response.startTask().commandLine());
        Assertions.assertEquals(569382071, response.startTask().maxTaskRetryCount());
        Assertions.assertEquals(true, response.startTask().waitForSuccess());
        Assertions.assertEquals("xtdr", response.applicationLicenses().get(0));
        Assertions.assertEquals(NodeCommunicationMode.DEFAULT, response.targetNodeCommunicationMode());
    }
}
