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

package com.azure.resourcemanager.devtestlabs.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devtestlabs.models.Port;
import com.azure.resourcemanager.devtestlabs.models.SubnetOverride;
import com.azure.resourcemanager.devtestlabs.models.SubnetSharedPublicIpAddressConfiguration;
import com.azure.resourcemanager.devtestlabs.models.TransportProtocol;
import com.azure.resourcemanager.devtestlabs.models.UsagePermissionType;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class SubnetOverrideTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SubnetOverride model =
            BinaryData
                .fromString(
                    "{\"resourceId\":\"w\",\"labSubnetName\":\"qszdtmaajquhuxyl\",\"useInVmCreationPermission\":\"Allow\",\"usePublicIpAddressPermission\":\"Default\",\"sharedPublicIpAddressConfiguration\":{\"allowedPorts\":[{\"transportProtocol\":\"Udp\",\"backendPort\":81881982},{\"transportProtocol\":\"Tcp\",\"backendPort\":561494498},{\"transportProtocol\":\"Tcp\",\"backendPort\":26175151}]},\"virtualNetworkPoolName\":\"fkyjpmspbpssdfpp\"}")
                .toObject(SubnetOverride.class);
        Assertions.assertEquals("w", model.resourceId());
        Assertions.assertEquals("qszdtmaajquhuxyl", model.labSubnetName());
        Assertions.assertEquals(UsagePermissionType.ALLOW, model.useInVmCreationPermission());
        Assertions.assertEquals(UsagePermissionType.DEFAULT, model.usePublicIpAddressPermission());
        Assertions
            .assertEquals(
                TransportProtocol.UDP,
                model.sharedPublicIpAddressConfiguration().allowedPorts().get(0).transportProtocol());
        Assertions
            .assertEquals(81881982, model.sharedPublicIpAddressConfiguration().allowedPorts().get(0).backendPort());
        Assertions.assertEquals("fkyjpmspbpssdfpp", model.virtualNetworkPoolName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SubnetOverride model =
            new SubnetOverride()
                .withResourceId("w")
                .withLabSubnetName("qszdtmaajquhuxyl")
                .withUseInVmCreationPermission(UsagePermissionType.ALLOW)
                .withUsePublicIpAddressPermission(UsagePermissionType.DEFAULT)
                .withSharedPublicIpAddressConfiguration(
                    new SubnetSharedPublicIpAddressConfiguration()
                        .withAllowedPorts(
                            Arrays
                                .asList(
                                    new Port().withTransportProtocol(TransportProtocol.UDP).withBackendPort(81881982),
                                    new Port().withTransportProtocol(TransportProtocol.TCP).withBackendPort(561494498),
                                    new Port().withTransportProtocol(TransportProtocol.TCP).withBackendPort(26175151))))
                .withVirtualNetworkPoolName("fkyjpmspbpssdfpp");
        model = BinaryData.fromObject(model).toObject(SubnetOverride.class);
        Assertions.assertEquals("w", model.resourceId());
        Assertions.assertEquals("qszdtmaajquhuxyl", model.labSubnetName());
        Assertions.assertEquals(UsagePermissionType.ALLOW, model.useInVmCreationPermission());
        Assertions.assertEquals(UsagePermissionType.DEFAULT, model.usePublicIpAddressPermission());
        Assertions
            .assertEquals(
                TransportProtocol.UDP,
                model.sharedPublicIpAddressConfiguration().allowedPorts().get(0).transportProtocol());
        Assertions
            .assertEquals(81881982, model.sharedPublicIpAddressConfiguration().allowedPorts().get(0).backendPort());
        Assertions.assertEquals("fkyjpmspbpssdfpp", model.virtualNetworkPoolName());
    }
}
