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 25 public class HostSelectorTestCase extends SitemapComponentTestCase { 26 27 private static final String HOST_SELECTOR = "host"; 28 29 34 public static void main( String [] args ) { 35 TestRunner.run(suite()); 36 } 37 38 42 public static Test suite() { 43 TestSuite suite = new TestSuite(HostSelectorTestCase.class); 44 return suite; 45 } 46 47 50 public void testHostSelectEurope() throws Exception { 51 final String host = "myhost-dns-name-in-a-europe-country"; 52 String expectedHostName; 53 54 getRequest().setHeader("Host", host ); 55 Parameters parameters = new Parameters(); 56 boolean result; 57 58 expectedHostName = "myhost-eu"; 60 result = this.select( HOST_SELECTOR, expectedHostName, parameters ); 61 System.out.println(result); 62 assertTrue( "Test if host is " + expectedHostName, result ); 63 64 expectedHostName = "myhost-us"; 66 result = this.select( HOST_SELECTOR, expectedHostName, parameters ); 67 System.out.println(result); 68 assertTrue( "Test if host is not " + expectedHostName, !result ); 69 } 70 71 74 public void testHostSelectUnknownHost() throws Exception { 75 final String host = "myhost-dns-name-in-a-asia-country"; 76 String expectedHostName; 77 78 getRequest().setHeader("Host", host ); 79 Parameters parameters = new Parameters(); 80 boolean result; 81 82 expectedHostName = "myhost-eu"; 84 result = this.select( HOST_SELECTOR, expectedHostName, parameters ); 85 System.out.println(result); 86 assertTrue( "Test if host is not " + expectedHostName, !result ); 87 88 expectedHostName = "myhost-us"; 90 result = this.select( HOST_SELECTOR, expectedHostName, parameters ); 91 System.out.println(result); 92 assertTrue( "Test if host is not " + expectedHostName, !result ); 93 } 94 } 95 | Popular Tags |