1#! /bin/sh
2# $Id: testMultipleAppenders 550 2007-05-22 16:45:22Z sfsetse $
3
4MY_NAME=`basename $0`
5MY_PATH=`dirname $0`
6
7APP_ONE_NAME="appenderOne"
8APP_ONE_FILE="${MY_NAME}-one.log"
9APP_TWO_NAME="appenderTwo"
10APP_TWO_FILE="${MY_NAME}-two.log"
11
12# load common unit test functions
13. "${MY_PATH}/test-functions.inc"
14
15#------------------------------------------------------------------------------
16# suite tests
17#
18
19testTwoSimilarFileAppenders()
20{
21  # configure log4sh
22  logger_setLevel INFO
23
24  # setup first appender
25  logger_addAppender ${APP_ONE_NAME}
26  appender_setType ${APP_ONE_NAME} FileAppender
27  appender_file_setFile ${APP_ONE_NAME} "${APP_ONE_FILE}"
28  appender_activateOptions ${APP_ONE_NAME}
29
30  # setup second appender
31  logger_addAppender ${APP_TWO_NAME}
32  appender_setType ${APP_TWO_NAME} FileAppender
33  appender_file_setFile ${APP_TWO_NAME} "${APP_TWO_FILE}"
34  appender_activateOptions ${APP_TWO_NAME}
35
36  # log a message
37  tf_generateRandom
38  random=${tf_RANDOM}
39  logger_info "dummy message ${random}"
40
41  # verify first appender
42  matched=`tail "${APP_ONE_FILE}" |grep "${random}"`
43  assertNotNull \
44    'first appender did not properly receive message' \
45    "${matched}"
46
47  # verify second appender
48  matched=`tail "${APP_TWO_FILE}" |grep "${random}"`
49  assertNotNull \
50    'second appender did not properly receive message' \
51    "${matched}"
52}
53
54#------------------------------------------------------------------------------
55# suite functions
56#
57
58oneTimeSetUp()
59{
60  # source log4sh
61  ${DEBUG} 'loading log4sh'
62  LOG4SH_CONFIGURATION='none' . ./log4sh
63}
64
65setUp()
66{
67  log4sh_resetConfiguration
68}
69
70oneTimeTearDown()
71{
72  rm "${APP_ONE_FILE}" "${APP_TWO_FILE}"
73}
74
75#------------------------------------------------------------------------------
76# main
77#
78
79suite()
80{
81  suite_addTest testTwoSimilarFileAppenders
82}
83
84# load and run shUnit
85${DEBUG} 'loading shUnit'
86. ./shunit2
87