You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by up...@apache.org on 2004/04/30 14:55:55 UTC

cvs commit: cocoon-2.1/src/test/org/apache/cocoon/bean CocoonBeanTestCase.java

upayavira    2004/04/30 05:55:55

  Modified:    src/java/org/apache/cocoon Main.java
               src/java/org/apache/cocoon/bean CocoonBean.java
               src/java/org/apache/cocoon/bean/helpers AntDelegate.java
  Added:       src/test/org/apache/cocoon/bean CocoonBeanTestCase.java
  Log:
  Adding a simple (to be extended CocoonBeanTestCase.
  First test: the processURI(uri, outputStream) method.
  Fixes to actually make the processURI method work
  
  Revision  Changes    Path
  1.26      +6 -1      cocoon-2.1/src/java/org/apache/cocoon/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/Main.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- Main.java	28 Mar 2004 20:51:24 -0000	1.25
  +++ Main.java	30 Apr 2004 12:55:55 -0000	1.26
  @@ -312,6 +312,11 @@
   
           listener.messageGenerated(CocoonBean.getProlog());
   
  +        if (cocoon.getTargetCount() ==0 && cocoon.isPrecompileOnly()) {
  +            listener.messageGenerated("Please, specify at least one starting URI.");
  +            System.exit(1);
  +        }
  +
           cocoon.initialize();
           cocoon.process();
           cocoon.dispose();
  
  
  
  1.41      +14 -7     cocoon-2.1/src/java/org/apache/cocoon/bean/CocoonBean.java
  
  Index: CocoonBean.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/bean/CocoonBean.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- CocoonBean.java	10 Mar 2004 12:58:09 -0000	1.40
  +++ CocoonBean.java	30 Apr 2004 12:55:55 -0000	1.41
  @@ -96,12 +96,6 @@
           if (this.initialized == false) {
               super.initialize();
   
  -            if (crawler.getRemainingCount() == 0 && !precompileOnly) {
  -                String error = "Please, specify at least one starting URI.";
  -                log.fatalError(error);
  -                throw new ProcessingException(error);
  -            }
  -
               this.sourceResolver =
                   (SourceResolver) getComponentManager().lookup(
                       SourceResolver.ROLE);
  @@ -131,6 +125,10 @@
           this.precompileOnly = precompileOnly;
       }
   
  +    public boolean isPrecompileOnly() {
  +        return precompileOnly;
  +    }
  +    
       public void setVerbose(boolean verbose) {
           this.verbose = verbose;
       }
  @@ -239,6 +237,10 @@
           crawler.addTarget(target);
       }
   
  +    public int getTargetCount() {
  +        return crawler.getRemainingCount();
  +    }
  +    
       public void addExcludePattern(String pattern) {
           int preparedPattern[] = WildcardHelper.compilePattern(pattern);
           excludePatterns.add(preparedPattern);
  @@ -331,6 +333,11 @@
   
           if (!this.initialized) {
               this.initialize();
  +        }
  +
  +        if (crawler.getRemainingCount() == 0 && !precompileOnly) {
  +            log.info("No targets for to be processed.");
  +            return;
           }
   
           if (this.checksumsURI != null) {
  
  
  
  1.3       +6 -1      cocoon-2.1/src/java/org/apache/cocoon/bean/helpers/AntDelegate.java
  
  Index: AntDelegate.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/bean/helpers/AntDelegate.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AntDelegate.java	5 Mar 2004 13:02:45 -0000	1.2
  +++ AntDelegate.java	30 Apr 2004 12:55:55 -0000	1.3
  @@ -39,6 +39,11 @@
   
           System.out.println(CocoonBean.getProlog());
   
  +        if (cocoon.getTargetCount() ==0 && cocoon.isPrecompileOnly()) {
  +            listener.messageGenerated("Please, specify at least one starting URI.");
  +            System.exit(1);
  +        }
  +
           cocoon.initialize();
           cocoon.process();
           cocoon.dispose();
  
  
  
  1.1                  cocoon-2.1/src/test/org/apache/cocoon/bean/CocoonBeanTestCase.java
  
  Index: CocoonBeanTestCase.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.bean;
  
  import java.io.ByteArrayOutputStream;
  
  import org.apache.cocoon.bean.helpers.OutputStreamListener;
  
  import junit.framework.TestCase;
  
  /**
   * <p>Test case for the CocoonBean.</p>
   * 
   * <p>To function correctly, this test case expects a built webapp at
   *    <code>build/webapp/</code>, which includes the test-suite 
   *    within it. Ensure this is included in build.properties by
   *    commenting out <code>exclude.webapp.test-suite=true</code>.</p>
   * 
   * @version CVS $Id: CocoonBeanTestCase.java,v 1.1 2004/04/30 12:55:55 upayavira Exp $
   */
  public class CocoonBeanTestCase extends TestCase {
  
  	/**
  	 * Constructor for CocoonBeanTest.
  	 * @param arg0
  	 */
  	public CocoonBeanTestCase(String arg0) {
  		super(arg0);
          
  	}
      
      public void testProcessToStream() throws Exception {
          CocoonBean cocoon = getCocoonBean();
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          cocoon.processURI("test-suite/static-site/index.html", baos);
          String result = baos.toString();
          assertEquals(1603, result.length());
          assertTrue(result.indexOf("Cocoon TestSuite")>-1);
          assertTrue(result.indexOf("<h1>General information</h1>")>-1);
          cocoon.dispose();
      }
      
      private CocoonBean getCocoonBean() throws Exception {
          CocoonBean cocoon = new CocoonBean();
          cocoon.setContextDir("build/webapp");
          cocoon.setConfigFile("WEB-INF/cocoon.xconf");
          cocoon.setPrecompileOnly(false);
          cocoon.setWorkDir("build/work");
          cocoon.setLogKit("build/webapp/WEB-INF/logkit.xconf");
          cocoon.setLogger("cli-test");
          cocoon.setLogLevel("DEBUG");
          //cocoon.setAgentOptions(*something*));
          //cocoon.setAcceptOptions(*something*);
          //cocoon.setDefaultFilename(*something*);
          //listener.setReportFile(*something*);
          cocoon.setFollowLinks(true);
          cocoon.setConfirmExtensions(false);
          //cocoon.addLoadedClasses(Arrays.asList(*something*));
          //cocoon.addTargets(BeanConfigurator.processURIFile(*some file*), destDir);
          cocoon.addListener(new OutputStreamListener(System.out));
          cocoon.initialize();
          return cocoon;        
      }
  }