// 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 ResourceProvidersGetOperationResultWithResponseMockTests {
    @Test
    public void testGetOperationResultWithResponse() 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\":\"judpfrxt\",\"tenantId\":\"hzv\",\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"provisioningState\":\"qbrqubpaxhexiili\",\"upgradeDetails\":{\"operationId\":\"tiirqtdqoa\",\"startTimeUtc\":\"2021-03-24T09:09:32Z\",\"lastUpdatedTimeUtc\":\"2021-10-06T16:31:40Z\",\"endTimeUtc\":\"2021-03-04T22:00:59Z\",\"status\":\"InProgress\",\"message\":\"yfxrx\",\"triggerType\":\"UserTriggered\",\"upgradedResourceId\":\"tramxjez\",\"previousResourceId\":\"wnwxuqlcvyd\"},\"privateEndpointConnections\":[],\"privateEndpointStateForBackup\":\"Enabled\",\"privateEndpointStateForSiteRecovery\":\"None\",\"encryption\":{\"infrastructureEncryption\":\"Disabled\"},\"moveDetails\":{\"operationId\":\"dkooebwnu\",\"startTimeUtc\":\"2021-05-07T18:52:45Z\",\"completionTimeUtc\":\"2021-05-06T02:47:02Z\",\"sourceResourceId\":\"bvdkcrodtjin\",\"targetResourceId\":\"jlfltkacjvefkdlf\"},\"moveState\":\"PrepareTimedout\",\"backupStorageVersion\":\"V2\",\"publicNetworkAccess\":\"Disabled\",\"monitoringSettings\":{},\"restoreSettings\":{},\"redundancySettings\":{\"standardTierStorageRedundancy\":\"ZoneRedundant\",\"crossRegionRestore\":\"Disabled\"},\"securitySettings\":{}},\"sku\":{\"name\":\"RS0\",\"tier\":\"s\",\"family\":\"k\",\"size\":\"nsj\",\"capacity\":\"vti\"},\"etag\":\"sdszue\",\"location\":\"psbzkfzbeyvpn\",\"tags\":{\"xdxr\":\"vinvkj\",\"aztz\":\"uukzclewyhmlw\",\"yq\":\"ofncckwyfzqwhxxb\",\"ztppriolxorjalto\":\"xzfe\"},\"id\":\"mncwsobqwcsdb\",\"name\":\"wdcfhucqdpfuv\",\"type\":\"lsbjjcanvxbv\"}";

        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
                .resourceProviders()
                .getOperationResultWithResponse(
                    "rzrtuzqogsex", "evfdnwnwm", "wzsyyceuzs", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("psbzkfzbeyvpn", response.location());
        Assertions.assertEquals("vinvkj", response.tags().get("xdxr"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, response.identity().type());
        Assertions
            .assertEquals(
                InfrastructureEncryptionState.DISABLED, response.properties().encryption().infrastructureEncryption());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, response.properties().publicNetworkAccess());
        Assertions.assertEquals(SkuName.RS0, response.sku().name());
        Assertions.assertEquals("s", response.sku().tier());
        Assertions.assertEquals("k", response.sku().family());
        Assertions.assertEquals("nsj", response.sku().size());
        Assertions.assertEquals("vti", response.sku().capacity());
        Assertions.assertEquals("sdszue", response.etag());
    }
}
