OSDN Git Service

Create SMTPclient test class.
authorTakuya Ono <takuya-o@users.sourceforge.jp>
Thu, 9 Aug 2007 16:59:24 +0000 (16:59 +0000)
committerTakuya Ono <takuya-o@users.sourceforge.jp>
Thu, 9 Aug 2007 16:59:24 +0000 (16:59 +0000)
test/org/jent/checksmtp/SMTPclientTest.java [new file with mode: 0644]

diff --git a/test/org/jent/checksmtp/SMTPclientTest.java b/test/org/jent/checksmtp/SMTPclientTest.java
new file mode 100644 (file)
index 0000000..1c61c9a
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * SMTPclientTest.java
+ * JUnit based test
+ *
+ * Created on 2007/08/10, 0:10
+ */
+
+package org.jent.checksmtp;
+
+import junit.framework.*;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketTimeoutException;
+
+/**
+ *
+ * @author tkyn
+ */
+public class SMTPclientTest extends TestCase {
+  
+  public SMTPclientTest(String testName) {
+    super(testName);
+  }
+  
+  protected void setUp() throws Exception {
+  }
+  
+  protected void tearDown() throws Exception {
+  }
+  
+  
+  /**
+   * Stop theard which wait connect from SMTP client
+   */
+  private void stopClient(SMTPclient instance) {
+    System.out.println(">>>>>>>>>>>>>>>>>>>>>>> Set wrong Port number, it will be occurred Faital Error and stop thread.");
+    ApplicationProperties.setSmtpPort(65536);
+    instance.configChangeNotify();
+    sleep();
+    System.out.println("<<<<<<<<<<<<<<<<<<<<<<<");
+  }
+  
+  private void sleep() {
+    try {
+      Thread.sleep(1500); //Wait soTimeOut on accept.  now setSoTimeout(1000);
+    } catch (InterruptedException ex) {
+      ex.printStackTrace();
+    }
+  }
+  
+  /**
+   * Test of normal port number, of class org.jent.checksmtp.SMTPclient.
+   */
+  public void testNormalPortNumber() {
+    System.out.println("run testNormalPortNumber");
+    
+    ApplicationProperties.setSmtpPort(8725);
+    SMTPclient instance = new SMTPclient();
+    
+    assertNotNull(instance);
+    stopClient(instance);
+    assertNotNull(instance);
+  }
+  
+  /**
+   * Test on abnormal port number.
+   */
+  public void testAbnormalPortNumber() {
+    System.out.println("test abnormal port number.");
+    
+    ApplicationProperties.setSmtpPort(65540);
+    SMTPclient instance = new SMTPclient();
+    sleep();
+    assertNotNull(instance);
+    
+    ApplicationProperties.setSmtpPort(-1);
+    instance = new SMTPclient();
+    sleep();
+    assertNotNull(instance);
+    
+  }
+  
+  
+  
+}