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

package com.azure.resourcemanager.cognitiveservices.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.cognitiveservices.models.IpRule;
import com.azure.resourcemanager.cognitiveservices.models.NetworkRuleAction;
import com.azure.resourcemanager.cognitiveservices.models.NetworkRuleSet;
import com.azure.resourcemanager.cognitiveservices.models.VirtualNetworkRule;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class NetworkRuleSetTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        NetworkRuleSet model =
            BinaryData
                .fromString(
                    "{\"defaultAction\":\"Deny\",\"ipRules\":[{\"value\":\"lsuuvmkjozkrwfnd\"}],\"virtualNetworkRules\":[{\"id\":\"jpslwejd\",\"state\":\"wryoqpsoacc\",\"ignoreMissingVnetServiceEndpoint\":true},{\"id\":\"akl\",\"state\":\"ahbc\",\"ignoreMissingVnetServiceEndpoint\":true}]}")
                .toObject(NetworkRuleSet.class);
        Assertions.assertEquals(NetworkRuleAction.DENY, model.defaultAction());
        Assertions.assertEquals("lsuuvmkjozkrwfnd", model.ipRules().get(0).value());
        Assertions.assertEquals("jpslwejd", model.virtualNetworkRules().get(0).id());
        Assertions.assertEquals("wryoqpsoacc", model.virtualNetworkRules().get(0).state());
        Assertions.assertEquals(true, model.virtualNetworkRules().get(0).ignoreMissingVnetServiceEndpoint());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        NetworkRuleSet model =
            new NetworkRuleSet()
                .withDefaultAction(NetworkRuleAction.DENY)
                .withIpRules(Arrays.asList(new IpRule().withValue("lsuuvmkjozkrwfnd")))
                .withVirtualNetworkRules(
                    Arrays
                        .asList(
                            new VirtualNetworkRule()
                                .withId("jpslwejd")
                                .withState("wryoqpsoacc")
                                .withIgnoreMissingVnetServiceEndpoint(true),
                            new VirtualNetworkRule()
                                .withId("akl")
                                .withState("ahbc")
                                .withIgnoreMissingVnetServiceEndpoint(true)));
        model = BinaryData.fromObject(model).toObject(NetworkRuleSet.class);
        Assertions.assertEquals(NetworkRuleAction.DENY, model.defaultAction());
        Assertions.assertEquals("lsuuvmkjozkrwfnd", model.ipRules().get(0).value());
        Assertions.assertEquals("jpslwejd", model.virtualNetworkRules().get(0).id());
        Assertions.assertEquals("wryoqpsoacc", model.virtualNetworkRules().get(0).state());
        Assertions.assertEquals(true, model.virtualNetworkRules().get(0).ignoreMissingVnetServiceEndpoint());
    }
}
