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

package com.azure.resourcemanager.security.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.security.fluent.models.AdaptiveNetworkHardeningInner;
import com.azure.resourcemanager.security.models.Direction;
import com.azure.resourcemanager.security.models.EffectiveNetworkSecurityGroups;
import com.azure.resourcemanager.security.models.Rule;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class AdaptiveNetworkHardeningInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AdaptiveNetworkHardeningInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"rules\":[{\"name\":\"rfe\",\"direction\":\"Outbound\",\"destinationPort\":301630864,\"protocols\":[],\"ipAddresses\":[]},{\"name\":\"hcans\",\"direction\":\"Inbound\",\"destinationPort\":1800110701,\"protocols\":[],\"ipAddresses\":[]},{\"name\":\"igdivbkbxg\",\"direction\":\"Inbound\",\"destinationPort\":2081513021,\"protocols\":[],\"ipAddresses\":[]},{\"name\":\"sqvdaeyygux\",\"direction\":\"Outbound\",\"destinationPort\":1119953964,\"protocols\":[],\"ipAddresses\":[]}],\"rulesCalculationTime\":\"2021-01-11T12:34:59Z\",\"effectiveNetworkSecurityGroups\":[{\"networkInterface\":\"gims\",\"networkSecurityGroups\":[]},{\"networkInterface\":\"asi\",\"networkSecurityGroups\":[]}]},\"id\":\"dyvvjskgfmocwahp\",\"name\":\"gat\",\"type\":\"eaahhvjhhn\"}")
                .toObject(AdaptiveNetworkHardeningInner.class);
        Assertions.assertEquals("rfe", model.rules().get(0).name());
        Assertions.assertEquals(Direction.OUTBOUND, model.rules().get(0).direction());
        Assertions.assertEquals(301630864, model.rules().get(0).destinationPort());
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-11T12:34:59Z"), model.rulesCalculationTime());
        Assertions.assertEquals("gims", model.effectiveNetworkSecurityGroups().get(0).networkInterface());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AdaptiveNetworkHardeningInner model =
            new AdaptiveNetworkHardeningInner()
                .withRules(
                    Arrays
                        .asList(
                            new Rule()
                                .withName("rfe")
                                .withDirection(Direction.OUTBOUND)
                                .withDestinationPort(301630864)
                                .withProtocols(Arrays.asList())
                                .withIpAddresses(Arrays.asList()),
                            new Rule()
                                .withName("hcans")
                                .withDirection(Direction.INBOUND)
                                .withDestinationPort(1800110701)
                                .withProtocols(Arrays.asList())
                                .withIpAddresses(Arrays.asList()),
                            new Rule()
                                .withName("igdivbkbxg")
                                .withDirection(Direction.INBOUND)
                                .withDestinationPort(2081513021)
                                .withProtocols(Arrays.asList())
                                .withIpAddresses(Arrays.asList()),
                            new Rule()
                                .withName("sqvdaeyygux")
                                .withDirection(Direction.OUTBOUND)
                                .withDestinationPort(1119953964)
                                .withProtocols(Arrays.asList())
                                .withIpAddresses(Arrays.asList())))
                .withRulesCalculationTime(OffsetDateTime.parse("2021-01-11T12:34:59Z"))
                .withEffectiveNetworkSecurityGroups(
                    Arrays
                        .asList(
                            new EffectiveNetworkSecurityGroups()
                                .withNetworkInterface("gims")
                                .withNetworkSecurityGroups(Arrays.asList()),
                            new EffectiveNetworkSecurityGroups()
                                .withNetworkInterface("asi")
                                .withNetworkSecurityGroups(Arrays.asList())));
        model = BinaryData.fromObject(model).toObject(AdaptiveNetworkHardeningInner.class);
        Assertions.assertEquals("rfe", model.rules().get(0).name());
        Assertions.assertEquals(Direction.OUTBOUND, model.rules().get(0).direction());
        Assertions.assertEquals(301630864, model.rules().get(0).destinationPort());
        Assertions.assertEquals(OffsetDateTime.parse("2021-01-11T12:34:59Z"), model.rulesCalculationTime());
        Assertions.assertEquals("gims", model.effectiveNetworkSecurityGroups().get(0).networkInterface());
    }
}
