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

package com.azure.resourcemanager.signalr.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.signalr.models.AclAction;
import com.azure.resourcemanager.signalr.models.NetworkAcl;
import com.azure.resourcemanager.signalr.models.PrivateEndpointAcl;
import com.azure.resourcemanager.signalr.models.SignalRNetworkACLs;
import com.azure.resourcemanager.signalr.models.SignalRRequestType;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class SignalRNetworkACLsTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SignalRNetworkACLs model =
            BinaryData
                .fromString(
                    "{\"defaultAction\":\"Allow\",\"publicNetwork\":{\"allow\":[\"RESTAPI\",\"RESTAPI\"],\"deny\":[\"ServerConnection\"]},\"privateEndpoints\":[{\"name\":\"xolzdahzx\",\"allow\":[\"Trace\",\"RESTAPI\",\"ServerConnection\"],\"deny\":[\"ServerConnection\",\"Trace\",\"ServerConnection\"]},{\"name\":\"zpostmgrcfbu\",\"allow\":[\"Trace\",\"RESTAPI\",\"ServerConnection\"],\"deny\":[\"ServerConnection\",\"RESTAPI\"]},{\"name\":\"bpvjymjhx\",\"allow\":[\"ClientConnection\",\"Trace\"],\"deny\":[\"ServerConnection\",\"ClientConnection\"]}]}")
                .toObject(SignalRNetworkACLs.class);
        Assertions.assertEquals(AclAction.ALLOW, model.defaultAction());
        Assertions.assertEquals(SignalRRequestType.RESTAPI, model.publicNetwork().allow().get(0));
        Assertions.assertEquals(SignalRRequestType.SERVER_CONNECTION, model.publicNetwork().deny().get(0));
        Assertions.assertEquals(SignalRRequestType.TRACE, model.privateEndpoints().get(0).allow().get(0));
        Assertions.assertEquals(SignalRRequestType.SERVER_CONNECTION, model.privateEndpoints().get(0).deny().get(0));
        Assertions.assertEquals("xolzdahzx", model.privateEndpoints().get(0).name());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SignalRNetworkACLs model =
            new SignalRNetworkACLs()
                .withDefaultAction(AclAction.ALLOW)
                .withPublicNetwork(
                    new NetworkAcl()
                        .withAllow(Arrays.asList(SignalRRequestType.RESTAPI, SignalRRequestType.RESTAPI))
                        .withDeny(Arrays.asList(SignalRRequestType.SERVER_CONNECTION)))
                .withPrivateEndpoints(
                    Arrays
                        .asList(
                            new PrivateEndpointAcl()
                                .withAllow(
                                    Arrays
                                        .asList(
                                            SignalRRequestType.TRACE,
                                            SignalRRequestType.RESTAPI,
                                            SignalRRequestType.SERVER_CONNECTION))
                                .withDeny(
                                    Arrays
                                        .asList(
                                            SignalRRequestType.SERVER_CONNECTION,
                                            SignalRRequestType.TRACE,
                                            SignalRRequestType.SERVER_CONNECTION))
                                .withName("xolzdahzx"),
                            new PrivateEndpointAcl()
                                .withAllow(
                                    Arrays
                                        .asList(
                                            SignalRRequestType.TRACE,
                                            SignalRRequestType.RESTAPI,
                                            SignalRRequestType.SERVER_CONNECTION))
                                .withDeny(
                                    Arrays.asList(SignalRRequestType.SERVER_CONNECTION, SignalRRequestType.RESTAPI))
                                .withName("zpostmgrcfbu"),
                            new PrivateEndpointAcl()
                                .withAllow(
                                    Arrays.asList(SignalRRequestType.CLIENT_CONNECTION, SignalRRequestType.TRACE))
                                .withDeny(
                                    Arrays
                                        .asList(
                                            SignalRRequestType.SERVER_CONNECTION, SignalRRequestType.CLIENT_CONNECTION))
                                .withName("bpvjymjhx")));
        model = BinaryData.fromObject(model).toObject(SignalRNetworkACLs.class);
        Assertions.assertEquals(AclAction.ALLOW, model.defaultAction());
        Assertions.assertEquals(SignalRRequestType.RESTAPI, model.publicNetwork().allow().get(0));
        Assertions.assertEquals(SignalRRequestType.SERVER_CONNECTION, model.publicNetwork().deny().get(0));
        Assertions.assertEquals(SignalRRequestType.TRACE, model.privateEndpoints().get(0).allow().get(0));
        Assertions.assertEquals(SignalRRequestType.SERVER_CONNECTION, model.privateEndpoints().get(0).deny().get(0));
        Assertions.assertEquals("xolzdahzx", model.privateEndpoints().get(0).name());
    }
}
