Raible's Wiki

Raible Designs
Wiki Home
Recent Changes


  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in

Referenced by

JSPWiki v2.2.33


Hide Menu


Difference between version 7 and version 6:

At line 15 changed 2 lines.
* [4] Modify User Junit test
* [5] Run User Junit test
* [4] Modify User Service Junit test
* [5] Run User Service Junit test
At line 325 added 70 lines.
To support the execution of the User service level test, we need another helper file. This file (attached at the end) is called FOPHelper.java and lives in src/service/**/utils.
Add the following method to UserManagerTest.java:
import java.io.File;
import java.io.OutputStream;
import java.io.IOException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerException;
import javax.xml.transform.Source;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.sax.SAXResult;
import org.apache.avalon.framework.ExceptionUtil;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.FOPException;
import org.apache.fop.messaging.MessageHandler;
import org.appfuse.fop.UserInputSource;
import org.appfuse.utils.FOPHelper;
public void testGeneratePDF() throws Exception {
try {
User testData = new User();
testData.getRoles().add(new Role("user"));
// set expected behavior on dao
user = userManager.getUser("tomcat");
File baseDir = new File(".");
File xslFile = new File(baseDir, "./src/web/org/appfuse/webapp/fop/user2fo.xsl");
if (xslFile.exists()) {
log.info("xslFile exists");
File pdfFile = new File(baseDir, "user.pdf");
File xmlFile = new File(baseDir, "user.xml");
log.debug("Input: a User object");
log.debug("Stylesheet: " + xslFile);
log.debug("Output: PDF (" + pdfFile + ")");
FOPHelper fopHelper = new FOPHelper();
fopHelper.convertUser2PDF(user, xslFile, pdfFile);
fopHelper.convertUser2XML(user, xmlFile);
catch (Throwable e) {
log.error("Error [" + e.getMessage() + "]", e);
At line 397 added 13 lines.
Now execute ant test-service. The testGeneratePDF method will execute and generate the 3 files involved in the PDF generation
process. user.xml, user.fo and user.pdf (all three attached at the end of this tutorial).
You should see output:
[junit] [appfuse] INFO [main] UserManagerTest.testGeneratePDF(83) | xslFile exists
[junit] [appfuse] DEBUG [main] UserManagerTest.testGeneratePDF(88) | Input: a User object
[junit] [appfuse] DEBUG [main] UserManagerTest.testGeneratePDF(89) | Stylesheet: ././src/web/org/appfuse/webapp/fop/user2fo.xsl
[junit] [appfuse] DEBUG [main] UserManagerTest.testGeneratePDF(90) | Output: PDF (./user.pdf)
[junit] [appfuse] DEBUG [main] UserManagerTest.testGeneratePDF(91) | Transforming...
At line 618 added 1 line.

Back to POJOToPDF, or to the Page History.