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

package com.azure.resourcemanager.logic.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.logic.LogicManager;
import com.azure.resourcemanager.logic.models.ApiOperation;
import com.azure.resourcemanager.logic.models.ApiTier;
import com.azure.resourcemanager.logic.models.StatusAnnotation;
import com.azure.resourcemanager.logic.models.SwaggerSchemaType;
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 IntegrationServiceEnvironmentManagedApiOperationsListMockTests {
    @Test
    public void testList() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"value\":[{\"properties\":{\"summary\":\"ukmkczynu\",\"description\":\"oq\",\"visibility\":\"shavljqkx\",\"trigger\":\"qolnthbbn\",\"triggerHint\":\"zukwdrnzkj\",\"pageable\":false,\"annotation\":{\"status\":\"NotSpecified\",\"family\":\"ncjmlfuyf\",\"revision\":1643362919},\"api\":{\"displayName\":\"ddhlrufzcqyj\",\"description\":\"rfuiocusel\",\"iconUri\":\"rsazrhxud\",\"swagger\":\"datamdtff\",\"brandColor\":\"jmr\",\"category\":\"Premium\",\"id\":\"dmdlgyqixokw\",\"name\":\"awhva\",\"type\":\"qfqqdlcvmyolc\"},\"inputsDefinition\":{\"ref\":\"jchtvsnvlaqd\",\"type\":\"Boolean\",\"title\":\"awatuwqkokbczo\",\"properties\":{},\"additionalProperties\":\"datagobllms\",\"required\":[],\"maxProperties\":1217854392,\"minProperties\":1379724649,\"allOf\":[],\"discriminator\":\"neakh\",\"readOnly\":false,\"example\":\"datayanrfvq\",\"notificationUrlExtension\":true},\"responsesDefinition\":{},\"isWebhook\":true,\"isNotification\":true},\"location\":\"aoaqymhccto\",\"tags\":{\"uhczy\":\"wyrnskbyh\"},\"id\":\"xvhajpxec\",\"name\":\"qnwhscozawmvg\",\"type\":\"smpknpwi\"}]}";

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

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

        PagedIterable<ApiOperation> response =
            manager
                .integrationServiceEnvironmentManagedApiOperations()
                .list("gfjzcvaax", "ia", "ahfxwccok", com.azure.core.util.Context.NONE);

        Assertions.assertEquals("aoaqymhccto", response.iterator().next().location());
        Assertions.assertEquals("wyrnskbyh", response.iterator().next().tags().get("uhczy"));
        Assertions.assertEquals("ukmkczynu", response.iterator().next().properties().summary());
        Assertions.assertEquals("oq", response.iterator().next().properties().description());
        Assertions.assertEquals("shavljqkx", response.iterator().next().properties().visibility());
        Assertions.assertEquals("qolnthbbn", response.iterator().next().properties().trigger());
        Assertions.assertEquals("zukwdrnzkj", response.iterator().next().properties().triggerHint());
        Assertions.assertEquals(false, response.iterator().next().properties().pageable());
        Assertions
            .assertEquals(
                StatusAnnotation.NOT_SPECIFIED, response.iterator().next().properties().annotation().status());
        Assertions.assertEquals("ncjmlfuyf", response.iterator().next().properties().annotation().family());
        Assertions.assertEquals(1643362919, response.iterator().next().properties().annotation().revision());
        Assertions.assertEquals("dmdlgyqixokw", response.iterator().next().properties().api().id());
        Assertions.assertEquals("ddhlrufzcqyj", response.iterator().next().properties().api().displayName());
        Assertions.assertEquals("rfuiocusel", response.iterator().next().properties().api().description());
        Assertions.assertEquals("rsazrhxud", response.iterator().next().properties().api().iconUri());
        Assertions.assertEquals("jmr", response.iterator().next().properties().api().brandColor());
        Assertions.assertEquals(ApiTier.PREMIUM, response.iterator().next().properties().api().category());
        Assertions.assertEquals("jchtvsnvlaqd", response.iterator().next().properties().inputsDefinition().ref());
        Assertions
            .assertEquals(SwaggerSchemaType.BOOLEAN, response.iterator().next().properties().inputsDefinition().type());
        Assertions.assertEquals("awatuwqkokbczo", response.iterator().next().properties().inputsDefinition().title());
        Assertions.assertEquals(1217854392, response.iterator().next().properties().inputsDefinition().maxProperties());
        Assertions.assertEquals(1379724649, response.iterator().next().properties().inputsDefinition().minProperties());
        Assertions.assertEquals("neakh", response.iterator().next().properties().inputsDefinition().discriminator());
        Assertions.assertEquals(false, response.iterator().next().properties().inputsDefinition().readOnly());
        Assertions
            .assertEquals(true, response.iterator().next().properties().inputsDefinition().notificationUrlExtension());
        Assertions.assertEquals(true, response.iterator().next().properties().isWebhook());
        Assertions.assertEquals(true, response.iterator().next().properties().isNotification());
    }
}
