geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/test/javax/enterprise/deploy/spi/factories MockDeploymentFactory.java
Date Thu, 14 Aug 2003 09:14:05 GMT
jstrachan    2003/08/14 02:14:05

  Modified:    modules/core/src/java/javax/enterprise/deploy/shared/factories
                        DeploymentFactoryManager.java
  Added:       modules/core/src/test/javax/enterprise/deploy/shared/factories
                        DeploymentFactoryManagerTest.java
               modules/core/src/test/javax/enterprise/deploy/spi
                        MockDeploymentManager.java
               modules/core/src/test/javax/enterprise/deploy/spi/factories
                        MockDeploymentFactory.java
  Log:
  applied patch by Maas van den Berg to add an implementation & unit tests of DeploymentFactoryManager
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/core/src/test/javax/enterprise/deploy/shared/factories/DeploymentFactoryManagerTest.java
  
  Index: DeploymentFactoryManagerTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", 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/>.
   *
   * ====================================================================
   */
  package javax.enterprise.deploy.shared.factories;
  
  import junit.framework.TestCase;
  
  import javax.enterprise.deploy.spi.factories.DeploymentFactory;
  import javax.enterprise.deploy.spi.factories.MockDeploymentFactory;
  import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
  import javax.enterprise.deploy.spi.DeploymentManager;
  
  /**
   * Low level tests on the DeploymentFactoryManager.
   */
  public class DeploymentFactoryManagerTest extends TestCase {
      private DeploymentFactoryManager factoryManager;
  
      protected void setUp() throws Exception {
          super.setUp();
          factoryManager = DeploymentFactoryManager.getInstance();
      }
  
      protected void tearDown() throws Exception {
          factoryManager = null;
          super.tearDown();
      }
  
      public void testGetDeploymentManagerWithoutAnyRegisteredFactories() {
          try {
              factoryManager.getDeploymentManager(null, null, null);
          } catch (DeploymentManagerCreationException e) {
              assertEquals("Could not get DeploymentManager", e.getMessage());
              return;
          }
          fail("Expected a DeploymentManagerCreationException");
      }
  
      public void testDisconnectedGetDeploymentManagerWithoutAnyRegisteredFactories() {
          try {
              factoryManager.getDisconnectedDeploymentManager(null);
          } catch (DeploymentManagerCreationException e) {
              assertEquals("Could not get DeploymentManager", e.getMessage());
              return;
          }
          fail("Expected a DeploymentManagerCreationException");
      }
  
      public void testRegisterDeploymentFactory() {
          int initialNumberOfFactories = factoryManager.getDeploymentFactories().length;
  
          DeploymentFactory factory = new MockDeploymentFactory();
          factoryManager.registerDeploymentFactory(factory);
  
          int expectedNumberOfFactories = initialNumberOfFactories + 1;
          int currentNumberOfFactories = factoryManager.getDeploymentFactories().length;
  
          assertEquals(expectedNumberOfFactories, currentNumberOfFactories);
      }
  
      /**
       * Relies on succesful completion of @link #testRegisterDeploymentFactory()
       * bacause we need a registered DeploymentManager for this test.
       */
      public void testGetDeploymentManager() {
          int numberOfFactories = factoryManager.getDeploymentFactories().length;
          assertTrue("We should have a registered MockDeploymentFactory", numberOfFactories
> 0);
  
          DeploymentManager deploymentManager = null;
          try {
              deploymentManager = factoryManager.getDeploymentManager(null, null, null);
          } catch (DeploymentManagerCreationException e) {
              fail("Didn't expect a DeploymentManagerException here.");
          }
          assertNotNull("Expected an instance of the MockDeploymentManager", deploymentManager);
      }
  
      public void testDeploymentManagerCreationException() {
          try {
              factoryManager.getDisconnectedDeploymentManager("throw-exception");
          } catch (DeploymentManagerCreationException e) {
              assertEquals("Could not get DeploymentManager", e.getMessage());
              return;
          }
          fail("Expected a DeploymentManagerCreationException");
      }
  
      public void testGetNullDeploymentManagerCreationException() {
          DeploymentManager disconnectedDeploymentManager = null;
          try {
              disconnectedDeploymentManager = factoryManager.getDisconnectedDeploymentManager("return-null");
          } catch (DeploymentManagerCreationException e) {
              fail("Didn't expect a DeploymentManagerException here.");
          }
          // Apperently the DeploymentFactoryManager doesn't care about the DeploymentFactory
          // returning null
          assertNull(disconnectedDeploymentManager);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/javax/enterprise/deploy/spi/MockDeploymentManager.java
  
  Index: MockDeploymentManager.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", 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/>.
   *
   * ====================================================================
   */
  package javax.enterprise.deploy.spi;
  
  import javax.enterprise.deploy.model.DeployableObject;
  import javax.enterprise.deploy.shared.DConfigBeanVersionType;
  import javax.enterprise.deploy.shared.ModuleType;
  import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException;
  import javax.enterprise.deploy.spi.exceptions.InvalidModuleException;
  import javax.enterprise.deploy.spi.exceptions.TargetException;
  import javax.enterprise.deploy.spi.status.ProgressObject;
  import java.io.File;
  import java.io.InputStream;
  import java.util.Locale;
  
  public class MockDeploymentManager implements DeploymentManager {
      public Target[] getTargets() throws IllegalStateException {
          return new Target[0];
      }
  
      public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[] targetList)
throws TargetException, IllegalStateException {
          return new TargetModuleID[0];
      }
  
      public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] targetList)
