1 19 25 26 package org.netbeans.modules.j2ee.sun.share.configbean; 27 28 import java.io.InputStream ; 29 import java.io.OutputStream ; 30 import java.io.StringBufferInputStream ; 31 import java.io.StringWriter ; 32 import java.io.File ; 33 import java.io.FileInputStream ; 34 import java.io.FileOutputStream ; 35 import java.io.ByteArrayInputStream ; 36 import java.io.ByteArrayOutputStream ; 37 import java.util.ArrayList ; 38 import java.util.Collections ; 39 import java.util.HashMap ; 40 import java.util.Iterator ; 41 import java.util.LinkedHashMap ; 42 import java.util.List ; 43 import java.util.Map ; 44 import java.util.Set ; 45 import junit.framework.*; 46 import org.netbeans.modules.schema2beans.BaseBean; 47 import org.netbeans.modules.schema2beans.Schema2BeansRuntimeException; 48 import javax.enterprise.deploy.model.DDBean ; 49 import javax.enterprise.deploy.model.DDBeanRoot ; 50 import javax.enterprise.deploy.model.DeployableObject ; 51 import javax.enterprise.deploy.shared.ModuleType ; 52 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 53 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 54 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException ; 55 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 56 import org.netbeans.modules.j2ee.sun.share.Constants; 57 import org.netbeans.modules.j2ee.sun.share.SunDeploymentManager; 58 import org.netbeans.modules.j2ee.sun.share.plan.DeploymentPlan; 59 import org.netbeans.modules.j2ee.sun.share.plan.FileEntry; 60 import org.netbeans.modules.j2ee.sun.common.dd.webapp.SunWebApp; 61 62 import org.netbeans.modules.j2ee.sun.share.SunDeploymentFactory; 63 import javax.enterprise.deploy.spi.DeploymentManager ; 64 import org.netbeans.modules.j2ee.sun.share.MockDeployableObject; 65 import org.netbeans.modules.j2ee.sun.share.TestConstants; 66 70 public class SunONEDeploymentConfigurationTest extends TestCase { 71 72 public void testRemove() { 73 WebAppRoot war = null; 74 try { 75 war = (WebAppRoot) dc2.getDConfigBeanRoot(waddbean); 76 assertNotNull(war); 77 dc2.removeDConfigBean(war); 78 dc2.removeDConfigBean(war); 80 fail("I should not be here"); 81 } 82 catch (BeanNotFoundException bnfe) { 83 assertTrue(bnfe.getMessage().startsWith("No match for")); 84 } 85 catch (ConfigurationException ce) { 86 ce.printStackTrace(); 87 } 88 } 89 90 91 public void testDirectoryDeploySupport() { 92 WebAppRoot war = null; 93 try { 94 war = (WebAppRoot) warDC.getDConfigBeanRoot(waddbean); 95 assertNotNull(war); 96 war.setContextRoot("myTestCR"); 97 java.io.File f = new java.io.File ("sun-web.xml"); 98 f.createNewFile(); 99 warDC.extractFileFromPlanForModule(f, warDC.getDeployableObject()); war.setContextRoot("anotherCR"); 101 warDC.addFileToPlanForModule(f, warDC.getDeployableObject()); 102 assertEquals(war.getContextRoot(), "myTestCR"); 103 } 104 catch (java.io.IOException ioe) { 105 ioe.printStackTrace(); 106 fail("got an ioe"); 107 } 108 catch (java.beans.PropertyVetoException pve) { 109 pve.printStackTrace(); 110 fail("got a pve"); 111 } 112 catch (ConfigurationException ce) { 113 ce.printStackTrace(); 114 fail("go a ce"); 115 } 116 } 117 118 public void testContextRootStuff() { 119 WebAppRoot war = null; 120 try { 121 war = (WebAppRoot) warDC.getDConfigBeanRoot(waddbean); 122 assertNotNull(war); 123 war.setContextRoot("testContextRootValue"); 124 assertEquals(war.getContextRoot(), warDC.getContextRoot()); 125 warDC.setContextRoot("newContextRoot"); 126 assertEquals(war.getContextRoot(), warDC.getContextRoot()); 127 } 128 catch (java.beans.PropertyVetoException pve) { 129 pve.printStackTrace(); 130 fail("got a pve"); 131 } 132 catch (ConfigurationException ce) { 133 ce.printStackTrace(); 134 fail("got a ce"); 135 } 136 } 137 138 139 public void testSaveRestore() { 140 try { 141 java.io.ByteArrayOutputStream baos = 142 new java.io.ByteArrayOutputStream (); 143 148 WebAppRoot war = null; 149 war = (WebAppRoot) warDC.getDConfigBeanRoot(waddbean); 150 assertNotNull(war); 151 war.setContextRoot("testContextRootValue"); 152 baos = new java.io.ByteArrayOutputStream (); 153 warDC.save(baos); 154 assertTrue(baos.toString().indexOf("testContextRootValue") > 0); 155 war.setContextRoot("ContextRootValueTest"); 156 warDC.restore(new java.io.ByteArrayInputStream (baos.toByteArray())); 157 assertEquals(war.getContextRoot(), "testContextRootValue"); 158 } 160 catch (java.beans.PropertyVetoException pve) { 161 fail("setter got veto'ed"); 162 } 163 catch (ConfigurationException ce) { 164 ce.printStackTrace(); 165 fail("check on this"); 166 } 167 } 168 169 public void testCreate() { 170 assertNotNull(warDC); 171 } 172 173 public SunONEDeploymentConfigurationTest(java.lang.String testName) { 174 super(testName); 175 } 176 177 static SunDeploymentFactory DF = new SunDeploymentFactory(); 178 static DeploymentManager DM = null; 179 static SunONEDeploymentConfiguration warDC = null; 180 static DConfigBeanRoot WAR = null; 181 static MockDDBeanRoot waddbean = null; 182 static DeploymentConfiguration dc2 = null; 183 static { 184 try { 185 DM = DF.getDisconnectedDeploymentManager("deployer:Sun:AppServer::localhost:4848"); 186 MockDeployableObject dObj = new MockDeployableObject(); 187 waddbean = new MockDDBeanRoot(); 188 waddbean.setXpath("/web-app"); 189 dObj.setDDBeanRoot(waddbean); 190 waddbean.setRoot(waddbean); 191 warDC = (SunONEDeploymentConfiguration) DM.createConfiguration(dObj); 192 dc2 = DM.createConfiguration(dObj); 193 } 195 catch (Throwable t) { 196 fail(t.getMessage()); 197 } 198 } 199 200 201 202 } 203 | Popular Tags |