Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Java Tools for Extreme programming mastering open source tools including - Hightower R.

Hightower R. Java Tools for Extreme programming mastering open source tools including - Wiley publishing , 2002. - 417 p.
ISBN: 0-471-20708
Download (direct link): javatoolsforextremeprog2002.pdf
Previous << 1 .. 20 21 22 23 24 25 < 26 > 27 28 29 30 31 32 .. 159 >> Next

}
public SubcategoryTest(java.lang.String testName) { super(testName);
}
public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite());
}
public static Test suite() {
TestSuite suite = new TestSuite(SubcategoryTest.class);
return suite;
}
/** Test of getFkCategoryld method, of class xptoolkit.petstore.model.Subcateg ory. */
public void testGetters() { assertNotNull("name", category.getName()); assertNotNull("description", category.getDescription());
}
/** Test of getProducts method, of class xptoolkit.petstore.model.Subcateg ory. */
public void testGetProducts() throws Exception{
String [] testDataExpected = new String []
{"Poodle", "Scottie", "Schnauzer"};
67
Product products [] = category.getProducts(); for (int index = 0; index < products.length; index++){ Product product = products[index]; assertEquals("check Name", testDataExpected[index], product.getName());
}
}
}
Listing 3.16: ProductTest.
package test.xptoolkit.petstore.model;
import xptoolkit.petstore.model.*;
import junit.framework.*;
public class ProductTest extends TestCase {
CategorySystem system;
Product product;
protected void setUp()throws Exception{ system = new CategorySystem(); system.getSubcategory(111); product = system.getProduct(l);
}
public ProductTest(java.lang.String testName) { super(testName);
}
68
public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite());
}
public static Test suite() {
TestSuite suite = new TestSuite(ProductTest.class);
return suite;
}
/** Test of getPrice method
of class xptoolkit.petstore.model.Product. */ public void testSetters() { product.setName("Boo"); product.setDescription("Designer"); product.setPrice(5); product.setQty(5);
}
/** Test of getPrice method
of class xptoolkit.petstore.model.Product. */ public void testGetters() { this.assertEquals("name", product.getName(), "Poodle"); this.assertEquals("description",
product.getDescription(),
"Poodle description"); testSetters();
this.assertEquals("name", product.getName(), "Boo"); this.assertEquals("description",
product.getDescription(),
"Designer");
69
}
}
Listing 3.17: InitPackageTest.
package xptoolkit.petstore.dbmodel;
import java.sql.*; import junit.framework.*;
public class InitPackageTest extends TestCase {
public InitPackageTest(java.lang.String testName) { super(testName);
}
public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite());
}
public static Test suite() {
TestSuite suite = new TestSuite(InitPackageTest.class);
return suite;
}
/** Test of getConnection method, of class xptoolkit.petstore.dbmodel.InitPackage. */ public void testGetConnection() throws SQLException{ System.out.println("testGetConnection");
Connection connection=InitPackage.getConnection();
70
assertNotNull("connection", connection);
}
}
JSPs and Web.xml Complete Listings
The JSPs (Listings 3.18 through 3.26) don't have a corresponding test like the model. They will be added after we cover the HttpUnit in Chapter 9.
Listing 3.18: Header.jsp.
<%@ include file="category_sys.jsp" %>
<html>
<head>
<title>
AAA Pets: <%= request.getParameter("title")%>
</title>
</head>
<body>
<h1>AAA Pets</h1>
<table border="1" width="100%">
<tr>
<td width="20%" align="center">
<a href="index.jsp">Company</a>
</td>
<td width="20%" align="center">
<a href="under_construction.html">Mission</a>
</td>
<td width="20%" align="center">
<a href="under_construction.html">Shopping Cart</a>
</td>
71
<td width="20%" align="center">
<a href="under_construction.html">Links</a>
</td>
</table>
<table border="1" width="100%">
<tr>
<%
Category category = categorySystem.getCurrentCategory(); Subcategory [] subcategories = category.getSubcategories(); for (int index=0; index < subcategories.length; index++){ Subcategory subcategory = subcategories[index];
%>
<td width="20%" align="center">
<a href="subcategory.jsp?id=<%=subcategory.getId()%>"> <%=subcategory.getName()%>
</a>
<br />
</td>
<%}%>
</table>
<table width="100%">
Listing 3.19: Footer.jsp.
<tr>
<td width="100%" align="left">
</td>
</tr>
</table>
72
<p align="center">
<font size="-1">
Copyright 2001, Rick Hightower<br>
AAA Pets is a fictional company any similarities to a real company is coincidental.
</font>
</p>
</body>
</html>
Listing 3.20: Category_sys.jsp.
<%@page import="xptoolkit.petstore.model.*" %>
<jsp:useBean id="categorySystem" class="CategorySystem" scope="session"/>
Listing 3.21: Index.jsp.
<jsp:include page="header.jsp" flush="true">
<jsp:param name="title" value="Welcome"/>
</jsp:include>
<div align="center">
<b>Welcome to AAA Pets</b>
</div>
<jsp:include page="footer.jsp" flush="true" />
Listing 3.22: NotFound.jsp.
<jsp:include page="header.jsp" flush="true">
<jsp:param name="title" value="Welcome"/>
</jsp:include>
<div align="center">
<b>Sorry, I could not find that page.</b>
73
</div>
<jsp:include page="footer.jsp" flush="true" />
Previous << 1 .. 20 21 22 23 24 25 < 26 > 27 28 29 30 31 32 .. 159 >> Next