Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Include XML declaration when exporting TMX, expand StreamSerializerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Aug 1, 2013
1 parent 66f13d1 commit 67e168c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Expand Up @@ -79,6 +79,7 @@ public void write(OutputStream output) throws IOException, WebApplicationExcepti
if (iter.hasNext()) iter.peek();

StreamSerializer tmxWriter = new StreamSerializer(output);
tmxWriter.writeXMLDeclaration();

Element tmx = new Element("tmx");
tmx.addAttribute(new Attribute("version", "1.4"));
Expand Down
30 changes: 22 additions & 8 deletions zanata-war/src/test/java/org/zanata/xml/StreamSerializerTest.java
Expand Up @@ -2,38 +2,52 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

import javax.xml.XMLConstants;

import nu.xom.Attribute;
import nu.xom.Element;

import org.hamcrest.text.StringContainsInOrder;
import org.testng.annotations.Test;
import org.zanata.xml.StreamSerializer;

public class StreamSerializerTest
{

@Test
public void streamSerializer() throws IOException
public void sanityTest() throws IOException
{
Element rootElement = new Element("root");
OutputStream out = new ByteArrayOutputStream();
StreamSerializer serializer = new StreamSerializer(out);

serializer.writeXMLDeclaration();
Element rootElement = new Element("root");
rootElement.addAttribute(new Attribute("rootAttr", "rootAttrVal"));
serializer.writeStartTag(rootElement);

serializer.write(new Element("sub"));
serializer.write(new Element("sub"));
serializer.write(new Element("sub"));
Element sub1 = new Element("sub");
sub1.addAttribute(new Attribute("subAttr", "subAttrVal"));
serializer.write(sub1);

Element sub2 = new Element("sub");
sub2.addAttribute(new Attribute("xml:lang", XMLConstants.XML_NS_URI, "en"));
serializer.write(sub2);

serializer.writeEndTag(rootElement);
serializer.flush();
String output = out.toString();

assertThat(output, containsString("<root><sub/><sub/><sub/></root>"));
assertThat(output, startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
String expected =
"<root rootAttr=\"rootAttrVal\">" +
"<sub subAttr=\"subAttrVal\"/>" +
"<sub xml:lang=\"en\"/>" +
"</root>";
assertThat(output, containsString(expected));
}
}

0 comments on commit 67e168c

Please sign in to comment.