1 17 18 24 package javax.enterprise.deploy.shared.factories; 25 26 import junit.framework.TestCase; 27 28 import javax.enterprise.deploy.spi.factories.DeploymentFactory; 29 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException; 30 import javax.enterprise.deploy.spi.DeploymentManager; 31 32 import javax.enterprise.deploy.spi.factories.MockDeploymentFactory; 33 34 37 public class DeploymentFactoryManagerTest extends TestCase { 38 private DeploymentFactoryManager factoryManager; 39 40 protected void setUp() throws Exception { 41 super.setUp(); 42 factoryManager = DeploymentFactoryManager.getInstance(); 43 } 44 45 protected void tearDown() throws Exception { 46 factoryManager = null; 47 super.tearDown(); 48 } 49 50 public void testGetDeploymentManagerWithoutAnyRegisteredFactories() { 51 try { 52 factoryManager.getDeploymentManager("invalid-uri", null, null); 53 fail("Expected a DeploymentManagerCreationException"); 54 } catch (DeploymentManagerCreationException e) { 55 assertTrue(e.getMessage().startsWith("Could not get DeploymentManager")); 56 } 57 } 58 59 public void testDisconnectedGetDeploymentManagerWithoutAnyRegisteredFactories() { 60 try { 61 factoryManager.getDisconnectedDeploymentManager("invalid-uri"); 62 fail("Expected a DeploymentManagerCreationException"); 63 } catch (DeploymentManagerCreationException e) { 64 assertTrue(e.getMessage().startsWith("Could not get DeploymentManager")); 65 } 66 } 67 68 public void testGetDeploymentManagerWithNullURI() { 69 try { 70 factoryManager.getDeploymentManager(null, null, null); 71 fail("Expected an IllegalArgumentException"); 72 } catch (IllegalArgumentException e) { 73 } catch(DeploymentManagerCreationException e) { 74 fail("Unexpected Exception: "+e.getMessage()); 75 } 76 } 77 78 public void testDisconnectedGetDeploymentManagerWithNullURI() { 79 try { 80 factoryManager.getDisconnectedDeploymentManager(null); 81 fail("Expected an IllegalArgumentException"); 82 } catch (IllegalArgumentException e) { 83 } catch(DeploymentManagerCreationException e) { 84 fail("Unexpected Exception: "+e.getMessage()); 85 } 86 } 87 88 public void testRegisterNull() { 89 try { 90 factoryManager.registerDeploymentFactory(null); 91 fail("Should have gotten an IllegalArgumentException"); 92 } catch(IllegalArgumentException e) { 93 } 94 } 95 96 public void testRegisterDeploymentFactory() { 97 int initialNumberOfFactories = factoryManager.getDeploymentFactories().length; 98 99 DeploymentFactory factory = new MockDeploymentFactory(); 100 factoryManager.registerDeploymentFactory(factory); 101 102 int expectedNumberOfFactories = initialNumberOfFactories + 1; 103 int currentNumberOfFactories = factoryManager.getDeploymentFactories().length; 104 105 assertEquals(expectedNumberOfFactories, currentNumberOfFactories); 106 } 107 108 public void testGetDeploymentManager() { 109 ensureFactoryRegistered(); 110 DeploymentManager deploymentManager = null; 111 try { 112 deploymentManager = factoryManager.getDeploymentManager("deployer:geronimo://server:port/application", "username", "password"); 113 } catch (DeploymentManagerCreationException e) { 114 fail("Didn't expect a DeploymentManagerException here."); 115 } 116 assertNotNull("Expected an instance of the DeploymentManager", deploymentManager); 117 } 118 119 public void testGetDisconnectedDeploymentManager() { 120 ensureFactoryRegistered(); 121 DeploymentManager deploymentManager = null; 122 try { 123 deploymentManager = factoryManager.getDeploymentManager("deployer:geronimo:", null, null); 124 } catch (DeploymentManagerCreationException e) { 125 fail("Didn't expect a DeploymentManagerException here."); 126 } 127 assertNotNull("Expected an instance of the DeploymentManager", deploymentManager); 128 } 129 130 public void testDeploymentManagerCreationException() { 131 ensureFactoryRegistered(); 132 try { 133 factoryManager.getDisconnectedDeploymentManager("throw-exception"); 134 fail("Expected a DeploymentManagerCreationException"); 135 } catch (DeploymentManagerCreationException e) { 136 } 141 } 142 143 private void ensureFactoryRegistered() { 144 int numberOfFactories = factoryManager.getDeploymentFactories().length; 145 if(numberOfFactories == 0) { 146 factoryManager.registerDeploymentFactory(new MockDeploymentFactory()); 147 } 148 assertTrue("We should have a registered DeploymentFactory", numberOfFactories > 0); 149 } 150 } 151 | Popular Tags |