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

package com.azure.resourcemanager.frontdoor.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.frontdoor.models.ActionType;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleEnabledState;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleExclusion;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleExclusionMatchVariable;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleExclusionSelectorMatchOperator;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleOverride;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class ManagedRuleOverrideTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ManagedRuleOverride model =
            BinaryData
                .fromString(
                    "{\"ruleId\":\"bljofxqeof\",\"enabledState\":\"Disabled\",\"action\":\"AnomalyScoring\",\"exclusions\":[{\"matchVariable\":\"RequestHeaderNames\",\"selectorMatchOperator\":\"Equals\",\"selector\":\"asvm\"},{\"matchVariable\":\"RequestCookieNames\",\"selectorMatchOperator\":\"EqualsAny\",\"selector\":\"qulngsntnbybkzgc\"}]}")
                .toObject(ManagedRuleOverride.class);
        Assertions.assertEquals("bljofxqeof", model.ruleId());
        Assertions.assertEquals(ManagedRuleEnabledState.DISABLED, model.enabledState());
        Assertions.assertEquals(ActionType.ANOMALY_SCORING, model.action());
        Assertions
            .assertEquals(
                ManagedRuleExclusionMatchVariable.REQUEST_HEADER_NAMES, model.exclusions().get(0).matchVariable());
        Assertions
            .assertEquals(
                ManagedRuleExclusionSelectorMatchOperator.EQUALS, model.exclusions().get(0).selectorMatchOperator());
        Assertions.assertEquals("asvm", model.exclusions().get(0).selector());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ManagedRuleOverride model =
            new ManagedRuleOverride()
                .withRuleId("bljofxqeof")
                .withEnabledState(ManagedRuleEnabledState.DISABLED)
                .withAction(ActionType.ANOMALY_SCORING)
                .withExclusions(
                    Arrays
                        .asList(
                            new ManagedRuleExclusion()
                                .withMatchVariable(ManagedRuleExclusionMatchVariable.REQUEST_HEADER_NAMES)
                                .withSelectorMatchOperator(ManagedRuleExclusionSelectorMatchOperator.EQUALS)
                                .withSelector("asvm"),
                            new ManagedRuleExclusion()
                                .withMatchVariable(ManagedRuleExclusionMatchVariable.REQUEST_COOKIE_NAMES)
                                .withSelectorMatchOperator(ManagedRuleExclusionSelectorMatchOperator.EQUALS_ANY)
                                .withSelector("qulngsntnbybkzgc")));
        model = BinaryData.fromObject(model).toObject(ManagedRuleOverride.class);
        Assertions.assertEquals("bljofxqeof", model.ruleId());
        Assertions.assertEquals(ManagedRuleEnabledState.DISABLED, model.enabledState());
        Assertions.assertEquals(ActionType.ANOMALY_SCORING, model.action());
        Assertions
            .assertEquals(
                ManagedRuleExclusionMatchVariable.REQUEST_HEADER_NAMES, model.exclusions().get(0).matchVariable());
        Assertions
            .assertEquals(
                ManagedRuleExclusionSelectorMatchOperator.EQUALS, model.exclusions().get(0).selectorMatchOperator());
        Assertions.assertEquals("asvm", model.exclusions().get(0).selector());
    }
}
