2 properties (Access=
private)
8 self = self@
mxberry.unittest.TestCase(varargin{:});
9 % Save current Internet preferences
10 if ispref(
'Internet',
'SMTP_Server')
11 self.smtpServer = getpref('Internet','SMTP_Server');
15 if ispref('Internet','E_mail')
16 self.eMail = getpref('Internet','E_mail');
24 function self = test_emaillogger_fail(self)
26 'emailDistributionList',{
'billy@microsoft.com'},...
27 'emailAttachmentNameList',{},...
28 'smtpServer',
'invalid.server',...
29 'subjectSuffix',
'for mydatabase on mypc',...
30 'loggerName',
'MyApplication',...
31 'isThrowExceptions',
true); %#ok<NASGU>
32 commandStr=[
'obj.sendMessage(''calculation started'',',...
33 '''calculation started
'')
']; %#ok<NASGU> 34 self.runAndCheckError('evalc(commandStr)
','sendEmailFailed
'); 37 function self = test_emaillogger_preferences(self) 38 testSmtpServer = 'some.server
'; 39 [userName,hostName]=mxberry.system.getuserhost(); 47 testEmail = [userName, '@
', hostName]; 48 % EmailLogger sets preferences Internet.SMTP_Server and 50 logger=mxberry.log.EmailLogger(... 51 'emailDistributionList
',{'billy@microsoft.com
'},... 52 'smtpServer
',testSmtpServer,... 53 'subjectSuffix
','for mydatabase on mypc
',... 54 'loggerName
','MyApplication
'); 55 self.verifyEqual(testSmtpServer,... 56 logger.getSMTPServer()); 57 self.verifyEqual(testEmail,... 58 logger.getFromEmailAddress()); 59 % EmailLogger should warn about changed preferences and reset 60 % them to their original values 61 setpref('Internet
','SMTP_Server
','some.other.server
'); 62 setpref('Internet
','E_mail
','some.other@email
'); 63 outputText = evalc(... 65 '''calculation started
'')
']); 66 nWarnings = length(strfind('Warning:
',outputText)); 67 self.verifyEqual(0,nWarnings) 68 self.verifyEqual(testSmtpServer,... 69 logger.getSMTPServer()); 70 self.verifyEqual(testEmail,... 71 logger.getFromEmailAddress()); 72 % If 'dryRun
' property is set, EmailLogger should also change 74 FROM_EMAIL_ADDRESS='test@mydomain.com
'; 75 logger=mxberry.log.EmailLogger(... 76 'emailDistributionList
',{'billy@microsoft.com
'},... 77 'smtpServer
','some.other.server
',... 78 'subjectSuffix
','for mydatabase on mypc
',... 79 'loggerName
','MyApplication
',... 80 'dryRun
',true,'fromEmailAddress
',FROM_EMAIL_ADDRESS); 81 self.verifyEqual('some.other.server
',... 82 logger.getSMTPServer()); 83 self.verifyEqual(FROM_EMAIL_ADDRESS,... 84 logger.getFromEmailAddress()); 87 function self = tear_down(self) 88 if ~isempty(self.smtpServer) 89 setpref('Internet
','SMTP_Server
',self.smtpServer); 90 elseif ispref('Internet
','SMTP_Server
') 91 rmpref('Internet
','SMTP_Server
'); 93 if ~isempty(self.eMail) 94 setpref('Internet
','E_mail
',self.eMail); 95 elseif ispref('Internet
','E_mail
') 96 rmpref('Internet
','E_mail
'); function sendMessage(in self, in subjectMessage, in varargin)