1 19 27 28 package org.netbeans.modules.j2ee.sun.test; 29 30 import java.io.BufferedReader ; 31 import java.io.File ; 32 import java.io.InputStreamReader ; 33 import org.netbeans.junit.NbTestCase; 34 import org.netbeans.junit.NbTestSuite; 35 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 36 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 37 import org.netbeans.modules.j2ee.sun.api.ServerInterface; 38 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 39 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources; 40 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils; 41 import org.netbeans.modules.j2ee.sun.ide.sunresources.resourcesloader.SunResourceDataObject; 42 import org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.ResourceConfigData; 43 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants; 44 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair; 45 import org.openide.filesystems.FileObject; 46 import org.openide.filesystems.FileUtil; 47 51 public class MailResourceTest extends NbTestCase implements WizardConstants{ 52 53 private static String MAIL_RESOURCE_NAME = "mailResourceTest"; 54 private static String MAIL_USER= "default"; 55 private static String MAIL_FROM = "default@sun.com"; 56 57 58 public MailResourceTest(String testName) { 59 super(testName); 60 } 61 62 public void registerMailResource() { 63 try { 64 ResourceConfigData mrdata = new ResourceConfigData(); 66 ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL); 67 NameValuePair v =new NameValuePair(); 69 v.setParamName("imqDestination"); 70 v.setParamValue("dont know"); 71 v.setParamDescription("test property"); 72 mrdata.addProperty(v); 73 mrdata.setString(__JndiName, MAIL_RESOURCE_NAME); 74 mrdata.setString(__StoreProtocol, "imap"); 75 mrdata.setString(__StoreProtocolClass, "com.sun.mail.imap.IMAPStore"); 76 mrdata.setString(__TransportProtocol, "smtp"); 77 mrdata.setString(__TransportProtocolClass, "com.sun.mail.smtp.SMTPTransport"); 78 mrdata.setString(__Host, "mail-apac.sun.com"); 79 mrdata.setString(__MailUser, MAIL_USER); 80 mrdata.setString(__Debug, "false"); 81 mrdata.setString(__From,MAIL_FROM); 82 mrdata.setString(__Enabled,"true"); 83 File fpf = File.createTempFile("falseProject",""); 85 fpf.delete(); 86 FileObject falseProject = FileUtil.createFolder(fpf); 87 falseProject.createFolder("setup"); 88 mrdata.setTargetFileObject(falseProject); 89 mrdata.setTargetFile("mailResourceTest"); 90 ResourceUtils.saveMailResourceDatatoXml(mrdata); 91 SunResourceDataObject resourceObj = (SunResourceDataObject)SunResourceDataObject.find(falseProject.getFileObject("setup/mailResourceTest.sun-resource")); 92 Resources res = Util.getResourcesObject(resourceObj); 93 ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement(); 94 ResourceUtils.register(res.getMailResource(0), mejb, false); 95 resourceObj.delete(); 96 falseProject.delete(); 97 Util.sleep(5000); 99 String [] mailResource=Util.getResourcesNames("getMailResource","jndi-name",mejb); 100 for(int i=0;i<mailResource.length;i++) { 101 if(mailResource[i].equals(MAIL_RESOURCE_NAME)) 102 return; 103 } 104 throw new Exception ("Java Mail Resource hasn't been created !"); 105 } catch(Exception e) { 106 fail(e.getMessage()); 107 } 108 } 109 public void unregisterMailResource() { 110 try { 111 ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL); 112 ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement(); 113 String [] command = new String [] {"delete-javamail-resource", "--user", "admin", MAIL_RESOURCE_NAME}; 114 Process p=Util.runAsadmin(command); 115 Util.sleep(Util.SLEEP); 116 BufferedReader error = new BufferedReader (new InputStreamReader (p.getErrorStream())); 117 String errorMess = error.readLine(); 118 BufferedReader input = new BufferedReader (new InputStreamReader (p.getInputStream())); 119 String output=input.readLine(); 120 if(errorMess!=null) 121 throw new Exception (errorMess+"\n"+output); 122 System.out.println(output); 123 Util.closeProject(Util.WEB_PROJECT_NAME); 124 Util.sleep(5000); 125 String [] mailResource = Util.getResourcesNames("getMailResource", "jndi-name", mejb); 126 for(int i=0;i<mailResource.length;i++) { 127 if(mailResource[i].equals(MAIL_RESOURCE_NAME)) 128 throw new Exception ("Java Mail Resource hasn't been removed !"); 129 } 130 } catch(Exception e) { 131 fail(e.getMessage()); 132 } 133 } 134 public static NbTestSuite suite() { 135 NbTestSuite suite = new NbTestSuite("MailResourcesTest"); 136 suite.addTest(new AddRemoveSjsasInstanceTest("addSjsasInstance")); 137 suite.addTest(new StartStopServerTest("startServer")); 138 suite.addTest(new MailResourceTest("registerMailResource")); 139 suite.addTest(new MailResourceTest("unregisterMailResource")); 140 suite.addTest(new StartStopServerTest("stopServer")); 141 suite.addTest(new AddRemoveSjsasInstanceTest("removeSjsasInstance")); 142 return suite; 143 } 144 } 145 | Popular Tags |