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

package com.azure.resourcemanager.devtestlabs.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.devtestlabs.DevTestLabsManager;
import com.azure.resourcemanager.devtestlabs.models.EnableStatus;
import com.azure.resourcemanager.devtestlabs.models.EnvironmentPermission;
import com.azure.resourcemanager.devtestlabs.models.Lab;
import com.azure.resourcemanager.devtestlabs.models.PremiumDataDisk;
import com.azure.resourcemanager.devtestlabs.models.StorageType;
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 LabsGetByResourceGroupWithResponseMockTests {
    @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\":{\"defaultStorageAccount\":\"uuybnchrsz\",\"defaultPremiumStorageAccount\":\"oyuelyetn\",\"artifactsStorageAccount\":\"bf\",\"premiumDataDiskStorageAccount\":\"ggagfln\",\"vaultName\":\"mtrwah\",\"labStorageType\":\"Premium\",\"mandatoryArtifactsResourceIdsLinux\":[\"ftbyrplro\",\"kpigqfusu\"],\"mandatoryArtifactsResourceIdsWindows\":[\"mkwkl\"],\"createdDate\":\"2021-04-09T11:30:43Z\",\"premiumDataDisks\":\"Disabled\",\"environmentPermission\":\"Reader\",\"announcement\":{\"title\":\"qalhhjnh\",\"markdown\":\"ydyynfsvkh\",\"enabled\":\"Disabled\",\"expirationDate\":\"2021-02-24T07:07:12Z\",\"expired\":true,\"provisioningState\":\"rfdl\",\"uniqueIdentifier\":\"kh\"},\"support\":{\"enabled\":\"Enabled\",\"markdown\":\"izjcpeog\"},\"vmCreationResourceGroup\":\"nmg\",\"publicIpId\":\"ouxddbhfhpfpazj\",\"loadBalancerId\":\"ywjxh\",\"networkSecurityGroupId\":\"ulontacnpqwteht\",\"extendedProperties\":{\"duugwbsre\":\"rhrljyoogwxhn\"},\"provisioningState\":\"fqkfuarenl\",\"uniqueIdentifier\":\"htkln\"},\"location\":\"nafvvkyfedev\",\"tags\":{\"inqcymczngnbdxxe\":\"slcqxypokkh\"},\"id\":\"unin\",\"name\":\"udbchaqdtv\",\"type\":\"ec\"}";

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

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

        Lab response =
            manager
                .labs()
                .getByResourceGroupWithResponse("fcsserxhtvsox", "lwntsjgqrs", "y", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("nafvvkyfedev", response.location());
        Assertions.assertEquals("slcqxypokkh", response.tags().get("inqcymczngnbdxxe"));
        Assertions.assertEquals(StorageType.PREMIUM, response.labStorageType());
        Assertions.assertEquals("ftbyrplro", response.mandatoryArtifactsResourceIdsLinux().get(0));
        Assertions.assertEquals("mkwkl", response.mandatoryArtifactsResourceIdsWindows().get(0));
        Assertions.assertEquals(PremiumDataDisk.DISABLED, response.premiumDataDisks());
        Assertions.assertEquals(EnvironmentPermission.READER, response.environmentPermission());
        Assertions.assertEquals("qalhhjnh", response.announcement().title());
        Assertions.assertEquals("ydyynfsvkh", response.announcement().markdown());
        Assertions.assertEquals(EnableStatus.DISABLED, response.announcement().enabled());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-24T07:07:12Z"), response.announcement().expirationDate());
        Assertions.assertEquals(true, response.announcement().expired());
        Assertions.assertEquals(EnableStatus.ENABLED, response.support().enabled());
        Assertions.assertEquals("izjcpeog", response.support().markdown());
        Assertions.assertEquals("rhrljyoogwxhn", response.extendedProperties().get("duugwbsre"));
    }
}
