cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hu...@apache.org
Subject cvs commit: cocoon-2.1/src/test/org/apache/cocoon/selection BrowserSelectorTestCase.java BrowserSelectorTestCase.xtest CookieSelectorTestCase.java CookieSelectorTestCase.xtest ExceptionSelectorTestCase.java ExceptionSelectorTestCase.xtest HeaderSelectorTestCase.java HeaderSelectorTestCase.xtest HostSelectorTestCase.java HostSelectorTestCase.xtest ParameterSelectorTestCase.java ParameterSelectorTestCase.xtest RegexpRequestParameterSelectorTestCase.java RegexpRequestParameterSelectorTestCase.xtest RequestAttributeSelectorTestCase.java RequestAttributeSelectorTestCase.xtest RequestMethodSelectorTestCase.java RequestMethodSelectorTestCase.xtest RequestParameterSelectorTestCase.java RequestParameterSelectorTestCase.xtest ResourceExistsSelectorTestCase.java ResourceExistsSelectorTestCase.xtest SessionAttributeSelectorTestCase.java SessionAttributeSelectorTestCase.xtest SimpleSelectorTestCase.java SimpleSelectorTestCase.xtest
Date Sun, 04 Jul 2004 17:58:49 GMT
huber       2004/07/04 10:58:49

  Added:       src/test/org/apache/cocoon/selection
                        BrowserSelectorTestCase.java
                        BrowserSelectorTestCase.xtest
                        CookieSelectorTestCase.java
                        CookieSelectorTestCase.xtest
                        ExceptionSelectorTestCase.java
                        ExceptionSelectorTestCase.xtest
                        HeaderSelectorTestCase.java
                        HeaderSelectorTestCase.xtest
                        HostSelectorTestCase.java
                        HostSelectorTestCase.xtest
                        ParameterSelectorTestCase.java
                        ParameterSelectorTestCase.xtest
                        RegexpRequestParameterSelectorTestCase.java
                        RegexpRequestParameterSelectorTestCase.xtest
                        RequestAttributeSelectorTestCase.java
                        RequestAttributeSelectorTestCase.xtest
                        RequestMethodSelectorTestCase.java
                        RequestMethodSelectorTestCase.xtest
                        RequestParameterSelectorTestCase.java
                        RequestParameterSelectorTestCase.xtest
                        ResourceExistsSelectorTestCase.java
                        ResourceExistsSelectorTestCase.xtest
                        SessionAttributeSelectorTestCase.java
                        SessionAttributeSelectorTestCase.xtest
                        SimpleSelectorTestCase.java
                        SimpleSelectorTestCase.xtest
  Log:
  added junit tests for nearly all selector components of cocoon core
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/BrowserSelectorTestCase.java
  
  Index: BrowserSelectorTestCase.java
  ===================================================================
  /*
  * 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 );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/BrowserSelectorTestCase.xtest
  
  Index: BrowserSelectorTestCase.xtest
  ===================================================================
  <?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>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/CookieSelectorTestCase.java
  
  Index: CookieSelectorTestCase.java
  ===================================================================
  /*
  * 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 java.util.Map;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.SitemapComponentTestCase;
  import org.apache.cocoon.environment.mock.MockCookie;
  
  public class CookieSelectorTestCase extends SitemapComponentTestCase {
  
      private final String COOKIE_SELECTOR = "cookie";
      
      public CookieSelectorTestCase(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(CookieSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A simple cookie select test
       */
      public void testCookieSelect() throws Exception {
          final String cookieName = "cookieSelectorTestCase";
          final String cookieValue = "cookieValue";
          // create a cookie
          // setting name := cookieName, value := cookieValue
          Map cookies = getRequest().getCookieMap();
          MockCookie mockCookie = new MockCookie();
          mockCookie.setName( cookieName);
          mockCookie.setValue( cookieValue );
          cookies.put( cookieName, mockCookie );
          
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection success
          result = this.select( COOKIE_SELECTOR, cookieValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a cookie is selected", result );
          
          // test selection failure
          result = this.select( COOKIE_SELECTOR, "unknownCookieValue", parameters );
          System.out.println( result );
          assertTrue( "Test if a cookie is not selected", !result );
      }
  
      /**
       * A simple cookie select test
       */
      public void testCookieSelectUsingParameters() throws Exception {
          final String cookieName = "cookieSelectorTestCase1";
          final String cookieValue = "cookieValue";
          
          // create a cookie
          // setting name := cookieName, value := cookieValue
          Map cookies = getRequest().getCookieMap();
          MockCookie mockCookie = new MockCookie();
          // this cookie shall get selected
          mockCookie.setName( cookieName);
          mockCookie.setValue( cookieValue );
          cookies.put( cookieName, mockCookie );
          
          // this cookie shall be ignored, as its name differs
          // from the parameterized cookie name
          mockCookie = new MockCookie();
          mockCookie.setName( "cookieSelectorTestCase" );
          mockCookie.setValue( "unknownCookieValue" );
          cookies.put( "cookieSelectorTestCase", mockCookie );
  
          // check the cookie as defined by this parameter, not as
          // defined in the component configuration
          Parameters parameters = new Parameters();
          parameters.setParameter( "cookie-name", cookieName );
          
          boolean result;
          
          // test selection success
          result = this.select( COOKIE_SELECTOR, cookieValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a cookie is selected", result );
          
          // test selection failure
          result = this.select( COOKIE_SELECTOR, "unknownCookieValue", parameters );
          System.out.println( result );
          assertTrue( "Test if a cookie is not selected", !result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/CookieSelectorTestCase.xtest
  
  Index: CookieSelectorTestCase.xtest
  ===================================================================
  <?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: CookieSelector
   </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.CookieSelector" 
                         name="cookie">
        <cookie-name>cookieSelectorTestCase</cookie-name>
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/ExceptionSelectorTestCase.java
  
  Index: ExceptionSelectorTestCase.java
  ===================================================================
  /*
  * 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 java.util.Map;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.SitemapComponentTestCase;
  import org.apache.cocoon.environment.ObjectModelHelper;
  
  public class ExceptionSelectorTestCase extends SitemapComponentTestCase {
  
      private final String EXCEPTION_SELECTOR = "exception";    
  
      public ExceptionSelectorTestCase(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(ExceptionSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A simple exception select test
       */
      public void testExceptionSelect() throws Exception {
          
          // create an exception
          final java.lang.NullPointerException npe = new java.lang.NullPointerException( "ExceptionSelectorTestCase");
  
          // put the exception into the objectModel
          Map objectModel = this.getObjectModel();
          objectModel.put( ObjectModelHelper.THROWABLE_OBJECT, npe );
          
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection success
          result = this.select( EXCEPTION_SELECTOR, "npe", parameters );
          System.out.println( result );
          assertTrue( "Test if a npe is selected", result );
          
          // test selection failure
          result = this.select( EXCEPTION_SELECTOR, "non-specified-exception", parameters );
          System.out.println( result );
          assertTrue( "Test if a non specified exception is not selected", !result );
      }
  
      /**
       * A simple exception select test
       */
      public void testExceptionSelectUnknownException() throws Exception {
          
          // create an exception
          final java.lang.IllegalArgumentException iae = new IllegalArgumentException( "ExceptionSelectorTestCase");
  
          // put the exception into the objectModel
          Map objectModel = this.getObjectModel();
          objectModel.put( ObjectModelHelper.THROWABLE_OBJECT, iae );
          
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection failure
          result = this.select( EXCEPTION_SELECTOR, "npe", parameters );
          System.out.println( result );
          assertTrue( "Test if a npe is not selected selected", !result );
      }
      
      /**
       * A simple exception select test
       * The causing exception is listed, thus selecting the unrolling
       * exception fails, selecting the causing exception succeeds.
       */
      public void testExceptionSelectProcessingException() throws Exception {
          
          // create an exception
          final java.lang.NullPointerException npe = new NullPointerException( "NullPointerExceptionSelectorTestCase" );
          final ProcessingException pe = new ProcessingException( "ProcessingExceptionSelectorTestCase", npe );
          
          // put the exception into the objectModel
          Map objectModel = this.getObjectModel();
          objectModel.put( ObjectModelHelper.THROWABLE_OBJECT, pe );
          
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection success
          result = this.select( EXCEPTION_SELECTOR, "npe", parameters );
          System.out.println( result );
          assertTrue( "Test if a npe is selected", result );
          
          // test selection failure
          result = this.select( EXCEPTION_SELECTOR, "pe", parameters );
          System.out.println( result );
          assertTrue( "Test if a pe is not selected", !result );
      }
      
      /**
       * A simple exception select test.
       * The causing exception is not listed, thus matching the unrolling
       * exception succeeds
       */
      public void testExceptionSelectProcessingException2() throws Exception {
          
          // create an exception
          final java.lang.IllegalArgumentException iae = new IllegalArgumentException( "ExceptionSelectorTestCase");
          final ProcessingException pe = new ProcessingException( "ProcessingExceptionSelectorTestCase", iae );
          
          // put the exception into the objectModel
          Map objectModel = this.getObjectModel();
          objectModel.put( ObjectModelHelper.THROWABLE_OBJECT, pe );
          
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection success
          result = this.select( EXCEPTION_SELECTOR, "pe", parameters );
          System.out.println( result );
          assertTrue( "Test if a pe is not selected", result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/ExceptionSelectorTestCase.xtest
  
  Index: ExceptionSelectorTestCase.xtest
  ===================================================================
  <?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: ExceptionSelector
   </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.ExceptionSelector" 
                         name="exception">
        <exception name="npe" class="java.lang.NullPointerException"/>
        <exception name="not-found" class="org.apache.cocoon.ResourceNotFoundException"/>
        <exception name="pe" class="org.apache.cocoon.ProcessingException" unroll="true"/>
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/HeaderSelectorTestCase.java
  
  Index: HeaderSelectorTestCase.java
  ===================================================================
  /*
  * 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 HeaderSelectorTestCase extends SitemapComponentTestCase {
  
      private final String HEADER_SELECTOR = "header";
  
      public HeaderSelectorTestCase(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(HeaderSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A simple header select test
       */
      public void testHeaderSelect() throws Exception {
          final String headerName = "headerSelectorTestCase";
          final String headerValue = "headerValue";
          // create a header
          // setting name := headerName, value := headerValue
          getRequest().setHeader(headerName, headerValue);
          
          Parameters parameters = new Parameters();
          boolean result;
  
          // test selection success
          result = this.select( HEADER_SELECTOR, headerValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a header is selected", result );
          
          // test selection failure
          result = this.select( HEADER_SELECTOR, "unknownHeaderValue", parameters );
          System.out.println( result );
          assertTrue( "Test if a header is not selected", !result );
      }
  
      /**
       * A simple header select test
       */
      public void testHeaderSelectUsingParameters() throws Exception {        
          final String headerName = "headerSelectorTestCase1";
          final String headerValue = "headerValue1";
          // create a header
          // setting name := headerName, value := headerValue
          getRequest().setHeader(headerName, headerValue);
  
          // check the header as defined by this parameter, not as
          // defined in the component configuration
          Parameters parameters = new Parameters();
          parameters.setParameter( "header-name", headerName );
          
          boolean result;
          
          // test selection success
          result = this.select( HEADER_SELECTOR, headerValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a header is selected", result );
          
          // test selection failure
          result = this.select( HEADER_SELECTOR, "unknownHeaderValue", parameters );
          System.out.println( result );
          assertTrue( "Test if a header is not selected", !result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/HeaderSelectorTestCase.xtest
  
  Index: HeaderSelectorTestCase.xtest
  ===================================================================
  <?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: HeaderSelector
   </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.HeaderSelector" 
                         name="header">
        <header-name>headerSelectorTestCase</header-name>
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/HostSelectorTestCase.java
  
  Index: HostSelectorTestCase.java
  ===================================================================
  /*
  * 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 HostSelectorTestCase extends SitemapComponentTestCase {
  
      private final String HOST_SELECTOR = "host";
  
      public HostSelectorTestCase(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(HostSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A simple host selector test
       */
      public void testHostSelectEurope() throws Exception {
          final String host = "myhost-dns-name-in-a-europe-country";
          String expectedHostName;
          
          getRequest().setHeader("Host", host );
          Parameters parameters = new Parameters();
          boolean result;
   
          // test selecting succeeds
          expectedHostName = "myhost-eu";
          result = this.select( HOST_SELECTOR, expectedHostName, parameters );
          System.out.println(result);
          assertTrue( "Test if host is " + expectedHostName, result );
          
          // test selecting fails
          expectedHostName = "myhost-us";
          result = this.select( HOST_SELECTOR, expectedHostName, parameters );
          System.out.println(result);
          assertTrue( "Test if host is not " + expectedHostName, !result );
      }
      
      /**
       * A simple host selector test
       */
      public void testHostSelectUnknownHost() throws Exception {
          final String host = "myhost-dns-name-in-a-asia-country";
          String expectedHostName;
          
          getRequest().setHeader("Host", host );
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selecting succeeds
          expectedHostName = "myhost-eu";
          result = this.select( HOST_SELECTOR, expectedHostName, parameters );
          System.out.println(result);
          assertTrue( "Test if host is not " + expectedHostName, !result );
          
          // test selecting fails
          expectedHostName = "myhost-us";
          result = this.select( HOST_SELECTOR, expectedHostName, parameters );
          System.out.println(result);
          assertTrue( "Test if host is not " + expectedHostName, !result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/HostSelectorTestCase.xtest
  
  Index: HostSelectorTestCase.xtest
  ===================================================================
  <?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: HostSelector
   </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.HostSelector" 
                         name="host">
        <host name="myhost-eu" value="myhost-dns-name-in-a-europe-country"/>
        <host name="myhost-us" value="myhost-dns-name-in-a-us-state"/>
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/ParameterSelectorTestCase.java
  
  Index: ParameterSelectorTestCase.java
  ===================================================================
  /*
  * 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 ParameterSelectorTestCase extends SitemapComponentTestCase {
  
      public ParameterSelectorTestCase(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(ParameterSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A simple parameter select test
       */
      public void testParameterSelect() throws Exception {
          final String parameterName = "parameterSelectorTestCase";
          
          Parameters parameters = new Parameters();
          parameters.setParameter( "parameter-selector-test", parameterName );
          boolean result;
          
          // test selection success
          result = this.select( "parameter", parameterName, parameters );
          System.out.println( result );
          assertTrue( "Test if a parameter is selected", result );
          
          // test selection failure
          result = this.select( "parameter", "unknownParameterName", parameters );
          System.out.println( result );
          assertTrue( "Test if a parameter is not selected", !result );
      }
  
      /**
       * A simple parameter select test
       */
      public void testParameterSelectUndefined() throws Exception {
          final String parameterName = "parameterSelectorTestCase";
          
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection fails
          result = this.select( "parameter", parameterName, parameters );
          System.out.println( result );
          assertTrue( "Test if a parameter is not selected", !result );
          
          parameters.setParameter( "parameter-selector-test", "some-parameter-name" );
          result = this.select( "parameter", parameterName, parameters );
          System.out.println( result );
          assertTrue( "Test if a parameter is not selected", !result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/ParameterSelectorTestCase.xtest
  
  Index: ParameterSelectorTestCase.xtest
  ===================================================================
  <?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: ParameterSelector
   </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.ParameterSelector" 
                         name="parameter">
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/RegexpRequestParameterSelectorTestCase.java
  
  Index: RegexpRequestParameterSelectorTestCase.java
  ===================================================================
  /*
  * 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 RegexpRequestParameterSelectorTestCase extends SitemapComponentTestCase {
  
      public RegexpRequestParameterSelectorTestCase(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(RegexpRequestParameterSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A simple regexp-request-parameter selector test
       */
      public void testRegexpRequestParameterSelectEmpty() throws Exception {
          // create a request parameter
          getRequest().addParameter( "parameterRegexpRequestParameterSelector", "" );
          
          Parameters parameters = new Parameters();
          boolean result;
          
          result = this.select( "regexp-request-parameter", "empty", parameters );
          System.out.println( result );
          assertTrue( "Test is regexp-request-parameter selects successfully", result );
          
          result = this.select( "regexp-request-parameter", "number", parameters );
          System.out.println( result );
          assertTrue( "Test is regexp-request-parameter does not select successfully", !result );
          
          result = this.select( "regexp-request-parameter", "non-defined-name", parameters );
          System.out.println( result );
          assertTrue( "Test is regexp-request-parameter does not select successfully", !result );
      }
  
      /**
       * A simple regexp-request-parameter selector test
       */
      public void testRegexpRequestParameterSelectNumber() throws Exception {
          Parameters parameters = new Parameters();
          boolean result;
          
          // test w/o set request parameter
          result = this.select( "regexp-request-parameter", "number", parameters );
          System.out.println( result );
          assertTrue( "Test is regexp-request-parameter does not select successfully", !result );
          
          // create a request parameter
          getRequest().addParameter( "parameterRegexpRequestParameterSelector1", "123" );
  
          // override configured parameter name
          parameters.setParameter( "parameter-name", "parameterRegexpRequestParameterSelector1" );
          
          result = this.select( "regexp-request-parameter", "number", parameters );
          System.out.println( result );
          assertTrue( "Test is regexp-request-parameter does not selects successfully", result );
  
          result = this.select( "regexp-request-parameter", "non-defined-name", parameters );
          System.out.println( result );
          assertTrue( "Test is regexp-request-parameter does not select successfully", !result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/RegexpRequestParameterSelectorTestCase.xtest
  
  Index: RegexpRequestParameterSelectorTestCase.xtest
  ===================================================================
  <?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: RegexpRequestParameterSelector
   </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.RegexpRequestParameterSelector" 
                         name="regexp-request-parameter">
        <pattern name="empty">^$</pattern>
        <pattern name="number">^[0-9]+$</pattern>
        <pattern name="string">^.+$</pattern>
        <parameter-name>parameterRegexpRequestParameterSelector</parameter-name>
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/RequestAttributeSelectorTestCase.java
  
  Index: RequestAttributeSelectorTestCase.java
  ===================================================================
  /*
  * 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 RequestAttributeSelectorTestCase extends SitemapComponentTestCase {
  
      public RequestAttributeSelectorTestCase(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(RequestAttributeSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A request-attribute parameter select test
       */
      public void testRequestAttributeSelect() throws Exception {
          final String attributeName = "requestAttributeSelector";
          final String attributeValue = "requestAttributeSelectorValue";
          getRequest().setAttribute( attributeName, attributeValue );        
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection success
          result = this.select( "request-attribute", attributeValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a request attribtue is selected", result );
          
          // test selection failure
          result = this.select( "request-attribute", "unknownValue", parameters );
          System.out.println( result );
          assertTrue( "Test if a request attribute is not selected", !result );
      }
  
      /**
       * A request-attribute parameter select test
       */
      public void testRequestAttributeSelectOverridden() throws Exception {
          final String attributeName = "requestAttributeSelector1";
          final String attributeValue = "requestAttributeSelectorValue1";
          getRequest().setAttribute( attributeName, attributeValue );
          
          final String attributeNameOverridden = "requestAttributeSelector";
          final String attributeValueOverridden = "requestAttributeSelectorValue";
          getRequest().setAttribute( attributeNameOverridden, attributeValueOverridden );
          
          Parameters parameters = new Parameters();
          parameters.setParameter( "attribute-name", attributeName );
          boolean result;
          
          // test selection success
          result = this.select( "request-attribute", attributeValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a requst attribtue is selected", result );
          
          // test selection failure
          result = this.select( "request-attribute", attributeValueOverridden, parameters );
          System.out.println( result );
          assertTrue( "Test if a request attribute is not selected", !result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/RequestAttributeSelectorTestCase.xtest
  
  Index: RequestAttributeSelectorTestCase.xtest
  ===================================================================
  <?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: RequestAttributeSelector
   </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.RequestAttributeSelector" 
                         name="request-attribute">
        <attribute-name>requestAttributeSelector</attribute-name>
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/RequestMethodSelectorTestCase.java
  
  Index: RequestMethodSelectorTestCase.java
  ===================================================================
  /*
  * 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 RequestMethodSelectorTestCase extends SitemapComponentTestCase {
  
      public RequestMethodSelectorTestCase(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(RequestMethodSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A request-method select test
       */
      public void testRequestMethodSelect() throws Exception {
          final String method = "POST";
          getRequest().setMethod( "POST" );
          
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection success
          result = this.select( "request-method", method, parameters );
          System.out.println( result );
          assertTrue( "Test if a method is selected", result );
          
          // test selection failure
          result = this.select( "request-method", "post", parameters );
          System.out.println( result );
          assertTrue( "Test if a method is not selected", !result );
          
          // test selection failure
          result = this.select( "request-method", "GET", parameters );
          System.out.println( result );
          assertTrue( "Test if a method is not selected", !result );
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/RequestMethodSelectorTestCase.xtest
  
  Index: RequestMethodSelectorTestCase.xtest
  ===================================================================
  <?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: RequestMethodSelector
   </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.RequestMethodSelector" 
                         name="request-method">
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/RequestParameterSelectorTestCase.java
  
  Index: RequestParameterSelectorTestCase.java
  ===================================================================
  /*
  * 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 RequestParameterSelectorTestCase extends SitemapComponentTestCase {
  
      public RequestParameterSelectorTestCase(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(RequestParameterSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A request-parameter parameter select test
       */
      public void testRequestParameterSelect() throws Exception {
          final String parameterName = "requestParameterSelector";
          final String parameterValue = "requestParameterSelectorValue";
          getRequest().addParameter( parameterName, parameterValue );        
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection success
          result = this.select( "request-parameter", parameterValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a requst parameter is selected", result );
          
          // test selection failure
          result = this.select( "request-parameter", "unknownValue", parameters );
          System.out.println( result );
          assertTrue( "Test if a request parameter is not selected", !result );
      }
  
      /**
       * A request-parameter parameter select test
       */
      public void testRequestParameterSelectOverridden() throws Exception {
          final String parameterName = "requestParameterSelector1";
          final String parameterValue = "requestParameterSelectorValue1";
          getRequest().addParameter( parameterName, parameterValue );
          
          final String parameterNameOverridden = "requestParameterSelector";
          final String parameterValueOverridden = "requestParameterSelectorValue";
          getRequest().addParameter( parameterNameOverridden, parameterValueOverridden );
          
          Parameters parameters = new Parameters();
          parameters.setParameter( "parameter-name", parameterName );
          boolean result;
          
          // test selection success
          result = this.select( "request-parameter", parameterValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a requst attribtue is selected", result );
          
          // test selection failure
          result = this.select( "request-parameter", parameterValueOverridden, parameters );
          System.out.println( result );
          assertTrue( "Test if a request parameter is not selected", !result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/RequestParameterSelectorTestCase.xtest
  
  Index: RequestParameterSelectorTestCase.xtest
  ===================================================================
  <?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: RequestParameterSelector
   </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.RequestParameterSelector" 
                         name="request-parameter">
        <parameter-name>requestParameterSelector</parameter-name>
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/ResourceExistsSelectorTestCase.java
  
  Index: ResourceExistsSelectorTestCase.java
  ===================================================================
  /*
  * 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 ResourceExistsSelectorTestCase extends SitemapComponentTestCase {
  
      public ResourceExistsSelectorTestCase(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(ResourceExistsSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A resource-exists parameter select test
       */
      public void testResourceExistsSelect() throws Exception {
          
          Parameters parameters = new Parameters();
          boolean result;
          String expression = "";
  
          // test selection success
          expression = "resource://org/apache/cocoon/selection/ResourceExistsSelectorTestCase.class";
          result = this.select( "resource-exists", expression, parameters );
          System.out.println( result );
          assertTrue( "Test if a exisitng resource is selected", result );
          
          // test selection failure
          expression = "resource://org/apache/cocoon/selection/NonExistingResource.class";
          result = this.select( "resource-exists", expression, parameters );
          System.out.println( result );
          assertTrue( "Test if a non exisitng resource is not selected", !result );
          
      }
  
      /**
       * A resource-exists parameter select test using the parameter prefix option
       */
      public void testResourceExistsSelectPrefix() throws Exception {
          
          Parameters parameters = new Parameters();
          final String prefix = "resource://org/apache/cocoon/selection/";
          parameters.setParameter( "prefix", prefix );
          boolean result;
          String expression = "";
  
          // test selection success
          expression = "ResourceExistsSelectorTestCase.class";
          result = this.select( "resource-exists", expression, parameters );
          System.out.println( result );
          assertTrue( "Test if a exisitng resource is selected", result );
          
          // test selection failure
          expression = "NonExistingResource.class";
          result = this.select( "resource-exists", expression, parameters );
          System.out.println( result );
          assertTrue( "Test if a non exisitng resource is not selected", !result );
          
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/ResourceExistsSelectorTestCase.xtest
  
  Index: ResourceExistsSelectorTestCase.xtest
  ===================================================================
  <?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: ResourceExistsSelector
   </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.ResourceExistsSelector" 
                         name="resource-exists">
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/SessionAttributeSelectorTestCase.java
  
  Index: SessionAttributeSelectorTestCase.java
  ===================================================================
  /*
  * 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;
  import org.apache.cocoon.environment.Session;
  
  public class SessionAttributeSelectorTestCase extends SitemapComponentTestCase {
  
      public SessionAttributeSelectorTestCase(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(SessionAttributeSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A session-attribute select test
       */
      public void testSessionAttributeSelect() throws Exception {
          final String attributeName = "sessionAttributeSelector";
          final String attributeValue = "sessionAttributeSelectorValue";
          
          Session session = getRequest().getSession(true);
          session.setAttribute( attributeName, attributeValue );        
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection success
          result = this.select( "session-attribute", attributeValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a session attribtue is selected", result );
          
          // test selection failure
          result = this.select( "session-attribute", "unknownValue", parameters );
          System.out.println( result );
          assertTrue( "Test if a session attribute is not selected", !result );
      }
  
      /**
       * A session-attribute select test
       */
      public void testSessionAttributeSelectOverridden() throws Exception {
          final String attributeName = "sessionAttributeSelector1";
          final String attributeValue = "sessionAttributeSelectorValue1";
          Session session = getRequest().getSession(true);
          session.setAttribute( attributeName, attributeValue );        
          
          final String attributeNameOverridden = "sessionAttributeSelector";
          final String attributeValueOverridden = "sessionAttributeSelectorValue";
          session.setAttribute( attributeNameOverridden, attributeValueOverridden );
          
          Parameters parameters = new Parameters();
          parameters.setParameter( "attribute-name", attributeName );
          boolean result;
          
          // test selection success
          result = this.select( "session-attribute", attributeValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a requst attribtue is selected", result );
          
          // test selection failure
          result = this.select( "session-attribute", attributeValueOverridden, parameters );
          System.out.println( result );
          assertTrue( "Test if a session attribute is not selected", !result );
      }
      
      /**
       * A session-attribute select test
       */
      public void testSessionAttributeSelectMissingSession() throws Exception {
          final String attributeValue = "sessionAttributeSelectorValue";
  
          // test w/o session
          getRequest().clearSession();
          
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection fails
          result = this.select( "session-attribute", attributeValue, parameters );
          System.out.println( result );
          assertTrue( "Test if a session attribtue is not selected", !result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/SessionAttributeSelectorTestCase.xtest
  
  Index: SessionAttributeSelectorTestCase.xtest
  ===================================================================
  <?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: SessionAttributeSelector
   </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.SessionAttributeSelector" 
                         name="session-attribute">
        <attribute-name>sessionAttributeSelector</attribute-name>
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/SimpleSelectorTestCase.java
  
  Index: SimpleSelectorTestCase.java
  ===================================================================
  /*
  * 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 SimpleSelectorTestCase extends SitemapComponentTestCase {
  
      public SimpleSelectorTestCase(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(SimpleSelectorTestCase.class);
          return suite;
      }
      
      /**
       * A simple parameter select test
       */
      public void testSimpleSelect() throws Exception {
          final String value = "simpleSelectorTestCase";
          
          Parameters parameters = new Parameters();
          parameters.setParameter( "value", value );
          boolean result;
          
          // test selection success
          result = this.select( "simple", value, parameters );
          System.out.println( result );
          assertTrue( "Test if a parameter is selected", result );
          
          // test selection failure
          result = this.select( "simple", "unknownValue", parameters );
          System.out.println( result );
          assertTrue( "Test if a parameter is not selected", !result );
      }
  
      /**
       * A simple parameter select test
       */
      public void testParameterSelectUndefined() throws Exception {
          final String value = "valueSelectorTestCase";
          
          Parameters parameters = new Parameters();
          boolean result;
          
          // test selection fails
          result = this.select( "simple", value, parameters );
          System.out.println( result );
          assertTrue( "Test if a parameter is not selected", !result );
  
          parameters.setParameter( "value", "some-value" );
          // test selection fails
          result = this.select( "simple", value, parameters );
          System.out.println( result );
          assertTrue( "Test if a parameter is not selected", !result );
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/selection/SimpleSelectorTestCase.xtest
  
  Index: SimpleSelectorTestCase.xtest
  ===================================================================
  <?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: SimpleSelector
   </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.SimpleSelector" 
                         name="simple">
      </component-instance>
    </selectors>
   </components>
  
  </testcase>
  
  
  

Mime
View raw message