cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: rev 37480 - cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection
Date Fri, 03 Sep 2004 15:20:27 GMT
Author: ugo
Date: Fri Sep  3 08:20:27 2004
New Revision: 37480

Added:
   cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/BrowserSelectorTestCase.java
  (contents, props changed)
   cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/BrowserSelectorTestCase.xtest
  (contents, props changed)
Log:
Sync with trunk

Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/BrowserSelectorTestCase.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/BrowserSelectorTestCase.java
Fri Sep  3 08:20:27 2004
@@ -0,0 +1,85 @@
+/*
+* Copyright 1999-2004 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.cocoon.selection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.SitemapComponentTestCase;
+
+
+public class BrowserSelectorTestCase extends SitemapComponentTestCase {
+
+    public BrowserSelectorTestCase(String name) {
+        super(name);
+    }
+
+    /**
+     * Run this test suite from commandline
+     *
+     * @param args commandline arguments (ignored)
+     */
+    public static void main( String[] args ) {
+        TestRunner.run(suite());
+    }
+    
+    /** Create a test suite.
+     * This test suite contains all test cases of this class.
+     * @return the Test object containing all test cases.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite(BrowserSelectorTestCase.class);
+        return suite;
+    }
+    
+    /**
+     * A simple non-configured browser name test
+     */
+    public void testBrowserSelectMisconfigured() throws Exception {
+        final String userAgent = "Mozilla";
+        
+        getRequest().setHeader("User-Agent", userAgent );
+        Parameters parameters = new Parameters();
+        boolean result;
+        
+        result = this.select( "browser", "non-configured-browser-name", parameters );
+        System.out.println( result );
+        assertTrue( "Test is browser is a non-configured-browser-name", !result );
+    }
+
+    /**
+     * A simple netscape browser test
+     */
+    public void testBrowserSelectNetscape() throws Exception {
+        final String userAgent = "Mozilla";
+        String expectedBrowserName;
+        
+        getRequest().setHeader("User-Agent", userAgent );
+        Parameters parameters = new Parameters();
+        boolean result;
+        
+        expectedBrowserName = "netscape";
+        result = this.select( "browser", expectedBrowserName, parameters );
+        System.out.println(result);
+        assertTrue( "Test if browser is " + expectedBrowserName, result );
+        
+        expectedBrowserName = "explorer";
+        result = this.select( "browser", expectedBrowserName, parameters );
+        System.out.println( result );
+        assertTrue( "Test if browser is NOT " + expectedBrowserName, !result );
+    }
+}

Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/BrowserSelectorTestCase.xtest
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/BrowserSelectorTestCase.xtest
Fri Sep  3 08:20:27 2004
@@ -0,0 +1,86 @@
+<?xml version="1.0" ?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<testcase>
+ <annotation>
+  Test Cases: BrowserSelector
+ </annotation>
+
+ <logkit>
+  <factories>
+   <factory type="stream" class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
+  </factories>
+  <targets>
+   <stream id="root">
+    <stream>System.out</stream>
+    <format type="extended">
+     %7.7{priority} %5.5{time}   [%9.9{category}] (%{context}): %{message}\n%{throwable}
+    </format>
+   </stream>
+  </targets>
+  <categories>
+   <category name="test" log-level="WARN">
+    <log-target id-ref="root"/>
+   </category>
+  </categories>
+ </logkit>
+
+ <context/>
+
+ <roles>
+  <role name="org.apache.excalibur.source.SourceFactorySelector"
+        shorthand="source-factories"
+        default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
+
+  <role name="org.apache.excalibur.source.SourceResolver"
+        shorthand="source-resolver"
+        default-class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
+
+  <role name="org.apache.cocoon.selection.SelectorSelector"
+        shorthand="selectors"
+        default-class="org.apache.cocoon.components.ExtendedComponentSelector"/>
+ </roles>
+
+ <components>
+  <source-factories>
+   <component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory"
name="resource"/>
+   <component-instance class="org.apache.excalibur.source.impl.URLSourceFactory" name="*"/>
+  </source-factories>
+
+  <source-resolver class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
+
+  <selectors logger="test">
+   <component-instance class="org.apache.cocoon.selection.BrowserSelector" 
+                       name="browser">
+      <browser name="explorer" useragent="MSIE"/>
+      <browser name="pocketexplorer" useragent="MSPIE"/>
+      <browser name="handweb" useragent="HandHTTP"/>
+      <browser name="avantgo" useragent="AvantGo"/>
+      <browser name="imode" useragent="DoCoMo"/>
+      <browser name="opera" useragent="Opera"/>
+      <browser name="lynx" useragent="Lynx"/>
+      <browser name="java" useragent="Java"/>
+      <browser name="wap" useragent="Nokia"/>
+      <browser name="wap" useragent="UP"/>
+      <browser name="wap" useragent="Wapalizer"/>
+      <browser name="mozilla5" useragent="Mozilla/5"/>
+      <browser name="mozilla5" useragent="Netscape6/"/>
+      <browser name="netscape" useragent="Mozilla"/>
+    </component-instance>
+  </selectors>
+ </components>
+
+</testcase>

Mime
View raw message