Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

changed to use the dumbster plugin

  • Loading branch information...
commit f4c09e757fd559c6105d70b04c801f8233e5d217 1 parent d65c4cc
Burt Beckwith burtbeckwith authored
5 .classpath
@@ -7,6 +7,11 @@
7 7 <classpathentry kind="src" path="test/unit"/>
8 8 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
9 9 <classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
  10 + <classpathentry kind="src" path=".link_to_grails_plugins/dumbster-0.2/src/groovy">
  11 + <attributes>
  12 + <attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
  13 + </attributes>
  14 + </classpathentry>
10 15 <classpathentry kind="src" path=".link_to_grails_plugins/release-2.2.0/src/groovy">
11 16 <attributes>
12 17 <attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
10 grails-app/conf/BuildConfig.groovy
@@ -5,7 +5,7 @@ grails.project.docs.output.dir = 'docs/manual' // for backwards-compatibility, t
5 5
6 6 grails.project.dependency.resolution = {
7 7
8   - inherits('global') {
  8 + inherits 'global', {
9 9 excludes 'grails-plugin-log4j'
10 10 }
11 11
@@ -30,10 +30,6 @@ grails.project.dependency.resolution = {
30 30 excludes 'janino', 'jansi', 'mail', 'geronimo-jms_1.1_spec', 'easymock', 'servlet-api', 'scala-library', 'junit', 'fest-assert'
31 31 }
32 32
33   - test 'dumbster:dumbster:1.6', {
34   - transitive = false
35   - export = false
36   - }
37 33 test 'javax.mail:mail:1.4.5', {
38 34 transitive = false
39 35 export = false
@@ -44,5 +40,9 @@ grails.project.dependency.resolution = {
44 40 build(':release:2.2.0', ':rest-client-builder:1.0.3') {
45 41 export = false
46 42 }
  43 +
  44 + test ':dumbster:0.2', {
  45 + export = false
  46 + }
47 47 }
48 48 }
95 test/unit/grails/plugin/logback/LogbackConfigTests.groovy
... ... @@ -1,5 +1,6 @@
1 1 package grails.plugin.logback
2 2
  3 +import grails.plugin.dumbster.Dumbster
3 4 import groovy.sql.Sql
4 5
5 6 import java.sql.Connection
@@ -9,16 +10,26 @@ import org.slf4j.LoggerFactory
9 10
10 11 import ch.qos.logback.classic.Level
11 12 import ch.qos.logback.classic.Logger
  13 +import ch.qos.logback.classic.LoggerContext
12 14 import ch.qos.logback.classic.db.DBAppender
13 15 import ch.qos.logback.classic.net.SMTPAppender
14 16 import ch.qos.logback.core.FileAppender
15 17 import ch.qos.logback.core.rolling.RollingFileAppender
16 18
17   -import com.dumbster.smtp.SimpleSmtpServer
18 19 import com.dumbster.smtp.SmtpMessage
19 20
20 21 class LogbackConfigTests extends GroovyTestCase {
21 22
  23 + private Dumbster dumbster = new Dumbster()
  24 +
  25 + @Override
  26 + protected void setUp() {
  27 + super.setUp()
  28 + dumbster.grailsApplication = [
  29 + config: [dumbster: [enabled: true]],
  30 + mainContext: [containsBean: { String -> false }]]
  31 + }
  32 +
22 33 void testParseSimple() {
23 34 String config = '''
24 35 logback = {
@@ -33,7 +44,8 @@ logback = {
33 44 parse config
34 45
35 46 def names = ['ROOT', 'StackTrace'] + split('org.codehaus.groovy.grails') + split('org.springframework') +
36   - split('org.hibernate') + split('net.sf.ehcache.hibernate') + split('com.foo.bar')
  47 + split('org.hibernate') + split('net.sf.ehcache.hibernate') + split('com.foo.bar') +
  48 + ['grails.plugin.dumbster', 'grails.plugin.dumbster.Dumbster']
37 49
38 50 def loggerNames = findLoggerNames()
39 51
@@ -136,7 +148,7 @@ logback = {
136 148 """
137 149 parse config
138 150
139   - LogbackLoggerAdapter logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
  151 + Logger logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
140 152 assert Level.INFO == logger.level
141 153
142 154 def appenders = logger.iteratorForAppenders().collect { it }.sort { it.getClass().name }
@@ -174,7 +186,7 @@ logback = {
174 186
175 187 parse config
176 188
177   - LogbackLoggerAdapter logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
  189 + Logger logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
178 190 assert Level.INFO == logger.level
179 191
180 192 def appenders = logger.iteratorForAppenders().collect { it }.sort { it.getClass().name }
@@ -215,7 +227,7 @@ logback = {
215 227
216 228 parse config
217 229
218   - LogbackLoggerAdapter logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
  230 + Logger logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
219 231 assert Level.INFO == logger.level
220 232
221 233 def appenders = logger.iteratorForAppenders().collect { it }.sort { it.getClass().name }
@@ -271,7 +283,7 @@ logback = {
271 283
272 284 parse config
273 285
274   - LogbackLoggerAdapter logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
  286 + Logger logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
275 287 assert Level.INFO == logger.level
276 288
277 289 def appenders = logger.iteratorForAppenders().collect { it }.sort { it.getClass().name }
@@ -352,7 +364,7 @@ CREATE TABLE logging_event_exception (
352 364 def sql = Sql.newInstance(url, user, password, driver)
353 365 ddl.split(';').each { sql.executeUpdate it }
354 366
355   - LogbackLoggerAdapter logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
  367 + Logger logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
356 368 assert Level.INFO == logger.level
357 369
358 370 def appenders = logger.iteratorForAppenders().collect { it }.sort { it.getClass().name }
@@ -374,28 +386,13 @@ CREATE TABLE logging_event_exception (
374 386
375 387 void testSmtpAppender() {
376 388
377   - int port = 1025
378   - while (true) {
379   - try {
380   - new ServerSocket(port).close()
381   - break
382   - }
383   - catch (IOException e) {
384   - port++
385   - if (port > 2000) {
386   - fail 'cannot find open port'
387   - }
388   - }
389   - }
  389 + dumbster.start()
390 390
391   - SimpleSmtpServer server = SimpleSmtpServer.start(port)
392   - try {
  391 + String from = 'test@testing.com'
  392 + String host = 'localhost'
  393 + String to = 'to@testing.com'
393 394
394   - String from = 'test@testing.com'
395   - String host = 'localhost'
396   - String to = 'to@testing.com'
397   -
398   - String config = """
  395 + String config = """
399 396 import ch.qos.logback.classic.PatternLayout
400 397 import ch.qos.logback.classic.net.SMTPAppender
401 398
@@ -404,7 +401,7 @@ logback = {
404 401
405 402 def layout = dslInit(new PatternLayout(outputPatternAsHeader: false, pattern: '%-4relative %-5level %class - %msg%n'))
406 403 def smtp = new SMTPAppender(name: 'smtp', asynchronousSending: false, from: '$from', smtpHost: '$host',
407   - smtpPort: $port, layout: layout)
  404 + smtpPort: $dumbster.port, layout: layout)
408 405 smtp.context = context // need this now for the parser that's used for the To address
409 406 smtp.addTo '$to'
410 407 appender smtp
@@ -413,31 +410,27 @@ logback = {
413 410 info smtp: 'grails.app.controllers.BookController'
414 411 }"""
415 412
416   - parse config
  413 + parse config
417 414
418   - LogbackLoggerAdapter logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
419   - assert Level.INFO == logger.level
  415 + Logger logger = LoggerFactory.getLogger('grails.app.controllers.BookController')
  416 + assert Level.INFO == logger.level
420 417
421   - def appenders = logger.iteratorForAppenders().collect { it }.sort { it.getClass().name }
422   - assert 1 == appenders.size()
  418 + def appenders = logger.iteratorForAppenders().collect { it }.sort { it.getClass().name }
  419 + assert 1 == appenders.size()
423 420
424   - assert appenders[0] instanceof SMTPAppender
  421 + assert appenders[0] instanceof SMTPAppender
425 422
426   - root.detachAppender 'stdout'
427   - 10000.times { logger.debug 'this is a debug message' }
  423 + root.detachAppender 'stdout'
  424 + 10000.times { logger.debug 'this is a debug message' }
428 425
429   - 10.times { logger.error "event$it" }
  426 + 10.times { logger.error "event$it" }
430 427
431   - assert 10 == server.receivedEmailSize
  428 + assert 10 == dumbster.messageCount
432 429
433   - server.receivedEmail.eachWithIndex { SmtpMessage email, int index ->
434   - assert "g.a.c.BookController - event$index" == email.getHeaderValue('Subject')
435   - assert email.body.contains('ERROR')
436   - assert email.body.contains("event$index")
437   - }
438   - }
439   - finally {
440   - server.stop()
  430 + dumbster.messages.eachWithIndex { SmtpMessage email, int index ->
  431 + assert "g.a.c.BookController - event$index" == email.getHeaderValue('Subject')
  432 + assert email.body.contains('ERROR')
  433 + assert email.body.contains("event$index")
441 434 }
442 435 }
443 436
@@ -445,7 +438,9 @@ logback = {
445 438 protected void tearDown() {
446 439 super.tearDown()
447 440 LoggerFactory.ILoggerFactory.reset()
448   - Utils.clearLoggers()
  441 + LoggerContext loggerFactory = LoggerFactory.ILoggerFactory
  442 + loggerFactory.loggerCache.clear()
  443 + dumbster.reset()
449 444 }
450 445
451 446 private List<String> split(String name) {
@@ -460,8 +455,8 @@ logback = {
460 455 }
461 456
462 457 private List<String> findLoggerNames() {
463   - LogbackLoggerFactory loggerFactory = LoggerFactory.ILoggerFactory
464   - List<Logger> loggers = loggerFactory.loggerContext.loggerList
  458 + LoggerContext loggerFactory = LoggerFactory.ILoggerFactory
  459 + List<Logger> loggers = loggerFactory.loggerList
465 460
466 461 def loggerNames = loggers.collect { it.name }.sort()
467 462 loggerNames.removeAll split(getClass().name)
@@ -470,7 +465,7 @@ logback = {
470 465 loggerNames
471 466 }
472 467
473   - private LogbackLoggerAdapter getRoot() {
  468 + private Logger getRoot() {
474 469 LoggerFactory.getLogger Logger.ROOT_LOGGER_NAME
475 470 }
476 471

0 comments on commit f4c09e7

Please sign in to comment.
Something went wrong with that request. Please try again.