Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package com.erichughes.tests;
  7.  
  8. import com.erichughes.database.DBUtil;
  9. import com.erichughes.database.JamDAO;
  10. import com.ericbehughes.email.JAMEmail;
  11. import com.erichughes.models.AppointmentRecord;
  12. import com.erichughes.models.Smtp;
  13. import java.sql.Timestamp;
  14. import java.time.LocalDateTime;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import org.junit.Test;
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22.  
  23. /**
  24. *
  25. * @author ehugh
  26. */
  27. public class TestEmail {
  28.  
  29. // This is my local MySQL server
  30.  
  31. private final Logger log = LoggerFactory.getLogger(
  32. this.getClass().getName());
  33. private final String url = "jdbc:mysql://localhost:3306/jam_1412844_db?autoReconnect=true&useSSL=false";
  34. private final String user = "root";
  35. private final String password = "dawson";
  36. private final DBUtil dbUtil = new DBUtil();
  37. private final JamDAO jamObj = dbUtil.getJamDAO();
  38.  
  39.  
  40. public TestEmail() {
  41.  
  42.  
  43. }
  44.  
  45. @Test
  46. public void mailTest() {
  47.  
  48. try {
  49. createMail();
  50. Timestamp t1 = Timestamp.valueOf(LocalDateTime.now().plusMinutes(117));
  51. Timestamp t2 = Timestamp.valueOf(LocalDateTime.now().plusMinutes(123));
  52. List<AppointmentRecord> mail = jamObj.findAllAppointmentsBetween(t1, t2);
  53. sendEmail(mail);
  54. } catch (Exception e) {
  55. }
  56.  
  57.  
  58. }
  59.  
  60. private void createMail(){
  61. AppointmentRecord ar1 = new AppointmentRecord();
  62. ar1.setTitle("Dawson appointment1");
  63. ar1.setLocation("Dawson");
  64. ar1.setWholeDay(0);
  65. ar1.setStartTime(Timestamp.valueOf(LocalDateTime.now().plusMinutes(120)));
  66. ar1.setEndTime(Timestamp.valueOf(LocalDateTime.now().plusMinutes(180)));
  67. ar1.setDetails("Some very long details");
  68. ar1.setAppointmentGroup(1);
  69. ar1.setAlarmReminderRequested(1);
  70.  
  71. AppointmentRecord ar2 = new AppointmentRecord();
  72. ar2.setTitle("Concordia appointment2");
  73. ar2.setLocation("Concordia");
  74. ar2.setWholeDay(0);
  75. ar2.setStartTime(Timestamp.valueOf(LocalDateTime.now().plusMinutes(120)));
  76. ar2.setEndTime(Timestamp.valueOf(LocalDateTime.now().plusMinutes(180)));
  77. ar2.setDetails("Some very long details");
  78. ar2.setAppointmentGroup(1);
  79. ar2.setAlarmReminderRequested(0);
  80.  
  81. AppointmentRecord ar3 = new AppointmentRecord();
  82. ar3.setTitle("Bellville appointment3");
  83. ar3.setLocation("Belleville");
  84. ar3.setWholeDay(0);
  85. ar3.setStartTime(Timestamp.valueOf(LocalDateTime.now().plusMinutes(120)));
  86. ar3.setEndTime(Timestamp.valueOf(LocalDateTime.now().plusMinutes(180)));
  87. ar3.setDetails("Some very long details");
  88. ar3.setAppointmentGroup(1);
  89. ar3.setAlarmReminderRequested(1);
  90. try {
  91.  
  92. jamObj.create(ar1);
  93. jamObj.create(ar2);
  94. jamObj.create(ar3);
  95.  
  96.  
  97. } catch (Exception e) {
  98. }
  99.  
  100.  
  101. }
  102.  
  103. public void sendEmail(List<AppointmentRecord> mailToSend){
  104. try {
  105. Smtp s = jamObj.findSmtpById(1);
  106. JAMEmail je = new JAMEmail(s);
  107. for (AppointmentRecord appointmentRecord : mailToSend) {
  108. //send email
  109. je.perform(appointmentRecord);
  110. }
  111. } catch (Exception e) {
  112. }
  113.  
  114.  
  115.  
  116. }
  117.  
  118.  
  119.  
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement