Adding regression test for sources from website - odftoolkit/simple/gettingstartguide.html
@@ -33,16 +33,15 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
+import java.net.URI;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
-
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -63,6 +62,8 @@ import org.odftoolkit.odfdom.pkg.OdfFileDom;
import org.odftoolkit.odfdom.pkg.OdfName;
import org.odftoolkit.odfdom.pkg.OdfPackage;
import org.odftoolkit.odfdom.pkg.OdfValidationException;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Table;
import org.odftoolkit.simple.utils.NodeAction;
import org.odftoolkit.simple.utils.ResourceUtilities;
import org.w3c.dom.Node;
@@ -576,6 +577,38 @@ public class DocumentTest {
LOG.log(Level.SEVERE, e.getMessage(), e);
Assert.fail(e.getMessage());
}
+ }
+
+ @Test
+ /**
+ * Testing the 'Hello World' example of https://incubator.apache.org/odftoolkit/simple/gettingstartguide.html
+ */
+ public void testHelloWorldExample() throws Exception {
+ TextDocument outputOdt;
+ try {
+ outputOdt = TextDocument.newTextDocument();
+
+ // add image
+ outputOdt.newImage(new URI(ResourceUtilities.getAbsolutePath("testA.jpg")));
+ // add paragraph
+ outputOdt.addParagraph("Hello World, Hello Simple ODF!");
+
+ // add list
+ outputOdt.addParagraph("The following is a list.");
+ org.odftoolkit.simple.text.list.List list = outputOdt.addList();
+ String[] items = {"item1", "item2", "item3"};
+ list.addItems(items);
+
+ // add table
+ Table table = outputOdt.addTable(2, 2);
+ Cell cell = table.getCellByPosition(0, 0);
+ cell.setStringValue("Hello World!");
+
+ outputOdt.save(ResourceUtilities.newTestOutputFile("HelloWorldExample.odt"));
+ outputOdt.close();
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, e.getMessage(), e);
+ }
}
}
