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

package com.azure.resourcemanager.mobilenetwork.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.mobilenetwork.MobileNetworkManager;
import com.azure.resourcemanager.mobilenetwork.models.AuthenticationType;
import com.azure.resourcemanager.mobilenetwork.models.BillingSku;
import com.azure.resourcemanager.mobilenetwork.models.CoreNetworkType;
import com.azure.resourcemanager.mobilenetwork.models.DesiredInstallationState;
import com.azure.resourcemanager.mobilenetwork.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.mobilenetwork.models.PacketCoreControlPlane;
import com.azure.resourcemanager.mobilenetwork.models.PlatformType;
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 PacketCoreControlPlanesListByResourceGroupMockTests {
    @Test
    public void testListByResourceGroup() 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\":{\"provisioningState\":\"Deleting\",\"installation\":{\"desiredState\":\"Uninstalled\",\"state\":\"Uninstalling\",\"reinstallRequired\":\"Required\",\"reasons\":[\"NoPacketCoreDataPlane\"],\"operation\":{\"id\":\"dxxewuninv\"}},\"sites\":[{\"id\":\"bchaqd\"}],\"platform\":{\"type\":\"AKS-HCI\",\"azureStackEdgeDevice\":{\"id\":\"ec\"},\"azureStackEdgeDevices\":[{\"id\":\"tmxxdtddmflhuy\"}],\"azureStackHciCluster\":{\"id\":\"zv\"},\"connectedCluster\":{\"id\":\"napxbannovv\"},\"customLocation\":{\"id\":\"czytprwn\"}},\"coreNetworkTechnology\":\"EPC"
                + " + 5GC\",\"version\":\"ev\",\"installedVersion\":\"lyokrrrou\",\"rollbackVersion\":\"vnsasbcrymodi\",\"controlPlaneAccessInterface\":{\"name\":\"xkl\",\"ipv4Address\":\"d\",\"ipv4Subnet\":\"azpmkmlmv\",\"ipv4Gateway\":\"f\"},\"sku\":\"G5\",\"ueMtu\":496692380,\"localDiagnosticsAccess\":{\"authenticationType\":\"Password\",\"httpsServerCertificate\":{\"certificateUrl\":\"bzxliohrdddtfgxq\",\"provisioning\":{\"state\":\"Failed\",\"reason\":\"bbnz\"}}},\"diagnosticsUpload\":{\"storageAccountContainerUrl\":\"yknapqofyuicdh\"},\"interopSettings\":\"datadyb\"},\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"bid\":{\"principalId\":\"26f5e9bb-45c3-4469-ab27-122fdb380b08\",\"clientId\":\"ccd04423-1e1a-46ab-a125-a66f34c07da0\"}}},\"location\":\"m\",\"tags\":{\"yoxoy\":\"plfmuvapckccrrvw\"},\"id\":\"ukphaimmoiroq\",\"name\":\"oshbragapyy\",\"type\":\"mfsvbpav\"}]}";

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

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

        PagedIterable<PacketCoreControlPlane> response =
            manager.packetCoreControlPlanes().listByResourceGroup("lcqxypokk", com.azure.core.util.Context.NONE);

        Assertions.assertEquals("m", response.iterator().next().location());
        Assertions.assertEquals("plfmuvapckccrrvw", response.iterator().next().tags().get("yoxoy"));
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, response.iterator().next().identity().type());
        Assertions
            .assertEquals(
                DesiredInstallationState.UNINSTALLED, response.iterator().next().installation().desiredState());
        Assertions.assertEquals("bchaqd", response.iterator().next().sites().get(0).id());
        Assertions.assertEquals(PlatformType.AKS_HCI, response.iterator().next().platform().type());
        Assertions.assertEquals("ec", response.iterator().next().platform().azureStackEdgeDevice().id());
        Assertions.assertEquals("zv", response.iterator().next().platform().azureStackHciCluster().id());
        Assertions.assertEquals("napxbannovv", response.iterator().next().platform().connectedCluster().id());
        Assertions.assertEquals("czytprwn", response.iterator().next().platform().customLocation().id());
        Assertions.assertEquals(CoreNetworkType.EPC_5GC, response.iterator().next().coreNetworkTechnology());
        Assertions.assertEquals("ev", response.iterator().next().version());
        Assertions.assertEquals("xkl", response.iterator().next().controlPlaneAccessInterface().name());
        Assertions.assertEquals("d", response.iterator().next().controlPlaneAccessInterface().ipv4Address());
        Assertions.assertEquals("azpmkmlmv", response.iterator().next().controlPlaneAccessInterface().ipv4Subnet());
        Assertions.assertEquals("f", response.iterator().next().controlPlaneAccessInterface().ipv4Gateway());
        Assertions.assertEquals(BillingSku.G5, response.iterator().next().sku());
        Assertions.assertEquals(496692380, response.iterator().next().ueMtu());
        Assertions
            .assertEquals(
                AuthenticationType.PASSWORD, response.iterator().next().localDiagnosticsAccess().authenticationType());
        Assertions
            .assertEquals(
                "bzxliohrdddtfgxq",
                response.iterator().next().localDiagnosticsAccess().httpsServerCertificate().certificateUrl());
        Assertions
            .assertEquals(
                "yknapqofyuicdh", response.iterator().next().diagnosticsUpload().storageAccountContainerUrl());
    }
}
