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

package com.azure.resourcemanager.advisor.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.advisor.AdvisorManager;
import com.azure.resourcemanager.advisor.models.Category;
import com.azure.resourcemanager.advisor.models.Impact;
import com.azure.resourcemanager.advisor.models.ResourceRecommendationBase;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.util.UUID;
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 RecommendationsGetWithResponseMockTests {
    @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\":{\"category\":\"Security\",\"impact\":\"High\",\"impactedField\":\"kfssxqukkf\",\"impactedValue\":\"gmgsxnkjzkde\",\"lastUpdated\":\"2021-08-30T18:12:55Z\",\"metadata\":{\"ighxpk\":\"dataopwi\",\"baumnyqupedeoj\":\"datawzbaiue\"},\"recommendationTypeId\":\"bckhsmtxpsi\",\"shortDescription\":{\"problem\":\"fhvpesaps\",\"solution\":\"dqmh\"},\"suppressionIds\":[\"b1eecfad-1b6f-4eda-bd1b-d71c2a0d518d\",\"b8b70fe5-ab05-4fed-a3d9-903cb3756293\",\"10d00cfa-8b19-45c1-be70-06062e19c80a\"],\"extendedProperties\":{\"ws\":\"ldwkyzxuutkn\",\"vnm\":\"wsvlxotogtwrupqs\",\"eil\":\"cykvceo\"},\"resourceMetadata\":{\"resourceId\":\"oty\",\"source\":\"fcnj\",\"action\":{},\"singular\":\"nxdhbt\",\"plural\":\"phywpnvj\"},\"description\":\"qnermclfplphoxu\",\"label\":\"rpabg\",\"learnMoreLink\":\"psbjta\",\"potentialBenefits\":\"ugxywpmueef\",\"actions\":[{\"onobglaocqx\":\"dataqkqujidsu\",\"yudxytlmoy\":\"dataccm\"},{\"hl\":\"datavwfudwpzntxhd\"}],\"remediation\":{\"kfrlhrxsbky\":\"databh\",\"afkuwb\":\"datapycanuzbpz\",\"ehhseyvjusrts\":\"datarnwb\"},\"exposedMetadataProperties\":{\"elmqk\":\"datapkdeemaofmxagkvt\",\"hcdhmdual\":\"datahahvljuahaq\"}},\"id\":\"exq\",\"name\":\"vfadmws\",\"type\":\"crgvxpvgom\"}";

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

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

        ResourceRecommendationBase response =
            manager.recommendations().getWithResponse("ovplw", "bhvgy", com.azure.core.util.Context.NONE).getValue();

        Assertions.assertEquals(Category.SECURITY, response.category());
        Assertions.assertEquals(Impact.HIGH, response.impact());
        Assertions.assertEquals("kfssxqukkf", response.impactedField());
        Assertions.assertEquals("gmgsxnkjzkde", response.impactedValue());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-30T18:12:55Z"), response.lastUpdated());
        Assertions.assertEquals("bckhsmtxpsi", response.recommendationTypeId());
        Assertions.assertEquals("fhvpesaps", response.shortDescription().problem());
        Assertions.assertEquals("dqmh", response.shortDescription().solution());
        Assertions
            .assertEquals(UUID.fromString("b1eecfad-1b6f-4eda-bd1b-d71c2a0d518d"), response.suppressionIds().get(0));
        Assertions.assertEquals("ldwkyzxuutkn", response.extendedProperties().get("ws"));
        Assertions.assertEquals("oty", response.resourceMetadata().resourceId());
        Assertions.assertEquals("fcnj", response.resourceMetadata().source());
        Assertions.assertEquals("nxdhbt", response.resourceMetadata().singular());
        Assertions.assertEquals("phywpnvj", response.resourceMetadata().plural());
        Assertions.assertEquals("qnermclfplphoxu", response.description());
        Assertions.assertEquals("rpabg", response.label());
        Assertions.assertEquals("psbjta", response.learnMoreLink());
        Assertions.assertEquals("ugxywpmueef", response.potentialBenefits());
    }
}
