01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.selection;
18:
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:
25: public class HostSelectorTestCase extends SitemapComponentTestCase {
26:
27: private static final String 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[] 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 {
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: // test selecting succeeds
59: expectedHostName = "myhost-eu";
60: result = this .select(HOST_SELECTOR, expectedHostName,
61: parameters);
62: System.out.println(result);
63: assertTrue("Test if host is " + expectedHostName, result);
64:
65: // test selecting fails
66: expectedHostName = "myhost-us";
67: result = this .select(HOST_SELECTOR, expectedHostName,
68: parameters);
69: System.out.println(result);
70: assertTrue("Test if host is not " + expectedHostName, !result);
71: }
72:
73: /**
74: * A simple host selector test
75: */
76: public void testHostSelectUnknownHost() throws Exception {
77: final String host = "myhost-dns-name-in-a-asia-country";
78: String expectedHostName;
79:
80: getRequest().setHeader("Host", host);
81: Parameters parameters = new Parameters();
82: boolean result;
83:
84: // test selecting succeeds
85: expectedHostName = "myhost-eu";
86: result = this .select(HOST_SELECTOR, expectedHostName,
87: parameters);
88: System.out.println(result);
89: assertTrue("Test if host is not " + expectedHostName, !result);
90:
91: // test selecting fails
92: expectedHostName = "myhost-us";
93: result = this .select(HOST_SELECTOR, expectedHostName,
94: parameters);
95: System.out.println(result);
96: assertTrue("Test if host is not " + expectedHostName, !result);
97: }
98: }
|