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

package com.azure.resourcemanager.recoveryservices.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.recoveryservices.RecoveryServicesManager;
import com.azure.resourcemanager.recoveryservices.models.InfrastructureEncryptionState;
import com.azure.resourcemanager.recoveryservices.models.PublicNetworkAccess;
import com.azure.resourcemanager.recoveryservices.models.ResourceIdentityType;
import com.azure.resourcemanager.recoveryservices.models.SkuName;
import com.azure.resourcemanager.recoveryservices.models.Vault;
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 VaultsGetByResourceGroupWithResponseMockTests {
    @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 =
            "{\"identity\":{\"principalId\":\"bmnzbtbhjpgl\",\"tenantId\":\"gohdneuelfphsd\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"provisioningState\":\"ikdowwquuvx\",\"upgradeDetails\":{\"operationId\":\"lvithhqzonosgg\",\"startTimeUtc\":\"2021-07-06T22:10:43Z\",\"lastUpdatedTimeUtc\":\"2021-02-03T18:39:52Z\",\"endTimeUtc\":\"2021-09-10T06:03:01Z\",\"status\":\"InProgress\",\"message\":\"n\",\"triggerType\":\"UserTriggered\",\"upgradedResourceId\":\"utiiswacf\",\"previousResourceId\":\"dkzzewkfvhqcrail\"},\"privateEndpointConnections\":[],\"privateEndpointStateForBackup\":\"None\",\"privateEndpointStateForSiteRecovery\":\"None\",\"encryption\":{\"infrastructureEncryption\":\"Disabled\"},\"moveDetails\":{\"operationId\":\"dlxyjrxs\",\"startTimeUtc\":\"2021-10-27T14:22:38Z\",\"completionTimeUtc\":\"2020-12-27T20:37:24Z\",\"sourceResourceId\":\"hgw\",\"targetResourceId\":\"pnedgf\"},\"moveState\":\"Unknown\",\"backupStorageVersion\":\"V1\",\"publicNetworkAccess\":\"Enabled\",\"monitoringSettings\":{},\"restoreSettings\":{},\"redundancySettings\":{\"standardTierStorageRedundancy\":\"LocallyRedundant\",\"crossRegionRestore\":\"Enabled\"},\"securitySettings\":{}},\"sku\":{\"name\":\"RS0\",\"tier\":\"sotbob\",\"family\":\"opcjwvnhd\",\"size\":\"wmgxcxrsl\",\"capacity\":\"utwu\"},\"etag\":\"rpkhjwn\",\"location\":\"yqsluic\",\"tags\":{\"zl\":\"gk\",\"sbpfvmwyhr\":\"mbmpaxmodfvuefy\",\"wiyzvqtmnubexkp\":\"ouyftaakc\"},\"id\":\"ksmond\",\"name\":\"mquxvypo\",\"type\":\"gkopkwhojvpajqgx\"}";

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

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

        Vault response =
            manager
                .vaults()
                .getByResourceGroupWithResponse("pbttdum", "rp", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("yqsluic", response.location());
        Assertions.assertEquals("gk", response.tags().get("zl"));
        Assertions.assertEquals(ResourceIdentityType.USER_ASSIGNED, response.identity().type());
        Assertions
            .assertEquals(
                InfrastructureEncryptionState.DISABLED, response.properties().encryption().infrastructureEncryption());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, response.properties().publicNetworkAccess());
        Assertions.assertEquals(SkuName.RS0, response.sku().name());
        Assertions.assertEquals("sotbob", response.sku().tier());
        Assertions.assertEquals("opcjwvnhd", response.sku().family());
        Assertions.assertEquals("wmgxcxrsl", response.sku().size());
        Assertions.assertEquals("utwu", response.sku().capacity());
        Assertions.assertEquals("rpkhjwn", response.etag());
    }
}
