// 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.CustomRule;
import com.azure.resourcemanager.frontdoor.models.CustomRuleEnabledState;
import com.azure.resourcemanager.frontdoor.models.MatchCondition;
import com.azure.resourcemanager.frontdoor.models.MatchVariable;
import com.azure.resourcemanager.frontdoor.models.Operator;
import com.azure.resourcemanager.frontdoor.models.RuleType;
import com.azure.resourcemanager.frontdoor.models.TransformType;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class CustomRuleTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        CustomRule model =
            BinaryData
                .fromString(
                    "{\"name\":\"ipjoxzjnchgejs\",\"priority\":178199431,\"enabledState\":\"Enabled\",\"ruleType\":\"RateLimitRule\",\"rateLimitDurationInMinutes\":1543997460,\"rateLimitThreshold\":1345546955,\"matchConditions\":[{\"matchVariable\":\"RequestBody\",\"selector\":\"o\",\"operator\":\"BeginsWith\",\"negateCondition\":false,\"matchValue\":[\"uxinpmqnjaq\",\"ixjsprozvcputeg\",\"vwmf\"],\"transforms\":[\"UrlDecode\"]}],\"action\":\"Block\"}")
                .toObject(CustomRule.class);
        Assertions.assertEquals("ipjoxzjnchgejs", model.name());
        Assertions.assertEquals(178199431, model.priority());
        Assertions.assertEquals(CustomRuleEnabledState.ENABLED, model.enabledState());
        Assertions.assertEquals(RuleType.RATE_LIMIT_RULE, model.ruleType());
        Assertions.assertEquals(1543997460, model.rateLimitDurationInMinutes());
        Assertions.assertEquals(1345546955, model.rateLimitThreshold());
        Assertions.assertEquals(MatchVariable.REQUEST_BODY, model.matchConditions().get(0).matchVariable());
        Assertions.assertEquals("o", model.matchConditions().get(0).selector());
        Assertions.assertEquals(Operator.BEGINS_WITH, model.matchConditions().get(0).operator());
        Assertions.assertEquals(false, model.matchConditions().get(0).negateCondition());
        Assertions.assertEquals("uxinpmqnjaq", model.matchConditions().get(0).matchValue().get(0));
        Assertions.assertEquals(TransformType.URL_DECODE, model.matchConditions().get(0).transforms().get(0));
        Assertions.assertEquals(ActionType.BLOCK, model.action());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        CustomRule model =
            new CustomRule()
                .withName("ipjoxzjnchgejs")
                .withPriority(178199431)
                .withEnabledState(CustomRuleEnabledState.ENABLED)
                .withRuleType(RuleType.RATE_LIMIT_RULE)
                .withRateLimitDurationInMinutes(1543997460)
                .withRateLimitThreshold(1345546955)
                .withMatchConditions(
                    Arrays
                        .asList(
                            new MatchCondition()
                                .withMatchVariable(MatchVariable.REQUEST_BODY)
                                .withSelector("o")
                                .withOperator(Operator.BEGINS_WITH)
                                .withNegateCondition(false)
                                .withMatchValue(Arrays.asList("uxinpmqnjaq", "ixjsprozvcputeg", "vwmf"))
                                .withTransforms(Arrays.asList(TransformType.URL_DECODE))))
                .withAction(ActionType.BLOCK);
        model = BinaryData.fromObject(model).toObject(CustomRule.class);
        Assertions.assertEquals("ipjoxzjnchgejs", model.name());
        Assertions.assertEquals(178199431, model.priority());
        Assertions.assertEquals(CustomRuleEnabledState.ENABLED, model.enabledState());
        Assertions.assertEquals(RuleType.RATE_LIMIT_RULE, model.ruleType());
        Assertions.assertEquals(1543997460, model.rateLimitDurationInMinutes());
        Assertions.assertEquals(1345546955, model.rateLimitThreshold());
        Assertions.assertEquals(MatchVariable.REQUEST_BODY, model.matchConditions().get(0).matchVariable());
        Assertions.assertEquals("o", model.matchConditions().get(0).selector());
        Assertions.assertEquals(Operator.BEGINS_WITH, model.matchConditions().get(0).operator());
        Assertions.assertEquals(false, model.matchConditions().get(0).negateCondition());
        Assertions.assertEquals("uxinpmqnjaq", model.matchConditions().get(0).matchValue().get(0));
        Assertions.assertEquals(TransformType.URL_DECODE, model.matchConditions().get(0).transforms().get(0));
        Assertions.assertEquals(ActionType.BLOCK, model.action());
    }
}
