dobbs       02/03/28 18:36:50

  Added:       src/test/org/apache/fulcrum/xmlrpc Fulcrum.properties
                        XmlRpcTest.java
  Log:
  Testcase for xmlrpc.
  
  Currently demonstrates that Fulcrum.class does not stand on its own at
  the moment.  Reverse the comments in the catch() block in
  testInitializeFulcrum to see the test fail (unless I fix Fulcrum.class
  before you get to it. 8^)
  
  Revision  Changes    Path
  1.1                  
jakarta-turbine-fulcrum/src/test/org/apache/fulcrum/xmlrpc/Fulcrum.properties
  
  Index: Fulcrum.properties
  ===================================================================
  services.XmlRpcService.classname=org.apache.fulcrum.xmlrpc.TurbineXmlRpcService
  
  # -------------------------------------------------------------------
  #
  #  X M L R P C  S E R V I C E
  #
  # -------------------------------------------------------------------
  # This property specifies which class should be used to parse
  # xml for XmlRpc functionality.
  #
  # Default: org.apache.xerces.parsers.SAXParser
  
  services.XmlRpcService.parser=org.apache.xerces.parsers.SAXParser
  
  # This property specifies which port the server part of the XmlRpc
  # should listen, if it is active.
  #
  # Default: 12345
  
  services.XmlRpcService.port=12345
  
  # If any classes are specified here, the Service will create an
  # instance of them here and start up a listener on the specified
  # port.
  #
  # Note that the handlers demonstrated are not very useful.  You
  # will have to invent your own services.  They do however
  # illustrate that any class with a default constructor can be
  # added here
  #
  # The handler parameter without further extension determines
  # the default handler for the service
  #
  # Default: no classes are specified by default
  
  #services.XmlRpcService.handler.$default=java.util.Hashtable
  #services.XmlRpcService.handler.stringhandler=java.lang.String
  
  # The following properties allow the transfer of data between
  # separate Turbine applications running on different servers.
  # This allows B2B type behavior such as sending database
  # updates in the form of XML or whatever type of data
  # that needs to be shared between Turbine applications
  # running on separate servers.
  
  services.XmlRpcService.handler.file = org.apache.fulcrum.xmlrpc.util.FileHandler
  services.XmlRpcService.paranoid = false
  services.XmlRpcService.acceptClient = 192.168.1.*
  services.XmlRpcService.denyClient =
  
  # Do we want a secure server
  
  services.XmlRpcService.secure.server = false
  
  # Secure server options
  
  services.XmlRpcService.secure.server.option.java.protocol.handler.pkgs = \
      com.sun.net.ssl.internal.www.protocol
  
  services.XmlRpcService.secure.server.option.security.provider = \
      com.sun.net.ssl.internal.ssl.Provider
  
  services.XmlRpcService.secure.server.option.security.protocol = TLS
  
  # You probably want to keep your key stores and trust stores
  # clear out of your webapp.
  
  services.XmlRpcService.secure.server.option.javax.net.ssl.keyStore = /tmp/keystore
  services.XmlRpcService.secure.server.option.javax.net.ssl.keyStoreType = jks
  services.XmlRpcService.secure.server.option.javax.net.ssl.keyStorePassword = password
  services.XmlRpcService.secure.server.option.javax.net.ssl.trustStore = 
/tmp/truststore
  services.XmlRpcService.secure.server.option.javax.net.ssl.trustStoreType = jks
  services.XmlRpcService.secure.server.option.javax.net.ssl.trustStorePassword = 
password
  
  services.XmlRpcService.secure.server.option.sun.ssl.keymanager.type = SunX509
  services.XmlRpcService.secure.server.option.sun.ssl.trust.manager.type = SunX509
  
  # These values should be set to 'all' for debugging purposes.
  
  services.XmlRpcService.secure.server.option.javax.net.debug = none
  services.XmlRpcService.secure.server.option.java.security.debug = none
  
  services.XmlRpcService.earlyInit = true
  
  
  
  1.1                  
