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

package com.azure.resourcemanager.chaos.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.chaos.fluent.models.ExperimentInner;
import com.azure.resourcemanager.chaos.models.Action;
import com.azure.resourcemanager.chaos.models.Branch;
import com.azure.resourcemanager.chaos.models.Filter;
import com.azure.resourcemanager.chaos.models.ResourceIdentity;
import com.azure.resourcemanager.chaos.models.ResourceIdentityType;
import com.azure.resourcemanager.chaos.models.Selector;
import com.azure.resourcemanager.chaos.models.Step;
import com.azure.resourcemanager.chaos.models.UserAssignedIdentity;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ExperimentInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ExperimentInner model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{\"udwtiukbl\":{\"principalId\":\"a61f533d-4cb4-48c5-b497-037970f7a5e4\",\"clientId\":\"a2b0ed87-2549-4a89-a548-e0201ea73b97\"},\"kpoc\":{\"principalId\":\"42cfbeff-7124-4ed5-9328-09adb1b652ac\",\"clientId\":\"dfd5c108-4321-42c2-a063-44f4503fa5fa\"},\"z\":{\"principalId\":\"a42405b6-1569-4569-ad74-4ffedceb4851\",\"clientId\":\"206e8550-f951-4176-b6b6-464869be91a1\"}},\"principalId\":\"o\",\"tenantId\":\"ukgjnpiucgygevq\"},\"properties\":{\"steps\":[{\"name\":\"typmrbpizcdrqjsd\",\"branches\":[{\"name\":\"dnfyhxdeoejzicwi\",\"actions\":[{\"type\":\"Action\",\"name\":\"jttgzf\"},{\"type\":\"Action\",\"name\":\"ishc\"},{\"type\":\"Action\",\"name\":\"khaj\"}]},{\"name\":\"eyeam\",\"actions\":[{\"type\":\"Action\",\"name\":\"hagalpbuxwgipwh\"}]},{\"name\":\"nowkgshw\",\"actions\":[{\"type\":\"Action\",\"name\":\"kix\"},{\"type\":\"Action\",\"name\":\"bin\"},{\"type\":\"Action\",\"name\":\"eputtmrywnuzoqf\"}]},{\"name\":\"iyqzrnk\",\"actions\":[{\"type\":\"Action\",\"name\":\"vyxlwhzlsicohoqq\"},{\"type\":\"Action\",\"name\":\"wvl\"},{\"type\":\"Action\",\"name\":\"yav\"},{\"type\":\"Action\",\"name\":\"hheunmmqhgyx\"}]}]},{\"name\":\"konocu\",\"branches\":[{\"name\":\"klyaxuconu\",\"actions\":[{\"type\":\"Action\",\"name\":\"zf\"},{\"type\":\"Action\",\"name\":\"beypewrmjmw\"}]},{\"name\":\"vjektcxsenh\",\"actions\":[{\"type\":\"Action\",\"name\":\"rsffrzpwvlqdqgbi\"}]},{\"name\":\"ylihkaetckt\",\"actions\":[{\"type\":\"Action\",\"name\":\"civfsnkymuctq\"},{\"type\":\"Action\",\"name\":\"jf\"},{\"type\":\"Action\",\"name\":\"ebrjcxe\"}]}]},{\"name\":\"fuwutttxf\",\"branches\":[{\"name\":\"rbirphxe\",\"actions\":[{\"type\":\"Action\",\"name\":\"yva\"}]},{\"name\":\"fnljky\",\"actions\":[{\"type\":\"Action\",\"name\":\"j\"},{\"type\":\"Action\",\"name\":\"uujqgidokgjljyo\"},{\"type\":\"Action\",\"name\":\"gvcl\"},{\"type\":\"Action\",\"name\":\"bgsncghkjeszzhb\"}]},{\"name\":\"jhtxfvgxbfsmxne\",\"actions\":[{\"type\":\"Action\",\"name\":\"pvecxgodeb\"},{\"type\":\"Action\",\"name\":\"qkkrb\"},{\"type\":\"Action\",\"name\":\"pukgriwflzlfb\"},{\"type\":\"Action\",\"name\":\"zpuzycisp\"}]},{\"name\":\"qzahmgkbrp\",\"actions\":[{\"type\":\"Action\",\"name\":\"dhibnuq\"}]}]},{\"name\":\"kpikadrgvt\",\"branches\":[{\"name\":\"gnbuy\",\"actions\":[{\"type\":\"Action\",\"name\":\"ijggmebfsiar\"},{\"type\":\"Action\",\"name\":\"utrc\"}]}]}],\"selectors\":[{\"type\":\"Selector\",\"id\":\"na\",\"filter\":{\"type\":\"Filter\"},\"\":{\"bh\":\"datajrunmpxtt\"}},{\"type\":\"Selector\",\"id\":\"bnlankxmyskpb\",\"filter\":{\"type\":\"Filter\"},\"\":{\"lqidyby\":\"datatkcxywnytnrsy\",\"haaxdbabphl\":\"dataczfc\",\"yazttbtwwrqpue\":\"datarqlfktsthsucocmn\",\"xibxujwbhqwalm\":\"datackzywbiexzfeyue\"}}],\"startOnCreation\":false},\"location\":\"oxaepd\",\"tags\":{\"bavxbniwdjswzt\":\"ancuxrhd\",\"xbzpfzab\":\"dbpgnxytxhp\"},\"id\":\"lcuhxwtctyqiklb\",\"name\":\"ovplw\",\"type\":\"bhvgy\"}")
                .toObject(ExperimentInner.class);
        Assertions.assertEquals("oxaepd", model.location());
        Assertions.assertEquals("ancuxrhd", model.tags().get("bavxbniwdjswzt"));
        Assertions.assertEquals(ResourceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals("typmrbpizcdrqjsd", model.steps().get(0).name());
        Assertions.assertEquals("dnfyhxdeoejzicwi", model.steps().get(0).branches().get(0).name());
        Assertions.assertEquals("jttgzf", model.steps().get(0).branches().get(0).actions().get(0).name());
        Assertions.assertEquals("na", model.selectors().get(0).id());
        Assertions.assertEquals(false, model.startOnCreation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ExperimentInner model =
            new ExperimentInner()
                .withLocation("oxaepd")
                .withTags(mapOf("bavxbniwdjswzt", "ancuxrhd", "xbzpfzab", "dbpgnxytxhp"))
                .withIdentity(
                    new ResourceIdentity()
                        .withType(ResourceIdentityType.NONE)
                        .withUserAssignedIdentities(
                            mapOf(
                                "udwtiukbl",
                                new UserAssignedIdentity(),
                                "kpoc",
                                new UserAssignedIdentity(),
                                "z",
                                new UserAssignedIdentity())))
                .withSteps(
                    Arrays
                        .asList(
                            new Step()
                                .withName("typmrbpizcdrqjsd")
                                .withBranches(
                                    Arrays
                                        .asList(
                                            new Branch()
                                                .withName("dnfyhxdeoejzicwi")
                                                .withActions(
                                                    Arrays
                                                        .asList(
                                                            new Action().withName("jttgzf"),
                                                            new Action().withName("ishc"),
                                                            new Action().withName("khaj"))),
                                            new Branch()
                                                .withName("eyeam")
                                                .withActions(Arrays.asList(new Action().withName("hagalpbuxwgipwh"))),
                                            new Branch()
                                                .withName("nowkgshw")
                                                .withActions(
                                                    Arrays
                                                        .asList(
                                                            new Action().withName("kix"),
                                                            new Action().withName("bin"),
                                                            new Action().withName("eputtmrywnuzoqf"))),
                                            new Branch()
                                                .withName("iyqzrnk")
                                                .withActions(
                                                    Arrays
                                                        .asList(
                                                            new Action().withName("vyxlwhzlsicohoqq"),
                                                            new Action().withName("wvl"),
                                                            new Action().withName("yav"),
                                                            new Action().withName("hheunmmqhgyx"))))),
                            new Step()
                                .withName("konocu")
                                .withBranches(
                                    Arrays
                                        .asList(
                                            new Branch()
                                                .withName("klyaxuconu")
                                                .withActions(
                                                    Arrays
                                                        .asList(
                                                            new Action().withName("zf"),
                                                            new Action().withName("beypewrmjmw"))),
                                            new Branch()
                                                .withName("vjektcxsenh")
                                                .withActions(Arrays.asList(new Action().withName("rsffrzpwvlqdqgbi"))),
                                            new Branch()
                                                .withName("ylihkaetckt")
                                                .withActions(
                                                    Arrays
                                                        .asList(
                                                            new Action().withName("civfsnkymuctq"),
                                                            new Action().withName("jf"),
                                                            new Action().withName("ebrjcxe"))))),
                            new Step()
                                .withName("fuwutttxf")
                                .withBranches(
                                    Arrays
                                        .asList(
                                            new Branch()
                                                .withName("rbirphxe")
                                                .withActions(Arrays.asList(new Action().withName("yva"))),
                                            new Branch()
                                                .withName("fnljky")
                                                .withActions(
                                                    Arrays
                                                        .asList(
                                                            new Action().withName("j"),
                                                            new Action().withName("uujqgidokgjljyo"),
                                                            new Action().withName("gvcl"),
                                                            new Action().withName("bgsncghkjeszzhb"))),
                                            new Branch()
                                                .withName("jhtxfvgxbfsmxne")
                                                .withActions(
                                                    Arrays
                                                        .asList(
                                                            new Action().withName("pvecxgodeb"),
                                                            new Action().withName("qkkrb"),
                                                            new Action().withName("pukgriwflzlfb"),
                                                            new Action().withName("zpuzycisp"))),
                                            new Branch()
                                                .withName("qzahmgkbrp")
                                                .withActions(Arrays.asList(new Action().withName("dhibnuq"))))),
                            new Step()
                                .withName("kpikadrgvt")
                                .withBranches(
                                    Arrays
                                        .asList(
                                            new Branch()
                                                .withName("gnbuy")
                                                .withActions(
                                                    Arrays
                                                        .asList(
                                                            new Action().withName("ijggmebfsiar"),
                                                            new Action().withName("utrc")))))))
                .withSelectors(
                    Arrays
                        .asList(
                            new Selector()
                                .withId("na")
                                .withFilter(new Filter())
                                .withAdditionalProperties(mapOf("type", "Selector")),
                            new Selector()
                                .withId("bnlankxmyskpb")
                                .withFilter(new Filter())
                                .withAdditionalProperties(mapOf("type", "Selector"))))
                .withStartOnCreation(false);
        model = BinaryData.fromObject(model).toObject(ExperimentInner.class);
        Assertions.assertEquals("oxaepd", model.location());
        Assertions.assertEquals("ancuxrhd", model.tags().get("bavxbniwdjswzt"));
        Assertions.assertEquals(ResourceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals("typmrbpizcdrqjsd", model.steps().get(0).name());
        Assertions.assertEquals("dnfyhxdeoejzicwi", model.steps().get(0).branches().get(0).name());
        Assertions.assertEquals("jttgzf", model.steps().get(0).branches().get(0).actions().get(0).name());
        Assertions.assertEquals("na", model.selectors().get(0).id());
        Assertions.assertEquals(false, model.startOnCreation());
    }

    @SuppressWarnings("unchecked")
    private static <T> Map<String, T> mapOf(Object... inputs) {
        Map<String, T> map = new HashMap<>();
        for (int i = 0; i < inputs.length; i += 2) {
            String key = (String) inputs[i];
            T value = (T) inputs[i + 1];
            map.put(key, value);
        }
        return map;
    }
}
