portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/test HeadlessBaseTest.java jetspeed_testconfig.properties
Date Mon, 19 May 2003 23:17:49 GMT
taylor      2003/05/19 16:17:49

  Modified:    src/java/org/apache/jetspeed/modules/actions/portlets
                        ForwardDemoAction.java
               src/java/org/apache/jetspeed/services/lucene
                        LuceneSearch.java LuceneSearchService.java
                        SearchResults.java TestLuceneSearch.java
               src/java/org/apache/jetspeed/services/resources
                        JetspeedResourceService.java
               src/java/org/apache/jetspeed/test HeadlessBaseTest.java
                        jetspeed_testconfig.properties
  Log:
  1. - added ability to run unit tests with a different set of properties
    set your specific properties in test/conf/jetspeed-test.properties
  
  2. - added ability to set runtime properties by the sys admin (deployer)
     To use 'runtime' time properties, define a directory where you are keeping your
    'runtime' parameters and pass it in as a System Property named 'jetspeed.conf.dir'
  
    This implementation will take the name of the web application (i.e. 'jetspeed') and  
  use it to  find the name of a properties file. These properties are merged with the    
 TurbineResources/JetspeedResources.properties
  
    Similarly, you can override Torque properties by naming a file in your runtime directory
    as ${webapp.name}_Torque.properties
  
    Examples:
       jetspeed.conf.dir = /Users/sysadmin/conf
  
       This directory contains two files:
        1. jetspeed.properties - overrides properties in JetspeedResources.properties and
                                                      TurbineResources.properties
        2. jetspeed_torque.properties - overrides properties in Torque.properties
  
  3. Set JetspeedResourceService as the default Resource service
  
  4. Continue development on Lucene Service, allowing for a different index to be used
     in the system test from the index used in default deployment
  
  Revision  Changes    Path
  1.4       +1 -4      jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/ForwardDemoAction.java
  
  Index: ForwardDemoAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/ForwardDemoAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ForwardDemoAction.java	14 Apr 2003 19:01:45 -0000	1.3
  +++ ForwardDemoAction.java	19 May 2003 23:17:48 -0000	1.4
  @@ -139,9 +139,6 @@
   
       public void doUpdate(RunData rundata, Context context)
       {
  -        org.apache.jetspeed.portal.Portlet portlet = (org.apache.jetspeed.portal.Portlet)context.get("portlet");
  -        System.out.println("Portlet = " + portlet);
  -
           // get posted new target
           String next = (String)rundata.getParameters().getString(PARAM_NEXT);
           
  
  
  
  1.3       +18 -1     jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/LuceneSearch.java
  
  Index: LuceneSearch.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/LuceneSearch.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LuceneSearch.java	10 May 2003 13:31:49 -0000	1.2
  +++ LuceneSearch.java	19 May 2003 23:17:48 -0000	1.3
  @@ -55,6 +55,7 @@
   package org.apache.jetspeed.services.lucene;
   
   // Java Imports
  +import java.io.File;
   import java.net.URL;
   
   // Turbine imports
  @@ -96,6 +97,22 @@
       public static boolean add(URL pageToAdd)
       {
           return getService().add(pageToAdd);
  +    }
  +
  +    public boolean addDirectory(String path, String extension)
  +    {
  +        File directory = new File(path); 
  +        File[] files = directory.listFiles();
  +        for (int ix=0; ix < files.length; ix++)
  +        {
  +            if (files[ix].isDirectory())
  +            {
  +                continue;
  +            }
  +
  +            // TODO: subdirectories
  +        }
  +        return true;                        
       }
   
   }
  
  
  
  1.4       +1 -0      jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/LuceneSearchService.java
  
  Index: LuceneSearchService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/LuceneSearchService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LuceneSearchService.java	10 May 2003 13:31:49 -0000	1.3
  +++ LuceneSearchService.java	19 May 2003 23:17:48 -0000	1.4
  @@ -115,6 +115,7 @@
        */
       public synchronized void init(ServletConfig conf) throws InitializationException
       {
  +        System.out.println("Initializing Lucene Service");
           
           // already initialized
           if (getInit())
  
  
  
  1.2       +4 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/SearchResults.java
  
  Index: SearchResults.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/SearchResults.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SearchResults.java	7 May 2003 00:17:16 -0000	1.1
  +++ SearchResults.java	19 May 2003 23:17:48 -0000	1.2
  @@ -100,5 +100,8 @@
           return results.size();
       }
       
  -    
  +    public List getResults()
  +    {
  +        return this.results;
  +    }
   }
  
  
  
  1.4       +10 -28    jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/TestLuceneSearch.java
  
  Index: TestLuceneSearch.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/TestLuceneSearch.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestLuceneSearch.java	10 May 2003 13:31:49 -0000	1.3
  +++ TestLuceneSearch.java	19 May 2003 23:17:48 -0000	1.4
  @@ -65,40 +65,21 @@
   // Turbine imports
   import org.apache.turbine.util.TurbineConfig;
   import org.apache.turbine.util.StringUtils;
  +import org.apache.jetspeed.services.resources.JetspeedResources;
  +
  +import org.apache.jetspeed.test.HeadlessBaseTest;
   
   /**
  - * TestIdGenerator
  + * Test Lucene Service 
    *
    * @author <a href="paulsp@apache.org">Paul Spencer</a>
  + * @author <a href="taylor@apache.org">David Sean Taylor</a>
  + * 
    * @version $Id$
    */
  -public class TestLuceneSearch extends TestCase
  +public class TestLuceneSearch extends HeadlessBaseTest
   {
  -    
  -    /**
  -     * Configuration object to run Turbine outside a servlet container
  -     * ( uses turbine.properties )
  -     */
  -    private static TurbineConfig config = null;
  -    
  -    /**
  -     * Sets up TurbineConfig using the system property:
  -     * <pre>turbine.properties</pre>
  -     */
  -    static
  -    {
  -        try
  -        {
  -            config = new TurbineConfig("../webapp",
  -            "/WEB-INF/conf/TurbineResources.properties");
  -            config.init();
  -        }
  -        catch (Exception e)
  -        {
  -            fail(StringUtils.stackTrace(e));
  -        }
  -    }
  -    
  +        
       /**
        * Defines the testcase name for JUnit.
        *
  @@ -133,6 +114,7 @@
       
       public void testPutWebPage() throws Exception
       {
  +        System.out.println("lucene home = " + JetspeedResources.getString("services.LuceneSearch.directory"));
           URL jetspeedHomePage = new URL("http://jakarta.apache.org/jetspeed");
           assertNotNull("Created URL to Jetspeed Home Page",  jetspeedHomePage);
           assertTrue("Adding to index", LuceneSearch.add(jetspeedHomePage));
  
  
  
  1.4       +124 -1    jakarta-jetspeed/src/java/org/apache/jetspeed/services/resources/JetspeedResourceService.java
  
  Index: JetspeedResourceService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/resources/JetspeedResourceService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JetspeedResourceService.java	4 Mar 2003 00:05:10 -0000	1.3
  +++ JetspeedResourceService.java	19 May 2003 23:17:48 -0000	1.4
  @@ -53,10 +53,20 @@
    */
   package org.apache.jetspeed.services.resources;
   
  +import java.io.File;
  +import java.io.IOException;
  +import java.io.FileInputStream;
  +import java.util.Properties;
  +import java.util.Iterator;
  +import java.util.Map.Entry;
  +
  +import javax.servlet.ServletConfig;
  +
   // Turbine stuff
   import org.apache.turbine.util.Log;
   import org.apache.turbine.services.resources.TurbineResourceService;
   import org.apache.turbine.services.resources.ResourceService;
  +import org.apache.turbine.services.InitializationException;
   
   import org.apache.commons.configuration.Configuration;
   
  @@ -101,6 +111,8 @@
    * </P>
    * 
    * @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>
  + * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  + * 
    * @version $Id$
    */
   public class JetspeedResourceService
  @@ -275,6 +287,117 @@
           }
   
           return (ResourceService) res;
  +    }
  +
  +    /**
  +     * This method is called when the Service is initialized
  +     * It provides a way to override properties at runtime.
  +     * To use 'runtime' time properties, define a directory where you are keeping your
  +     * 'runtime' parameters and pass it in as a System Property named 'jetspeed.conf.dir'
  +     * 
  +     * This implementation will take the name of the web application (i.e. 'jetspeed')
and use it to 
  +     * find the name of a properties file. These properties are merged with the TurbineResources/JetspeedResources.properties
  +     * Similarly, you can override Torque properties by naming a file in your runtime directory
as ${webapp.name}_Torque.properties
  +     * 
  +     * Examples:
  +     *    jetspeed.conf.dir = /Users/sysadmin/conf
  +     *    
  +     *    This directory contains two files:
  +     *      1. jetspeed.properties - overrides properties in JetspeedResources.properties
and TurbineResources.properties
  +     *      2. jetspeed_torque.properties - overrides properties in Torque.properties
  +     * 
  +     * @param config a ServletConfig object
  +     */
  +    public void init()
  +        throws InitializationException
  +    {     
  +        System.out.println("Jetspeed Services: Starting with no parameters");
  +        super.init();
  +    }
  +       
  +    public synchronized void init(ServletConfig config) throws InitializationException
       
  +    {               
  +        String propsDir = null;
  +        String appName = config.getServletName();
  +        String deployFilename = appName + ".properties";
  +        String torqueFilename = appName + "_torque.properties";
  +        super.init(config);
  +        
  +        System.out.println("Jetspeed Services: Starting servlet: [" + appName +"]");
  +
  +        try
  +        {
  +            propsDir = System.getProperty("jetspeed.conf.dir", null);
  +            if (null == propsDir)
  +            {
  +                // no deploy-time directory defined to find properties, return
  +                return;
  +            }
  +
  +
  +            String torqueProps = makeFileNamePath(propsDir, torqueFilename);
  +            String deployProps = makeFileNamePath(propsDir, deployFilename);
  +
  +            System.out.println("torque props = " + torqueProps);
  +            System.out.println("deploy props = " + deployProps);
  +
  +            File deployFile = new File(deployProps);
  +            if (deployFile.exists())
  +            {
  +                FileInputStream is = new FileInputStream(deployProps);
  +                Properties props = new Properties();
  +                props.load(is);
  +
  +                Iterator it = props.entrySet().iterator();
  +                while (it.hasNext())
  +                {
  +                    Entry entry = (Entry)it.next();
  +                    //if (entry.getValue() != null && ((String)entry.getValue()).length()
> 0)
  +                    this.setProperty((String)entry.getKey(), (String)entry.getValue());
  +                    System.out.println("setting key/value: " + entry.getKey() + ":" + entry.getValue());
                       
  +                }
  +            }
  +            else
  +            {
  +                String msg = "Failed to find Deploy properties: " + deployProps;
  +                System.err.println(msg);
  +            }
  +
  +            File torqueFile = new File(torqueProps);
  +            if (torqueFile.exists())
  +            {
  +                this.setProperty("component.torque.config", torqueProps);
  +                
  +                FileInputStream tis = new FileInputStream(torqueProps);
  +                Properties tprops = new Properties();
  +                tprops.load(tis);
  +                
  +                System.out.println("Connecting to: "+tprops.getProperty("database.default.url"));
  +                System.out.println("Database Username: "+tprops.getProperty("database.default.username"));
  +            }
  +
  +        }
  +        catch (IOException e)
  +        {
  +            StringBuffer msg = new StringBuffer("Error reading properties for appName:
");
  +            msg.append(appName);
  +            msg.append(", props Dir: " + propsDir);
  +            System.err.println("Exception in loading properties: " + propsDir);
  +            e.printStackTrace();
  +        }
  +    }
  +
  +
  +    protected String makeFileNamePath(String propsDir, String fileName)
  +    {
  +        StringBuffer name = new StringBuffer(propsDir);
  +    
  +        if (!propsDir.endsWith(File.separator))
  +        {
  +            name.append(File.separator);
  +        }
  +        name.append(fileName);
  +        return name.toString();
       }
   
   }
  
  
  
  1.3       +2 -2      jakarta-jetspeed/src/java/org/apache/jetspeed/test/HeadlessBaseTest.java
  
  Index: HeadlessBaseTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/test/HeadlessBaseTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HeadlessBaseTest.java	4 Mar 2003 00:05:14 -0000	1.2
  +++ HeadlessBaseTest.java	19 May 2003 23:17:49 -0000	1.3
  @@ -94,7 +94,7 @@
       ( uses turbine.properties )
       */
       private static TurbineConfig config = null;
  -    private static final PropertiesConfiguration testConfig = new PropertiesConfiguration();;
  +    private static final PropertiesConfiguration testConfig = new PropertiesConfiguration();
       
       protected TestResult testResult;
   
  
  
  
  1.2       +3 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/test/jetspeed_testconfig.properties
  
  Index: jetspeed_testconfig.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/test/jetspeed_testconfig.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- jetspeed_testconfig.properties	28 Jan 2003 05:57:48 -0000	1.1
  +++ jetspeed_testconfig.properties	19 May 2003 23:17:49 -0000	1.2
  @@ -1,5 +1,7 @@
   webapp.path=../webapp
  -tr.props.path=/WEB-INF/conf/TurbineResources.properties
  +# tr.props.path=/WEB-INF/conf/test/jetspeed.properties
  +tr.props.path=../test/conf/jetspeed-test.properties
  +
   #Whether or not print() method outputs
   verbose=false
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message