1 19 package org.netbeans.modules.j2ee.archive.xtests; 20 21 import java.io.BufferedReader ; 22 import java.io.File ; 23 import java.io.FileReader ; 24 import java.io.IOException ; 25 import javax.enterprise.deploy.shared.ModuleType ; 26 import javax.enterprise.deploy.spi.Target ; 27 import javax.enterprise.deploy.spi.TargetModuleID ; 28 import javax.management.ObjectName ; 29 import org.netbeans.junit.NbTestCase; 30 import org.netbeans.junit.ide.ProjectSupport; 31 import org.netbeans.modules.j2ee.archive.project.ArchiveProjectProperties; 32 import org.netbeans.modules.j2ee.archive.ui.JavaEePlatformUiSupport; 33 import org.netbeans.modules.j2ee.archive.wizard.*; 34 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 35 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 36 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 37 import org.netbeans.spi.project.ui.support.ProjectChooser; 38 import org.openide.WizardDescriptor; 39 40 45 public class TestUtil { 46 47 public static final String EJB_PROJECT_NAME = "SjsasTestEjb"; 49 public static final String WEB_PROJECT_NAME = "SjsasTestWeb"; 50 public static final String EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EJB_PROJECT_NAME; 51 public static final String WEB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + WEB_PROJECT_NAME; 52 public static final int SLEEP = 10000; 53 54 public static final String _SEP = System.getProperty("file.separator"); 56 public static final String _DISPLAY_NAME = "Sun Java System Application Server"; 57 public static final String _PLATFORM_LOCATION = System.getProperty("sjsas.server.path"); 58 public static final String _INSTALL_LOCATION = _PLATFORM_LOCATION+_SEP+"domains"; 59 public static final String _DOMAIN = "domain1"; 60 public static final String _HOST = "localhost"; 61 public static final String _PORT = getPort(new File (_INSTALL_LOCATION+_SEP+_DOMAIN+_SEP+"config"+_SEP+"domain.xml")); 62 public static final String _USER_NAME = "admin"; 63 public static final String _PASSWORD = "adminadmin"; 64 public static final String _URL = "["+_PLATFORM_LOCATION+"]deployer:Sun:AppServer::"+_HOST+":"+_PORT; 65 66 public static final String USER_NAME = "username"; 68 public static final String PASSWORD = "password"; 69 public static final String HOST = "host"; 70 public static final String PORT = "port"; 71 public static final String PLATFORM_LOCATION = "platform_location"; 72 public static final String INSTALL_LOCATION = "install_location"; 73 public static final String DOMAIN = "domain"; 74 public static final String TYPE = "type"; 75 public static final String PROP_DISPLAY_NAME = "ServInstWizard_displayName"; 76 77 80 public static String getPort(File domainXml){ 81 String adminPort = null; 82 String buffer = null; 83 84 try { 85 FileReader reader = new FileReader (domainXml); 86 BufferedReader br = new BufferedReader (reader); 87 88 while((buffer = br.readLine()) != null) { 89 if(buffer.indexOf("admin-listener") > -1) { 90 int x = buffer.indexOf(34, buffer.indexOf("port")); 91 int y = buffer.indexOf(34, ++x); 92 adminPort = buffer.substring(x, y); 93 break; 94 } 95 } 96 97 br.close(); 98 reader.close(); 99 } catch (Exception ex) { 100 ex.printStackTrace(); 101 } 102 103 return adminPort; 104 } 105 106 public static void sleep(int i) { 107 try { 108 Thread.sleep(i); 109 } catch(Exception e) { 110 } 112 } 113 114 162 172 189 197 static void createProjectFromArchive(String archiveName, String type, int sleepTime) { 198 WizardDescriptor wizDesc = new WizardDescriptor(new WizardDescriptor.Panel[0]); 199 File oldVal = ProjectChooser.getProjectsFolder(); 200 File projDest = new File (System.getProperty("xtest.tmpdir") + File.separator + archiveName); 201 wizDesc.putProperty(DeployableWizardIterator.PROJECT_DIR_PROP, projDest); 202 File archive = new File (System.getProperty("xtest.data")+File.separator + archiveName); 203 wizDesc.putProperty(DeployableWizardIterator.PROJECT_ARCHIVE_PROP, archive); 204 String subprojkey = archiveName; 206 wizDesc.putProperty(DeployableWizardIterator.PROJECT_NAME_PROP, 207 subprojkey); 208 209 wizDesc.putProperty(DeployableWizardIterator.PROJECT_TARGET_PROP, 210 JavaEePlatformUiSupport.getServerInstanceID(TestUtil._URL)); 211 wizDesc.putProperty(DeployableWizardIterator.PROJECT_TYPE_PROP, 212 type); 213 DeployableWizardIterator dwi = new DeployableWizardIterator(); 214 dwi.initialize(wizDesc); 215 try { 216 dwi.instantiate(); 217 } catch (IOException ioe) { 218 NbTestCase.fail(); } 220 if (null != oldVal) { 221 ProjectChooser.setProjectsFolder(oldVal); 222 } 223 try { 224 Thread.currentThread().sleep(sleepTime); 225 } catch (InterruptedException ex) { 226 ex.printStackTrace(); 227 } 228 } 229 230 } | Popular Tags |