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

package com.azure.resourcemanager.iotfirmwaredefense.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.http.rest.PagedIterable;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.iotfirmwaredefense.IoTFirmwareDefenseManager;
import com.azure.resourcemanager.iotfirmwaredefense.models.Cve;
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 FirmwaresListGenerateCveListMockTests {
    @Test
    public void testListGenerateCveList() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"value\":[{\"cveId\":\"cwwfvovbvme\",\"component\":\"datacivyhzceuo\",\"severity\":\"jrwjueiotwm\",\"name\":\"ytdxwit\",\"cvssScore\":\"rjaw\",\"cvssVersion\":\"wgxhn\",\"cvssV2Score\":\"kxfbkpycgklwndn\",\"cvssV3Score\":\"dauwhvylwzbtd\",\"publishDate\":\"2021-05-11T10:23:35Z\",\"updatedDate\":\"2021-06-17T22:36:31Z\",\"links\":[{\"href\":\"pow\",\"label\":\"przqlveu\"}],\"description\":\"upjm\"}]}";

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

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

        PagedIterable<Cve> response =
            manager
                .firmwares()
                .listGenerateCveList("uhashsfwx", "sowzxcugi", "jooxdjebw", com.azure.core.util.Context.NONE);

        Assertions.assertEquals("cwwfvovbvme", response.iterator().next().cveId());
        Assertions.assertEquals("jrwjueiotwm", response.iterator().next().severity());
        Assertions.assertEquals("ytdxwit", response.iterator().next().name());
        Assertions.assertEquals("rjaw", response.iterator().next().cvssScore());
        Assertions.assertEquals("wgxhn", response.iterator().next().cvssVersion());
        Assertions.assertEquals("kxfbkpycgklwndn", response.iterator().next().cvssV2Score());
        Assertions.assertEquals("dauwhvylwzbtd", response.iterator().next().cvssV3Score());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-11T10:23:35Z"), response.iterator().next().publishDate());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-17T22:36:31Z"), response.iterator().next().updatedDate());
        Assertions.assertEquals("upjm", response.iterator().next().description());
    }
}
