KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > selection > HostSelectorTestCase


1 /*
2 * Copyright 1999-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */

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 JavaDoc HOST_SELECTOR = "host";
28
29     /**
30      * Run this test suite from commandline
31      *
32      * @param args commandline arguments (ignored)
33      */

34     public static void main( String JavaDoc[] args ) {
35         TestRunner.run(suite());
36     }
37     
38     /** Create a test suite.
39      * This test suite contains all test cases of this class.
40      * @return the Test object containing all test cases.
41      */

42     public static Test suite() {
43         TestSuite suite = new TestSuite(HostSelectorTestCase.class);
44         return suite;
45     }
46     
47     /**
48      * A simple host selector test
49      */

50     public void testHostSelectEurope() throws Exception JavaDoc {
51         final String JavaDoc host = "myhost-dns-name-in-a-europe-country";
52         String JavaDoc expectedHostName;
53         
54         getRequest().setHeader("Host", host );
55         Parameters parameters = new Parameters();
56         boolean result;
57  
58         // test selecting succeeds
59
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         // test selecting fails
65
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     /**
72      * A simple host selector test
73      */

74     public void testHostSelectUnknownHost() throws Exception JavaDoc {
75         final String JavaDoc host = "myhost-dns-name-in-a-asia-country";
76         String JavaDoc expectedHostName;
77         
78         getRequest().setHeader("Host", host );
79         Parameters parameters = new Parameters();
80         boolean result;
81         
82         // test selecting succeeds
83
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         // test selecting fails
89
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