}
public void testSetHeader() throws IOException {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
// no header is set (yet)
XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
assertNull(policy.getDefaultHeader());
assertNull(policy.getFirstPageHeader());
assertNull(policy.getDefaultFooter());
CTP ctP1 = CTP.Factory.newInstance();
CTR ctR1 = ctP1.addNewR();
CTText t = ctR1.addNewT();
t.setStringValue("Paragraph in header");
// Commented MB 23 May 2010
//CTP ctP2 = CTP.Factory.newInstance();
//CTR ctR2 = ctP2.addNewR();
//CTText t2 = ctR2.addNewT();
//t2.setStringValue("Second paragraph.. for footer");
// Create two paragraphs for insertion into the footer.
// Previously only one was inserted MB 23 May 2010
CTP ctP2 = CTP.Factory.newInstance();
CTR ctR2 = ctP2.addNewR();
CTText t2 = ctR2.addNewT();
t2.setStringValue("First paragraph for the footer");
CTP ctP3 = CTP.Factory.newInstance();
CTR ctR3 = ctP3.addNewR();
CTText t3 = ctR3.addNewT();
t3.setStringValue("Second paragraph for the footer");
XWPFParagraph p1 = new XWPFParagraph(ctP1, sampleDoc);
XWPFParagraph[] pars = new XWPFParagraph[1];
pars[0] = p1;
XWPFParagraph p2 = new XWPFParagraph(ctP2, sampleDoc);
XWPFParagraph p3 = new XWPFParagraph(ctP3, sampleDoc);
XWPFParagraph[] pars2 = new XWPFParagraph[2];
pars2[0] = p2;
pars2[1] = p3;
// Set headers
policy.createHeader(policy.DEFAULT, pars);
policy.createHeader(policy.FIRST);
// Set a default footer and capture the returned XWPFFooter object.
XWPFFooter footer = policy.createFooter(policy.DEFAULT, pars2);
// Ensure the headers and footer were set correctly....
assertNotNull(policy.getDefaultHeader());
assertNotNull(policy.getFirstPageHeader());
assertNotNull(policy.getDefaultFooter());
// ....and that the footer object captured above contains two
// paragraphs of text.
assertEquals(2, footer.getParagraphs().size());
// As an additional check, recover the defauls footer and
// make sure that it contains two paragraphs of text and that
// both do hold what is expected.
footer = policy.getDefaultFooter();
XWPFParagraph[] paras = new XWPFParagraph[footer.getParagraphs().size()];
int i=0;
for(XWPFParagraph p : footer.getParagraphs()) {
paras[i++] = p;