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

package com.azure.resourcemanager.managednetworkfabric.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.managednetworkfabric.ManagedNetworkFabricManager;
import com.azure.resourcemanager.managednetworkfabric.models.AllowASOverride;
import com.azure.resourcemanager.managednetworkfabric.models.BgpConfiguration;
import com.azure.resourcemanager.managednetworkfabric.models.BooleanEnumProperty;
import com.azure.resourcemanager.managednetworkfabric.models.InternalNetwork;
import com.azure.resourcemanager.managednetworkfabric.models.StaticRouteConfiguration;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.util.Arrays;
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 InternalNetworksCreateMockTests {
    @Test
    public void testCreate() throws Exception {
        HttpClient httpClient = Mockito.mock(HttpClient.class);
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        ArgumentCaptor<HttpRequest> httpRequest = ArgumentCaptor.forClass(HttpRequest.class);

        String responseStr =
            "{\"properties\":{\"disabledOnResources\":[\"ijiufehgmvfln\",\"yvqkxr\",\"rlniyl\"],\"administrativeState\":\"Enabled\",\"bgpDisabledOnResources\":[\"xzutgqztwhghmupg\",\"yjtcdxabbujftab\"],\"bfdDisabledOnResources\":[\"bklqpxz\",\"cafeddw\",\"nlzafwxudgnh\"],\"bfdForStaticRoutesDisabledOnResources\":[\"krtalvn\",\"wgpbemeluclv\",\"jjukyrdnqodxah\"],\"provisioningState\":\"Succeeded\",\"vlanId\":318386162,\"mtu\":1931668946,\"connectedIPv4Subnets\":[],\"connectedIPv6Subnets\":[],\"staticRouteConfiguration\":{\"ipv4Routes\":[],\"ipv6Routes\":[]},\"bgpConfiguration\":{\"defaultRouteOriginate\":\"False\",\"allowAS\":885497604,\"allowASOverride\":\"Disable\",\"fabricASN\":2088110978,\"peerASN\":794448473,\"ipv4ListenRangePrefixes\":[],\"ipv6ListenRangePrefixes\":[],\"ipv4NeighborAddress\":[],\"ipv6NeighborAddress\":[],\"annotation\":\"txptlghw\"},\"importRoutePolicyId\":\"omew\",\"exportRoutePolicyId\":\"s\",\"annotation\":\"iuh\"},\"id\":\"wmoaiancznvodrrs\",\"name\":\"blxydkxr\",\"type\":\"vvbxiwkgfbqljnq\"}";

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

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

        InternalNetwork response =
            manager
                .internalNetworks()
                .define("xwbjs")
                .withExistingL3IsolationDomain("ka", "mrrqmbzmqkratb")
                .withVlanId(1420258043)
                .withMtu(1992477161)
                .withConnectedIPv4Subnets(Arrays.asList())
                .withConnectedIPv6Subnets(Arrays.asList())
                .withStaticRouteConfiguration(
                    new StaticRouteConfiguration().withIpv4Routes(Arrays.asList()).withIpv6Routes(Arrays.asList()))
                .withBgpConfiguration(
                    new BgpConfiguration()
                        .withAnnotation("fq")
                        .withDefaultRouteOriginate(BooleanEnumProperty.TRUE)
                        .withAllowAS(1905073411)
                        .withAllowASOverride(AllowASOverride.ENABLE)
                        .withPeerAsn(1435760253)
                        .withIpv4ListenRangePrefixes(Arrays.asList())
                        .withIpv6ListenRangePrefixes(Arrays.asList())
                        .withIpv4NeighborAddress(Arrays.asList())
                        .withIpv6NeighborAddress(Arrays.asList()))
                .withImportRoutePolicyId("sqxfxjelgcmpz")
                .withExportRoutePolicyId("hhhqxuwyv")
                .withAnnotation("co")
                .create();

        Assertions.assertEquals(318386162, response.vlanId());
        Assertions.assertEquals(1931668946, response.mtu());
        Assertions.assertEquals("txptlghw", response.bgpConfiguration().annotation());
        Assertions.assertEquals(BooleanEnumProperty.FALSE, response.bgpConfiguration().defaultRouteOriginate());
        Assertions.assertEquals(885497604, response.bgpConfiguration().allowAS());
        Assertions.assertEquals(AllowASOverride.DISABLE, response.bgpConfiguration().allowASOverride());
        Assertions.assertEquals(794448473, response.bgpConfiguration().peerAsn());
        Assertions.assertEquals("omew", response.importRoutePolicyId());
        Assertions.assertEquals("s", response.exportRoutePolicyId());
        Assertions.assertEquals("iuh", response.annotation());
    }
}
