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

package com.azure.resourcemanager.servicefabric.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.servicefabric.models.ApplicationDeltaHealthPolicy;
import com.azure.resourcemanager.servicefabric.models.ApplicationHealthPolicy;
import com.azure.resourcemanager.servicefabric.models.ClusterHealthPolicy;
import com.azure.resourcemanager.servicefabric.models.ClusterUpgradeDeltaHealthPolicy;
import com.azure.resourcemanager.servicefabric.models.ClusterUpgradePolicy;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ClusterUpgradePolicyTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ClusterUpgradePolicy model =
            BinaryData
                .fromString(
                    "{\"forceRestart\":false,\"upgradeReplicaSetCheckTimeout\":\"wvukx\",\"healthCheckWaitDuration\":\"audccsnhs\",\"healthCheckStableDuration\":\"cnyejhkryhtnapcz\",\"healthCheckRetryTimeout\":\"lokjyemkk\",\"upgradeTimeout\":\"ni\",\"upgradeDomainTimeout\":\"joxzjnchgejspodm\",\"healthPolicy\":{\"maxPercentUnhealthyNodes\":1543997460,\"maxPercentUnhealthyApplications\":1345546955,\"applicationHealthPolicies\":{\"jwyahuxinpmqnja\":{\"serviceTypeHealthPolicies\":{}}}},\"deltaHealthPolicy\":{\"maxPercentDeltaUnhealthyNodes\":1876507017,\"maxPercentUpgradeDomainDeltaUnhealthyNodes\":288433409,\"maxPercentDeltaUnhealthyApplications\":1052966015,\"applicationDeltaHealthPolicies\":{\"zvcputegjvwmfda\":{\"serviceTypeDeltaHealthPolicies\":{}},\"mdvpjhulsu\":{\"serviceTypeDeltaHealthPolicies\":{}},\"kjozkrwfnd\":{\"serviceTypeDeltaHealthPolicies\":{}},\"jpslwejd\":{\"serviceTypeDeltaHealthPolicies\":{}}}}}")
                .toObject(ClusterUpgradePolicy.class);
        Assertions.assertEquals(false, model.forceRestart());
        Assertions.assertEquals("wvukx", model.upgradeReplicaSetCheckTimeout());
        Assertions.assertEquals("audccsnhs", model.healthCheckWaitDuration());
        Assertions.assertEquals("cnyejhkryhtnapcz", model.healthCheckStableDuration());
        Assertions.assertEquals("lokjyemkk", model.healthCheckRetryTimeout());
        Assertions.assertEquals("ni", model.upgradeTimeout());
        Assertions.assertEquals("joxzjnchgejspodm", model.upgradeDomainTimeout());
        Assertions.assertEquals(1543997460, model.healthPolicy().maxPercentUnhealthyNodes());
        Assertions.assertEquals(1345546955, model.healthPolicy().maxPercentUnhealthyApplications());
        Assertions.assertEquals(1876507017, model.deltaHealthPolicy().maxPercentDeltaUnhealthyNodes());
        Assertions.assertEquals(288433409, model.deltaHealthPolicy().maxPercentUpgradeDomainDeltaUnhealthyNodes());
        Assertions.assertEquals(1052966015, model.deltaHealthPolicy().maxPercentDeltaUnhealthyApplications());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ClusterUpgradePolicy model =
            new ClusterUpgradePolicy()
                .withForceRestart(false)
                .withUpgradeReplicaSetCheckTimeout("wvukx")
                .withHealthCheckWaitDuration("audccsnhs")
                .withHealthCheckStableDuration("cnyejhkryhtnapcz")
                .withHealthCheckRetryTimeout("lokjyemkk")
                .withUpgradeTimeout("ni")
                .withUpgradeDomainTimeout("joxzjnchgejspodm")
                .withHealthPolicy(
                    new ClusterHealthPolicy()
                        .withMaxPercentUnhealthyNodes(1543997460)
                        .withMaxPercentUnhealthyApplications(1345546955)
                        .withApplicationHealthPolicies(
                            mapOf(
                                "jwyahuxinpmqnja",
                                new ApplicationHealthPolicy().withServiceTypeHealthPolicies(mapOf()))))
                .withDeltaHealthPolicy(
                    new ClusterUpgradeDeltaHealthPolicy()
                        .withMaxPercentDeltaUnhealthyNodes(1876507017)
                        .withMaxPercentUpgradeDomainDeltaUnhealthyNodes(288433409)
                        .withMaxPercentDeltaUnhealthyApplications(1052966015)
                        .withApplicationDeltaHealthPolicies(
                            mapOf(
                                "zvcputegjvwmfda",
                                new ApplicationDeltaHealthPolicy().withServiceTypeDeltaHealthPolicies(mapOf()),
                                "mdvpjhulsu",
                                new ApplicationDeltaHealthPolicy().withServiceTypeDeltaHealthPolicies(mapOf()),
                                "kjozkrwfnd",
                                new ApplicationDeltaHealthPolicy().withServiceTypeDeltaHealthPolicies(mapOf()),
                                "jpslwejd",
                                new ApplicationDeltaHealthPolicy().withServiceTypeDeltaHealthPolicies(mapOf()))));
        model = BinaryData.fromObject(model).toObject(ClusterUpgradePolicy.class);
        Assertions.assertEquals(false, model.forceRestart());
        Assertions.assertEquals("wvukx", model.upgradeReplicaSetCheckTimeout());
        Assertions.assertEquals("audccsnhs", model.healthCheckWaitDuration());
        Assertions.assertEquals("cnyejhkryhtnapcz", model.healthCheckStableDuration());
        Assertions.assertEquals("lokjyemkk", model.healthCheckRetryTimeout());
        Assertions.assertEquals("ni", model.upgradeTimeout());
        Assertions.assertEquals("joxzjnchgejspodm", model.upgradeDomainTimeout());
        Assertions.assertEquals(1543997460, model.healthPolicy().maxPercentUnhealthyNodes());
        Assertions.assertEquals(1345546955, model.healthPolicy().maxPercentUnhealthyApplications());
        Assertions.assertEquals(1876507017, model.deltaHealthPolicy().maxPercentDeltaUnhealthyNodes());
        Assertions.assertEquals(288433409, model.deltaHealthPolicy().maxPercentUpgradeDomainDeltaUnhealthyNodes());
        Assertions.assertEquals(1052966015, model.deltaHealthPolicy().maxPercentDeltaUnhealthyApplications());
    }

    @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;
    }
}
