1 16 package org.apache.cocoon.selection; 17 18 import junit.framework.Test; 19 import junit.framework.TestSuite; 20 import junit.textui.TestRunner; 21 import org.apache.avalon.framework.parameters.Parameters; 22 import org.apache.cocoon.SitemapComponentTestCase; 23 24 29 public class RegexpHeaderSelectorTestCase extends SitemapComponentTestCase { 30 31 private static final String REGEXP_HEADER_SELECTOR = "regexp-header"; 32 33 38 public static void main( String [] args ) { 39 TestRunner.run(suite()); 40 } 41 42 46 public static Test suite() { 47 TestSuite suite = new TestSuite(RegexpHeaderSelectorTestCase.class); 48 return suite; 49 } 50 51 52 55 public void testRegexpHeaderSelectEmpty() throws Exception { 56 final String headerName = "headerSelectorTestCase"; 58 getRequest().setHeader(headerName, ""); 59 60 Parameters parameters = new Parameters(); 61 boolean result; 62 63 result = this.select( REGEXP_HEADER_SELECTOR, "empty", parameters ); 64 System.out.println( result ); 65 assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " selects successfully", result ); 66 67 result = this.select( REGEXP_HEADER_SELECTOR, "number", parameters ); 68 System.out.println( result ); 69 assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result ); 70 71 result = this.select( REGEXP_HEADER_SELECTOR, "non-defined-name", parameters ); 72 System.out.println( result ); 73 assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result ); 74 } 75 76 79 public void testRegexpHeaderSelectNumber() throws Exception { 80 final String headerName = "headerSelectorTestCase"; 82 final String headerName2 = "headerSelectorTestCase1"; 83 84 Parameters parameters = new Parameters(); 85 boolean result; 86 87 result = this.select( REGEXP_HEADER_SELECTOR, "empty", parameters ); 89 System.out.println( result ); 90 assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result ); 91 92 getRequest().setHeader(headerName, ""); 94 95 getRequest().setHeader(headerName2, "123"); 97 98 parameters.setParameter( "header-name", headerName2 ); 100 101 result = this.select( REGEXP_HEADER_SELECTOR, "empty", parameters ); 102 System.out.println( result ); 103 assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result ); 104 105 result = this.select( REGEXP_HEADER_SELECTOR, "number", parameters ); 106 System.out.println( result ); 107 assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " selects successfully", result ); 108 109 result = this.select( REGEXP_HEADER_SELECTOR, "non-defined-name", parameters ); 110 System.out.println( result ); 111 assertTrue( "Test is " + REGEXP_HEADER_SELECTOR + " does not select successfully", !result ); 112 } 113 } 114 | Popular Tags |