geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/specs/j2ee-deployment/src/java/javax/enterprise/deploy/shared/factories DeploymentFactoryManager.java
Date Sat, 16 Aug 2003 15:37:52 GMT
jdillon     2003/08/16 08:37:52

  Modified:    modules/core/src/test/javax/enterprise/deploy/shared/factories
                        DeploymentFactoryManagerTest.java
               specs/j2ee-deployment/src/java/javax/enterprise/deploy/shared/factories
                        DeploymentFactoryManager.java
  Log:
   o Applied DFM patch take 3 from Aaron Mulder
  
  Revision  Changes    Path
  1.2       +57 -30    incubator-geronimo/modules/core/src/test/javax/enterprise/deploy/shared/factories/DeploymentFactoryManagerTest.java
  
  Index: DeploymentFactoryManagerTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/javax/enterprise/deploy/shared/factories/DeploymentFactoryManagerTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DeploymentFactoryManagerTest.java	14 Aug 2003 09:14:05 -0000	1.1
  +++ DeploymentFactoryManagerTest.java	16 Aug 2003 15:37:52 -0000	1.2
  @@ -58,9 +58,9 @@
   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;
  +import org.apache.geronimo.enterprise.deploy.provider.GeronimoDeploymentFactory;
   
   /**
    * Low level tests on the DeploymentFactoryManager.
  @@ -80,28 +80,54 @@
   
       public void testGetDeploymentManagerWithoutAnyRegisteredFactories() {
           try {
  -            factoryManager.getDeploymentManager(null, null, null);
  +            factoryManager.getDeploymentManager("invalid-uri", null, null);
  +            fail("Expected a DeploymentManagerCreationException");
           } catch (DeploymentManagerCreationException e) {
  -            assertEquals("Could not get DeploymentManager", e.getMessage());
  -            return;
  +            assertTrue(e.getMessage().startsWith("Could not get DeploymentManager"));
           }
  -        fail("Expected a DeploymentManagerCreationException");
       }
   
       public void testDisconnectedGetDeploymentManagerWithoutAnyRegisteredFactories() {
           try {
  -            factoryManager.getDisconnectedDeploymentManager(null);
  +            factoryManager.getDisconnectedDeploymentManager("invalid-uri");
  +            fail("Expected a DeploymentManagerCreationException");
           } catch (DeploymentManagerCreationException e) {
  -            assertEquals("Could not get DeploymentManager", e.getMessage());
  -            return;
  +            assertTrue(e.getMessage().startsWith("Could not get DeploymentManager"));
  +        }
  +    }
  +
  +    public void testGetDeploymentManagerWithNullURI() {
  +        try {
  +            factoryManager.getDeploymentManager(null, null, null);
  +            fail("Expected an IllegalArgumentException");
  +        } catch (IllegalArgumentException e) {
  +        } catch(DeploymentManagerCreationException e) {
  +            fail("Unexpected Exception: "+e.getMessage());
  +        }
  +    }
  +
  +    public void testDisconnectedGetDeploymentManagerWithNullURI() {
  +        try {
  +            factoryManager.getDisconnectedDeploymentManager(null);
  +            fail("Expected an IllegalArgumentException");
  +        } catch (IllegalArgumentException e) {
  +        } catch(DeploymentManagerCreationException e) {
  +            fail("Unexpected Exception: "+e.getMessage());
  +        }
  +    }
  +
  +    public void testRegisterNull() {
  +        try {
  +            factoryManager.registerDeploymentFactory(null);
  +            fail("Should have gotten an IllegalArgumentException");
  +        } catch(IllegalArgumentException e) {
           }
  -        fail("Expected a DeploymentManagerCreationException");
       }
   
       public void testRegisterDeploymentFactory() {
           int initialNumberOfFactories = factoryManager.getDeploymentFactories().length;
   
  -        DeploymentFactory factory = new MockDeploymentFactory();
  +        DeploymentFactory factory = new GeronimoDeploymentFactory();
           factoryManager.registerDeploymentFactory(factory);
   
           int expectedNumberOfFactories = initialNumberOfFactories + 1;
  @@ -110,42 +136,43 @@
           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);
  +        ensureFactoryRegistered();
  +        DeploymentManager deploymentManager = null;
  +        try {
  +            deploymentManager = factoryManager.getDeploymentManager("deployer:geronimo://server:port/application",
"username", "password");
  +        } catch (DeploymentManagerCreationException e) {
  +            fail("Didn't expect a DeploymentManagerException here.");
  +        }
  +        assertNotNull("Expected an instance of the DeploymentManager", deploymentManager);
  +    }
   
  +    public void testGetDisconnectedDeploymentManager() {
  +        ensureFactoryRegistered();
           DeploymentManager deploymentManager = null;
           try {
  -            deploymentManager = factoryManager.getDeploymentManager(null, null, null);
  +            deploymentManager = factoryManager.getDeploymentManager("deployer:geronimo:",
null, null);
           } catch (DeploymentManagerCreationException e) {
               fail("Didn't expect a DeploymentManagerException here.");
           }
  -        assertNotNull("Expected an instance of the MockDeploymentManager", deploymentManager);
  +        assertNotNull("Expected an instance of the DeploymentManager", deploymentManager);
       }
   
       public void testDeploymentManagerCreationException() {
  +        ensureFactoryRegistered();
           try {
               factoryManager.getDisconnectedDeploymentManager("throw-exception");
  +            fail("Expected a DeploymentManagerCreationException");
           } catch (DeploymentManagerCreationException e) {
  -            assertEquals("Could not get DeploymentManager", e.getMessage());
  -            return;
  +            assertTrue(e.getMessage().startsWith("Could not get DeploymentManager"));
           }
  -        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.");
  +    private void ensureFactoryRegistered() {
  +        int numberOfFactories = factoryManager.getDeploymentFactories().length;
  +        if(numberOfFactories == 0) {
  +            factoryManager.registerDeploymentFactory(new GeronimoDeploymentFactory());
           }
  -        // Apperently the DeploymentFactoryManager doesn't care about the DeploymentFactory
  -        // returning null
  -        assertNull(disconnectedDeploymentManager);
  +        assertTrue("We should have a registered DeploymentFactory", numberOfFactories >
0);
       }
   }
  
  
  
  1.2       +89 -32    incubator-geronimo/specs/j2ee-deployment/src/java/javax/enterprise/deploy/shared/factories/DeploymentFactoryManager.java
  
  Index: DeploymentFactoryManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/j2ee-deployment/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	16 Aug 2003 12:28:26 -0000	1.1
  +++ DeploymentFactoryManager.java	16 Aug 2003 15:37:52 -0000	1.2
  @@ -66,6 +66,22 @@
   import java.util.ArrayList;
   
   /**
  + * The DeploymentFactoryManager class is a central registry for J2EE
  + * DeploymentFactory objects. The DeploymentFactoryManager retains references
  + * to DeploymentFactory objects loaded by a tool. A DeploymentFactory object
  + * provides a reference to a DeploymentManager. The DeploymentFactoryManager
  + * has been implemented as a singleton. A tool gets a reference to the
  + * DeploymentFactoryManager via the getInstance method. The
  + * DeploymentFactoryManager can return two types of DeploymentManagers, a
  + * connected DeploymentManager and a disconnected DeploymentManager. The
  + * connected DeploymentManager provides access to any product resources that
  + * may be required for configurations and deployment. The method to retrieve a
  + * connected DeploymentManager is getDeploymentManager. This method provides
  + * parameters for user name and password that the product may require for user
  + * authentication. A disconnected DeploymentManager does not provide access to
  + * a running J2EE product. The method to retrieve a disconnected
  + * DeploymentManager is getDisconnectedDeploymentManager. A disconnected
  + * DeploymentManager does not need user authentication information.
    *
    * @version $Revision$ $Date$
    */
  @@ -77,59 +93,100 @@
       private DeploymentFactoryManager() {
       }
   
  +    /**
  +     * Retrieve the Singleton DeploymentFactoryManager
  +     *
  +     * @return DeploymentFactoryManager instance
  +     */
       public static DeploymentFactoryManager getInstance() {
  -        if (instance == null) {
  +        if(instance == null) {
               instance = new DeploymentFactoryManager();
           }
           return instance;
       }
   
  +    /**
  +     * Retrieve the lists of currently registered DeploymentFactories.
  +     *
  +     * @return the list of DeploymentFactory objects or an empty array if there are none.
  +     */
       public DeploymentFactory[] getDeploymentFactories() {
  -        return (DeploymentFactory[]) deploymentFactories.toArray(new DeploymentFactory[]{});
  +        return (DeploymentFactory[])deploymentFactories.toArray(new DeploymentFactory[deploymentFactories.size()]);
       }
   
  +    /**
  +     * Retrieves a DeploymentManager instance to use for deployment. The caller
  +     * provides a URI and optional username and password, and all registered
  +     * DeploymentFactories will be checked. The first one to understand the URI
  +     * provided will attempt to initiate a server connection and return a ready
  +     * DeploymentManager instance.
  +     *
  +     * @param uri      The uri to check
  +     * @param username An optional username (may be <tt>null</tt> if no
  +     *                 authentication is required for this platform).
  +     * @param password An optional password (may be <tt>null</tt> if no
  +     *                 authentication is required for this platform).
  +     *
  +     * @return A ready DeploymentManager instance.
  +     *
  +     * @throws DeploymentManagerCreationException Occurs when the factory
  +     *         appropriate to the specified URI was unable to initialize a
  +     *         DeploymentManager instance (server down, unable to authenticate,
  +     *         etc.).
  +     */
       public DeploymentManager getDeploymentManager(String uri, String username, String password)
throws DeploymentManagerCreationException {
  -        // 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.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");
  -                    }
  +        if(uri == null) {
  +            throw new IllegalArgumentException("URI for DeploymentManager should not be
null");
  +        }
  +        DeploymentManager manager = null;
  +        for(Iterator i = deploymentFactories.iterator(); i.hasNext();) {
  +            DeploymentFactory factory = (DeploymentFactory)i.next();
  +            if(factory.handlesURI(uri)) {
  +                manager = factory.getDeploymentManager(uri, username, password);
  +                if(manager != null) {
  +                    return manager;
                   }
               }
           }
  -        throw new DeploymentManagerCreationException("Could not get DeploymentManager");
  +        throw new DeploymentManagerCreationException("Could not get DeploymentManager;
No registered DeploymentFactory handles this URI");
       }
   
  +    /**
  +     * Return a disconnected DeploymentManager instance.
  +     *
  +     * @param uri identifier of the disconnected DeploymentManager to return.
  +     *
  +     * @return A DeploymentManager instance.
  +     *
  +     * @throws DeploymentManagerCreationException occurs if the
  +     *         DeploymentManager could not be created.
  +     */
       public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException
{
  -        // 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");
  -                    }
  +        if(uri == null) {
  +            throw new IllegalArgumentException("URI for DeploymentManager should not be
null");
  +        }
  +        DeploymentManager manager = null;
  +        for(Iterator i = deploymentFactories.iterator(); i.hasNext();) {
  +            DeploymentFactory factory = (DeploymentFactory)i.next();
  +            if(factory.handlesURI(uri)) {
  +                manager = factory.getDisconnectedDeploymentManager(uri);
  +                if(manager != null) {
  +                    return manager;
                   }
               }
           }
  -        throw new DeploymentManagerCreationException("Could not get DeploymentManager");
  +        throw new DeploymentManagerCreationException("Could not get DeploymentManager;
No registered DeploymentFactory handles this URI");
       }
   
  +    /**
  +     * Registers a DeploymentFactory so it will be able to handle requests.
  +     */ 
       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);
  +        if(factory == null) {
  +            throw new IllegalArgumentException("DeploymentFactory to register should not
be null");
  +        }
  +        if(!deploymentFactories.contains(factory)) {
  +            deploymentFactories.add(factory);
  +        }
       }
   }
  
  
  

Mime
View raw message