// 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.ManagedRuleExclusion;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleExclusionMatchVariable;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleExclusionSelectorMatchOperator;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleGroupOverride;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleSet;
import com.azure.resourcemanager.frontdoor.models.ManagedRuleSetActionType;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class ManagedRuleSetTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ManagedRuleSet model =
            BinaryData
                .fromString(
                    "{\"ruleSetType\":\"wzo\",\"ruleSetVersion\":\"xjtfelluwfzit\",\"ruleSetAction\":\"Block\",\"exclusions\":[{\"matchVariable\":\"QueryStringArgNames\",\"selectorMatchOperator\":\"Contains\",\"selector\":\"jkjlxofpdvhpfx\"},{\"matchVariable\":\"RequestBodyJsonArgNames\",\"selectorMatchOperator\":\"EndsWith\",\"selector\":\"ininmay\"}],\"ruleGroupOverrides\":[{\"ruleGroupName\":\"bbkpodep\",\"exclusions\":[],\"rules\":[]}]}")
                .toObject(ManagedRuleSet.class);
        Assertions.assertEquals("wzo", model.ruleSetType());
        Assertions.assertEquals("xjtfelluwfzit", model.ruleSetVersion());
        Assertions.assertEquals(ManagedRuleSetActionType.BLOCK, model.ruleSetAction());
        Assertions
            .assertEquals(
                ManagedRuleExclusionMatchVariable.QUERY_STRING_ARG_NAMES, model.exclusions().get(0).matchVariable());
        Assertions
            .assertEquals(
                ManagedRuleExclusionSelectorMatchOperator.CONTAINS, model.exclusions().get(0).selectorMatchOperator());
        Assertions.assertEquals("jkjlxofpdvhpfx", model.exclusions().get(0).selector());
        Assertions.assertEquals("bbkpodep", model.ruleGroupOverrides().get(0).ruleGroupName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ManagedRuleSet model =
            new ManagedRuleSet()
                .withRuleSetType("wzo")
                .withRuleSetVersion("xjtfelluwfzit")
                .withRuleSetAction(ManagedRuleSetActionType.BLOCK)
                .withExclusions(
                    Arrays
                        .asList(
                            new ManagedRuleExclusion()
                                .withMatchVariable(ManagedRuleExclusionMatchVariable.QUERY_STRING_ARG_NAMES)
                                .withSelectorMatchOperator(ManagedRuleExclusionSelectorMatchOperator.CONTAINS)
                                .withSelector("jkjlxofpdvhpfx"),
                            new ManagedRuleExclusion()
                                .withMatchVariable(ManagedRuleExclusionMatchVariable.REQUEST_BODY_JSON_ARG_NAMES)
                                .withSelectorMatchOperator(ManagedRuleExclusionSelectorMatchOperator.ENDS_WITH)
                                .withSelector("ininmay")))
                .withRuleGroupOverrides(
                    Arrays
                        .asList(
                            new ManagedRuleGroupOverride()
                                .withRuleGroupName("bbkpodep")
                                .withExclusions(Arrays.asList())
                                .withRules(Arrays.asList())));
        model = BinaryData.fromObject(model).toObject(ManagedRuleSet.class);
        Assertions.assertEquals("wzo", model.ruleSetType());
        Assertions.assertEquals("xjtfelluwfzit", model.ruleSetVersion());
        Assertions.assertEquals(ManagedRuleSetActionType.BLOCK, model.ruleSetAction());
        Assertions
            .assertEquals(
                ManagedRuleExclusionMatchVariable.QUERY_STRING_ARG_NAMES, model.exclusions().get(0).matchVariable());
        Assertions
            .assertEquals(
                ManagedRuleExclusionSelectorMatchOperator.CONTAINS, model.exclusions().get(0).selectorMatchOperator());
        Assertions.assertEquals("jkjlxofpdvhpfx", model.exclusions().get(0).selector());
        Assertions.assertEquals("bbkpodep", model.ruleGroupOverrides().get(0).ruleGroupName());
    }
}
