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

package com.azure.resourcemanager.datalakeanalytics.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.datalakeanalytics.DataLakeAnalyticsManager;
import com.azure.resourcemanager.datalakeanalytics.models.DataLakeAnalyticsAccount;
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 AccountsGetByResourceGroupWithResponseMockTests {
    @Test
    public void testGetByResourceGroupWithResponse() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"defaultDataLakeStoreAccount\":\"zx\",\"dataLakeStoreAccounts\":[],\"publicDataLakeStoreAccounts\":[],\"storageAccounts\":[],\"computePolicies\":[],\"hiveMetastores\":[],\"virtualNetworkRules\":[],\"firewallRules\":[],\"firewallState\":\"Disabled\",\"firewallAllowAzureIps\":\"Enabled\",\"newTier\":\"Commitment_100AUHours\",\"currentTier\":\"Commitment_100000AUHours\",\"maxJobCount\":1946798268,\"maxActiveJobCountPerUser\":459931810,\"maxQueuedJobCountPerUser\":1077119628,\"maxJobRunningTimeInMin\":215049895,\"systemMaxJobCount\":1496719551,\"maxDegreeOfParallelism\":600848345,\"systemMaxDegreeOfParallelism\":1914741160,\"maxDegreeOfParallelismPerJob\":1589992877,\"minPriorityPerJob\":916120827,\"queryStoreRetention\":264036091,\"debugDataAccessLevel\":\"None\",\"accountId\":\"d1d504bf-59b3-4096-8d99-595b602df83e\",\"provisioningState\":\"Succeeded\",\"state\":\"Active\",\"creationTime\":\"2021-08-19T00:26:37Z\",\"lastModifiedTime\":\"2021-02-06T21:00:48Z\",\"endpoint\":\"ilvpnppfuflrwd\"},\"location\":\"hdlxyjrxsagafcn\",\"tags\":{\"vq\":\"wqapnedgfbcvk\"},\"id\":\"pkeqdcvdrhvoo\",\"name\":\"sotbob\",\"type\":\"dopcjwvnh\"}";

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

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

        DataLakeAnalyticsAccount response =
            manager
                .accounts()
                .getByResourceGroupWithResponse("phsdyhto", "fikdowwqu", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("hdlxyjrxsagafcn", response.location());
        Assertions.assertEquals("wqapnedgfbcvk", response.tags().get("vq"));
    }
}
