Java Tools for Extreme Programming—Mastering Open Source Tools Including Ant, Junit, and Cactus
Total Page:16
File Type:pdf, Size:1020Kb
Table of Contents Introduction - 4 Part I - Introduction and Key Concepts Chapter 1 -Introduction to Extreme Programming - 10 Chapter 2 -J2EE Deployment Concepts - 17 Chapter 3 -Example Applications - 27 Part II - Mastering the Tools Chapter 4 -Continuous Integration with Ant - 79 Chapter 5 -Building Java Applications with Ant - 90 Chapter 6 -Building J2EE Applications with Ant - 110 Chapter 7 -Unit Testing with JUnit - 156 Chapter 8 -Testing Container Services with Cactus - 204 Chapter 9 -Functional Testing with HttpUnit - 245 Chapter 10 -Measuring App. Performance with JMeter - 265 Chapter 11 -Load Testing with JUnitPerf - 282 Part III - API and Tag Reference Chapter 12 -Ant Tag Reference - 298 Chapter 13 -Ant API Reference - 319 Chapter 14 -JUnit API Reference - 345 Chapter 15 -Cactus API Reference - 357 Chapter 16 -HttpUnit API Reference - 383 Chapter 17 -JUnitPerf API Reference - 408 Java Tools for Extreme Programming—Mastering Open Source Tools Including Ant, JUnit, and Cactus Richard Hightower Nicholas Lesiecki Wiley Computer publishing John Wiley & Sons, Inc. NEW YORK • CHICHESTER • WEINHEIM • BRISBANE • SINGAPORE • TORONTO Publisher: Robert Ipsen Editor: Robert M. Elliott Managing Editor: John Atkins Book Packaging: Ryan Publishing Group, Inc. Copyeditor: Tiffany Taylor Designations used by companies to distinguish their products are often claimed as trademarks. In all instances where John Wiley & Sons, Inc., is aware of a claim, the product names appear in initial capital or ALL CAPITAL LETTERS. Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration. This book is printed on acid-free paper. Copyright © 2002 by John Wiley & Sons, Inc. All rights reserved. Published by John Wiley & Sons, Inc. Published simultaneously in Canada. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4744. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 605 Third Avenue, New York, NY 10158-0012, (212) 850-6011, fax (212) 850-6008, E-Mail: <PERMREQ @ WILEY.COM>. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold with the understanding that the publisher is not engaged in professional services. If professional advice or other expert assistance is required, the services of a competent professional person should be sought. Library of Congress Cataloging-in-Publication Data: ISBN: 0-471-20708-X Printed in the United States of America. 10 9 8 7 6 5 4 3 2 1 ACKNOWLEDGMENTS First and foremost, I'd like to thank my wife Kiley Hightower for putting up with me on this tight schedule. I spent many a night at a coffee shop with my laptop working until the coffee shop closed. I really appreciate working with Tim Ryan at Ryan Publishing Group. He orchestrated the work of the editor, contributing authors, co-authors, technical editors, and made this a painless and smooth operation for the authors and team. In addition, Tim provided advice and asked the right questions to guide the book along from the very beginning to the very end. Tim is a true professional. Thanks! Kudos to my co-author Nicholas Lesiecki! When I put together the outline of this book and pitched it to Tim Ryan, Wiley was excited about the project and put it on the finish-darn-quick list. I agreed to an aggressive schedule, and even considered taking time off from work to complete it, but decided not to. Nick was able to bail me out by stepping up to the plate and taking on a lot of responsibility, and eventually he became the co- author of the book. Thanks Nick. 2 Much thanks to Scott Fauerbach! Scott went over the pet store baseline application and simplified it a lot. Originally it was very abstract, but a little difficult to understand. Scott ripped through it and simplified it. Together we made it as simple as possible. Scott and I have been on several teams at several companies— we work well together. Scott also did an excellent job on the session bean case study for the business tier of the Pet store application. Thanks, Scott. Erik Hatcher is a wealth of information on Ant and JUnit. I consulted him many times. It was great having the FAQ moderator for Ant in the office next to you when you are having problems with Ant. Thanks Erik for all of the support. I'd like to thank Andy Barton for allowing me to host the Web site for the book for free, and Ron Tapia and Chris Lechner for setting up the site. Also, Ron helped me debug problems when porting the application from SQL Server to Hypersonic SQL. Thanks to Jon Thomas and Paul Visan for stepping up to the plate and taking on case studies. I would like to thank all of the contributing authors, Paul Visan, Erik Hatcher, Jon Thomas and Douglas Albright. I'd also like to thank Mary Hightower & Richard Hightower (Mom and Dad), Mrs. Wooten my third grade school teacher, and Whitney High-tower for understanding. Last, but not least, I'd like to thank Avery Regier and Tiffany Taylor for editing the book. Avery was the technical editor, and in my opinion he went above and beyond the call of duty. He had great suggestions and was able to contribute ideas that were readily incorporated into the book. Thanks, Avery. Tiffany, the copyeditor, found every misplaced tab and run on sentence—any remaining mistakes I take full credit for. Let's just say Tiffany had her work cut out for her. Thanks, Tiffany. ABOUT THE AUTHORS Rick Hightower is the Director of Development at eBlox, where he leads the adoption of new processes like Extreme Programming, and helps implement coding standards and guidelines for development. Rick is a software developer at heart with over a decade of development experience in creating frameworks & tools, enforcing processes, and developing enterprise applications using J2EE, XML, UML, CORBA, JDBC, SQL, and Oracle technologies. Formerly he was the Senior Software Engineer for Java Architecture at Intel's Enterprise Architecture Lab; there he lead a team of developers, designing and implementing three tier client-server applications, introduced O-O CASE tools to his department, and later created several frameworks using a variety of Java, COM, CORBA, middleware technologies. Rick also created ICBeans and authored the patent application for this technology, which was awarded to Intel. Rick has contributed to several Java books and written articles for the Java Developer's Journal. He has also taught classes on developing Enterprise JavaBeans, JDBC, CORBA, Applets as CORBA clients, and EJB. Nicholas Lesiecki serves eBlox as a Technical Team Lead where he takes charge of team development and architects the company's vertical application framework. Hired as an intern in the middle of the dot-com boom, he has since become a Java master, boasting the 5th highest Java 1 score in the nation according to Brainbench.com. He maintains active committer status on Jakarta's Cactus project and constantly looks for ways to improve code structure through testing and vigorous refactoring. Nick resides in the heart of Tucson Arizona where the fire-play in the sky at sunset sweeps through his mind and washes strange objects upon the shores of his memory. He lives with his wife Suzanne and their two "children"—Edgar the Dog and Juno the Wonder Cat. All three should be fairly regarded as contributors because of their generous donations of Nick's time. Nick loves his wife very much. About the Contributors Doug "Chakka" Albright is a software developer who wrote the Ant tag reference. Jon Thomas is a Senior Systems Engineer for HealthTrio in Tucson AZ. Prior to HealthTrio he developed Products for eBlox, SimplySay (Voice Portal) and GroupSystems.com, in both Java and VB. Originally from Los Angeles he "escaped" to the hidden jewel of the southwest in 1995. He lives in Tucson with his family, where he writes software, prays everyday, and cheers for the Minnesota Vikings (proof that not all prayers are answered the way we want them to be.) Jon wrote the Ant API reference. In addition, Jon wrote the case study that converted the Pet store sample application to use XML/XSL for the presentation. Erik Hatcher has more than 10 years of software development experience, most recently with J2EE. He is a Sun Certified Java Programmer, actively involved in Apache's Jakarta efforts, and is the Ant FAQ maintainer at jGuru. Erik is currently a Senior Java Architect for the University of Virginia's Darden Graduate School of Business Administration." He wrote the case study on using HttpUnit. In addition, he provided a technical support for using Ant when we ran into snags. Paul Visan is a Technical Lead for eBlox, Inc doing exciting J2EE development. He comes from Romania, where he was a close acquaintance of Vlad 'Dracul' a.k.a. 'Dracula' in the western world." He converted the Pet store application to use Struts, and the HttpUnit code to test both the straight JSP version and the Struts 3 version of the application. In addition, he wrote the case study explaining the struts conversion of the pet store application. Scott Fauerbach is a principal software engineer who specializes in software frameworks and development tools in both the user interface and server side realms of Java.