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 import org.apache.cocoon.environment.Session; 24 25 public class SessionAttributeSelectorTestCase extends SitemapComponentTestCase { 26 27 32 public static void main( String [] args ) { 33 TestRunner.run(suite()); 34 } 35 36 40 public static Test suite() { 41 TestSuite suite = new TestSuite(SessionAttributeSelectorTestCase.class); 42 return suite; 43 } 44 45 48 public void testSessionAttributeSelect() throws Exception { 49 final String attributeName = "sessionAttributeSelector"; 50 final String attributeValue = "sessionAttributeSelectorValue"; 51 52 Session session = getRequest().getSession(true); 53 session.setAttribute( attributeName, attributeValue ); 54 Parameters parameters = new Parameters(); 55 boolean result; 56 57 result = this.select( "session-attribute", attributeValue, parameters ); 59 System.out.println( result ); 60 assertTrue( "Test if a session attribtue is selected", result ); 61 62 result = this.select( "session-attribute", "unknownValue", parameters ); 64 System.out.println( result ); 65 assertTrue( "Test if a session attribute is not selected", !result ); 66 } 67 68 71 public void testSessionAttributeSelectOverridden() throws Exception { 72 final String attributeName = "sessionAttributeSelector1"; 73 final String attributeValue = "sessionAttributeSelectorValue1"; 74 Session session = getRequest().getSession(true); 75 session.setAttribute( attributeName, attributeValue ); 76 77 final String attributeNameOverridden = "sessionAttributeSelector"; 78 final String attributeValueOverridden = "sessionAttributeSelectorValue"; 79 session.setAttribute( attributeNameOverridden, attributeValueOverridden ); 80 81 Parameters parameters = new Parameters(); 82 parameters.setParameter( "attribute-name", attributeName ); 83 boolean result; 84 85 result = this.select( "session-attribute", attributeValue, parameters ); 87 System.out.println( result ); 88 assertTrue( "Test if a requst attribtue is selected", result ); 89 90 result = this.select( "session-attribute", attributeValueOverridden, parameters ); 92 System.out.println( result ); 93 assertTrue( "Test if a session attribute is not selected", !result ); 94 } 95 96 99 public void testSessionAttributeSelectMissingSession() throws Exception { 100 final String attributeValue = "sessionAttributeSelectorValue"; 101 102 getRequest().clearSession(); 104 105 Parameters parameters = new Parameters(); 106 boolean result; 107 108 result = this.select( "session-attribute", attributeValue, parameters ); 110 System.out.println( result ); 111 assertTrue( "Test if a session attribtue is not selected", !result ); 112 } 113 } 114 | Popular Tags |