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

package com.azure.resourcemanager.security.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.security.SecurityManager;
import com.azure.resourcemanager.security.models.RuleSeverity;
import com.azure.resourcemanager.security.models.RuleStatus;
import com.azure.resourcemanager.security.models.RuleType;
import com.azure.resourcemanager.security.models.ScanResult;
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 SqlVulnerabilityAssessmentScanResultsGetWithResponseMockTests {
    @Test
    public void testGetWithResponse() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"ruleId\":\"scle\",\"status\":\"InternalError\",\"isTrimmed\":true,\"queryResults\":[[\"qlmfdg\",\"n\",\"buypwovvv\"],[\"leev\",\"oqayrehjuqwv\"],[\"xrlzhpziha\"],[\"nqqz\",\"xnq\",\"ubfonfdbgmkf\"]],\"remediation\":{\"description\":\"cwtewfhxwyrkb\",\"scripts\":[],\"automated\":false,\"portalLink\":\"rynjpc\"},\"baselineAdjustedResult\":{\"status\":\"InternalError\",\"resultsNotInBaseline\":[],\"resultsOnlyInBaseline\":[]},\"ruleMetadata\":{\"ruleId\":\"ajubo\",\"severity\":\"Low\",\"category\":\"e\",\"ruleType\":\"BaselineExpected\",\"title\":\"ieikmwlaoklfnis\",\"description\":\"gucbmt\",\"rationale\":\"dscnns\",\"benchmarkReferences\":[]}},\"id\":\"yyuvtzrxzhclec\",\"name\":\"wtzqzcloyhy\",\"type\":\"pgidhzgyresgzsdt\"}";

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

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

        ScanResult response =
            manager
                .sqlVulnerabilityAssessmentScanResults()
                .getWithResponse("akmhz", "hwahfbw", "hbnnxemv", "nuqqkotauratnicp", com.azure.core.util.Context.NONE)
                .getValue();

        Assertions.assertEquals("scle", response.properties().ruleId());
        Assertions.assertEquals(RuleStatus.INTERNAL_ERROR, response.properties().status());
        Assertions.assertEquals(true, response.properties().isTrimmed());
        Assertions.assertEquals("qlmfdg", response.properties().queryResults().get(0).get(0));
        Assertions.assertEquals("cwtewfhxwyrkb", response.properties().remediation().description());
        Assertions.assertEquals(false, response.properties().remediation().automated());
        Assertions.assertEquals("rynjpc", response.properties().remediation().portalLink());
        Assertions.assertEquals(RuleStatus.INTERNAL_ERROR, response.properties().baselineAdjustedResult().status());
        Assertions.assertEquals("ajubo", response.properties().ruleMetadata().ruleId());
        Assertions.assertEquals(RuleSeverity.LOW, response.properties().ruleMetadata().severity());
        Assertions.assertEquals("e", response.properties().ruleMetadata().category());
        Assertions.assertEquals(RuleType.BASELINE_EXPECTED, response.properties().ruleMetadata().ruleType());
        Assertions.assertEquals("ieikmwlaoklfnis", response.properties().ruleMetadata().title());
        Assertions.assertEquals("gucbmt", response.properties().ruleMetadata().description());
        Assertions.assertEquals("dscnns", response.properties().ruleMetadata().rationale());
    }
}
