cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From step...@apache.org
Subject cvs commit: cocoon-2.1/src/test/org/apache/cocoon/matching WildcardURIMatcherTestCase.java WildcardURIMatcherTestCase.xtest
Date Mon, 02 Feb 2004 11:25:57 GMT
stephan     2004/02/02 03:25:57

  Modified:    src/test/org/apache/cocoon SitemapComponentTestCase.java
  Added:       src/test/org/apache/cocoon/matching
                        WildcardURIMatcherTestCase.java
                        WildcardURIMatcherTestCase.xtest
  Log:
  Add test method for Matchers, and example for the WildcardURIMatcher.
  Thanks to Wojciech Gdela, see
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26441
  
  Revision  Changes    Path
  1.3       +46 -1     cocoon-2.1/src/test/org/apache/cocoon/SitemapComponentTestCase.java
  
  Index: SitemapComponentTestCase.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/test/org/apache/cocoon/SitemapComponentTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SitemapComponentTestCase.java	23 Dec 2003 15:28:33 -0000	1.2
  +++ SitemapComponentTestCase.java	2 Feb 2004 11:25:57 -0000	1.3
  @@ -75,6 +75,7 @@
   import org.apache.cocoon.environment.mock.MockRequest;
   import org.apache.cocoon.environment.mock.MockResponse;
   import org.apache.cocoon.generation.Generator;
  +import org.apache.cocoon.matching.Matcher;
   import org.apache.cocoon.transformation.Transformer;
   import org.apache.cocoon.serialization.Serializer;
   import org.apache.cocoon.xml.WhitespaceFilter;
  @@ -149,6 +150,50 @@
           redirector.reset();
       }
   
  +    /**
  +     * Match with a pattern.
  +     *
  +     * @param type Hint of the matcher. 
  +     * @param pattern Pattern for the matcher.
  +     * @param parameters Matcher parameters.
  +     */
  +    public final Map match(String type, String pattern, Parameters parameters) {
  +
  +        ComponentSelector selector = null;
  +        Matcher matcher = null;
  +        SourceResolver resolver = null;
  +
  +        Map result = null;
  +        try {
  +            selector = (ComponentSelector) this.manager.lookup(Matcher.ROLE +
  +                "Selector");
  +            assertNotNull("Test lookup of matcher selector", selector);
  +
  +            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
  +            assertNotNull("Test lookup of source resolver", resolver);
  +
  +            assertNotNull("Test if matcher name is not null", type);
  +            matcher = (Matcher) selector.select(type);
  +            assertNotNull("Test lookup of matcher", matcher);
  +
  +            result = matcher.match(pattern, objectmodel, parameters);
  +
  +        } catch (ComponentException ce) {
  +            getLogger().error("Could not retrieve generator", ce);
  +            fail("Could not retrieve generator: " + ce.toString());
  +        } catch (Exception e) {
  +            getLogger().error("Could not execute test", e);
  +            fail("Could not execute test: " + e);
  +        } finally {
  +            if (matcher != null) {
  +                selector.release(matcher);
  +            }
  +            this.manager.release(selector);
  +            this.manager.release(resolver);
  +        }
  +        return result;
  +    }
  +    
       /**
        * Perform the action component.
        *
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/matching/WildcardURIMatcherTestCase.java
  
  Index: WildcardURIMatcherTestCase.java
  ===================================================================
  package org.apache.cocoon.matching;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.SitemapComponentTestCase;
  
  public class WildcardURIMatcherTestCase extends SitemapComponentTestCase {
  
      public WildcardURIMatcherTestCase(String name) {
          super(name);
      }
  
      public void testWildcardURIMatch() {
          getRequest().setRequestURI("/test/foo/bla/end");
  
          Parameters parameters = new Parameters();
  
          Map result = match("wildcard-uri", "**", parameters);
          System.out.println(result);
          assertNotNull("Test if resource exists", result);
          assertEquals("Test for **", "test/foo/bla/end", result.get("1"));
          
          result = match("wildcard-uri", "**/bla/*", parameters);
          System.out.println(result);
          assertNotNull("Test if resource exists", result);
          assertEquals("Test for **/bla/* {1}", "test/foo", result.get("1"));
          assertEquals("Test for **/bla/* {2}", "end", result.get("2"));
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/matching/WildcardURIMatcherTestCase.xtest
  
  Index: WildcardURIMatcherTestCase.xtest
  ===================================================================
  <?xml version="1.0" ?>
  <testcase>
   <annotation>
    Test Cases: WildcardUriMatcher
   </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.matching.MatcherSelector"
          shorthand="matchers"
          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"/>
  
    <matchers logger="test">
     <component-instance class="org.apache.cocoon.matching.WildcardURIMatcher" 
                         name="wildcard-uri"/>
    </matchers>
   </components>
  
  </testcase>
  
  
  

Mime
View raw message