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

package com.azure.resourcemanager.kubernetesconfiguration.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.kubernetesconfiguration.models.PatchExtension;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class PatchExtensionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        PatchExtension model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"autoUpgradeMinorVersion\":true,\"releaseTrain\":\"ikxwc\",\"version\":\"yscnpqxu\",\"configurationSettings\":{\"n\":\"y\"},\"configurationProtectedSettings\":{\"vd\":\"ybrk\"}}}")
                .toObject(PatchExtension.class);
        Assertions.assertEquals(true, model.autoUpgradeMinorVersion());
        Assertions.assertEquals("ikxwc", model.releaseTrain());
        Assertions.assertEquals("yscnpqxu", model.version());
        Assertions.assertEquals("y", model.configurationSettings().get("n"));
        Assertions.assertEquals("ybrk", model.configurationProtectedSettings().get("vd"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        PatchExtension model =
            new PatchExtension()
                .withAutoUpgradeMinorVersion(true)
                .withReleaseTrain("ikxwc")
                .withVersion("yscnpqxu")
                .withConfigurationSettings(mapOf("n", "y"))
                .withConfigurationProtectedSettings(mapOf("vd", "ybrk"));
        model = BinaryData.fromObject(model).toObject(PatchExtension.class);
        Assertions.assertEquals(true, model.autoUpgradeMinorVersion());
        Assertions.assertEquals("ikxwc", model.releaseTrain());
        Assertions.assertEquals("yscnpqxu", model.version());
        Assertions.assertEquals("y", model.configurationSettings().get("n"));
        Assertions.assertEquals("ybrk", model.configurationProtectedSettings().get("vd"));
    }

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