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

package com.azure.resourcemanager.securitydevops.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.securitydevops.fluent.models.AzureDevOpsConnectorInner;
import com.azure.resourcemanager.securitydevops.models.AzureDevOpsConnectorListResponse;
import com.azure.resourcemanager.securitydevops.models.AzureDevOpsConnectorProperties;
import com.azure.resourcemanager.securitydevops.models.ProvisioningState;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class AzureDevOpsConnectorListResponseTests {
    @Test
    public void testDeserialize() {
        AzureDevOpsConnectorListResponse model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"provisioningState\":\"Succeeded\",\"orgs\":[]},\"location\":\"xpyb\",\"tags\":{\"sphrupidgs\":\"ehmtzop\"},\"id\":\"bb\",\"name\":\"jhphoyc\",\"type\":\"sx\"},{\"properties\":{\"provisioningState\":\"Succeeded\",\"orgs\":[]},\"location\":\"mtqio\",\"tags\":{\"fpownoizhwlr\":\"ehtbm\",\"dmbpazlobcufpdz\":\"ybqsoqijg\"},\"id\":\"rbt\",\"name\":\"qqjnqgl\",\"type\":\"qgn\"},{\"properties\":{\"provisioningState\":\"Succeeded\",\"orgs\":[]},\"location\":\"wifsq\",\"tags\":{\"xrifkwmrvkts\":\"agdfmglzlh\",\"ucmpoyfd\":\"zntocipaouajps\"},\"id\":\"fogknygjofjdde\",\"name\":\"s\",\"type\":\"deupewnwrei\"}],\"nextLink\":\"zyf\"}")
                .toObject(AzureDevOpsConnectorListResponse.class);
        Assertions.assertEquals("xpyb", model.value().get(0).location());
        Assertions.assertEquals("ehmtzop", model.value().get(0).tags().get("sphrupidgs"));
        Assertions.assertEquals(ProvisioningState.SUCCEEDED, model.value().get(0).properties().provisioningState());
        Assertions.assertEquals("zyf", model.nextLink());
    }

    @Test
    public void testSerialize() {
        AzureDevOpsConnectorListResponse model =
            new AzureDevOpsConnectorListResponse()
                .withValue(
                    Arrays
                        .asList(
                            new AzureDevOpsConnectorInner()
                                .withLocation("xpyb")
                                .withTags(mapOf("sphrupidgs", "ehmtzop"))
                                .withProperties(
                                    new AzureDevOpsConnectorProperties()
                                        .withProvisioningState(ProvisioningState.SUCCEEDED)
                                        .withOrgs(Arrays.asList())),
                            new AzureDevOpsConnectorInner()
                                .withLocation("mtqio")
                                .withTags(mapOf("fpownoizhwlr", "ehtbm", "dmbpazlobcufpdz", "ybqsoqijg"))
                                .withProperties(
                                    new AzureDevOpsConnectorProperties()
                                        .withProvisioningState(ProvisioningState.SUCCEEDED)
                                        .withOrgs(Arrays.asList())),
                            new AzureDevOpsConnectorInner()
                                .withLocation("wifsq")
                                .withTags(mapOf("xrifkwmrvkts", "agdfmglzlh", "ucmpoyfd", "zntocipaouajps"))
                                .withProperties(
                                    new AzureDevOpsConnectorProperties()
                                        .withProvisioningState(ProvisioningState.SUCCEEDED)
                                        .withOrgs(Arrays.asList()))))
                .withNextLink("zyf");
        model = BinaryData.fromObject(model).toObject(AzureDevOpsConnectorListResponse.class);
        Assertions.assertEquals("xpyb", model.value().get(0).location());
        Assertions.assertEquals("ehmtzop", model.value().get(0).tags().get("sphrupidgs"));
        Assertions.assertEquals(ProvisioningState.SUCCEEDED, model.value().get(0).properties().provisioningState());
        Assertions.assertEquals("zyf", model.nextLink());
    }

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