Skip to main content
summaryrefslogtreecommitdiffstats
blob: c462830befbf64e5c23682e85683df5d82d60a03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.test.cases;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import org.eclipse.osee.framework.jdk.core.util.AHTML;
import org.eclipse.osee.framework.jdk.core.util.windows.OutlookCalendarEvent;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.ui.skynet.render.PresentationType;
import org.eclipse.osee.framework.ui.skynet.render.RendererManager;
import org.eclipse.osee.framework.ui.skynet.util.OseeEmail;
import org.eclipse.osee.framework.ui.skynet.util.OseeEmail.BodyType;
import org.junit.Before;

/**
 * @author Donald G. Dunne
 */
public class OseeEmailTest {

   public static String emailAddress = null;
   public static final StringBuffer results = new StringBuffer();
   private static String infoStr =
      "\n\nOseeEmailTest: This test will send 3 emails. If you do not receive 3, the test failed.";

   @Before
   public void setUp() throws Exception {
      if (emailAddress == null) {
         RendererManager.open(UserManager.getUser(), PresentationType.DEFAULT_OPEN);
         emailAddress = UserManager.getUser().getEmail();
         assertFalse("Invalid email address " + emailAddress + " for user " + UserManager.getUser(),
            emailAddress.contains("\\@"));
      }
   }

   @org.junit.Test
   public void testTextEmail() throws Exception {
      final String TEST_NAME = "Email Test 1/3 - Text Body";
      OseeEmail emailMessage =
         new OseeEmail(emailAddress, TEST_NAME, "Hello World - this is text only" + infoStr, BodyType.Text);
      emailMessage.send();
      System.out.println(TEST_NAME + " sent to \"" + emailAddress + "\"");
   }

   @org.junit.Test
   public void testHtmlEmail() throws Exception {
      final String TEST_NAME = "Email Test 2/3 - Html Body";
      OseeEmail emailMessage =
         new OseeEmail(emailAddress, TEST_NAME,
            AHTML.simplePage(AHTML.bold("Hello World - this should be bold" + infoStr)), BodyType.Html);
      emailMessage.send();
      System.out.println(TEST_NAME + " sent to \"" + emailAddress + "\"");
   }

   @org.junit.Test
   public void testAttachementEmail() throws Exception {
      final String TEST_NAME = "Email Test 3/3 - with Outlook Attachment";
      OseeEmail emailMessage = new OseeEmail(emailAddress, TEST_NAME, TEST_NAME + "\n\nTesting the attachment\n" +
      //
      "1) Double-click open attachment opens calendar event dialog\n" +
      //
      "2) Verify Time 8am - 1pm\n" +
      //
      "3) Verify date (today)\n" +
      //
      "4) Verify location: Conference Room\n" +
      //
      "5) Verify subject is name of this test" + infoStr, BodyType.Text);
      String context = new OutlookCalendarEvent("Conference Room", TEST_NAME, new Date(), "0800", "1300").getEvent();
      emailMessage.addAttachment(context, "schedule class.vcs");
      emailMessage.send();
      System.out.println(TEST_NAME + " sent to \"" + emailAddress + "\"");
   }

   /**
    * This test only exists to report the results of the email tests above
    */
   @org.junit.Test
   public void testReportResults() throws Exception {
      if (!results.toString().equals("")) {
         System.err.println(results.toString());
         assertTrue(false);
      } else {
         assertTrue(true);
      }
   }
}

Back to the top