1 16 package org.apache.cocoon.selection; 17 18 import java.util.Map ; 19 import junit.framework.Test; 20 import junit.framework.TestSuite; 21 import junit.textui.TestRunner; 22 import org.apache.avalon.framework.parameters.Parameters; 23 import org.apache.cocoon.ProcessingException; 24 import org.apache.cocoon.SitemapComponentTestCase; 25 import org.apache.cocoon.environment.ObjectModelHelper; 26 27 public class ExceptionSelectorTestCase extends SitemapComponentTestCase { 28 29 private static final String EXCEPTION_SELECTOR = "exception"; 30 31 36 public static void main( String [] args ) { 37 TestRunner.run(suite()); 38 } 39 40 44 public static Test suite() { 45 TestSuite suite = new TestSuite(ExceptionSelectorTestCase.class); 46 return suite; 47 } 48 49 52 public void testExceptionSelect() throws Exception { 53 54 final java.lang.NullPointerException npe = new java.lang.NullPointerException ( "ExceptionSelectorTestCase"); 56 57 Map objectModel = this.getObjectModel(); 59 objectModel.put( ObjectModelHelper.THROWABLE_OBJECT, npe ); 60 61 Parameters parameters = new Parameters(); 62 boolean result; 63 64 result = this.select( EXCEPTION_SELECTOR, "npe", parameters ); 66 System.out.println( result ); 67 assertTrue( "Test if a npe is selected", result ); 68 69 result = this.select( EXCEPTION_SELECTOR, "non-specified-exception", parameters ); 71 System.out.println( result ); 72 assertTrue( "Test if a non specified exception is not selected", !result ); 73 } 74 75 78 public void testExceptionSelectUnknownException() throws Exception { 79 80 final java.lang.IllegalArgumentException iae = new IllegalArgumentException ( "ExceptionSelectorTestCase"); 82 83 Map objectModel = this.getObjectModel(); 85 objectModel.put( ObjectModelHelper.THROWABLE_OBJECT, iae ); 86 87 Parameters parameters = new Parameters(); 88 boolean result; 89 90 result = this.select( EXCEPTION_SELECTOR, "npe", parameters ); 92 System.out.println( result ); 93 assertTrue( "Test if a npe is not selected selected", !result ); 94 } 95 96 101 public void testExceptionSelectProcessingException() throws Exception { 102 103 final java.lang.NullPointerException npe = new NullPointerException ( "NullPointerExceptionSelectorTestCase" ); 105 final ProcessingException pe = new ProcessingException( "ProcessingExceptionSelectorTestCase", npe ); 106 107 Map objectModel = this.getObjectModel(); 109 objectModel.put( ObjectModelHelper.THROWABLE_OBJECT, pe ); 110 111 Parameters parameters = new Parameters(); 112 boolean result; 113 114 result = this.select( EXCEPTION_SELECTOR, "npe", parameters ); 116 System.out.println( result ); 117 assertTrue( "Test if a npe is selected", result ); 118 119 result = this.select( EXCEPTION_SELECTOR, "pe", parameters ); 121 System.out.println( result ); 122 assertTrue( "Test if a pe is not selected", !result ); 123 } 124 125 130 public void testExceptionSelectProcessingException2() throws Exception { 131 132 final java.lang.IllegalArgumentException iae = new IllegalArgumentException ( "ExceptionSelectorTestCase"); 134 final ProcessingException pe = new ProcessingException( "ProcessingExceptionSelectorTestCase", iae ); 135 136 Map objectModel = this.getObjectModel(); 138 objectModel.put( ObjectModelHelper.THROWABLE_OBJECT, pe ); 139 140 Parameters parameters = new Parameters(); 141 boolean result; 142 143 result = this.select( EXCEPTION_SELECTOR, "pe", parameters ); 145 System.out.println( result ); 146 assertTrue( "Test if a pe is not selected", result ); 147 } 148 } 149 | Popular Tags |