-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bug-67396] StreamHelper does not set standalone=yes when built-in ja…
…vax Transformer is used git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912305 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestStreamHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.apache.poi.openxml4j.opc; | ||
|
||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; | ||
import org.apache.poi.ooxml.util.DocumentHelper; | ||
import org.junit.jupiter.api.Test; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_WORDPROCESSINGML; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class TestStreamHelper { | ||
@Test | ||
void testStandaloneFlag() throws IOException { | ||
Document doc = DocumentHelper.createDocument(); | ||
Element elDocument = doc.createElementNS(NS_WORDPROCESSINGML, "w:document"); | ||
doc.appendChild(elDocument); | ||
Element elBody = doc.createElementNS(NS_WORDPROCESSINGML, "w:body"); | ||
elDocument.appendChild(elBody); | ||
Element elParagraph = doc.createElementNS(NS_WORDPROCESSINGML, "w:p"); | ||
elBody.appendChild(elParagraph); | ||
Element elRun = doc.createElementNS(NS_WORDPROCESSINGML, "w:r"); | ||
elParagraph.appendChild(elRun); | ||
Element elText = doc.createElementNS(NS_WORDPROCESSINGML, "w:t"); | ||
elRun.appendChild(elText); | ||
elText.setTextContent("Hello Open XML !"); | ||
|
||
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) { | ||
StreamHelper.saveXmlInStream(doc, bos); | ||
String xml = bos.toString(StandardCharsets.UTF_8); | ||
assertTrue(xml.contains("standalone=\"yes\""), "xml contains standalone=yes?"); | ||
assertTrue(xml.contains("encoding=\"UTF-8\""), "xml contains encoding=UTF-8?"); | ||
} | ||
} | ||
} |