/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.apache.poi.hwpf.converter;
import static org.apache.poi.POITestCase.assertContains;
import java.io.StringWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.util.XMLHelper;
import org.junit.jupiter.api.Test;
/**
* Test cases for {@link WordToFoConverter}
*/
public class TestWordToFoConverter
{
private static String getFoText( final String sampleFileName )
throws Exception
{
HWPFDocument hwpfDocument = new HWPFDocument( POIDataSamples
.getDocumentInstance().openResourceAsStream( sampleFileName ) );
WordToFoConverter wordToFoConverter = new WordToFoConverter(
XMLHelper.newDocumentBuilder().newDocument() );
wordToFoConverter.processDocument( hwpfDocument );
StringWriter stringWriter = new StringWriter();
Transformer transformer = XMLHelper.newTransformer();
transformer.transform(
new DOMSource( wordToFoConverter.getDocument() ),
new StreamResult( stringWriter ) );
return stringWriter.toString();
}
@Test
void testDocumentProperties() throws Exception
{
String result = getFoText( "documentProperties.doc" );
assertContains(
result,
"This is document title" );
assertContains(
result,
"This is document keywords" );
}
@Test
void testEndnote() throws Exception
{
String result = getFoText( "endingnote.doc" );
assertContains( result,
"" );
assertContains( result,
"1" );
assertContains( result,
"" );
assertContains( result,
"1 " );
assertContains( result, "Ending note text" );
}
@Test
void testEquation() throws Exception
{
final String sampleFileName = "equation.doc";
String result = getFoText( sampleFileName );
assertContains( result, "" );
}
@Test
void testHyperlink() throws Exception
{
final String sampleFileName = "hyperlink.doc";
String result = getFoText( sampleFileName );
assertContains( result,
"" );
assertContains( result, "Hyperlink text" );
}
@Test
void testInnerTable() throws Exception
{
final String sampleFileName = "innertable.doc";
String result = getFoText( sampleFileName );
assertContains( result,
"padding-end=\"0.0in\" padding-start=\"0.0in\" width=\"1.0770833in\"" );
}
@Test
void testPageBreak() throws Exception
{
final String sampleFileName = "page-break.doc";
String result = getFoText( sampleFileName );
assertContains( result, "" );
assertContains( result, "1" );
assertContains( result, "" );
}
}