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

package com.azure.resourcemanager.webpubsub.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.webpubsub.fluent.models.WebPubSubHubInner;
import com.azure.resourcemanager.webpubsub.models.EventHandler;
import com.azure.resourcemanager.webpubsub.models.EventListener;
import com.azure.resourcemanager.webpubsub.models.EventListenerEndpoint;
import com.azure.resourcemanager.webpubsub.models.EventListenerFilter;
import com.azure.resourcemanager.webpubsub.models.ManagedIdentitySettings;
import com.azure.resourcemanager.webpubsub.models.UpstreamAuthSettings;
import com.azure.resourcemanager.webpubsub.models.UpstreamAuthType;
import com.azure.resourcemanager.webpubsub.models.WebPubSubHubProperties;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class WebPubSubHubInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WebPubSubHubInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"eventHandlers\":[{\"urlTemplate\":\"fq\",\"userEventPattern\":\"mtdh\",\"systemEvents\":[\"vypgikdg\",\"zywkb\",\"rryuzhlhkjo\"],\"auth\":{\"type\":\"ManagedIdentity\",\"managedIdentity\":{\"resource\":\"atjinrvgoupmfiib\"}}},{\"urlTemplate\":\"ggjioolvr\",\"userEventPattern\":\"kvtkkg\",\"systemEvents\":[\"wjygvjayvblmhvk\",\"uhbxvvy\"],\"auth\":{\"type\":\"ManagedIdentity\",\"managedIdentity\":{\"resource\":\"yrqufegxuvwz\"}}}],\"eventListeners\":[{\"filter\":{\"type\":\"EventListenerFilter\"},\"endpoint\":{\"type\":\"EventListenerEndpoint\"}},{\"filter\":{\"type\":\"EventListenerFilter\"},\"endpoint\":{\"type\":\"EventListenerEndpoint\"}},{\"filter\":{\"type\":\"EventListenerFilter\"},\"endpoint\":{\"type\":\"EventListenerEndpoint\"}}],\"anonymousConnectPolicy\":\"lmctlpd\"},\"id\":\"gitvg\",\"name\":\"mhrixkwmyijejve\",\"type\":\"rh\"}")
                .toObject(WebPubSubHubInner.class);
        Assertions.assertEquals("fq", model.properties().eventHandlers().get(0).urlTemplate());
        Assertions.assertEquals("mtdh", model.properties().eventHandlers().get(0).userEventPattern());
        Assertions.assertEquals("vypgikdg", model.properties().eventHandlers().get(0).systemEvents().get(0));
        Assertions
            .assertEquals(UpstreamAuthType.MANAGED_IDENTITY, model.properties().eventHandlers().get(0).auth().type());
        Assertions
            .assertEquals(
                "atjinrvgoupmfiib", model.properties().eventHandlers().get(0).auth().managedIdentity().resource());
        Assertions.assertEquals("lmctlpd", model.properties().anonymousConnectPolicy());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WebPubSubHubInner model =
            new WebPubSubHubInner()
                .withProperties(
                    new WebPubSubHubProperties()
                        .withEventHandlers(
                            Arrays
                                .asList(
                                    new EventHandler()
                                        .withUrlTemplate("fq")
                                        .withUserEventPattern("mtdh")
                                        .withSystemEvents(Arrays.asList("vypgikdg", "zywkb", "rryuzhlhkjo"))
                                        .withAuth(
                                            new UpstreamAuthSettings()
                                                .withType(UpstreamAuthType.MANAGED_IDENTITY)
                                                .withManagedIdentity(
                                                    new ManagedIdentitySettings().withResource("atjinrvgoupmfiib"))),
                                    new EventHandler()
                                        .withUrlTemplate("ggjioolvr")
                                        .withUserEventPattern("kvtkkg")
                                        .withSystemEvents(Arrays.asList("wjygvjayvblmhvk", "uhbxvvy"))
                                        .withAuth(
                                            new UpstreamAuthSettings()
                                                .withType(UpstreamAuthType.MANAGED_IDENTITY)
                                                .withManagedIdentity(
                                                    new ManagedIdentitySettings().withResource("yrqufegxuvwz")))))
                        .withEventListeners(
                            Arrays
                                .asList(
                                    new EventListener()
                                        .withFilter(new EventListenerFilter())
                                        .withEndpoint(new EventListenerEndpoint()),
                                    new EventListener()
                                        .withFilter(new EventListenerFilter())
                                        .withEndpoint(new EventListenerEndpoint()),
                                    new EventListener()
                                        .withFilter(new EventListenerFilter())
                                        .withEndpoint(new EventListenerEndpoint())))
                        .withAnonymousConnectPolicy("lmctlpd"));
        model = BinaryData.fromObject(model).toObject(WebPubSubHubInner.class);
        Assertions.assertEquals("fq", model.properties().eventHandlers().get(0).urlTemplate());
        Assertions.assertEquals("mtdh", model.properties().eventHandlers().get(0).userEventPattern());
        Assertions.assertEquals("vypgikdg", model.properties().eventHandlers().get(0).systemEvents().get(0));
        Assertions
            .assertEquals(UpstreamAuthType.MANAGED_IDENTITY, model.properties().eventHandlers().get(0).auth().type());
        Assertions
            .assertEquals(
                "atjinrvgoupmfiib", model.properties().eventHandlers().get(0).auth().managedIdentity().resource());
        Assertions.assertEquals("lmctlpd", model.properties().anonymousConnectPolicy());
    }
}
