1 package org.tigris.scarab.services.email; 2 3 48 49 50 import java.io.BufferedReader ; 51 import java.io.IOException ; 52 import java.io.StringReader ; 53 import java.util.HashMap ; 54 import java.util.ResourceBundle ; 55 56 import org.apache.fulcrum.TurbineServices; 57 import org.apache.fulcrum.localization.LocalizationService; 58 import org.apache.velocity.VelocityContext; 59 import org.tigris.scarab.test.BaseTurbineTestCase; 60 import org.tigris.scarab.tools.ScarabLocalizationTool; 61 import org.tigris.scarab.util.ScarabConstants; 62 63 70 public class VelocityEmailServiceTest extends BaseTurbineTestCase 71 { 72 73 78 public class MockLink { 79 85 public String getIssueIdLink(HashMap issue) { 86 return "http://issue.test.org/" + issue.get("UniqueId"); 87 } 88 } 89 90 private HashMap issue; 91 private HashMap user; 92 private HashMap rModuleIssueType; 93 private VelocityContext context; 94 private VelocityEmailService ves; 95 private ResourceBundle l10n; 96 private MockLink link; 97 98 99 102 public void setUp() throws Exception { 103 super.setUp(); 104 105 ves = (VelocityEmailService)TurbineServices.getInstance().getService("EmailService"); 106 107 context = new VelocityContext(); 109 110 ScarabLocalizationTool slt = new ScarabLocalizationTool(); 112 slt.init(ScarabLocalizationTool.DEFAULT_LOCALE); 113 context.put(ScarabConstants.LOCALIZATION_TOOL,slt); 114 115 user = new HashMap (); 117 user.put("Name","tester"); 118 user.put("UserName", "Ted E. Ster"); 119 user.put("Email", "tester@test.org"); 120 121 rModuleIssueType = new HashMap (); 123 rModuleIssueType.put("DisplayName","Defect"); 124 125 issue = new HashMap (); 127 context.put("issue", issue); 128 issue.put("ModifiedBy", user); 129 issue.put("DefaultText", "This is the default issue text."); 130 issue.put("UniqueId", "TEST1"); 131 issue.put("RModuleIssueType",rModuleIssueType); 132 133 link = new MockLink(); 135 context.put("link", link); 136 137 } 138 139 146 private int countLines(String msg) throws IOException { 147 BufferedReader rdr = new BufferedReader (new StringReader (msg)); 148 int i = 0; 149 while (rdr.readLine() != null) { 150 i++; 151 } 152 return i; 153 } 154 155 public void testModifyIssueMessage() throws Exception { 156 String msg = ves.handleRequest(context, "email/ModifyIssue.vm"); 157 assertNotNull("Null ModifyIssue Message Returned",msg); 158 assertTrue("Unexpected few lines in ModifyIssue Message : " + countLines(msg),countLines(msg) > 5); 159 assertTrue("Name expected in ModifyIssue Message.", 160 msg.indexOf((String )user.get("Name")) > 0); 161 assertTrue("Email expected in ModifyIssue Message.", 164 msg.indexOf((String )user.get("Email")) > 0); 165 assertTrue("IssueId expected in ModifyIssue Message.", 166 msg.indexOf((String )issue.get("UniqueId")) > 0); 167 assertTrue("DefaultText expected in ModifyIssue Message.", 168 msg.indexOf((String )issue.get("DefaultText")) > 0); 169 assertTrue("IssueType expected in ModifyIssue Message.", 170 msg.indexOf((String )rModuleIssueType.get("DisplayName")) > 0); 171 assertTrue("Link url to issue expected in ModifyIssue Message.", 172 msg.indexOf(link.getIssueIdLink(issue)) > 0); 173 174 System.out.println(msg); 175 } 176 } 177 178 | Popular Tags |