Blame | Last modification | View Log | RSS feed
package com.erggroup.buildtool.utf;import static org.junit.Assert.*;import org.junit.Test;import com.erggroup.buildtool.utilities.XmlBuilder;public class XmlBuilderTest {private static final String mlf = new String( System.getProperty("line.separator") );@Testpublic void BasicXmlElement(){XmlBuilder element = new XmlBuilder("test1");assertTrue(element.toString(" ").equals(" <test1/>" + mlf));}@Testpublic void XmlWith1Attribute(){XmlBuilder element = new XmlBuilder("test2");element.addAttribute("attr1", "value1");assertTrue(element.toString(" ").equals(" <test2 attr1=\"value1\"/>" + mlf));}@Testpublic void XmlWithIntAttribute(){XmlBuilder element = new XmlBuilder("test2");element.addAttribute("attr1", 1234);assertTrue(element.toString(" ").equals(" <test2 attr1=\"1234\"/>" + mlf));}@Testpublic void XmlWithLongAttribute(){XmlBuilder element = new XmlBuilder("test2");element.addAttribute("attr1", 12345671234567890L);assertTrue(element.toString(" ").equals(" <test2 attr1=\"12345671234567890\"/>" + mlf));}@Testpublic void XmlWith2Attribute(){XmlBuilder element = new XmlBuilder("test3");element.addAttribute("attr1", "value1").addAttribute("attr2", "value2");assertTrue(element.toString(" ").equals(" <test3 attr1=\"value1\" attr2=\"value2\"/>" + mlf));}@Testpublic void XmlWith1Element(){XmlBuilder element = new XmlBuilder("test4");XmlBuilder element1 = new XmlBuilder("testa");element.addAttribute("attr1", "value1");element1.addAttribute("attr2", "value2");element.addElement(element1);String expect = " <test4 attr1=\"value1\">" + mlf +" <testa attr2=\"value2\"/>" + mlf +" </test4>" +mlf;assertTrue(element.toString(" ").equals(expect));}@Testpublic void XmlWith2Element(){XmlBuilder element = new XmlBuilder("test4");XmlBuilder element1 = new XmlBuilder("testa");XmlBuilder element2 = new XmlBuilder("testb");element.addAttribute("attr1", "value1");element1.addAttribute("attr2", "value2");element2.addAttribute("attr3", "value3");element.addElement(element1).addElement(element2);String expect = " <test4 attr1=\"value1\">" + mlf +" <testa attr2=\"value2\"/>" + mlf +" <testb attr3=\"value3\"/>" + mlf +" </test4>" +mlf;assertTrue(element.toString(" ").equals(expect));}@Testpublic void XmlWithComment(){XmlBuilder element = new XmlBuilder("testc").isComment();//System.out.println("testx:" + mlf +element.toString());assertTrue(element.toString(" ").equals(" <!-- testc -->" + mlf));}@Testpublic void XmlMixed(){XmlBuilder element = new XmlBuilder("test4");XmlBuilder element1 = new XmlBuilder("testa");XmlBuilder element2 = new XmlBuilder("testb");XmlBuilder element3 = new XmlBuilder("testc");XmlBuilder elementc = new XmlBuilder("This is a comment").isComment();element.addAttribute("attr1", "value1");element1.addAttribute("attr2", "value2");element2.addAttribute("attr3", "value3");element3.addAttribute("attr4", "value4").addAttribute("attr5", "value6");element.addElement(elementc).addElement(element1).addElement(element2);element1.addElement(element3);String expect = " <test4 attr1=\"value1\">" + mlf +" <!-- This is a comment -->" + mlf +" <testa attr2=\"value2\">" + mlf +" <testc attr4=\"value4\" attr5=\"value6\"/>" + mlf +" </testa>" + mlf +" <testb attr3=\"value3\"/>" + mlf +" </test4>" +mlf;//System.out.println("testx:" + mlf +element.toString(" "));//System.out.println("teste:" + mlf +expect);assertTrue(element.toString(" ").equals(expect));}@Testpublic void XmlMixedConcat(){XmlBuilder element = new XmlBuilder("test4");element.addAttribute("attr1", "value1").addNewElement("testa").addAttribute("attr2", "value2").addComment("This is a comment").addNewElement("testb").addAttribute("attr3", "value3").addAttribute("attr4", "value4");String expect = " <test4 attr1=\"value1\">" + mlf +" <testa attr2=\"value2\">" + mlf +" <!-- This is a comment -->" + mlf +" <testb attr3=\"value3\" attr4=\"value4\"/>" + mlf +" </testa>" + mlf+" </test4>" +mlf;//System.out.println("testx:" + mlf +element.toString(" "));//System.out.println("teste:" + mlf +expect);assertTrue(element.toString(" ").equals(expect));}}