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 BrowserSelectorTestCase extends SitemapComponentTestCase {
26:
27: /**
28: * Run this test suite from commandline
29: *
30: * @param args commandline arguments (ignored)
31: */
32: public static void main(String[] args) {
33: TestRunner.run(suite());
34: }
35:
36: /** Create a test suite.
37: * This test suite contains all test cases of this class.
38: * @return the Test object containing all test cases.
39: */
40: public static Test suite() {
41: TestSuite suite = new TestSuite(BrowserSelectorTestCase.class);
42: return suite;
43: }
44:
45: /**
46: * A simple non-configured browser name test
47: */
48: public void testBrowserSelectMisconfigured() throws Exception {
49: final String userAgent = "Mozilla";
50:
51: getRequest().setHeader("User-Agent", userAgent);
52: Parameters parameters = new Parameters();
53: boolean result;
54:
55: result = this .select("browser", "non-configured-browser-name",
56: parameters);
57: System.out.println(result);
58: assertTrue("Test is browser is a non-configured-browser-name",
59: !result);
60: }
61:
62: /**
63: * A simple netscape browser test
64: */
65: public void testBrowserSelectNetscape() throws Exception {
66: final String userAgent = "Mozilla";
67: String expectedBrowserName;
68:
69: getRequest().setHeader("User-Agent", userAgent);
70: Parameters parameters = new Parameters();
71: boolean result;
72:
73: expectedBrowserName = "netscape";
74: result = this
75: .select("browser", expectedBrowserName, parameters);
76: System.out.println(result);
77: assertTrue("Test if browser is " + expectedBrowserName, result);
78:
79: expectedBrowserName = "explorer";
80: result = this
81: .select("browser", expectedBrowserName, parameters);
82: System.out.println(result);
83: assertTrue("Test if browser is NOT " + expectedBrowserName,
84: !result);
85: }
86: }
|