1 19 25 26 package org.netbeans.modules.j2ee.sun.share.configbean; 27 28 import junit.framework.*; 29 import org.netbeans.modules.j2ee.sun.share.SunDeploymentFactory; 30 import org.netbeans.modules.j2ee.sun.share.MockDeployableObject; 31 import javax.enterprise.deploy.spi.DeploymentManager ; 32 import org.netbeans.modules.j2ee.sun.share.SunDeploymentManager; 33 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 34 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration; 35 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 36 import javax.enterprise.deploy.spi.DConfigBean ; 37 38 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 39 40 44 public class WebAppRootTest extends TestCase { 45 46 51 52 public void testGetXPathsAbsolutely() { 53 doTestGetXPaths("/web-app/"); 54 } 55 56 private void doTestGetXPaths(String prefix) { 57 MockDDBeanRoot waddbean = new MockDDBeanRoot(); 58 waddbean.setXpath("/web-app"); 59 waddbean.setRoot(waddbean); 60 WebAppRoot war = null; 61 try { 62 war = (WebAppRoot) DC.getDConfigBeanRoot(waddbean); 63 assertNotNull(war); 64 } 65 catch (ConfigurationException ce) { 66 fail("this should not fail"); 67 } 68 String [] xpaths = war.getXpaths(); 69 assertNotNull(xpaths); 70 assertEquals(6, xpaths.length); 71 for (int i = 0; i < xpaths.length; i++) { 72 MockDDBean mddb = new MockDDBean(); 73 mddb.setXpath(prefix+xpaths[i]); 74 mddb.setRoot(waddbean); 75 DConfigBean dcb = null; 76 try { 77 dcb = war.getDConfigBean(mddb); 78 assertNotNull("got null dcb for xpath: "+xpaths[i],dcb); 79 if (null != dcb) 80 try { 81 war.removeDConfigBean(dcb); 82 } 83 catch (javax.enterprise.deploy.spi.exceptions.BeanNotFoundException bnfe) { 84 fail("got a bean not found, I should not!"); 85 } 86 } 87 catch (ConfigurationException ce) { 88 ce.printStackTrace(); 89 fail("got a ce for xpath: "+xpaths[i]); 90 } 91 try { 92 war.removeDConfigBean(dcb); 93 fail("I should not be able to find the dcb... I had removed it"); 94 } 95 catch (javax.enterprise.deploy.spi.exceptions.BeanNotFoundException bnfe) { 96 assertTrue(bnfe.getMessage(),bnfe.getMessage().startsWith("No match for bean")); 97 } 98 } 99 } 100 101 102 103 public void testProperCreate() { 104 MockDDBeanRoot waddbean = new MockDDBeanRoot(); 105 WebAppRoot war = null; 106 try { 107 war = (WebAppRoot) DC.getDConfigBeanRoot(null); 108 fail(war.toString()); 109 } 110 catch (ConfigurationException ce) { 111 assertEquals("DDBean cannot be null.",ce.getMessage()); 112 } 113 try { 114 war = (WebAppRoot) DC.getDConfigBeanRoot(waddbean); 115 fail(war.toString()); 116 } 117 catch (ConfigurationException ce) { 118 assertEquals("DDBean cannot have a null Xpath.",ce.getMessage()); 119 } 120 waddbean.setXpath("/web-app"); 121 waddbean.setRoot(waddbean); 122 try { 123 war = (WebAppRoot) DC.getDConfigBeanRoot(waddbean); 124 assertTrue(war.isValid()); 125 } 126 catch (ConfigurationException ce) { 127 fail("I should not fail here"); 128 } 129 } 130 131 static SunDeploymentFactory DF = new SunDeploymentFactory(); 132 static DeploymentManager DM = null; 133 static DeploymentConfiguration DC = null; 134 static DConfigBeanRoot WAR = null; 135 static { 136 try { 137 DM = DF.getDisconnectedDeploymentManager("deployer:Sun:AppServer::localhost:4848"); 138 DC = DM.createConfiguration(new MockDeployableObject()); 139 } 141 catch (Throwable t) { 142 fail(t.getMessage()); 143 } 144 } 145 146 public WebAppRootTest(java.lang.String testName) { 147 super(testName); 148 } 149 150 } 151 152 | Popular Tags |