[jboss-cvs] JBossAS SVN: r105613 - projects/docs/enterprise/EAP/trunk/5.x/Seam_Reference_Guide/en-US.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 3 01:39:01 EDT 2010


Author: misty at redhat.com
Date: 2010-06-03 01:39:01 -0400 (Thu, 03 Jun 2010)
New Revision: 105613

Modified:
   projects/docs/enterprise/EAP/trunk/5.x/Seam_Reference_Guide/en-US/Testing.xml
Log:
JBPAPP-4387

Modified: projects/docs/enterprise/EAP/trunk/5.x/Seam_Reference_Guide/en-US/Testing.xml
===================================================================
--- projects/docs/enterprise/EAP/trunk/5.x/Seam_Reference_Guide/en-US/Testing.xml	2010-06-03 05:34:45 UTC (rev 105612)
+++ projects/docs/enterprise/EAP/trunk/5.x/Seam_Reference_Guide/en-US/Testing.xml	2010-06-03 05:39:01 UTC (rev 105613)
@@ -19,7 +19,7 @@
 			The following Seam Component which creates a statement of account for a customer:
 		</para>
 		 
-<programlisting role="JAVA"><![CDATA[@Stateless
+<programlisting language="Java" role="JAVA">@Stateless
 @Scope(EVENT)
 @Name("statementOfAccount")
 public class StatementOfAccount {
@@ -33,7 +33,7 @@
    
   @Create
   public void create() {
-    List<Invoice> invoices = entityManager
+    List&lt;Invoice&gt; invoices = entityManager
       .createQuery("select invoice from Invoice invoice where " + 
                    "invoice.customer = :customer")
       .setParameter("customer", customer)
@@ -41,7 +41,7 @@
     statementTotal = calculateTotal(invoices);
   }
    
-  public double calculateTotal(List<Invoice> invoices) {
+  public double calculateTotal(List&lt;Invoice&gt; invoices) {
     double total = 0.0;
       for (Invoice invoice: invoices) {
         double += invoice.getTotal();
@@ -49,22 +49,22 @@
       return total;
      }
    // getter and setter for statementTotal
-}]]>
+}
 </programlisting>
 		 <para>
 			We can test the <literal>calculateTotal</literal> method, which tests the component's business logic, as follows:
 		</para>
 		 
-<programlisting role="JAVA"><![CDATA[public class StatementOfAccountTest { 
+<programlisting language="Java" role="JAVA">public class StatementOfAccountTest { 
   @Test 
   public testCalculateTotal { 
-    List<Invoice> invoices = 
+    List&lt;Invoice&gt; invoices = 
       generateTestInvoices(); // A test data generator 
     double statementTotal = 
       new StatementOfAccount().calculateTotal(invoices); 
     assert statementTotal = 123.45; 
   }   
-}]]>
+}
 </programlisting>
 		 <para>
 			Note that we are not testing data retrieval or persistence, or any of the functions provided by Seam. Here, we are testing only the logic of our POJOs. Seam components do not usually depend directly upon container infrastructure, so most unit tests are just as easy.
@@ -83,7 +83,7 @@
 			Seam lets you use the JBoss Embedded container to test your components — see the configuration chapter for details. This means you can write tests to exercise your application fully within a minimized container:
 		</para>
 		 
-<programlisting role="JAVA"><![CDATA[public class RegisterTest extends SeamTest {
+<programlisting language="Java" role="JAVA">public class RegisterTest extends SeamTest {
    
   @Test
   public void testRegisterComponent() throws Exception {
@@ -106,7 +106,7 @@
 
   ...
    
-}]]>
+}
 </programlisting>
 		 <section>
 			<title>Using mocks in integration tests</title>
@@ -114,22 +114,22 @@
 				You may need to replace Seam components requiring resources that are unavailable in the integration test environment. For example, suppose that you use the following Seam component as a facade to some payment processing system:
 			</para>
 			 
-<programlisting role="JAVA"><![CDATA[@Name("paymentProcessor") 
+<programlisting language="Java" role="JAVA">@Name("paymentProcessor") 
 public class PaymentProcessor {
   public boolean processPayment(Payment payment) { .... } 
-}]]>
+}
 </programlisting>
 			 <para>
 				For integration tests, we can make a mock component like so:
 			</para>
 			 
-<programlisting role="JAVA"><![CDATA[@Name("paymentProcessor")
+<programlisting language="Java" role="JAVA">@Name("paymentProcessor")
 @Install(precedence=MOCK)
 public class MockPaymentProcessor extends PaymentProcessor {
   public boolean processPayment(Payment payment) {
     return true;
   }
-}]]>
+}
 </programlisting>
 			 <para>
 				The <literal>MOCK</literal> precedence is higher than the default precedence of application components, so Seam will install the mock implementation whenever it is in the classpath. When deployed into production, the mock implementation is absent, so the real component will be installed.
@@ -150,7 +150,7 @@
 			Consider a JSP view for the component we unit tested above:
 		</para>
 		 