throws TargetException, IllegalStateException {
          return new TargetModuleID[0];
      }
  
      public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] targetList)
throws TargetException, IllegalStateException {
          return new TargetModuleID[0];
      }
  
      public DeploymentConfiguration createConfiguration(DeployableObject dObj) throws InvalidModuleException
{
          return null;
      }
  
      public ProgressObject distribute(Target[] targetList, File moduleArchive, File deploymentPlan)
throws IllegalStateException {
          return null;
      }
  
      public ProgressObject distribute(Target[] targetList, InputStream moduleArchive, InputStream
deploymentPlan) throws IllegalStateException {
          return null;
      }
  
      public ProgressObject start(TargetModuleID[] moduleIDList) throws IllegalStateException
{
          return null;
      }
  
      public ProgressObject stop(TargetModuleID[] moduleIDList) throws IllegalStateException
{
          return null;
      }
  
      public ProgressObject undeploy(TargetModuleID[] moduleIDList) throws IllegalStateException
{
          return null;
      }
  
      public boolean isRedeploySupported() {
          return false;
      }
  
      public ProgressObject redeploy(TargetModuleID[] moduleIDList, File moduleArchive, File
deploymentPlan) throws UnsupportedOperationException, IllegalStateException {
          return null;
      }
  
      public ProgressObject redeploy(TargetModuleID[] moduleIDList, InputStream moduleArchive,
InputStream deploymentPlan) throws UnsupportedOperationException, IllegalStateException {
          return null;
      }
  
      public void release() {
      }
  
      public Locale getDefaultLocale() {
          return null;
      }
  
      public Locale getCurrentLocale() {
          return null;
      }
  
      public void setLocale(Locale locale) throws UnsupportedOperationException {
      }
  
      public Locale[] getSupportedLocales() {
          return new Locale[0];
      }
  
      public boolean isLocaleSupported(Locale locale) {
          return false;
      }
  
      public DConfigBeanVersionType getDConfigBeanVersion() {
          return null;
      }
  
      public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType version) {
          return false;
      }
  
      public void setDConfigBeanVersion(DConfigBeanVersionType version) throws DConfigBeanVersionUnsupportedException
{
      }
  }
  
  
  
  1.2       +49 -11    incubator-geronimo/modules/core/src/java/javax/enterprise/deploy/shared/factories/DeploymentFactoryManager.java
  
  Index: DeploymentFactoryManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/javax/enterprise/deploy/shared/factories/DeploymentFactoryManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DeploymentFactoryManager.java	13 Aug 2003 19:42:07 -0000	1.1
  +++ DeploymentFactoryManager.java	14 Aug 2003 09:14:05 -0000	1.2
  @@ -62,29 +62,67 @@
   import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
   import javax.enterprise.deploy.spi.DeploymentManager;
   import javax.enterprise.deploy.spi.factories.DeploymentFactory;
  +import java.util.Iterator;
  +import java.util.ArrayList;
   
   public class DeploymentFactoryManager {
  -    /**@todo imlement */
  +    private static DeploymentFactoryManager instance;
  +
  +    private ArrayList deploymentFactories = new ArrayList();
  +
       public static DeploymentFactoryManager getInstance() {
  -        return null;
  +        if (instance == null) {
  +            instance = new DeploymentFactoryManager();
  +        }
  +        return instance;
       }
   
  -    /**@todo imlement */
  +    public void registerDeploymentFactory(DeploymentFactory factory) {
  +          // apparently we dont care about null values, the Sun RI even adds the null
  +          // to the list. So after registerDeploymentFactory(null) getDeploymentFactories()
  +          // return an array with length 1.
  +          deploymentFactories.add(factory);
  +      }
  +
       public DeploymentFactory[] getDeploymentFactories() {
  -        return null;
  +        return (DeploymentFactory[]) deploymentFactories.toArray(new DeploymentFactory[]{});
       }
   
  -    /**@todo imlement */
       public DeploymentManager getDeploymentManager(String uri, String username, String password)
throws DeploymentManagerCreationException {
  -        return null;
  -    }
  +        // RI doesn't care about uri being null, neither do we
   
  -    /**@todo imlement */
  -    public void registerDeploymentFactory(DeploymentFactory factory) {
  +        for (Iterator i = deploymentFactories.iterator(); i.hasNext();) {
  +            DeploymentFactory factory = (DeploymentFactory) i.next();
  +            if (factory != null) {
  +                if (factory.handlesURI(uri)) {
  +                    try {
  +                        return factory.getDeploymentManager(uri, username, password);
  +                    } catch (DeploymentManagerCreationException e) {
  +                        // Just like the RI we throw a new exception with a generic message
  +                        throw new DeploymentManagerCreationException("Could not get DeploymentManager");
  +                    }
  +                }
  +            }
  +        }
  +        throw new DeploymentManagerCreationException("Could not get DeploymentManager");
       }
   
  -    /**@todo imlement */
       public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException
{
  -        return null;
  +        // RI doesn't care about uri being null, neither do we
  +
  +        for (Iterator i = deploymentFactories.iterator(); i.hasNext();) {
  +            DeploymentFactory factory = (DeploymentFactory) i.next();
  +            if (factory != null) {
  +                if (factory.handlesURI(uri)) {
  +                    try {
  +                        return factory.getDisconnectedDeploymentManager(uri);
  +                    } catch (DeploymentManagerCreationException e) {
  +                        // Just like the RI we throw a new exception with a generic message
  +                        throw new DeploymentManagerCreationException("Could not get DeploymentManager");
  +                    }
  +                }
  +            }
  +        }
  +        throw new DeploymentManagerCreationException("Could not get DeploymentManager");
       }
   }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/javax/enterprise/deploy/spi/factories/MockDeploymentFactory.java
  
  Index: MockDeploymentFactory.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 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 Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", 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/>.
   *
   * ====================================================================
   */
  package javax.enterprise.deploy.spi.factories;
  
  import javax.enterprise.deploy.spi.MockDeploymentManager;
  import javax.enterprise.deploy.spi.DeploymentManager;
  import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
  
  public class MockDeploymentFactory implements DeploymentFactory {
      public boolean handlesURI(String uri) {
          // for the moment we accept all uri's
          return true;
      }
  
      public DeploymentManager getDeploymentManager(String uri, String username, String password)
throws DeploymentManagerCreationException {
          return getDisconnectedDeploymentManager(uri);
      }
  
      public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException
{
          if ("return-null".equals(uri)) {
              return null;
          } else if ("throw-exception".equals(uri)) {
              throw new DeploymentManagerCreationException("Simulated Exception");
          } else {
              return new MockDeploymentManager();
          }
      }
  
      public String getDisplayName() {
          return null;
      }
  
      public String getProductVersion() {
          return null;
      }
  }
  
  
  

Mime
View raw message