forked from kward/log4sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log4sh_test_smtp_appender.sh
executable file
·128 lines (105 loc) · 3.4 KB
/
log4sh_test_smtp_appender.sh
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#! /bin/sh
# $Id$
# vim:et:ft=sh:sts=2:sw=2
#
# Copyright 2008 Kate Ward. All Rights Reserved.
# Released under the LGPL (GNU Lesser General Public License)
# Author: [email protected] (Kate Ward)
#
# log4sh unit test for the SMTPAppender.
# load test helpers
. ./log4sh_test_helpers
APP_NAME='mySMTP'
APP_CONFIG="${TH_TESTDATA_DIR}/smtp_appender.log4sh"
TEST_SUBJECT='This is a Subject worth testing'
TEST_TO='[email protected]'
#------------------------------------------------------------------------------
# suite tests
#
testSubjectGetterSetter()
{
# configure log4sh
logger_addAppender ${APP_NAME}
appender_setType ${APP_NAME} SMTPAppender
appender_activateOptions ${APP_NAME}
${DEBUG} 'testing that the default Subject is empty'
currSubject=`appender_smtp_getSubject ${APP_NAME}`
${TRACE} "currSubject='${currSubject}'"
assertNull \
'the default SMTP Subject was not empty' \
"${currSubject}"
${DEBUG} 'testing that it is possible to set and get the SMTP Subject'
# TODO: test for the log4sh:ERROR message
appender_smtp_setSubject ${APP_NAME} "${TEST_SUBJECT}"
appender_activateOptions ${APP_NAME}
currSubject=`appender_smtp_getSubject ${APP_NAME}`
${TRACE} "currSubject='${currSubject}'"
assertEquals \
'the returned SMTP Subject does not match the one that was set' \
"${currSubject}" "${TEST_SUBJECT}"
# TODO: test the passing of invalid params
unset currSubject
}
testToGetterSetter()
{
# configure log4sh
logger_addAppender ${APP_NAME}
appender_setType ${APP_NAME} SMTPAppender
appender_activateOptions ${APP_NAME}
${DEBUG} 'testing that the default To is empty'
currTo=`appender_smtp_getTo ${APP_NAME}`
${TRACE} "currTo='${currTo}'"
assertNull \
'the default SMTP To was not empty' \
"${currTo}"
${DEBUG} 'testing that it is possible to set and get the SMTP To'
# TODO: test for the log4sh:ERROR message
appender_smtp_setTo ${APP_NAME} "${TEST_TO}"
appender_activateOptions ${APP_NAME}
currTo=`appender_smtp_getTo ${APP_NAME}`
${TRACE} "currTo='${currTo}'"
assertEquals \
'the returned SMTP To does not match the one that was set' \
"${currTo}" "${TEST_TO}"
# TODO: test the passing of invalid params
unset currTo
}
testAppenderSetupFromConfig()
{
# configure log4sh
log4sh_doConfigure "${APP_CONFIG}"
${DEBUG} 'verifying that the appender Type was properly set'
currType=`appender_getType ${APP_NAME}`
${TRACE} "currType='${currType}'"
assertEquals \
'the returned appender type was not SMTPAppender' \
"${currType}" 'SMTPAppender'
${DEBUG} 'verifying that the appender Subject was properly set'
currSubject=`appender_smtp_getSubject ${APP_NAME}`
${TRACE} "currSubject='${currSubject}'"
assertEquals \
'the returned SMTP Subject does not match what was expected' \
"${currSubject}" "${TEST_SUBJECT}"
${DEBUG} 'verifying that the appender To was properly set'
currTo=`appender_smtp_getTo ${APP_NAME}`
${TRACE} "currTo='${currTo}'"
assertEquals \
'the returned SMTP To does not match what was expected' \
"${currTo}" "${TEST_TO}"
unset currType currSubject currTo
}
#------------------------------------------------------------------------------
# suite functions
#
oneTimeSetUp()
{
LOG4SH_CONFIGURATION='none'
th_oneTimeSetUp
}
setUp()
{
log4sh_resetConfiguration
}
# load and run shUnit2
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
. ${TH_SHUNIT}