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.SitemapComponentTestCase; 24 import org.apache.cocoon.environment.mock.MockCookie; 25 26 public class CookieSelectorTestCase extends SitemapComponentTestCase { 27 28 private static final String COOKIE_SELECTOR = "cookie"; 29 30 35 public static void main( String [] args ) { 36 TestRunner.run(suite()); 37 } 38 39 43 public static Test suite() { 44 TestSuite suite = new TestSuite(CookieSelectorTestCase.class); 45 return suite; 46 } 47 48 51 public void testCookieSelect() throws Exception { 52 final String cookieName = "cookieSelectorTestCase"; 53 final String cookieValue = "cookieValue"; 54 Map cookies = getRequest().getCookieMap(); 57 MockCookie mockCookie = new MockCookie(); 58 mockCookie.setName( cookieName); 59 mockCookie.setValue( cookieValue ); 60 cookies.put( cookieName, mockCookie ); 61 62 Parameters parameters = new Parameters(); 63 boolean result; 64 65 result = this.select( COOKIE_SELECTOR, cookieValue, parameters ); 67 System.out.println( result ); 68 assertTrue( "Test if a cookie is selected", result ); 69 70 result = this.select( COOKIE_SELECTOR, "unknownCookieValue", parameters ); 72 System.out.println( result ); 73 assertTrue( "Test if a cookie is not selected", !result ); 74 } 75 76 79 public void testCookieSelectUsingParameters() throws Exception { 80 final String cookieName = "cookieSelectorTestCase1"; 81 final String cookieValue = "cookieValue"; 82 83 Map cookies = getRequest().getCookieMap(); 86 MockCookie mockCookie = new MockCookie(); 87 mockCookie.setName( cookieName); 89 mockCookie.setValue( cookieValue ); 90 cookies.put( cookieName, mockCookie ); 91 92 mockCookie = new MockCookie(); 95 mockCookie.setName( "cookieSelectorTestCase" ); 96 mockCookie.setValue( "unknownCookieValue" ); 97 cookies.put( "cookieSelectorTestCase", mockCookie ); 98 99 Parameters parameters = new Parameters(); 102 parameters.setParameter( "cookie-name", cookieName ); 103 104 boolean result; 105 106 result = this.select( COOKIE_SELECTOR, cookieValue, parameters ); 108 System.out.println( result ); 109 assertTrue( "Test if a cookie is selected", result ); 110 111 result = this.select( COOKIE_SELECTOR, "unknownCookieValue", parameters ); 113 System.out.println( result ); 114 assertTrue( "Test if a cookie is not selected", !result ); 115 } 116 } 117 | Popular Tags |