jakarta-turbine-fulcrum/src/test/org/apache/fulcrum/xmlrpc/XmlRpcTest.java
  
  Index: XmlRpcTest.java
  ===================================================================
  package org.apache.fulcrum.xmlrpc;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.IOException;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.stratum.configuration.PropertiesConfiguration;
  import org.apache.fulcrum.Fulcrum;
  import org.apache.fulcrum.ServiceManager;
  import org.apache.fulcrum.TurbineServices;
  import org.apache.fulcrum.InstantiationException;
  import org.apache.fulcrum.xmlrpc.TurbineXmlRpc;
  import org.apache.fulcrum.xmlrpc.XmlRpcService;
  
  /**
   * Tests the API of the
   * {@link org.apache.fulcrum.xmlrpc.XmlRpcService}.
   * <br>
   *
   * Depends on an external config file definied by CONFIG_FILE
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Eric Dobbs</a>
   */
  public class XmlRpcTest
      extends TestCase
  {
      public static final String CONFIG_FILE =
          "src/test/org/apache/fulcrum/xmlrpc/Fulcrum.properties";
      private ServiceManager manager = null;
      private Fulcrum fulcrum = null;
      private static boolean initialized = false;
  
      public XmlRpcTest(String name)
      {
          super(name);
      }
  
      public void testInitializeTurbineServices()
      {
          // These testInitialize* cases must be synchronized against
          // the class.  JUnit will run them in separate threads.  If
          // testInitializeTurbineServices has not shutdown its
          // XmlRpcService when testInitializeFulcrum runs, the call to
          // TurbineXmlRpc.getService() will get the service in
          // TurbineServices that has not yet shutdown.
          synchronized (XmlRpcTest.class)
          {
              initTurbineServices();
              try
              {
                  XmlRpcService xmlrpc = TurbineXmlRpc.getService();
                  assertNotNull(xmlrpc);
                  assertTrue(xmlrpc.isInitialized());
              }
              catch (InstantiationException ie)
              {
                  fail("could not get the service: " + XmlRpcService.SERVICE_NAME);
              }
              shutdownTurbineServices();
          }
      }
  
      public void testInitializeFulcrum()
      {
          synchronized (XmlRpcTest.class)
          {
              initFulcrum();
              try
              {
                  XmlRpcService xmlrpc = TurbineXmlRpc.getService();
                  assertNotNull(xmlrpc);
                  assertTrue(xmlrpc.isInitialized());
              }
              catch (InstantiationException ie)
              {
                  System.out.println("couldn't instantiate " + 
XmlRpcService.SERVICE_NAME);
                  //fail("could not get the service: " + XmlRpcService.SERVICE_NAME);
              }
              shutdownFulcrum();
          }
      }
  
      /**
       * Configures and initializes Fulcrum in the same way that
       * Stratum's ComponentLoader does.
       */
      private void initFulcrum()
      {
          try
          {
              fulcrum = new Fulcrum();
              fulcrum.configure(new PropertiesConfiguration(CONFIG_FILE));
              fulcrum.initialize();
          }
          catch (IOException ioe)
          {
              reportIOExceptionAndFail("Fulcrum",ioe);
          }
          catch (Exception e)
          {
              reportExceptionAndFail("Fulcrum",e);
          }
      }
  
      private void initTurbineServices()
      {
          try
          {
              manager = TurbineServices.getInstance();
              manager.setConfiguration(new PropertiesConfiguration(CONFIG_FILE));
              manager.init();
          }
          catch (IOException ioe)
          {
              reportIOExceptionAndFail("Fulcrum",ioe);
          }
          catch (Exception e)
          {
              reportExceptionAndFail("Fulcrum",e);
          }
      }
  
      private void shutdownFulcrum()
      {
          fulcrum.shutdownServices();
      }
  
      private void shutdownTurbineServices()
      {
          manager.shutdownServices();
      }
  
      private void reportIOExceptionAndFail(String name, IOException ioe)
      {
          String errorMessage = name +" could not be configured with file '"
              + CONFIG_FILE + "'.";
          ioe.printStackTrace();
          fail(errorMessage);
      }
  
      private void reportExceptionAndFail(String name, Exception e)
      {
          String errorMessage = name + " could not be initialized!";
          e.printStackTrace();
          fail(errorMessage);
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to