| @@ -0,0 +1,231 @@ | ||
| var j=0; | ||
|
|
||
| function generate(){ | ||
| context.clearRect(0, 0, canvas.width, canvas.height); | ||
| var inpText_name=document.getElementById("inpText_Name").value; | ||
| var inpText_course=document.getElementById("inpText_Course").value; | ||
| var inpText_year=document.getElementById("inpText_Year").value; | ||
| var inpText_month=document.getElementById("inpText_Month").value; | ||
| var inpText_day=document.getElementById("inpText_Day").value; | ||
| var wordstyle=document.getElementById("sel").value; | ||
| var ctx = myCanvas.getContext('2d'); | ||
| var imageObj = new Image(); | ||
| var x = 0; | ||
| var y = 0; | ||
| var width = 578; | ||
| var height = 400; | ||
|
|
||
| imageObj.onload = function() { | ||
| ctx.drawImage(imageObj, x,y ,width,height); | ||
| ctx.font = "20px " + wordstyle; | ||
| ctx.textAlign="right"; | ||
| ctx.fillText(inpText_name ,190, 120); | ||
| ctx.textAlign="center"; | ||
| ctx.fillText(inpText_year ,240, 122); | ||
| ctx.fillText(inpText_month ,295, 122); | ||
| ctx.fillText(inpText_day ,360, 122); | ||
| ctx.fillText(inpText_course ,279, 160); | ||
| ctx.fillText("12" ,223, 207); | ||
| ctx.font = "15px " + wordstyle; | ||
| ctx.fillText("104598007" ,485, 75); | ||
| ctx.fillText(checkedBoxes ,500, 160); | ||
| download(myCanvas); | ||
|
|
||
| }; | ||
| imageObj.src = 'Screenshot_2016-03-30_22.11.28.png'; | ||
| } | ||
|
|
||
| function e_mail_preview(Name,Course){ | ||
| var temp_name=document.createElement('temp'); | ||
| temp.fahr.value= | ||
| 'Hi ' | ||
| + Name | ||
| + ',\n' | ||
| + ' 您好,歡迎報名' | ||
| + Course | ||
| + ',以下是您的上課通知,請參考。\n' | ||
| + '若有任何問題,歡迎隨時聯絡我們。\n' | ||
| + '泰迪軟體 Erica' | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| function download(canvas) { | ||
| var filename = 'Certificate.png'; | ||
| var lnk = document.createElement('buffer'),e; | ||
| lnk.download = filename; | ||
| lnk.href = canvas.toDataURL(); | ||
| if (document.createEvent) { | ||
| e = document.createEvent("MouseEvents"); | ||
| e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | ||
| lnk.dispatchEvent(e); | ||
| } else if (lnk.fireEvent) { | ||
| lnk.fireEvent("onclick"); | ||
| } | ||
| } | ||
| */ | ||
|
|
||
|
|
||
| function renew(index){ | ||
| for(var i=0;i<department[index].length;i++) | ||
| document.myForm.member.options[i]=new Option(department[index][i], department[index][i]); // 設定新選項 | ||
| document.myForm.member.length=department[index].length; // 刪除多餘的選項 | ||
| } | ||
|
|
||
| function renew_mail(index){ | ||
| var s2=document.getElementById("inpText_Name_1"); | ||
| s2.innerHTML = ""; | ||
|
|
||
| for(var option in department[index]) | ||
| { | ||
| if (department[index].hasOwnProperty(option)) { | ||
| var pair = department[index][option]; | ||
| var checkbox = document.createElement("input"); | ||
| checkbox.type = "checkbox"; | ||
| checkbox.name = "checkbox_name"; | ||
| checkbox.value = pair; | ||
| checkbox.checked = true; | ||
| s2.appendChild(checkbox); | ||
|
|
||
| var label = document.createElement('label') | ||
| label.htmlFor = pair; | ||
| label.appendChild(document.createTextNode(pair)); | ||
| s2.appendChild(label); | ||
| s2.appendChild(document.createElement("br")); | ||
| } | ||
| } | ||
| var temp_name=document.createElement('temp'); | ||
| temp.fahr.value= '請按下產生'; | ||
| document.temp.member.options.length = 0; | ||
| } | ||
|
|
||
| function generatemail(){ | ||
| j=0; | ||
| var s2=document.getElementById("inpText_Name_1").childNodes[1].firstChild; | ||
| var inpText_Name=s2.parentNode; | ||
| //Get students name | ||
| var inptext_name=inpText_Name.parentNode.innerText; | ||
| //var innerHTMLteset = inpText_Name.parentNode.innerHTML; | ||
| //Get number of students | ||
| //var numberofstudent = (innerHTMLteset.split("</label><br>").length)-1; | ||
| //Import students name into array for mail preview purpose | ||
| var array_name = inptext_name.split('\n'); | ||
| var checkbox_list= document.getElementsByName('checkbox_name'); | ||
| for (i=0;i<array_name.length-1;i++) { | ||
| document.temp.member.options[i] = null; | ||
| } | ||
| for(i=0;i<array_name.length-1;i++){ | ||
| if(checkbox_list[i].checked){ | ||
| document.temp.member.options[j]=new Option(checkbox_list[i].value, checkbox_list[i].value); | ||
| j=j+1;} | ||
| } | ||
| var temp_name=document.createElement('temp'); | ||
| temp.fahr.value= '請透過選取右邊名單來預覽信件'; | ||
| } | ||
|
|
||
| //Trigger event when user click student name for preview input | ||
| function renew_mailcontent(){ | ||
| var inptext_course=document.getElementById("inpText_Course").value; | ||
| //check which one student be choose by user | ||
| for(i=0;i<j;i++){ | ||
| if(document.temp.member.options[i].selected) | ||
| //Call function to update e-mail preview content | ||
| e_mail_preview(document.temp.member.options[i].value,inptext_course); | ||
| } | ||
| } | ||
|
|
||
| function sendmail(){ | ||
| var data=new Object(); | ||
| var data_buffer=[]; | ||
| var s2=document.getElementById("inpText_Name_1").childNodes[1].firstChild; | ||
| var inpText_Name=s2.parentNode; | ||
| var inptext_name=inpText_Name.parentNode.innerText; | ||
| var array_name = inptext_name.split('\n'); | ||
| var checkbox_list= document.getElementsByName('checkbox_name'); | ||
| //Return index to back end | ||
| var checked=0; | ||
| for(i=0;i<array_name.length-1;i++){ | ||
| if(checkbox_list[i].checked){ | ||
|
|
||
| data_buffer.push(i); | ||
| checked=1; | ||
| } | ||
| } | ||
| if(checked==1){ | ||
| data.indexes=data_buffer; | ||
| console.log(data); | ||
| $.post("http://localhost:8080/SLM2016/SendGmailServlet",JSON.stringify(data)) | ||
| .done(function(data) | ||
| { | ||
|
|
||
| }); | ||
|
|
||
| } | ||
|
|
||
| if(checked==0) | ||
| window.alert("Please choose Recipient!!"); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| function getclassname(){ | ||
|
|
||
| $.get("http://localhost:8080/SLM2016/SendGmailServlet", | ||
| function(responseText) { | ||
| document.myForm.inpText_Course.options[j]=new Option(responseText.className, responseText.className); | ||
| }); | ||
| } | ||
|
|
||
| function getstudentname(){ | ||
|
|
||
| $.get("http://localhost:8080/SLM2016/SendGmailServlet", | ||
| function(responseText) { | ||
| department[0]=responseText.students; | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| function showList() { | ||
| var message = "顯示清單"; | ||
| document.getElementById("message").innerHTML = message; | ||
| $ | ||
| .ajax({ | ||
| type : 'POST', | ||
| contentType : "application/json; charset=UTF8", | ||
| dataType : "json", | ||
| // http://ilab.csie.ntut.edu.tw:8080/XX_hw11/spring/ajax/doPay | ||
| // http://ilab.csie.ntut.edu.tw:8080/44_hw11/spring/ajax/doPay | ||
| url : 'http://ilab.csie.ntut.edu.tw:8080/Final_44/spring/project/doCustomerList', | ||
| data : JSON.stringify({ | ||
| name : $("#user").html() | ||
|
|
||
| }), | ||
| success : function(response) { | ||
| $("#list").show(); | ||
| // console.log(response); | ||
| $("#list") | ||
| .html( | ||
| "<table id=\"tablea\" border=\"1\" valign=\"middle\"><tr><td>訂單序號</td><td>訂單狀況</td><td>訂單使用者</td><td>訂單地址</td></tr></table>") | ||
| $.each(response, function(k, v) { | ||
| console.log(v); | ||
| $("#tablea").append( | ||
| "<tr><td>" + v.id + "</td><td>" + v.state | ||
| + "</td><td>" + v.customer | ||
| + "</td><td>" + v.address | ||
| + "</td></tr>"); | ||
| }); | ||
| } | ||
| }); | ||
| } |
| @@ -1,4 +1,4 @@ | ||
| package database; | ||
|
|
||
| public class Account { | ||
| private int mId = -1; | ||
| @@ -0,0 +1,34 @@ | ||
| package mailSending; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class ClassInfomation { | ||
| private String className; | ||
| private List<String> students; | ||
|
|
||
| public ClassInfomation(String className) { | ||
| this.className = className; | ||
| students = new ArrayList<String>(); | ||
| } | ||
|
|
||
| public ClassInfomation Clone() { | ||
| ClassInfomation cloneObject = new ClassInfomation(this.className); | ||
| cloneObject.students = new ArrayList<String>(); | ||
| for (int i = 0; i < this.students.size(); i++) | ||
| cloneObject.students.add(this.students.get(i)); | ||
| return cloneObject; | ||
| } | ||
|
|
||
| public void AddStudent(String studentName) { | ||
| students.add(studentName); | ||
| } | ||
|
|
||
| public String GetClassName() { | ||
| return className; | ||
| } | ||
|
|
||
| public List<String> GetStudents() { | ||
| return students; | ||
| } | ||
| } |
| @@ -0,0 +1,81 @@ | ||
| package mailSending; | ||
|
|
||
|
|
||
| import java.util.Properties; | ||
|
|
||
| import javax.mail.Authenticator; | ||
| import javax.mail.Message; | ||
| import javax.mail.MessagingException; | ||
| import javax.mail.PasswordAuthentication; | ||
| import javax.mail.Session; | ||
| import javax.mail.Transport; | ||
| import javax.mail.internet.InternetAddress; | ||
| import javax.mail.internet.MimeMessage; | ||
|
|
||
| public class GmailSender { | ||
| private final String host = "smtp.gmail.com"; | ||
| private final int port = 587; | ||
| private String username; | ||
| private String password; | ||
| private Properties props = new Properties(); | ||
| private Session session; | ||
|
|
||
| public GmailSender(String username, String password) { | ||
| this.username = username; | ||
| this.password = password; | ||
| System.setProperty("mail.mime.charset", "big5"); | ||
| props.put("mail.smtp.host", host); | ||
| props.put("mail.smtp.auth", "true"); | ||
| props.put("mail.smtp.starttls.enable", "true"); | ||
| props.put("mail.smtp.port", port); | ||
| session = Session.getInstance(props, new Authenticator() { | ||
| protected PasswordAuthentication getPasswordAuthentication() { | ||
| return new PasswordAuthentication(username, password); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public String Send(String address, String subject, String name, String className) { | ||
| try { | ||
|
|
||
| Message message = new MimeMessage(session); | ||
| message.setFrom(new InternetAddress(username)); | ||
| message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(address)); | ||
| message.setSubject(subject); | ||
| String text = "Hi " + name + ",\n您好,歡迎報名" + className + ",以下是您的上課通知,請參考。\n若有任何問題,歡迎隨時聯絡我們。\n泰迪軟體 Erica"; | ||
| message.setText(text); | ||
|
|
||
| Transport transport = session.getTransport("smtp"); | ||
| transport.connect(host, port, username, password); | ||
|
|
||
| Transport.send(message); | ||
|
|
||
| return "寄送email結束."; | ||
|
|
||
| } catch (MessagingException e) { | ||
| String errorMessage = e.getMessage().toString(); | ||
| if (errorMessage.contains("https://accounts.google.com/signin/continue?")) { | ||
| return "請開啟 安全性較低的應用程式存取權限"; | ||
| } | ||
| else if (errorMessage.contains("Username and Password not accepted")) { | ||
| return "帳號密碼不正確"; | ||
| } | ||
| else if (errorMessage.contains("Invalid Addresses")) { | ||
| return "送信位址格式不正確"; | ||
| } | ||
| else if (errorMessage.contains("Could not connect to SMTP host: smtp.gmail.com")) { | ||
| return "無法連線到SMTP host,請檢察防火牆或Proxy設定"; | ||
| } | ||
| else if (errorMessage.contains("Unknown SMTP host: smtp.gmail.com")) { | ||
| return "Unknown SMTP host: smtp.gmail.com,請檢察網路連線"; | ||
| } | ||
| else { | ||
| return e.getMessage().toString(); | ||
|
|
||
| // "Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1" | ||
| // Unknown SMTP host: smtp.gmail.com | ||
| } | ||
| // throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,28 @@ | ||
| package mailSending; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class SendStudentIndex { | ||
| private ArrayList<Integer> indexes; | ||
|
|
||
| public SendStudentIndex(){ | ||
| indexes=new ArrayList<Integer>(); | ||
| } | ||
|
|
||
| public SendStudentIndex Clone(){ | ||
| SendStudentIndex cloneObject=new SendStudentIndex(); | ||
| cloneObject.indexes=new ArrayList<Integer>(); | ||
| for (int i = 0; i < this.indexes.size(); i++) | ||
| cloneObject.indexes.add(this.indexes.get(i)); | ||
| return cloneObject; | ||
| } | ||
|
|
||
| public void Add(int index){ | ||
| indexes.add(new Integer(index)); | ||
| } | ||
|
|
||
| public List<Integer> GetIndexes(){ | ||
| return indexes; | ||
| } | ||
| } |
| @@ -0,0 +1,105 @@ | ||
| package mailSending; | ||
|
|
||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class StudentInfomation { | ||
| private ArrayList<String> students; | ||
| private ArrayList<String> mailAddresses; | ||
|
|
||
| public StudentInfomation() { | ||
| students = new ArrayList<String>(); | ||
| mailAddresses = new ArrayList<String>(); | ||
| } | ||
|
|
||
| public StudentInfomation Clone() { | ||
| StudentInfomation cloneObject = new StudentInfomation(); | ||
| cloneObject.students = new ArrayList<String>(); | ||
| cloneObject.mailAddresses = new ArrayList<String>(); | ||
| for (int i = 0; i < this.students.size(); i++) | ||
| cloneObject.students.add(this.students.get(i)); | ||
| for (int i = 0; i < this.mailAddresses.size(); i++) | ||
| cloneObject.mailAddresses.add(this.mailAddresses.get(i)); | ||
|
|
||
| return cloneObject; | ||
| } | ||
|
|
||
| public void SetStudents() { | ||
| students.add("Alice"); | ||
| students.add("Bob"); | ||
| students.add("Chris"); | ||
| students.add("David"); | ||
| students.add("Eva"); | ||
| students.add("FLT"); | ||
| students.add("GTA"); | ||
| students.add("HIA"); | ||
| students.add("IT"); | ||
| students.add("Jack"); | ||
|
|
||
| students.add("Kevin"); | ||
| students.add("Lee"); | ||
| students.add("Mo"); | ||
| students.add("Net"); | ||
| students.add("Ox"); | ||
| students.add("P"); | ||
| students.add("Q"); | ||
| students.add("R"); | ||
| students.add("S"); | ||
| students.add("T"); | ||
|
|
||
| students.add("U"); | ||
| students.add("V"); | ||
| students.add("W"); | ||
| students.add("X"); | ||
| students.add("Y"); | ||
| students.add("Z"); | ||
| students.add("0.0"); | ||
| students.add("0w0"); | ||
| students.add("0o0"); | ||
| students.add("0A0"); | ||
| } | ||
|
|
||
| public void SetMailAddress() { | ||
| mailAddresses.add("t104598007+a@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+b@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+c@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+d@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+aaa@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+bbb@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+ccc@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+ddd@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+eee@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+fff@ntut.org.tw"); | ||
|
|
||
| mailAddresses.add("t104598007+ggg@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+hhh@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+iii@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+jjj@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+kkk@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+lll@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+mmm@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+nnn@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+ooo@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+ppp@ntut.org.tw"); | ||
|
|
||
| mailAddresses.add("t104598007+qqq@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+rrr@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+sss@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+ttt@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+uuu@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+vvv@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+www@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+xxx@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+yyy@ntut.org.tw"); | ||
| mailAddresses.add("t104598007+zzz@ntut.org.tw"); | ||
| } | ||
|
|
||
| public List<String> GetStudents() { | ||
| return students; | ||
| } | ||
|
|
||
| public List<String> GetMailAddress() { | ||
| return mailAddresses; | ||
| } | ||
| } |
| @@ -0,0 +1,79 @@ | ||
| package servlets; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import javax.servlet.ServletException; | ||
| import javax.servlet.annotation.WebServlet; | ||
| import javax.servlet.http.HttpServlet; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| import com.google.gson.Gson; | ||
|
|
||
| import mailSending.ClassInfomation; | ||
| import mailSending.GmailSender; | ||
| import mailSending.SendStudentIndex; | ||
| import mailSending.StudentInfomation; | ||
|
|
||
| @WebServlet("/SendGmailServlet") | ||
| public class SendGmailServlet extends HttpServlet { | ||
| private static final long serialVersionUID = 1L; | ||
| private StudentInfomation studentInfomation = new StudentInfomation(); | ||
| private ClassInfomation classInfomation = new ClassInfomation("Scurm敏捷發法實作班"); | ||
|
|
||
| public SendGmailServlet() { | ||
| super(); | ||
| studentInfomation.SetStudents(); | ||
| studentInfomation.SetMailAddress(); | ||
|
|
||
| List<String> name = studentInfomation.GetStudents(); | ||
| int size = 30; | ||
| for (int i = 0; i < size; i++) { | ||
| classInfomation.AddStudent(name.get(i)); | ||
| } | ||
| } | ||
|
|
||
| protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
| throws ServletException, IOException { | ||
|
|
||
|
|
||
|
|
||
| String json = new Gson().toJson(classInfomation); | ||
| // System.out.println(json); | ||
|
|
||
| response.setContentType("application/json"); | ||
| response.setCharacterEncoding("UTF-8"); | ||
| response.getWriter().write(json); | ||
| } | ||
|
|
||
| protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
| throws ServletException, IOException { | ||
| Gson gson = new Gson(); | ||
| SendStudentIndex sendStudentIndex = gson.fromJson(request.getReader().readLine(), SendStudentIndex.class); | ||
| List<Integer> studentIndex = sendStudentIndex.GetIndexes(); | ||
| List<String> studentName = new ArrayList<String>(); | ||
| List<String> addresses = new ArrayList<String>(); | ||
| for (int i = 0; i < studentIndex.size(); i++) | ||
| if (i == studentIndex.get(i).intValue()) { | ||
| studentName.add(studentInfomation.GetStudents().get(i)); | ||
| addresses.add(studentInfomation.GetMailAddress().get(i)); | ||
| } | ||
|
|
||
| String username = "news.teddysoft.tw@gmail.com"; | ||
| String password = "SLMTaipeiTech2016"; | ||
| GmailSender gmailSender=new GmailSender(username,password); | ||
| String subject = "泰迪軟體課程通知"; | ||
| String result=""; | ||
| for(int i=0;i<studentName.size();i++) | ||
| result = gmailSender.Send(addresses.get(i),subject,studentName.get(i),classInfomation.GetClassName()); | ||
|
|
||
| String json = new Gson().toJson(result); | ||
| System.out.println(result); | ||
|
|
||
| response.setContentType("application/json"); | ||
| response.setCharacterEncoding("UTF-8"); | ||
| response.getWriter().write(json); | ||
| } | ||
| } |
| @@ -0,0 +1,43 @@ | ||
| package unitTests; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import mailSending.ClassInfomation; | ||
|
|
||
| public class ClassInfomationTest { | ||
| private ClassInfomation classInfomation; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| classInfomation = new ClassInfomation("Scurm敏捷發法實作班"); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| } | ||
|
|
||
| @Test | ||
| public void testClone() { | ||
| classInfomation.AddStudent("Alice"); | ||
| classInfomation.AddStudent("Bob"); | ||
| ClassInfomation cloneObject = classInfomation.Clone(); | ||
| assertEquals("Scurm敏捷發法實作班", cloneObject.GetClassName()); | ||
| assertEquals("Alice", cloneObject.GetStudents().get(0)); | ||
| assertEquals("Bob", cloneObject.GetStudents().get(1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAddStudent() { | ||
| classInfomation.AddStudent("Alice"); | ||
| assertEquals("Alice", classInfomation.GetStudents().get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetClassName() { | ||
| assertEquals("Scurm敏捷發法實作班", classInfomation.GetClassName()); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,105 @@ | ||
| package unitTests; | ||
|
|
||
|
|
||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import mailSending.GmailSender; | ||
|
|
||
| public class GmailSenderTest { | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| } | ||
|
|
||
| @Test | ||
| public void testSendSuccess() { | ||
| String username = "news.teddysoft.tw@gmail.com"; | ||
| String password = "SLMTaipeiTech2016"; | ||
| GmailSender gmailSender = new GmailSender(username, password); | ||
| String address = "superchobits02@gmail.com"; | ||
| String subject = "泰迪軟體課程通知"; | ||
| String name = "Alice"; | ||
| String className = "Scurm敏捷發法實作班"; | ||
| String result = gmailSender.Send(address, subject, name, className); | ||
|
|
||
| assertEquals("寄送email結束.", result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAccountLoginFail() { | ||
| String username = "000111222333@gmail.com"; | ||
| String password = "123456"; | ||
| GmailSender gmailSender = new GmailSender(username, password); | ||
| String address = "superchobits02@gmail.com"; | ||
| String subject = "泰迪軟體課程通知"; | ||
| String name = "Alice"; | ||
| String className = "Scurm敏捷發法實作班"; | ||
| String result = gmailSender.Send(address, subject, name, className); | ||
|
|
||
| assertEquals("帳號密碼不正確", result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAccountLessSecureApps() { | ||
| String username = "t100590334@ntut.org.tw"; | ||
| String password = "angelbeats711529"; | ||
| GmailSender gmailSender = new GmailSender(username, password); | ||
| String address = "angelbeats711529@gmail.com"; | ||
| String subject = "泰迪軟體課程通知"; | ||
| String name = "Alice"; | ||
| String className = "Scurm敏捷發法實作班"; | ||
| String result = gmailSender.Send(address, subject, name, className); | ||
|
|
||
| assertEquals("請開啟 安全性較低的應用程式存取權限", result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRecipientAddressFormatError() { | ||
| String username = "news.teddysoft.tw@gmail.com"; | ||
| String password = "SLMTaipeiTech2016"; | ||
| GmailSender gmailSender = new GmailSender(username, password); | ||
| String address = "0000aaaaa@gmail,com"; | ||
| String subject = "泰迪軟體課程通知"; | ||
| String name = "Alice"; | ||
| String className = "Scurm敏捷發法實作班"; | ||
| String result = gmailSender.Send(address, subject, name, className); | ||
|
|
||
| assertEquals("送信位址格式不正確", result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSendFirewallFail() { | ||
| String username = "news.teddysoft.tw@gmail.com"; | ||
| String password = "SLMTaipeiTech2016"; | ||
| GmailSender gmailSender = new GmailSender(username, password); | ||
| String address = "superchobits02@gmail.com"; | ||
| String subject = "泰迪軟體課程通知"; | ||
| String name = "Alice"; | ||
| String className = "Scurm敏捷發法實作班"; | ||
| String result = gmailSender.Send(address, subject, name, className); | ||
|
|
||
| assertNotEquals("無法連線到SMTP host,請檢察防火牆或Proxy設定", result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSendNetwordFail() { | ||
| String username = "news.teddysoft.tw@gmail.com"; | ||
| String password = "SLMTaipeiTech2016"; | ||
| GmailSender gmailSender = new GmailSender(username, password); | ||
| String address = "superchobits02@gmail.com"; | ||
| String subject = "泰迪軟體課程通知"; | ||
| String name = "Alice"; | ||
| String className = "Scurm敏捷發法實作班"; | ||
| String result = gmailSender.Send(address, subject, name, className); | ||
|
|
||
| assertNotEquals("Unknown SMTP host: smtp.gmail.com,請檢察網路連線", result); | ||
| } | ||
| } |
| @@ -0,0 +1,42 @@ | ||
| package unitTests; | ||
|
|
||
|
|
||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import mailSending.SendStudentIndex; | ||
|
|
||
| public class SendStudentIndexTest { | ||
| private SendStudentIndex sendStudentIndex; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| sendStudentIndex = new SendStudentIndex(); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| } | ||
|
|
||
| @Test | ||
| public void testClone() { | ||
| sendStudentIndex.Add(0); | ||
| sendStudentIndex.Add(2); | ||
| sendStudentIndex.Add(6); | ||
| SendStudentIndex cloneObject = sendStudentIndex.Clone(); | ||
| assertEquals(cloneObject.GetIndexes().get(0).intValue(), 0); | ||
| assertEquals(cloneObject.GetIndexes().get(1).intValue(), 2); | ||
| assertEquals(cloneObject.GetIndexes().get(2).intValue(), 6); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAdd() { | ||
| sendStudentIndex.Add(0); | ||
| assertEquals(sendStudentIndex.GetIndexes().get(0).intValue(), 0); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,175 @@ | ||
| package unitTests; | ||
|
|
||
|
|
||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import mailSending.StudentInfomation; | ||
|
|
||
| public class StudentInfomationTest { | ||
| private StudentInfomation studentInfomation; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| studentInfomation = new StudentInfomation(); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| } | ||
|
|
||
| @Test | ||
| public void testClone() { | ||
| studentInfomation.SetStudents(); | ||
| studentInfomation.SetMailAddress(); | ||
| StudentInfomation cloneObject = studentInfomation.Clone(); | ||
| assertEquals("Alice", cloneObject.GetStudents().get(0)); | ||
| assertEquals("Bob", cloneObject.GetStudents().get(1)); | ||
| assertEquals("Chris", cloneObject.GetStudents().get(2)); | ||
| assertEquals("David", cloneObject.GetStudents().get(3)); | ||
| assertEquals("Eva", cloneObject.GetStudents().get(4)); | ||
| assertEquals("FLT", cloneObject.GetStudents().get(5)); | ||
| assertEquals("GTA", cloneObject.GetStudents().get(6)); | ||
| assertEquals("HIA", cloneObject.GetStudents().get(7)); | ||
| assertEquals("IT", cloneObject.GetStudents().get(8)); | ||
| assertEquals("Jack", cloneObject.GetStudents().get(9)); | ||
|
|
||
| assertEquals("Kevin", cloneObject.GetStudents().get(10)); | ||
| assertEquals("Lee", cloneObject.GetStudents().get(11)); | ||
| assertEquals("Mo", cloneObject.GetStudents().get(12)); | ||
| assertEquals("Net", cloneObject.GetStudents().get(13)); | ||
| assertEquals("Ox", cloneObject.GetStudents().get(14)); | ||
| assertEquals("P", cloneObject.GetStudents().get(15)); | ||
| assertEquals("Q", cloneObject.GetStudents().get(16)); | ||
| assertEquals("R", cloneObject.GetStudents().get(17)); | ||
| assertEquals("S", cloneObject.GetStudents().get(18)); | ||
| assertEquals("T", cloneObject.GetStudents().get(19)); | ||
|
|
||
| assertEquals("U", cloneObject.GetStudents().get(20)); | ||
| assertEquals("V", cloneObject.GetStudents().get(21)); | ||
| assertEquals("W", cloneObject.GetStudents().get(22)); | ||
| assertEquals("X", cloneObject.GetStudents().get(23)); | ||
| assertEquals("Y", cloneObject.GetStudents().get(24)); | ||
| assertEquals("Z", cloneObject.GetStudents().get(25)); | ||
| assertEquals("0.0", cloneObject.GetStudents().get(26)); | ||
| assertEquals("0w0", cloneObject.GetStudents().get(27)); | ||
| assertEquals("0o0", cloneObject.GetStudents().get(28)); | ||
| assertEquals("0A0", cloneObject.GetStudents().get(29)); | ||
|
|
||
| assertEquals("t104598007+a@ntut.org.tw", cloneObject.GetMailAddress().get(0)); | ||
| assertEquals("t104598007+b@ntut.org.tw", cloneObject.GetMailAddress().get(1)); | ||
| assertEquals("t104598007+c@ntut.org.tw", cloneObject.GetMailAddress().get(2)); | ||
| assertEquals("t104598007+d@ntut.org.tw", cloneObject.GetMailAddress().get(3)); | ||
| assertEquals("t104598007+aaa@ntut.org.tw", cloneObject.GetMailAddress().get(4)); | ||
| assertEquals("t104598007+bbb@ntut.org.tw", cloneObject.GetMailAddress().get(5)); | ||
| assertEquals("t104598007+ccc@ntut.org.tw", cloneObject.GetMailAddress().get(6)); | ||
| assertEquals("t104598007+ddd@ntut.org.tw", cloneObject.GetMailAddress().get(7)); | ||
| assertEquals("t104598007+eee@ntut.org.tw", cloneObject.GetMailAddress().get(8)); | ||
| assertEquals("t104598007+fff@ntut.org.tw", cloneObject.GetMailAddress().get(9)); | ||
|
|
||
| assertEquals("t104598007+ggg@ntut.org.tw", cloneObject.GetMailAddress().get(10)); | ||
| assertEquals("t104598007+hhh@ntut.org.tw", cloneObject.GetMailAddress().get(11)); | ||
| assertEquals("t104598007+iii@ntut.org.tw", cloneObject.GetMailAddress().get(12)); | ||
| assertEquals("t104598007+jjj@ntut.org.tw", cloneObject.GetMailAddress().get(13)); | ||
| assertEquals("t104598007+kkk@ntut.org.tw", cloneObject.GetMailAddress().get(14)); | ||
| assertEquals("t104598007+lll@ntut.org.tw", cloneObject.GetMailAddress().get(15)); | ||
| assertEquals("t104598007+mmm@ntut.org.tw", cloneObject.GetMailAddress().get(16)); | ||
| assertEquals("t104598007+nnn@ntut.org.tw", cloneObject.GetMailAddress().get(17)); | ||
| assertEquals("t104598007+ooo@ntut.org.tw", cloneObject.GetMailAddress().get(18)); | ||
| assertEquals("t104598007+ppp@ntut.org.tw", cloneObject.GetMailAddress().get(19)); | ||
|
|
||
| assertEquals("t104598007+qqq@ntut.org.tw", cloneObject.GetMailAddress().get(20)); | ||
| assertEquals("t104598007+rrr@ntut.org.tw", cloneObject.GetMailAddress().get(21)); | ||
| assertEquals("t104598007+sss@ntut.org.tw", cloneObject.GetMailAddress().get(22)); | ||
| assertEquals("t104598007+ttt@ntut.org.tw", cloneObject.GetMailAddress().get(23)); | ||
| assertEquals("t104598007+uuu@ntut.org.tw", cloneObject.GetMailAddress().get(24)); | ||
| assertEquals("t104598007+vvv@ntut.org.tw", cloneObject.GetMailAddress().get(25)); | ||
| assertEquals("t104598007+www@ntut.org.tw", cloneObject.GetMailAddress().get(26)); | ||
| assertEquals("t104598007+xxx@ntut.org.tw", cloneObject.GetMailAddress().get(27)); | ||
| assertEquals("t104598007+yyy@ntut.org.tw", cloneObject.GetMailAddress().get(28)); | ||
| assertEquals("t104598007+zzz@ntut.org.tw", cloneObject.GetMailAddress().get(29)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetStudents() { | ||
| studentInfomation.SetStudents(); | ||
| List<String> students = studentInfomation.GetStudents(); | ||
| assertEquals("Alice", students.get(0)); | ||
| assertEquals("Bob", students.get(1)); | ||
| assertEquals("Chris", students.get(2)); | ||
| assertEquals("David", students.get(3)); | ||
| assertEquals("Eva", students.get(4)); | ||
| assertEquals("FLT", students.get(5)); | ||
| assertEquals("GTA", students.get(6)); | ||
| assertEquals("HIA", students.get(7)); | ||
| assertEquals("IT", students.get(8)); | ||
| assertEquals("Jack", students.get(9)); | ||
|
|
||
| assertEquals("Kevin", students.get(10)); | ||
| assertEquals("Lee", students.get(11)); | ||
| assertEquals("Mo", students.get(12)); | ||
| assertEquals("Net", students.get(13)); | ||
| assertEquals("Ox", students.get(14)); | ||
| assertEquals("P", students.get(15)); | ||
| assertEquals("Q", students.get(16)); | ||
| assertEquals("R", students.get(17)); | ||
| assertEquals("S", students.get(18)); | ||
| assertEquals("T", students.get(19)); | ||
|
|
||
| assertEquals("U", students.get(20)); | ||
| assertEquals("V", students.get(21)); | ||
| assertEquals("W", students.get(22)); | ||
| assertEquals("X", students.get(23)); | ||
| assertEquals("Y", students.get(24)); | ||
| assertEquals("Z", students.get(25)); | ||
| assertEquals("0.0", students.get(26)); | ||
| assertEquals("0w0", students.get(27)); | ||
| assertEquals("0o0", students.get(28)); | ||
| assertEquals("0A0", students.get(29)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetMailAddress() { | ||
| studentInfomation.SetMailAddress(); | ||
| List<String> mailAddresses = studentInfomation.GetMailAddress(); | ||
| assertEquals("t104598007+a@ntut.org.tw", mailAddresses.get(0)); | ||
| assertEquals("t104598007+b@ntut.org.tw", mailAddresses.get(1)); | ||
| assertEquals("t104598007+c@ntut.org.tw", mailAddresses.get(2)); | ||
| assertEquals("t104598007+d@ntut.org.tw", mailAddresses.get(3)); | ||
| assertEquals("t104598007+aaa@ntut.org.tw", mailAddresses.get(4)); | ||
| assertEquals("t104598007+bbb@ntut.org.tw", mailAddresses.get(5)); | ||
| assertEquals("t104598007+ccc@ntut.org.tw", mailAddresses.get(6)); | ||
| assertEquals("t104598007+ddd@ntut.org.tw", mailAddresses.get(7)); | ||
| assertEquals("t104598007+eee@ntut.org.tw", mailAddresses.get(8)); | ||
| assertEquals("t104598007+fff@ntut.org.tw", mailAddresses.get(9)); | ||
|
|
||
| assertEquals("t104598007+ggg@ntut.org.tw", mailAddresses.get(10)); | ||
| assertEquals("t104598007+hhh@ntut.org.tw", mailAddresses.get(11)); | ||
| assertEquals("t104598007+iii@ntut.org.tw", mailAddresses.get(12)); | ||
| assertEquals("t104598007+jjj@ntut.org.tw", mailAddresses.get(13)); | ||
| assertEquals("t104598007+kkk@ntut.org.tw", mailAddresses.get(14)); | ||
| assertEquals("t104598007+lll@ntut.org.tw", mailAddresses.get(15)); | ||
| assertEquals("t104598007+mmm@ntut.org.tw", mailAddresses.get(16)); | ||
| assertEquals("t104598007+nnn@ntut.org.tw", mailAddresses.get(17)); | ||
| assertEquals("t104598007+ooo@ntut.org.tw", mailAddresses.get(18)); | ||
| assertEquals("t104598007+ppp@ntut.org.tw", mailAddresses.get(19)); | ||
|
|
||
| assertEquals("t104598007+qqq@ntut.org.tw", mailAddresses.get(20)); | ||
| assertEquals("t104598007+rrr@ntut.org.tw", mailAddresses.get(21)); | ||
| assertEquals("t104598007+sss@ntut.org.tw", mailAddresses.get(22)); | ||
| assertEquals("t104598007+ttt@ntut.org.tw", mailAddresses.get(23)); | ||
| assertEquals("t104598007+uuu@ntut.org.tw", mailAddresses.get(24)); | ||
| assertEquals("t104598007+vvv@ntut.org.tw", mailAddresses.get(25)); | ||
| assertEquals("t104598007+www@ntut.org.tw", mailAddresses.get(26)); | ||
| assertEquals("t104598007+xxx@ntut.org.tw", mailAddresses.get(27)); | ||
| assertEquals("t104598007+yyy@ntut.org.tw", mailAddresses.get(28)); | ||
| assertEquals("t104598007+zzz@ntut.org.tw", mailAddresses.get(29)); | ||
| } | ||
|
|
||
| } |