-<programlisting role="XHTML"><![CDATA[<html>
+<programlisting language="XML" role="XML"><![CDATA[<html>
   <head>
     <title>Register New User</title>
   </head>
@@ -183,7 +183,7 @@
 			We want to test the registration functionality of our application (that is, what happens when a user clicks the Register button). We will reproduce the JSF request lifecycle in an automated TestNG test:
 		</para>
 		 
-<programlisting role="JAVA"><![CDATA[public class RegisterTest extends SeamTesFt {
+<programlisting language="Java" role="JAVA">public class RegisterTest extends SeamTesFt {
    
   @Test
   public void testRegister() throws Exception {
@@ -219,7 +219,7 @@
     }.run();   
   }
   ...
-}]]>
+}
 </programlisting>
 		 <para>
 			Here, we extend <literal>SeamTest</literal> to provide a Seam environment for our components, and our test script is written as an anonymous class that extends <literal>SeamTest.FacesRequest</literal>, which provides an emulated JSF request lifecycle. (There is also a <literal>SeamTest.NonFacesRequest</literal> for testing GET requests.) Our code includes methods named for various JSF phases, to emulate the calls that JSF would make to our components. We have then included various assertions. <!-- #modify: descriptions of the assertions and JSF phases would help. -->
@@ -427,7 +427,7 @@
 				DBUnit supports two formats for dataset files, flat and XML. Seam's DBUnitSeamTest assumes that you use the flat format, so make sure that your dataset is in this format.
 			</para>
 			 
-<programlisting role="XML"><![CDATA[<dataset>
+<programlisting language="XML" role="XML"><![CDATA[<dataset>
    
   <ARTIST 
     id="1"
@@ -445,11 +445,11 @@
 			 In your test class, configure your dataset by overriding <literal>prepareDBUnitOperations()</literal> as follows:
 			</para>
 			 
-<programlisting role="JAVA"><![CDATA[protected void prepareDBUnitOperations() {
+<programlisting language="Java" role="JAVA">protected void prepareDBUnitOperations() {
   beforeTestOperations.add(
     new DataSetOperation("my/datasets/BaseData.xml")
   );
-}]]>
+}
 </programlisting>
 			 <para>
 				<literal>DataSetOperation</literal> defaults to <literal>DatabaseOperation.CLEAN_INSERT</literal> if no other operation is specified as a constructor argument. The previous example cleans all tables defined <literal>BaseData.xml</literal>, then inserts all rows declared in <literal>BaseData.xml</literal> before each <literal>@Test</literal> method is invoked.
@@ -461,18 +461,18 @@
 				You need to tell DBUnit about your datasource by setting a TestNG test parameter named <literal>datasourceJndiName</literal>:
 			</para>
 			 
-<programlisting role="XML"><![CDATA[<parameter name="datasourceJndiName" value="java:/seamdiscsDatasource"/>]]></programlisting>
+<programlisting language="XML" role="XML"><![CDATA[<parameter name="datasourceJndiName" value="java:/seamdiscsDatasource"/>]]></programlisting>
 			 <para>
 				DBUnitSeamTest supports both MySQL and HSQL. You must tell it which database is being used, otherwise it defaults to HSQL:
 			</para>
 			 
- <programlisting role="XML"><![CDATA[ <parameter name="database" value="MYSQL" />]]>
+ <programlisting language="XML" role="XML"><![CDATA[ <parameter name="database" value="MYSQL" />]]>
  </programlisting>
 			 <para>
 				It also allows you to insert binary data into the test data set. (Note that this is <emphasis>untested on Windows</emphasis>.) Tell DBUnitSeamTest where to find these resources on your classpath:
 			</para>
 			 
-<programlisting role="XML"><![CDATA[<parameter name="binaryDir" value="images/" />]]>
+<programlisting language="XML" role="XML"><![CDATA[<parameter name="binaryDir" value="images/" />]]>
 </programlisting>
 			<para> 
  				You do not have to configure any of these parameters if you use HSQL and have no binary imports. However, unless you specify <literal>datasourceJndiName</literal> in your test configuration, you will have to call <literal>setDatabaseJndiName()</literal> before your test runs. If you are not using HSQL or MySQL, you need to override some methods. See the Javadoc of <literal>DBUnitSeamTest</literal> for more details.
@@ -499,7 +499,7 @@
 				It is very easy to integration test your Seam Mail:
 			</para>
 			 
-<programlisting role="JAVA"><![CDATA[public class MailTest extends SeamTest {
+<programlisting language="Java" role="JAVA">public class MailTest extends SeamTest {
     
   @Test
   public void testSimpleMessage() throws Exception {
@@ -525,7 +525,7 @@
             
     }.run();       
   }
-}]]>
+}
 </programlisting>
 			 <para>
 				Create a new <literal>FacesRequest</literal> as normal. Inside the <literal>invokeApplication</literal> hook, we render the message using <literal>getRenderedMailMessage(viewId);</literal>, which passes the <literal>viewId</literal> of he message to be rendered. The method returns the rendered message on which you can perform tests. You can also use any standard JSF lifecycle method.




More information about the jboss-cvs-commits mailing list