// 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.models.EventHandler;
import com.azure.resourcemanager.webpubsub.models.ManagedIdentitySettings;
import com.azure.resourcemanager.webpubsub.models.UpstreamAuthSettings;
import com.azure.resourcemanager.webpubsub.models.UpstreamAuthType;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class EventHandlerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        EventHandler model =
            BinaryData
                .fromString(
                    "{\"urlTemplate\":\"myhgfipnsxkmc\",\"userEventPattern\":\"ekrrjr\",\"systemEvents\":[\"xt\",\"gumhjglikkxws\"],\"auth\":{\"type\":\"None\",\"managedIdentity\":{\"resource\":\"vuzlm\"}}}")
                .toObject(EventHandler.class);
        Assertions.assertEquals("myhgfipnsxkmc", model.urlTemplate());
        Assertions.assertEquals("ekrrjr", model.userEventPattern());
        Assertions.assertEquals("xt", model.systemEvents().get(0));
        Assertions.assertEquals(UpstreamAuthType.NONE, model.auth().type());
        Assertions.assertEquals("vuzlm", model.auth().managedIdentity().resource());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        EventHandler model =
            new EventHandler()
                .withUrlTemplate("myhgfipnsxkmc")
                .withUserEventPattern("ekrrjr")
                .withSystemEvents(Arrays.asList("xt", "gumhjglikkxws"))
                .withAuth(
                    new UpstreamAuthSettings()
                        .withType(UpstreamAuthType.NONE)
                        .withManagedIdentity(new ManagedIdentitySettings().withResource("vuzlm")));
        model = BinaryData.fromObject(model).toObject(EventHandler.class);
        Assertions.assertEquals("myhgfipnsxkmc", model.urlTemplate());
        Assertions.assertEquals("ekrrjr", model.userEventPattern());
        Assertions.assertEquals("xt", model.systemEvents().get(0));
        Assertions.assertEquals(UpstreamAuthType.NONE, model.auth().type());
        Assertions.assertEquals("vuzlm", model.auth().managedIdentity().resource());
    }
}
