/**
 * This code was generated by
 * \ / _    _  _|   _  _
 *  | (_)\/(_)(_|\/| |(/_  v1.0.0
 *       /       /
 */

package com.twilio.twiml.voice;

import com.twilio.twiml.GenericNode;
import org.junit.Assert;
import org.junit.Test;

/**
 * Test class for {@link VirtualAgent}
 */
public class VirtualAgentTest {
    @Test
    public void testEmptyElement() {
        VirtualAgent elem = new VirtualAgent.Builder().build();

        Assert.assertEquals(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<VirtualAgent/>",
            elem.toXml()
        );
    }

    @Test
    public void testEmptyElementUrl() {
        VirtualAgent elem = new VirtualAgent.Builder().build();

        Assert.assertEquals("%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3CVirtualAgent%2F%3E", elem.toUrl());
    }

    @Test
    public void testElementWithParams() {
        VirtualAgent elem = new VirtualAgent.Builder()
            .connectorName("connector_name")
            .language("language")
            .sentimentAnalysis(true)
            .statusCallback("status_callback")
            .build();

        Assert.assertEquals(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<VirtualAgent connectorName=\"connector_name\" language=\"language\" sentimentAnalysis=\"true\" statusCallback=\"status_callback\"/>",
            elem.toXml()
        );
    }

    @Test
    public void testElementWithExtraAttributes() {
        VirtualAgent elem = new VirtualAgent.Builder().option("foo", "bar").option("a", "b").build();

        Assert.assertEquals(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<VirtualAgent a=\"b\" foo=\"bar\"/>",
            elem.toXml()
        );
    }

    @Test
    public void testElementWithTextNode() {
        VirtualAgent.Builder builder = new VirtualAgent.Builder();

        builder.addText("Hey no tags!");

        VirtualAgent elem = builder.build();

        Assert.assertEquals(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<VirtualAgent>" +
            "Hey no tags!" +
            "</VirtualAgent>",
            elem.toXml()
        );
    }

    @Test
    public void testMixedContent() {
        GenericNode.Builder child = new GenericNode.Builder("Child");
        child.addText("content");

        VirtualAgent.Builder builder = new VirtualAgent.Builder();

        builder.addText("before");
        builder.addChild(child.build());
        builder.addText("after");

        Assert.assertEquals(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<VirtualAgent>" +
            "before" +
            "<Child>content</Child>" +
            "after" +
            "</VirtualAgent>",
            builder.build().toXml()
        );
    }

    @Test
    public void testElementWithGenericNode() {
        GenericNode.Builder genericBuilder = new GenericNode.Builder("genericTag");
        genericBuilder.addText("Some text");
        GenericNode node = genericBuilder.build();

        VirtualAgent.Builder builder = new VirtualAgent.Builder();
        VirtualAgent elem = builder.addChild(node).build();

        Assert.assertEquals(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<VirtualAgent>" +
            "<genericTag>" +
            "Some text" +
            "</genericTag>" +
            "</VirtualAgent>",
            elem.toXml()
        );
    }

    @Test
    public void testXmlAttributesDeserialization() {
        final VirtualAgent elem = new VirtualAgent.Builder()
            .connectorName("connector_name")
            .language("language")
            .sentimentAnalysis(true)
            .statusCallback("status_callback")
            .build();

        Assert.assertEquals(
            VirtualAgent.Builder.fromXml("<VirtualAgent connectorName=\"connector_name\" language=\"language\" sentimentAnalysis=\"true\" statusCallback=\"status_callback\"/>").build().toXml(),
            elem.toXml()
        );
    }
}