Commit 94fbf62aba89a4384677d45de757a9a726e72a4c
Exists in
master
Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into 2.4.0
Showing
4 changed files
with
171 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,83 @@ | @@ -0,0 +1,83 @@ | ||
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 37 | +package logger; | ||
| 38 | + | ||
| 39 | +import static junit.framework.Assert.assertTrue; | ||
| 40 | + | ||
| 41 | +import javax.inject.Inject; | ||
| 42 | + | ||
| 43 | +import logger.appender.LoggerMemory; | ||
| 44 | + | ||
| 45 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 46 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 47 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 48 | +import org.junit.Test; | ||
| 49 | +import org.junit.runner.RunWith; | ||
| 50 | +import org.slf4j.Logger; | ||
| 51 | + | ||
| 52 | +import test.Tests; | ||
| 53 | + | ||
| 54 | +@RunWith(Arquillian.class) | ||
| 55 | +public class LoggerTest { | ||
| 56 | + | ||
| 57 | + private static final String LOGGER_MESSAGE = "Testing log4j proxy"; | ||
| 58 | + | ||
| 59 | + @Inject | ||
| 60 | + private Logger logger; | ||
| 61 | + | ||
| 62 | + @Inject | ||
| 63 | + private LoggerMemory loggerMemory; | ||
| 64 | + | ||
| 65 | + @Deployment | ||
| 66 | + public static JavaArchive createDeployment() { | ||
| 67 | + | ||
| 68 | + JavaArchive deployment = Tests.createDeployment(LoggerTest.class); | ||
| 69 | + | ||
| 70 | + return deployment; | ||
| 71 | + | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Test | ||
| 75 | + public void testLoggerProducer() { | ||
| 76 | + | ||
| 77 | + logger.info(LOGGER_MESSAGE); | ||
| 78 | + | ||
| 79 | + assertTrue(loggerMemory.checkMessage(LOGGER_MESSAGE)); | ||
| 80 | + | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | +} |
impl/core/src/test/java/logger/appender/LoggerMemory.java
0 → 100644
| @@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
| 1 | +package logger.appender; | ||
| 2 | + | ||
| 3 | +import java.util.ArrayList; | ||
| 4 | +import java.util.List; | ||
| 5 | + | ||
| 6 | +import javax.inject.Inject; | ||
| 7 | + | ||
| 8 | +import org.slf4j.Logger; | ||
| 9 | + | ||
| 10 | +public class LoggerMemory { | ||
| 11 | + | ||
| 12 | + @Inject | ||
| 13 | + private Logger logger; | ||
| 14 | + | ||
| 15 | + private static List<String> messages = new ArrayList<String>(); | ||
| 16 | + | ||
| 17 | + public boolean checkMessage(String loggerMessage) { | ||
| 18 | + | ||
| 19 | + logger.info("Verificando a mensagem [" + loggerMessage + "]"); | ||
| 20 | + this.showMessages(); | ||
| 21 | + | ||
| 22 | + for (String mensagem : messages) { | ||
| 23 | + | ||
| 24 | + if (mensagem.equals(loggerMessage)) { | ||
| 25 | + | ||
| 26 | + logger.info("Mensagem encontrada"); | ||
| 27 | + return true; | ||
| 28 | + | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + logger.info("Mensagem não encontrada"); | ||
| 34 | + return false; | ||
| 35 | + | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + private void showMessages() { | ||
| 39 | + | ||
| 40 | + logger.debug("Inicio da listagem de mensagens armazenadas..."); | ||
| 41 | + for (String message : messages) { | ||
| 42 | + | ||
| 43 | + logger.debug("\"" + message + "\""); | ||
| 44 | + | ||
| 45 | + } | ||
| 46 | + logger.debug("Fim da listagem de mensagens armazenadas..."); | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public static void addMessage(String mensagem) { | ||
| 51 | + | ||
| 52 | + messages.add(mensagem); | ||
| 53 | + | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | +} |
impl/core/src/test/java/logger/appender/MemoryAppender.java
0 → 100644
| @@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
| 1 | +package logger.appender; | ||
| 2 | + | ||
| 3 | +import org.apache.log4j.AppenderSkeleton; | ||
| 4 | +import org.apache.log4j.spi.LoggingEvent; | ||
| 5 | + | ||
| 6 | +public class MemoryAppender extends AppenderSkeleton { | ||
| 7 | + | ||
| 8 | + @Override | ||
| 9 | + public void close() { | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + @Override | ||
| 13 | + public boolean requiresLayout() { | ||
| 14 | + return false; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + protected void append(LoggingEvent loggingEvent) { | ||
| 19 | + | ||
| 20 | + if (!LoggerMemory.class.getName().equals(loggingEvent.getLoggerName())) { | ||
| 21 | + | ||
| 22 | + LoggerMemory.addMessage(loggingEvent.getMessage().toString()); | ||
| 23 | + | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | +} |
impl/core/src/test/resources/log4j.properties
| @@ -40,3 +40,7 @@ log4j.logger.br.gov.frameworkdemoiselle=TRACE | @@ -40,3 +40,7 @@ log4j.logger.br.gov.frameworkdemoiselle=TRACE | ||
| 40 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender | 40 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender |
| 41 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | 41 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout |
| 42 | log4j.appender.stdout.layout.ConversionPattern=%-5p [%c{1}] %m%n | 42 | log4j.appender.stdout.layout.ConversionPattern=%-5p [%c{1}] %m%n |
| 43 | + | ||
| 44 | +# Custom Appender to log4j that holds messages in memory | ||
| 45 | +log4j.logger.logger=TRACE, MEMORYAPPENDER | ||
| 46 | +log4j.appender.MEMORYAPPENDER=logger.appender.MemoryAppender |