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

package com.azure.resourcemanager.databricks.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.databricks.AzureDatabricksManager;
import com.azure.resourcemanager.databricks.models.PublicNetworkAccess;
import com.azure.resourcemanager.databricks.models.RequiredNsgRules;
import com.azure.resourcemanager.databricks.models.Workspace;
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 WorkspacesGetByResourceGroupWithResponseMockTests {
    @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\":{\"managedResourceGroupId\":\"slpvlop\",\"parameters\":{},\"provisioningState\":\"Ready\",\"uiDefinitionUri\":\"m\",\"authorizations\":[],\"createdBy\":{\"oid\":\"c37ec0eb-5fcf-45a4-ae1d-fe0e71eec7a9\",\"puid\":\"deoj\",\"applicationId\":\"1304327b-8166-4cf0-a689-3ad13822d27c\"},\"updatedBy\":{\"oid\":\"9d632ff5-c609-4ec0-a601-86a6a47e6d2f\",\"puid\":\"hsmtxpsiebtfhvp\",\"applicationId\":\"0e9e2939-6907-4cb0-9d80-519cb831ba5e\"},\"createdDateTime\":\"2021-07-15T16:58:50Z\",\"workspaceId\":\"krdqmh\",\"workspaceUrl\":\"dhtldwkyz\",\"storageAccountIdentity\":{\"principalId\":\"3e4d5959-ec1f-4f19-ac22-b9f0108364d0\",\"tenantId\":\"7e91680d-0316-4e3c-84d7-b6679dde3de0\",\"type\":\"ncwscwsvlxoto\"},\"managedDiskIdentity\":{\"principalId\":\"e6a9e1e2-8d99-4b7a-8344-9910599bb1d7\",\"tenantId\":\"a8465cfc-3de9-4500-9de2-2166608ffc79\",\"type\":\"pqsxvnmicy\"},\"diskEncryptionSetId\":\"ceoveilovno\",\"encryption\":{},\"privateEndpointConnections\":[],\"publicNetworkAccess\":\"Disabled\",\"requiredNsgRules\":\"AllRules\"},\"sku\":{\"name\":\"k\",\"tier\":\"x\"},\"location\":\"bttk\",\"tags\":{\"jtoqne\":\"wpn\",\"abgy\":\"mclfplphoxuscr\"},\"id\":\"psbjta\",\"name\":\"qugxywpmueefjzwf\",\"type\":\"kqujidsuyono\"}";

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

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

        Workspace response =
            manager
                .workspaces()
                .getByResourceGroupWithResponse("plgmgsxnk", "zkd", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("bttk", response.location());
        Assertions.assertEquals("wpn", response.tags().get("jtoqne"));
        Assertions.assertEquals("k", response.sku().name());
        Assertions.assertEquals("x", response.sku().tier());
        Assertions.assertEquals("slpvlop", response.managedResourceGroupId());
        Assertions.assertEquals("m", response.uiDefinitionUri());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, response.publicNetworkAccess());
        Assertions.assertEquals(RequiredNsgRules.ALL_RULES, response.requiredNsgRules());
    }
}
