/**
 * 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 SsmlBreak}
 */
public class SsmlBreakTest {
    @Test
    public void testEmptyElement() {
        SsmlBreak elem = new SsmlBreak.Builder().build();

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

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

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

    @Test
    public void testElementWithParams() {
        SsmlBreak elem = new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build();

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

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

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

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

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

        SsmlBreak elem = builder.build();

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

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

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

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

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

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

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

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

    @Test
    public void testXmlAttributesDeserialization() {
        final SsmlBreak elem = new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build();

        Assert.assertEquals(
            SsmlBreak.Builder.fromXml("<break strength=\"none\" time=\"time\"/>").build().toXml(),
            elem.toXml()
        );
    }
}