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

package com.azure.resourcemanager.synapse.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.synapse.SynapseManager;
import com.azure.resourcemanager.synapse.models.DataMaskingFunction;
import com.azure.resourcemanager.synapse.models.DataMaskingRule;
import com.azure.resourcemanager.synapse.models.DataMaskingRuleState;
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 DataMaskingRulesCreateOrUpdateWithResponseMockTests {
    @Test
    public void testCreateOrUpdateWithResponse() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"id\":\"wly\",\"aliasName\":\"chpqvctsfaeuhww\",\"ruleState\":\"Enabled\",\"schemaName\":\"stvzuzhasupml\",\"tableName\":\"pdpg\",\"columnName\":\"vzqazvbkarkptg\",\"maskingFunction\":\"SSN\",\"numberFrom\":\"ruatsyiysjqhen\",\"numberTo\":\"beqngubabyjde\",\"prefixSize\":\"sc\",\"suffixSize\":\"ydzjemexm\",\"replacementString\":\"kvmuwrxlniwmcp\"},\"location\":\"rdlhvdvmiphbe\",\"kind\":\"qjzmhkdcl\",\"id\":\"croczf\",\"name\":\"unerke\",\"type\":\"uxzshxz\"}";

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

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

        DataMaskingRule response =
            manager
                .dataMaskingRules()
                .define("aczmuh")
                .withExistingSqlPool("abtvkbi", "znhtf", "ficudyhiz")
                .withAliasName("mmazdnckid")
                .withRuleState(DataMaskingRuleState.DISABLED)
                .withSchemaName("glhzqp")
                .withTableName("zbawkikcdgfh")
                .withColumnName("ssdpjeyoqxded")
                .withMaskingFunction(DataMaskingFunction.EMAIL)
                .withNumberFrom("iwhagxsur")
                .withNumberTo("qrshzzbgullcxiq")
                .withPrefixSize("jkoxdupna")
                .withSuffixSize("lrouigdmfiv")
                .withReplacementString("terdqqi")
                .create();

        Assertions.assertEquals("chpqvctsfaeuhww", response.aliasName());
        Assertions.assertEquals(DataMaskingRuleState.ENABLED, response.ruleState());
        Assertions.assertEquals("stvzuzhasupml", response.schemaName());
        Assertions.assertEquals("pdpg", response.tableName());
        Assertions.assertEquals("vzqazvbkarkptg", response.columnName());
        Assertions.assertEquals(DataMaskingFunction.SSN, response.maskingFunction());
        Assertions.assertEquals("ruatsyiysjqhen", response.numberFrom());
        Assertions.assertEquals("beqngubabyjde", response.numberTo());
        Assertions.assertEquals("sc", response.prefixSize());
        Assertions.assertEquals("ydzjemexm", response.suffixSize());
        Assertions.assertEquals("kvmuwrxlniwmcp", response.replacementString());
    }
}
