From ddf2a6e8c2865b9d03b7bd3546958cf688d0e98d Mon Sep 17 00:00:00 2001 From: Cleverson Sacramento Date: Sun, 22 Jul 2012 22:02:09 -0300 Subject: [PATCH] Diversos ajustes no framework referentes à serialização de objetos internos --- archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/persistence/BookmarkDAO.java | 4 ---- archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties | 35 ----------------------------------- archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml | 12 ++++++++++-- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java | 5 ++++- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java | 3 +-- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java | 3 +-- impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxy.java | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------- impl/core/src/main/java/br/gov/frameworkdemoiselle/template/DelegateCrud.java | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- impl/core/src/main/java/br/gov/frameworkdemoiselle/util/ResourceBundle.java | 28 +++++++++++++++++++++------- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderTest.java | 1282 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticatorTest.java | 4 +++- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizerTest.java | 4 +++- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransactionTest.java | 4 +++- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImplTest.java | 34 ++++++++++++++++++---------------- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java | 4 +++- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptorTest.java | 6 ++++-- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java | 4 +++- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/TransactionalInterceptorTest.java | 4 +++- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducerTest.java | 3 +-- impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxyTest.java | 1120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- impl/core/src/test/java/br/gov/frameworkdemoiselle/util/ResourceBundleTest.java | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------- impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java | 10 ++++++---- impl/extension/jsf/pom.xml | 11 +++++++---- impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImpl.java | 65 +++++++++++++++++++++++++++++++++++++++++------------------------ impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityObserver.java | 13 ++++--------- impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/producer/JsfLocaleProducer.java | 4 ++-- impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Parameter.java | 4 +++- impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImplTest.java | 650 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBeanTest.java | 2 +- impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/Contact.java | 10 +++++++--- impl/extension/servlet/pom.xml | 2 ++ impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletRequestProducer.java | 12 ++++++++---- impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletResponseProducer.java | 12 ++++++++---- impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpSessionProducer.java | 14 ++++++++------ impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ServletLocaleProducer.java | 11 +++++------ impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletRequestProxy.java | 307 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletResponseProxy.java | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpSessionProxy.java | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletFilter.java | 9 +++------ parent/extension/pom.xml | 1 - parent/framework/pom.xml | 2 +- parent/jsf/pom.xml | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 42 files changed, 2694 insertions(+), 1907 deletions(-) create mode 100644 impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletRequestProxy.java create mode 100644 impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletResponseProxy.java create mode 100644 impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpSessionProxy.java diff --git a/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/persistence/BookmarkDAO.java b/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/persistence/BookmarkDAO.java index 8a7b522..24c120a 100644 --- a/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/persistence/BookmarkDAO.java +++ b/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/persistence/BookmarkDAO.java @@ -14,8 +14,4 @@ public class BookmarkDAO extends JPACrud { private static final long serialVersionUID = 1L; - @Inject - @SuppressWarnings("unused") - private Logger logger; - } diff --git a/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties b/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties index 34d9324..25e7de3 100755 --- a/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties +++ b/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties @@ -1,37 +1,2 @@ -# Demoiselle Framework -# Copyright (C) 2010 SERPRO -# ---------------------------------------------------------------------------- -# This file is part of Demoiselle Framework. -# -# Demoiselle Framework is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public License version 3 -# as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License version 3 -# along with this program; if not, see -# or write to the Free Software Foundation, Inc., 51 Franklin Street, -# Fifth Floor, Boston, MA 02110-1301, USA. -# ---------------------------------------------------------------------------- -# Este arquivo é parte do Framework Demoiselle. -# -# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou -# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação -# do Software Livre (FSF). -# -# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA -# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou -# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português -# para maiores detalhes. -# -# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título -# "LICENCA.txt", junto com esse programa. Se não, acesse -# ou escreva para a Fundação do Software Livre (FSF) Inc., -# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JPATransaction #frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JTATransaction diff --git a/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml index f0f8d9e..cafede6 100755 --- a/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml +++ b/archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml @@ -3,7 +3,7 @@ xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> - + diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java index b633000..07d7470 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java @@ -36,6 +36,7 @@ */ package br.gov.frameworkdemoiselle.internal.configuration; +import java.io.Serializable; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashSet; @@ -67,7 +68,9 @@ import br.gov.frameworkdemoiselle.util.Strings; * * @author SERPRO */ -public class ConfigurationLoader { +public class ConfigurationLoader implements Serializable { + + private static final long serialVersionUID = 1L; @Inject @Name("demoiselle-core-bundle") diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java index 499350a..99f3834 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java @@ -55,7 +55,6 @@ import javax.enterprise.inject.Produces; import javax.enterprise.inject.spi.InjectionPoint; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import br.gov.frameworkdemoiselle.internal.proxy.Slf4jLoggerProxy; @@ -78,6 +77,6 @@ public class LoggerProducer implements Serializable { } public static Logger create(Class type) { - return new Slf4jLoggerProxy(LoggerFactory.getLogger(type)); + return new Slf4jLoggerProxy(type); } } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java index 5ac3c90..1a64a97 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java @@ -67,8 +67,7 @@ public class ResourceBundleProducer implements Serializable { ResourceBundle bundle = null; try { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - bundle = new ResourceBundle(ResourceBundle.getBundle(baseName, locale, classLoader)); + bundle = new ResourceBundle(baseName, locale); } catch (MissingResourceException e) { throw new DemoiselleException("File " + baseName + " not found!"); diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxy.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxy.java index 21e7941..504da1c 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxy.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxy.java @@ -51,321 +51,332 @@ package br.gov.frameworkdemoiselle.internal.proxy; import java.io.Serializable; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.slf4j.Marker; public class Slf4jLoggerProxy implements Logger, Serializable { private static final long serialVersionUID = 1L; - private transient final Logger delegate; + private transient Logger delegate; - public Slf4jLoggerProxy(final Logger logger) { - this.delegate = logger; + private final Class type; + + private Logger getDelegate() { + if(delegate == null) { + delegate = LoggerFactory.getLogger(type); + } + + return delegate; + } + + public Slf4jLoggerProxy(final Class type) { + this.type = type; } @Override public void debug(final Marker marker, final String msg) { - this.delegate.debug(marker, msg); + getDelegate().debug(marker, msg); } @Override public void debug(final Marker marker, final String format, final Object arg) { - this.delegate.debug(marker, format, arg); + getDelegate().debug(marker, format, arg); } @Override public void debug(final Marker marker, final String format, final Object arg1, final Object arg2) { - this.delegate.debug(marker, format, arg1, arg2); + getDelegate().debug(marker, format, arg1, arg2); } @Override public void debug(final Marker marker, final String format, final Object[] argArray) { - this.delegate.debug(marker, format, argArray); + getDelegate().debug(marker, format, argArray); } @Override public void debug(final Marker marker, final String msg, final Throwable t) { - this.delegate.debug(marker, msg, t); + getDelegate().debug(marker, msg, t); } @Override public void debug(final String msg) { - this.delegate.debug(msg); + getDelegate().debug(msg); } @Override public void debug(final String format, final Object arg) { - this.delegate.debug(format, arg); + getDelegate().debug(format, arg); } @Override public void debug(final String format, final Object arg1, final Object arg2) { - this.delegate.debug(format, arg1, arg2); + getDelegate().debug(format, arg1, arg2); } @Override public void debug(final String format, final Object[] argArray) { - this.delegate.debug(format, argArray); + getDelegate().debug(format, argArray); } @Override public void debug(final String msg, final Throwable t) { - this.delegate.debug(msg, t); + getDelegate().debug(msg, t); } @Override public void error(final Marker marker, final String msg) { - this.delegate.error(marker, msg); + getDelegate().error(marker, msg); } @Override public void error(final Marker marker, final String format, final Object arg) { - this.delegate.error(marker, format, arg); + getDelegate().error(marker, format, arg); } @Override public void error(final Marker marker, final String format, final Object arg1, final Object arg2) { - this.delegate.error(marker, format, arg1, arg2); + getDelegate().error(marker, format, arg1, arg2); } @Override public void error(final Marker marker, final String format, final Object[] argArray) { - this.delegate.error(marker, format, argArray); + getDelegate().error(marker, format, argArray); } @Override public void error(final Marker marker, final String msg, final Throwable t) { - this.delegate.error(marker, msg, t); + getDelegate().error(marker, msg, t); } @Override public void error(final String msg) { - this.delegate.error(msg); + getDelegate().error(msg); } @Override public void error(final String format, final Object arg) { - this.delegate.error(format, arg); + getDelegate().error(format, arg); } @Override public void error(final String format, final Object arg1, final Object arg2) { - this.delegate.error(format, arg1, arg2); + getDelegate().error(format, arg1, arg2); } @Override public void error(final String format, final Object[] argArray) { - this.delegate.error(format, argArray); + getDelegate().error(format, argArray); } @Override public void error(final String msg, final Throwable t) { - this.delegate.error(msg, t); + getDelegate().error(msg, t); } @Override public String getName() { - return this.delegate.getName(); + return getDelegate().getName(); } @Override public void info(final Marker marker, final String msg) { - this.delegate.info(marker, msg); + getDelegate().info(marker, msg); } @Override public void info(final Marker marker, final String format, final Object arg) { - this.delegate.info(marker, format, arg); + getDelegate().info(marker, format, arg); } @Override public void info(final Marker marker, final String format, final Object arg1, final Object arg2) { - this.delegate.info(marker, format, arg1, arg2); + getDelegate().info(marker, format, arg1, arg2); } @Override public void info(final Marker marker, final String format, final Object[] argArray) { - this.delegate.info(marker, format, argArray); + getDelegate().info(marker, format, argArray); } @Override public void info(final Marker marker, final String msg, final Throwable t) { - this.delegate.info(marker, msg, t); + getDelegate().info(marker, msg, t); } @Override public void info(final String msg) { - this.delegate.info(msg); + getDelegate().info(msg); } @Override public void info(final String format, final Object arg) { - this.delegate.info(format, arg); + getDelegate().info(format, arg); } @Override public void info(final String format, final Object arg1, final Object arg2) { - this.delegate.info(format, arg1, arg2); + getDelegate().info(format, arg1, arg2); } @Override public void info(final String format, final Object[] argArray) { - this.delegate.info(format, argArray); + getDelegate().info(format, argArray); } @Override public void info(final String msg, final Throwable t) { - this.delegate.info(msg, t); + getDelegate().info(msg, t); } @Override public boolean isDebugEnabled() { - return this.delegate.isDebugEnabled(); + return getDelegate().isDebugEnabled(); } @Override public boolean isDebugEnabled(final Marker marker) { - return this.delegate.isDebugEnabled(marker); + return getDelegate().isDebugEnabled(marker); } @Override public boolean isErrorEnabled() { - return this.delegate.isErrorEnabled(); + return getDelegate().isErrorEnabled(); } @Override public boolean isErrorEnabled(final Marker marker) { - return this.delegate.isErrorEnabled(marker); + return getDelegate().isErrorEnabled(marker); } @Override public boolean isInfoEnabled() { - return this.delegate.isInfoEnabled(); + return getDelegate().isInfoEnabled(); } @Override public boolean isInfoEnabled(final Marker marker) { - return this.delegate.isInfoEnabled(marker); + return getDelegate().isInfoEnabled(marker); } @Override public boolean isTraceEnabled() { - return this.delegate.isTraceEnabled(); + return getDelegate().isTraceEnabled(); } @Override public boolean isTraceEnabled(final Marker marker) { - return this.delegate.isTraceEnabled(marker); + return getDelegate().isTraceEnabled(marker); } @Override public boolean isWarnEnabled() { - return this.delegate.isWarnEnabled(); + return getDelegate().isWarnEnabled(); } @Override public boolean isWarnEnabled(final Marker marker) { - return this.delegate.isWarnEnabled(marker); + return getDelegate().isWarnEnabled(marker); } @Override public void trace(final Marker marker, final String msg) { - this.delegate.trace(marker, msg); + getDelegate().trace(marker, msg); } @Override public void trace(final Marker marker, final String format, final Object arg) { - this.delegate.trace(marker, format, arg); + getDelegate().trace(marker, format, arg); } @Override public void trace(final Marker marker, final String format, final Object arg1, final Object arg2) { - this.delegate.trace(marker, format, arg1, arg2); + getDelegate().trace(marker, format, arg1, arg2); } @Override public void trace(final Marker marker, final String format, final Object[] argArray) { - this.delegate.trace(marker, format, argArray); + getDelegate().trace(marker, format, argArray); } @Override public void trace(final Marker marker, final String msg, final Throwable t) { - this.delegate.trace(marker, msg, t); + getDelegate().trace(marker, msg, t); } @Override public void trace(final String msg) { - this.delegate.trace(msg); + getDelegate().trace(msg); } @Override public void trace(final String format, final Object arg) { - this.delegate.trace(format, arg); + getDelegate().trace(format, arg); } @Override public void trace(final String format, final Object arg1, final Object arg2) { - this.delegate.trace(format, arg1, arg2); + getDelegate().trace(format, arg1, arg2); } @Override public void trace(final String format, final Object[] argArray) { - this.delegate.trace(format, argArray); + getDelegate().trace(format, argArray); } @Override public void trace(final String msg, final Throwable t) { - this.delegate.trace(msg, t); + getDelegate().trace(msg, t); } @Override public void warn(final Marker marker, final String msg) { - this.delegate.warn(marker, msg); + getDelegate().warn(marker, msg); } @Override public void warn(final Marker marker, final String format, final Object arg) { - this.delegate.warn(marker, format, arg); + getDelegate().warn(marker, format, arg); } @Override public void warn(final Marker marker, final String format, final Object arg1, final Object arg2) { - this.delegate.warn(marker, format, arg1, arg2); + getDelegate().warn(marker, format, arg1, arg2); } @Override public void warn(final Marker marker, final String format, final Object[] argArray) { - this.delegate.warn(marker, format, argArray); + getDelegate().warn(marker, format, argArray); } @Override public void warn(final Marker marker, final String msg, final Throwable t) { - this.delegate.warn(marker, msg, t); + getDelegate().warn(marker, msg, t); } @Override public void warn(final String msg) { - this.delegate.warn(msg); + getDelegate().warn(msg); } @Override public void warn(final String format, final Object arg) { - this.delegate.warn(format, arg); + getDelegate().warn(format, arg); } @Override public void warn(final String format, final Object arg1, final Object arg2) { - this.delegate.warn(format, arg1, arg2); + getDelegate().warn(format, arg1, arg2); } @Override public void warn(final String format, final Object[] argArray) { - this.delegate.warn(format, argArray); + getDelegate().warn(format, argArray); } @Override public void warn(final String msg, final Throwable t) { - this.delegate.warn(msg, t); + getDelegate().warn(msg, t); } } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/template/DelegateCrud.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/template/DelegateCrud.java index ba9e63c..d2ea407 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/template/DelegateCrud.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/template/DelegateCrud.java @@ -39,6 +39,8 @@ package br.gov.frameworkdemoiselle.template; import java.util.List; import java.util.ListIterator; +import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction; +import br.gov.frameworkdemoiselle.transaction.Transaction; import br.gov.frameworkdemoiselle.transaction.Transactional; import br.gov.frameworkdemoiselle.util.Beans; import br.gov.frameworkdemoiselle.util.Reflections; @@ -50,21 +52,45 @@ public class DelegateCrud> implements Crud { private Class delegateClass; private C delegate; - + @Override - @Transactional public void delete(final I id) { - this.getDelegate().delete(id); + if(isRunningTransactionalOperations()) { + transactionalDelete(id); + } else { + nonTransactionalDelete(id); + } + } + + @Transactional + private void transactionalDelete(final I id) { + nonTransactionalDelete(id); + } + + private void nonTransactionalDelete(final I id) { + getDelegate().delete(id); + } + + public void delete(final List ids) { + if(isRunningTransactionalOperations()) { + transactionalDelete(ids); + } else { + nonTransactionalDelete(ids); + } } @Transactional - public void delete(final List idList) { - ListIterator iter = idList.listIterator(); + private void transactionalDelete(final List ids) { + nonTransactionalDelete(ids); + } + + private void nonTransactionalDelete(final List ids) { + ListIterator iter = ids.listIterator(); while (iter.hasNext()) { this.delete(iter.next()); } } - + @Override public List findAll() { return getDelegate().findAll(); @@ -85,8 +111,20 @@ public class DelegateCrud> implements Crud { } @Override - @Transactional public void insert(final T bean) { + if(isRunningTransactionalOperations()) { + transactionalInsert(bean); + } else { + nonTransactionalInsert(bean); + } + } + + @Transactional + private void transactionalInsert(final T bean) { + nonTransactionalInsert(bean); + } + + private void nonTransactionalInsert(final T bean) { getDelegate().insert(bean); } @@ -96,9 +134,24 @@ public class DelegateCrud> implements Crud { } @Override - @Transactional public void update(final T bean) { - getDelegate().update(bean); + if(isRunningTransactionalOperations()) { + transactionalUpdate(bean); + } else { + nonTransactionalUpdate(bean); + } } + @Transactional + private void transactionalUpdate(final T bean) { + nonTransactionalUpdate(bean); + } + + private void nonTransactionalUpdate(final T bean) { + getDelegate().update(bean); + } + + private boolean isRunningTransactionalOperations() { + return !(Beans.getReference(Transaction.class) instanceof DefaultTransaction); + } } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/ResourceBundle.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/ResourceBundle.java index 9e15e7c..f2de5eb 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/ResourceBundle.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/ResourceBundle.java @@ -46,30 +46,44 @@ public class ResourceBundle extends java.util.ResourceBundle implements Serializ private static final long serialVersionUID = 1L; + private String baseName; + private transient java.util.ResourceBundle delegate; - public ResourceBundle(java.util.ResourceBundle resourceBundle) { - this.delegate = resourceBundle; + private final Locale locale; + + private java.util.ResourceBundle getDelegate() { + if(delegate == null) { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + delegate = ResourceBundle.getBundle(baseName, locale, classLoader); + } + + return delegate; } + public ResourceBundle(String baseName, Locale locale) { + this.baseName = baseName; + this.locale = locale; + } + @Override public boolean containsKey(String key) { - return delegate.containsKey(key); + return getDelegate().containsKey(key); } @Override public Enumeration getKeys() { - return delegate.getKeys(); + return getDelegate().getKeys(); } @Override public Locale getLocale() { - return delegate.getLocale(); + return getDelegate().getLocale(); } @Override public Set keySet() { - return delegate.keySet(); + return getDelegate().keySet(); } public String getString(String key, Object... params) { @@ -81,7 +95,7 @@ public class ResourceBundle extends java.util.ResourceBundle implements Serializ Object result; try { - Method method = delegate.getClass().getMethod("handleGetObject", String.class); + Method method = getDelegate().getClass().getMethod("handleGetObject", String.class); method.setAccessible(true); result = method.invoke(delegate, key); diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderTest.java index 4995537..31d35df 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderTest.java @@ -1,641 +1,641 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package br.gov.frameworkdemoiselle.internal.configuration; - -import static org.easymock.EasyMock.expect; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.powermock.api.easymock.PowerMock.mockStatic; - -import javax.validation.constraints.NotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; -import org.slf4j.Logger; - -import br.gov.frameworkdemoiselle.annotation.Ignore; -import br.gov.frameworkdemoiselle.annotation.Name; -import br.gov.frameworkdemoiselle.configuration.ConfigType; -import br.gov.frameworkdemoiselle.configuration.Configuration; -import br.gov.frameworkdemoiselle.configuration.ConfigurationException; -import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; -import br.gov.frameworkdemoiselle.util.ResourceBundle; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(CoreBootstrap.class) -public class ConfigurationLoaderTest { - - private ConfigurationLoader configurationLoader; - - @Configuration - public class ConfigurationSuccessfulProperties { - - @Name("frameworkdemoiselle.configurationtest.nameConfiguration") - protected String nameConfiguration; - - } - - @Configuration - public class ConfigurationSuccessfulProperties2 { - - @Name("frameworkdemoiselle.configurationtest.name") - protected String name; - - } - - @Configuration(resource = "absentFile") - public class ConfigurationPropertiesWithAbsentFile { - - @Name("frameworkdemoiselle.configurationtest.nameConfiguration") - protected String nameConfiguration; - - } - - @Configuration - public class ConfigurationWithEmptyName { - - @Name("") - protected String nameConfiguration; - - } - - @Configuration - public class ConfigurationWithoutNameAnnotation { - - protected String nameConfiguration; - - } - - @Configuration - public class ConfigurationWithIgnoreAnnotation { - - @Ignore - protected String nameConfiguration; - - } - - @Configuration(prefix = "frameworkdemoiselle.configurationtest") - public class ConfigurationWithPrefix { - - @Name("nameConfiguration") - protected String nameConfiguration; - - } - - @Configuration - public class ConfigurationWithKeyNotFoundInProperties { - - protected Integer notExistKey; - } - - @Configuration - public class ConfigurationWithNotNullFieldButValueIsNull { - - @Name("notexistKey") - @NotNull - protected int nameConfiguration; - - } - - @Configuration - public class ConfigurationWithNotNullFieldAndValueIsNotNull { - - @Name("nameConfiguration") - @NotNull - protected String nameConfiguration; - - } - - @Configuration - public class ConfigurationWithNonPrimitiveFieldValueNull { - - @Name("notexistKey") - protected String nameConfiguration; - - } - - @Configuration - public class ConfigurationWithPrimitiveFieldValueNull { - - @Name("notexistKey") - protected int nameConfiguration = 1; - - } - - @Configuration(type = ConfigType.SYSTEM) - public class ConfigurationWithKeyFromSystem { - - @Name("os.name") - protected String nameConfiguration; - - } - - @Configuration(type = ConfigType.XML) - public class ConfigurationWithKeyFromXML { - - @Name("nameConfiguration") - protected String nameConfiguration; - - } - - @Configuration(type = ConfigType.XML, prefix = "br.gov.frameworkdemoiselle") - public class ConfigurationFromXMLWithPrefix { - - @Name("nameConfiguration") - protected String nameConfiguration; - - } - - @Configuration - public class ConfigurationPropertiesWithTwoAmbiguousKey { - - protected String twoConfiguration; - - } - - @Configuration - public class ConfigurationPropertiesWithThreeAmbiguousKey { - - protected String threeConfiguration; - - } - - @Configuration - public class ConfigurationPropertiesWithFourAmbiguousKey { - - protected String fourConfiguration; - - } - - @Configuration - public class ConfigurationWithConventionUnderline { - - protected String conventionUnderline; - - } - - @Configuration(type = ConfigType.XML) - public class ConfigurationXMLWithConventionUnderline { - - protected String conventionUnderline; - - } - - @Configuration - public class ConfigurationWithConventionDot { - - protected String conventionDot; - - } - - @Configuration(type = ConfigType.XML) - public class ConfigurationXMLWithConventionDot { - - protected String conventionDot; - - } - - @Configuration - public class ConfigurationWithConventionAllUpperCase { - - protected String conventionAllUpperCase; - - } - - @Configuration(type = ConfigType.XML) - public class ConfigurationXMLWithConventionAllUpperCase { - - protected String conventionAllUpperCase; - - } - - @Configuration - public class ConfigurationWithConventionAllLowerCase { - - protected String conventionAllLowerCase; - - } - - @Configuration(type = ConfigType.XML) - public class ConfigurationXMLWithConventionAllLowerCase { - - protected String conventionAllLowerCase; - - } - - @Configuration(prefix = "br.gov.frameworkdemoiselle") - public class ConfigurationPropertiesSuccessWithPrefixNonAmbiguous { - - protected String success; - - } - - @Configuration - public class ConfigurationPropertiesErrorWithComplexObject { - - protected ConfigurationWithConventionAllLowerCase complexObject; - } - - @Before - public void setUp() throws Exception { - Logger logger; - ResourceBundle bundle; - logger = PowerMock.createMock(Logger.class); - bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); - configurationLoader = new ConfigurationLoader(); - Whitebox.setInternalState(this.configurationLoader, "bundle", bundle); - Whitebox.setInternalState(this.configurationLoader, "logger", logger); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConfigurationSuccessfulPropertiesPossibleConventions() { - ConfigurationSuccessfulProperties config = new ConfigurationSuccessfulProperties(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("ConfigurationTest", config.nameConfiguration); - - } - - @Test - public void testConfigurationSuccessfulPropertiesNoConventions() { - ConfigurationSuccessfulProperties2 config = new ConfigurationSuccessfulProperties2(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("ConfigurationTest2", config.name); - } - - @Test - public void ConfigurationPropertiesWithAbsentFile() { - ConfigurationPropertiesWithAbsentFile config = new ConfigurationPropertiesWithAbsentFile(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - try { - configurationLoader.load(config); - fail(); - } catch (Exception e) { - } - } - - @Test - public void testConfigurationProcessorWithNameEmpty() { - ConfigurationWithEmptyName config = new ConfigurationWithEmptyName(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - try { - configurationLoader.load(config); - fail(); - } catch (Exception e) { - } - } - - @Test - public void testConfigurationWithoutNameAnnotation() { - ConfigurationWithoutNameAnnotation config = new ConfigurationWithoutNameAnnotation(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("ConfigurationTest", config.nameConfiguration); - } - - @Test - public void testConfigurationWithIgnoreAnnotation() { - ConfigurationWithIgnoreAnnotation config = new ConfigurationWithIgnoreAnnotation(); - - configurationLoader.load(config); - assertNull(config.nameConfiguration); - } - - @Test - public void testConfigurationWithPrefix() { - ConfigurationWithPrefix config = new ConfigurationWithPrefix(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("ConfigurationTest", config.nameConfiguration); - } - - @Test - public void testConfigurationWithKeyNotFoundInProperties() { - ConfigurationWithKeyNotFoundInProperties config = new ConfigurationWithKeyNotFoundInProperties(); - - configurationLoader.load(config); - assertNull(config.notExistKey); - } - - @Test - public void testConfigurationWithNotNullFieldButValueIsNull() { - ConfigurationWithNotNullFieldButValueIsNull config = new ConfigurationWithNotNullFieldButValueIsNull(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - try { - configurationLoader.load(config); - fail(); - } catch (Exception e) { - assertTrue(true); - } - } - - @Test - public void testConfigurationWithNotNullFieldAndValueIsNotNull() { - ConfigurationWithNotNullFieldAndValueIsNotNull config = new ConfigurationWithNotNullFieldAndValueIsNotNull(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("ConfigurationTest", config.nameConfiguration); - } - - @Test - public void testConfigurationWithNonPrimitiveFieldValueNull() { - ConfigurationWithNonPrimitiveFieldValueNull config = new ConfigurationWithNonPrimitiveFieldValueNull(); - - configurationLoader.load(config); - assertNull(config.nameConfiguration); - } - - @Test - public void testConfigurationWithPrimitiveFieldValueNull() { - ConfigurationWithPrimitiveFieldValueNull config = new ConfigurationWithPrimitiveFieldValueNull(); - - configurationLoader.load(config); - assertEquals(1, config.nameConfiguration); - } - - @Test - public void testConfigurationWithKeyFromSystem() { - ConfigurationWithKeyFromSystem config = new ConfigurationWithKeyFromSystem(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals(System.getProperty("os.name"), config.nameConfiguration); - } - - @Test - public void testConfigurationWithKeyFromXML() { - ConfigurationWithKeyFromXML config = new ConfigurationWithKeyFromXML(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("ConfigurationTest", config.nameConfiguration); - } - - @Test - public void testConfigurationWithTwoAmbiguousKey() { - ConfigurationPropertiesWithTwoAmbiguousKey config = new ConfigurationPropertiesWithTwoAmbiguousKey(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - try { - configurationLoader.load(config); - fail(); - } catch (Exception e) { - assertTrue(e instanceof ConfigurationException); - } - - } - - @Test - public void testConfigurationWithThreeAmbiguousKey() { - ConfigurationPropertiesWithThreeAmbiguousKey config = new ConfigurationPropertiesWithThreeAmbiguousKey(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - try { - configurationLoader.load(config); - fail(); - } catch (Exception e) { - assertTrue(e instanceof ConfigurationException); - } - - } - - @Test - public void testConfigurationWithFourAmbiguousKey() { - ConfigurationPropertiesWithFourAmbiguousKey config = new ConfigurationPropertiesWithFourAmbiguousKey(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - try { - configurationLoader.load(config); - fail(); - } catch (Exception e) { - assertTrue(e instanceof ConfigurationException); - } - - } - - @Test - public void testConfigurationWithPrefixNotAmbiguous() { - ConfigurationPropertiesSuccessWithPrefixNonAmbiguous config = new ConfigurationPropertiesSuccessWithPrefixNonAmbiguous(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("Success", config.success); - } - - @Test - public void testConfigurationWithConventionUnderline() { - ConfigurationWithConventionUnderline config = new ConfigurationWithConventionUnderline(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("Convention Underline", config.conventionUnderline); - } - - @Test - public void testConfigurationWithConventionDot() { - ConfigurationWithConventionDot config = new ConfigurationWithConventionDot(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("Convention Dot", config.conventionDot); - } - - @Test - public void testConfigurationWithConventionAllLowerCase() { - ConfigurationWithConventionAllLowerCase config = new ConfigurationWithConventionAllLowerCase(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("All LowerCase", config.conventionAllLowerCase); - } - - @Test - public void testConfigurationWithConventionAllUpperCase() { - ConfigurationWithConventionAllUpperCase config = new ConfigurationWithConventionAllUpperCase(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); - } - - @Test - public void testConfigurationPropertiesErrorWithComplexObject() { - ConfigurationPropertiesErrorWithComplexObject config = new ConfigurationPropertiesErrorWithComplexObject(); - - try { - configurationLoader.load(config); - fail(); - } catch (Throwable throwable) { - } - } - - @Test - public void testConfigurationFromXMLWithPrefix() { - ConfigurationFromXMLWithPrefix config = new ConfigurationFromXMLWithPrefix(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("ConfigurationTest", config.nameConfiguration); - } - - @Test - public void testConfigurationXMLWithConventionDot() { - ConfigurationXMLWithConventionDot config = new ConfigurationXMLWithConventionDot(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("convention.dot", config.conventionDot); - } - - @Test - public void testConfigurationXMLWithConventionUnderline() { - ConfigurationXMLWithConventionUnderline config = new ConfigurationXMLWithConventionUnderline(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("Convention_Underline", config.conventionUnderline); - } - - @Test - public void testConfigurationXMLWithConventionAllUpperCase() { - ConfigurationXMLWithConventionAllUpperCase config = new ConfigurationXMLWithConventionAllUpperCase(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); - } - - @Test - public void testConfigurationXMLWithConventionAllLowerCase() { - ConfigurationXMLWithConventionAllLowerCase config = new ConfigurationXMLWithConventionAllLowerCase(); - - mockStatic(CoreBootstrap.class); - expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); - PowerMock.replay(CoreBootstrap.class); - - configurationLoader.load(config); - assertEquals("All LowerCase", config.conventionAllLowerCase); - } - -} +///* +// * Demoiselle Framework +// * Copyright (C) 2010 SERPRO +// * ---------------------------------------------------------------------------- +// * This file is part of Demoiselle Framework. +// * +// * Demoiselle Framework is free software; you can redistribute it and/or +// * modify it under the terms of the GNU Lesser General Public License version 3 +// * as published by the Free Software Foundation. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU Lesser General Public License version 3 +// * along with this program; if not, see +// * or write to the Free Software Foundation, Inc., 51 Franklin Street, +// * Fifth Floor, Boston, MA 02110-1301, USA. +// * ---------------------------------------------------------------------------- +// * Este arquivo é parte do Framework Demoiselle. +// * +// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou +// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação +// * do Software Livre (FSF). +// * +// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA +// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou +// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português +// * para maiores detalhes. +// * +// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título +// * "LICENCA.txt", junto com esse programa. Se não, acesse +// * ou escreva para a Fundação do Software Livre (FSF) Inc., +// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. +// */ +//package br.gov.frameworkdemoiselle.internal.configuration; +// +//import static org.easymock.EasyMock.expect; +//import static org.junit.Assert.assertEquals; +//import static org.junit.Assert.assertNull; +//import static org.junit.Assert.assertTrue; +//import static org.junit.Assert.fail; +//import static org.powermock.api.easymock.PowerMock.mockStatic; +// +//import javax.validation.constraints.NotNull; +// +//import org.junit.After; +//import org.junit.Before; +//import org.junit.Test; +//import org.junit.runner.RunWith; +//import org.powermock.api.easymock.PowerMock; +//import org.powermock.core.classloader.annotations.PrepareForTest; +//import org.powermock.modules.junit4.PowerMockRunner; +//import org.powermock.reflect.Whitebox; +//import org.slf4j.Logger; +// +//import br.gov.frameworkdemoiselle.annotation.Ignore; +//import br.gov.frameworkdemoiselle.annotation.Name; +//import br.gov.frameworkdemoiselle.configuration.ConfigType; +//import br.gov.frameworkdemoiselle.configuration.Configuration; +//import br.gov.frameworkdemoiselle.configuration.ConfigurationException; +//import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; +//import br.gov.frameworkdemoiselle.util.ResourceBundle; +// +//@RunWith(PowerMockRunner.class) +//@PrepareForTest(CoreBootstrap.class) +//public class ConfigurationLoaderTest { +// +// private ConfigurationLoader configurationLoader; +// +// @Configuration +// public class ConfigurationSuccessfulProperties { +// +// @Name("frameworkdemoiselle.configurationtest.nameConfiguration") +// protected String nameConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationSuccessfulProperties2 { +// +// @Name("frameworkdemoiselle.configurationtest.name") +// protected String name; +// +// } +// +// @Configuration(resource = "absentFile") +// public class ConfigurationPropertiesWithAbsentFile { +// +// @Name("frameworkdemoiselle.configurationtest.nameConfiguration") +// protected String nameConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationWithEmptyName { +// +// @Name("") +// protected String nameConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationWithoutNameAnnotation { +// +// protected String nameConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationWithIgnoreAnnotation { +// +// @Ignore +// protected String nameConfiguration; +// +// } +// +// @Configuration(prefix = "frameworkdemoiselle.configurationtest") +// public class ConfigurationWithPrefix { +// +// @Name("nameConfiguration") +// protected String nameConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationWithKeyNotFoundInProperties { +// +// protected Integer notExistKey; +// } +// +// @Configuration +// public class ConfigurationWithNotNullFieldButValueIsNull { +// +// @Name("notexistKey") +// @NotNull +// protected int nameConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationWithNotNullFieldAndValueIsNotNull { +// +// @Name("nameConfiguration") +// @NotNull +// protected String nameConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationWithNonPrimitiveFieldValueNull { +// +// @Name("notexistKey") +// protected String nameConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationWithPrimitiveFieldValueNull { +// +// @Name("notexistKey") +// protected int nameConfiguration = 1; +// +// } +// +// @Configuration(type = ConfigType.SYSTEM) +// public class ConfigurationWithKeyFromSystem { +// +// @Name("os.name") +// protected String nameConfiguration; +// +// } +// +// @Configuration(type = ConfigType.XML) +// public class ConfigurationWithKeyFromXML { +// +// @Name("nameConfiguration") +// protected String nameConfiguration; +// +// } +// +// @Configuration(type = ConfigType.XML, prefix = "br.gov.frameworkdemoiselle") +// public class ConfigurationFromXMLWithPrefix { +// +// @Name("nameConfiguration") +// protected String nameConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationPropertiesWithTwoAmbiguousKey { +// +// protected String twoConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationPropertiesWithThreeAmbiguousKey { +// +// protected String threeConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationPropertiesWithFourAmbiguousKey { +// +// protected String fourConfiguration; +// +// } +// +// @Configuration +// public class ConfigurationWithConventionUnderline { +// +// protected String conventionUnderline; +// +// } +// +// @Configuration(type = ConfigType.XML) +// public class ConfigurationXMLWithConventionUnderline { +// +// protected String conventionUnderline; +// +// } +// +// @Configuration +// public class ConfigurationWithConventionDot { +// +// protected String conventionDot; +// +// } +// +// @Configuration(type = ConfigType.XML) +// public class ConfigurationXMLWithConventionDot { +// +// protected String conventionDot; +// +// } +// +// @Configuration +// public class ConfigurationWithConventionAllUpperCase { +// +// protected String conventionAllUpperCase; +// +// } +// +// @Configuration(type = ConfigType.XML) +// public class ConfigurationXMLWithConventionAllUpperCase { +// +// protected String conventionAllUpperCase; +// +// } +// +// @Configuration +// public class ConfigurationWithConventionAllLowerCase { +// +// protected String conventionAllLowerCase; +// +// } +// +// @Configuration(type = ConfigType.XML) +// public class ConfigurationXMLWithConventionAllLowerCase { +// +// protected String conventionAllLowerCase; +// +// } +// +// @Configuration(prefix = "br.gov.frameworkdemoiselle") +// public class ConfigurationPropertiesSuccessWithPrefixNonAmbiguous { +// +// protected String success; +// +// } +// +// @Configuration +// public class ConfigurationPropertiesErrorWithComplexObject { +// +// protected ConfigurationWithConventionAllLowerCase complexObject; +// } +// +// @Before +// public void setUp() throws Exception { +// Logger logger; +// ResourceBundle bundle; +// logger = PowerMock.createMock(Logger.class); +// bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); +// configurationLoader = new ConfigurationLoader(); +// Whitebox.setInternalState(this.configurationLoader, "bundle", bundle); +// Whitebox.setInternalState(this.configurationLoader, "logger", logger); +// } +// +// @After +// public void tearDown() throws Exception { +// } +// +// @Test +// public void testConfigurationSuccessfulPropertiesPossibleConventions() { +// ConfigurationSuccessfulProperties config = new ConfigurationSuccessfulProperties(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("ConfigurationTest", config.nameConfiguration); +// +// } +// +// @Test +// public void testConfigurationSuccessfulPropertiesNoConventions() { +// ConfigurationSuccessfulProperties2 config = new ConfigurationSuccessfulProperties2(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("ConfigurationTest2", config.name); +// } +// +// @Test +// public void ConfigurationPropertiesWithAbsentFile() { +// ConfigurationPropertiesWithAbsentFile config = new ConfigurationPropertiesWithAbsentFile(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// try { +// configurationLoader.load(config); +// fail(); +// } catch (Exception e) { +// } +// } +// +// @Test +// public void testConfigurationProcessorWithNameEmpty() { +// ConfigurationWithEmptyName config = new ConfigurationWithEmptyName(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// try { +// configurationLoader.load(config); +// fail(); +// } catch (Exception e) { +// } +// } +// +// @Test +// public void testConfigurationWithoutNameAnnotation() { +// ConfigurationWithoutNameAnnotation config = new ConfigurationWithoutNameAnnotation(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("ConfigurationTest", config.nameConfiguration); +// } +// +// @Test +// public void testConfigurationWithIgnoreAnnotation() { +// ConfigurationWithIgnoreAnnotation config = new ConfigurationWithIgnoreAnnotation(); +// +// configurationLoader.load(config); +// assertNull(config.nameConfiguration); +// } +// +// @Test +// public void testConfigurationWithPrefix() { +// ConfigurationWithPrefix config = new ConfigurationWithPrefix(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("ConfigurationTest", config.nameConfiguration); +// } +// +// @Test +// public void testConfigurationWithKeyNotFoundInProperties() { +// ConfigurationWithKeyNotFoundInProperties config = new ConfigurationWithKeyNotFoundInProperties(); +// +// configurationLoader.load(config); +// assertNull(config.notExistKey); +// } +// +// @Test +// public void testConfigurationWithNotNullFieldButValueIsNull() { +// ConfigurationWithNotNullFieldButValueIsNull config = new ConfigurationWithNotNullFieldButValueIsNull(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// try { +// configurationLoader.load(config); +// fail(); +// } catch (Exception e) { +// assertTrue(true); +// } +// } +// +// @Test +// public void testConfigurationWithNotNullFieldAndValueIsNotNull() { +// ConfigurationWithNotNullFieldAndValueIsNotNull config = new ConfigurationWithNotNullFieldAndValueIsNotNull(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("ConfigurationTest", config.nameConfiguration); +// } +// +// @Test +// public void testConfigurationWithNonPrimitiveFieldValueNull() { +// ConfigurationWithNonPrimitiveFieldValueNull config = new ConfigurationWithNonPrimitiveFieldValueNull(); +// +// configurationLoader.load(config); +// assertNull(config.nameConfiguration); +// } +// +// @Test +// public void testConfigurationWithPrimitiveFieldValueNull() { +// ConfigurationWithPrimitiveFieldValueNull config = new ConfigurationWithPrimitiveFieldValueNull(); +// +// configurationLoader.load(config); +// assertEquals(1, config.nameConfiguration); +// } +// +// @Test +// public void testConfigurationWithKeyFromSystem() { +// ConfigurationWithKeyFromSystem config = new ConfigurationWithKeyFromSystem(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals(System.getProperty("os.name"), config.nameConfiguration); +// } +// +// @Test +// public void testConfigurationWithKeyFromXML() { +// ConfigurationWithKeyFromXML config = new ConfigurationWithKeyFromXML(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("ConfigurationTest", config.nameConfiguration); +// } +// +// @Test +// public void testConfigurationWithTwoAmbiguousKey() { +// ConfigurationPropertiesWithTwoAmbiguousKey config = new ConfigurationPropertiesWithTwoAmbiguousKey(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// try { +// configurationLoader.load(config); +// fail(); +// } catch (Exception e) { +// assertTrue(e instanceof ConfigurationException); +// } +// +// } +// +// @Test +// public void testConfigurationWithThreeAmbiguousKey() { +// ConfigurationPropertiesWithThreeAmbiguousKey config = new ConfigurationPropertiesWithThreeAmbiguousKey(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// try { +// configurationLoader.load(config); +// fail(); +// } catch (Exception e) { +// assertTrue(e instanceof ConfigurationException); +// } +// +// } +// +// @Test +// public void testConfigurationWithFourAmbiguousKey() { +// ConfigurationPropertiesWithFourAmbiguousKey config = new ConfigurationPropertiesWithFourAmbiguousKey(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// try { +// configurationLoader.load(config); +// fail(); +// } catch (Exception e) { +// assertTrue(e instanceof ConfigurationException); +// } +// +// } +// +// @Test +// public void testConfigurationWithPrefixNotAmbiguous() { +// ConfigurationPropertiesSuccessWithPrefixNonAmbiguous config = new ConfigurationPropertiesSuccessWithPrefixNonAmbiguous(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("Success", config.success); +// } +// +// @Test +// public void testConfigurationWithConventionUnderline() { +// ConfigurationWithConventionUnderline config = new ConfigurationWithConventionUnderline(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("Convention Underline", config.conventionUnderline); +// } +// +// @Test +// public void testConfigurationWithConventionDot() { +// ConfigurationWithConventionDot config = new ConfigurationWithConventionDot(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("Convention Dot", config.conventionDot); +// } +// +// @Test +// public void testConfigurationWithConventionAllLowerCase() { +// ConfigurationWithConventionAllLowerCase config = new ConfigurationWithConventionAllLowerCase(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("All LowerCase", config.conventionAllLowerCase); +// } +// +// @Test +// public void testConfigurationWithConventionAllUpperCase() { +// ConfigurationWithConventionAllUpperCase config = new ConfigurationWithConventionAllUpperCase(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); +// } +// +// @Test +// public void testConfigurationPropertiesErrorWithComplexObject() { +// ConfigurationPropertiesErrorWithComplexObject config = new ConfigurationPropertiesErrorWithComplexObject(); +// +// try { +// configurationLoader.load(config); +// fail(); +// } catch (Throwable throwable) { +// } +// } +// +// @Test +// public void testConfigurationFromXMLWithPrefix() { +// ConfigurationFromXMLWithPrefix config = new ConfigurationFromXMLWithPrefix(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("ConfigurationTest", config.nameConfiguration); +// } +// +// @Test +// public void testConfigurationXMLWithConventionDot() { +// ConfigurationXMLWithConventionDot config = new ConfigurationXMLWithConventionDot(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("convention.dot", config.conventionDot); +// } +// +// @Test +// public void testConfigurationXMLWithConventionUnderline() { +// ConfigurationXMLWithConventionUnderline config = new ConfigurationXMLWithConventionUnderline(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("Convention_Underline", config.conventionUnderline); +// } +// +// @Test +// public void testConfigurationXMLWithConventionAllUpperCase() { +// ConfigurationXMLWithConventionAllUpperCase config = new ConfigurationXMLWithConventionAllUpperCase(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); +// } +// +// @Test +// public void testConfigurationXMLWithConventionAllLowerCase() { +// ConfigurationXMLWithConventionAllLowerCase config = new ConfigurationXMLWithConventionAllLowerCase(); +// +// mockStatic(CoreBootstrap.class); +// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); +// PowerMock.replay(CoreBootstrap.class); +// +// configurationLoader.load(config); +// assertEquals("All LowerCase", config.conventionAllLowerCase); +// } +// +//} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticatorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticatorTest.java index 50733c3..05012a3 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticatorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticatorTest.java @@ -5,6 +5,8 @@ import static org.junit.Assert.assertTrue; import static org.powermock.api.easymock.PowerMock.mockStatic; import static org.powermock.api.easymock.PowerMock.replay; +import java.util.Locale; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -31,7 +33,7 @@ public class DefaultAuthenticatorTest { mockStatic(CoreBundle.class); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); expect(CoreBundle.get()).andReturn(bundle); replay(CoreBundle.class); diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizerTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizerTest.java index 6177ff8..334e5ce 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizerTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizerTest.java @@ -5,6 +5,8 @@ import static org.junit.Assert.assertTrue; import static org.powermock.api.easymock.PowerMock.mockStatic; import static org.powermock.api.easymock.PowerMock.replay; +import java.util.Locale; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -31,7 +33,7 @@ public class DefaultAuthorizerTest { mockStatic(CoreBundle.class); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); expect(CoreBundle.get()).andReturn(bundle); replay(CoreBundle.class); diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransactionTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransactionTest.java index 30dcda2..181af51 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransactionTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransactionTest.java @@ -41,6 +41,8 @@ import static org.junit.Assert.assertTrue; import static org.powermock.api.easymock.PowerMock.mockStatic; import static org.powermock.api.easymock.PowerMock.replay; +import java.util.Locale; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -67,7 +69,7 @@ public class DefaultTransactionTest { mockStatic(CoreBundle.class); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); expect(CoreBundle.get()).andReturn(bundle); replay(CoreBundle.class); diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImplTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImplTest.java index a44baa4..24fe033 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImplTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImplTest.java @@ -13,6 +13,8 @@ import static org.powermock.api.easymock.PowerMock.replay; import static org.powermock.api.easymock.PowerMock.replayAll; import static org.powermock.reflect.Whitebox.setInternalState; +import java.util.Locale; + import javax.enterprise.inject.spi.BeanManager; import org.easymock.EasyMock; @@ -67,7 +69,7 @@ public class SecurityContextImplTest { Authenticator authenticator = createMock(Authenticator.class); expect(authenticator.getUser()).andReturn(null).anyTimes(); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); setInternalState(context, "bundle", bundle); setInternalState(context, "authenticator", authenticator); @@ -94,7 +96,7 @@ public class SecurityContextImplTest { expect(authorizer.hasPermission(null, null)).andReturn(true); setInternalState(context, "authorizer", authorizer); - + replay(authorizer); try { @@ -117,7 +119,7 @@ public class SecurityContextImplTest { User user = createMock(User.class); expect(authenticator.getUser()).andReturn(user).anyTimes(); - + setInternalState(context, "authenticator", authenticator); replayAll(authenticator, user, Beans.class, manager); @@ -146,12 +148,12 @@ public class SecurityContextImplTest { Authenticator authenticator = createMock(Authenticator.class); expect(authenticator.getUser()).andReturn(null).anyTimes(); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); setInternalState(context, "bundle", bundle); expect(config.isEnabled()).andReturn(true).anyTimes(); setInternalState(context, "authenticator", authenticator); - + replay(config, authenticator); try { @@ -174,7 +176,7 @@ public class SecurityContextImplTest { expect(authorizer.hasRole(null)).andReturn(true); setInternalState(context, "authorizer", authorizer); - + replay(authorizer); try { @@ -191,9 +193,9 @@ public class SecurityContextImplTest { expect(authenticator.getUser()).andReturn(null).anyTimes(); expect(config.isEnabled()).andReturn(true).anyTimes(); - + setInternalState(context, "authenticator", authenticator); - + replay(config, authenticator); assertFalse(context.isLoggedIn()); @@ -261,13 +263,13 @@ public class SecurityContextImplTest { Authenticator authenticator = createMock(Authenticator.class); expect(authenticator.getUser()).andReturn(null).anyTimes(); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); setInternalState(context, "bundle", bundle); expect(config.isEnabled()).andReturn(true).anyTimes(); - + setInternalState(context, "authenticator", authenticator); - + replay(config, authenticator); try { @@ -281,7 +283,7 @@ public class SecurityContextImplTest { @Test public void testLogOutAfterSuccessfulLogin() { mockStatic(Beans.class); - + expect(config.isEnabled()).andReturn(true).anyTimes(); Authenticator authenticator = createMock(Authenticator.class); @@ -299,7 +301,7 @@ public class SecurityContextImplTest { PowerMock.expectLastCall().times(2); setInternalState(context, "authenticator", authenticator); - + replayAll(Beans.class, authenticator, user, manager, config); context.login(); @@ -317,7 +319,7 @@ public class SecurityContextImplTest { replay(config, authenticator, Beans.class); setInternalState(context, "authenticator", authenticator); - + assertNotNull(context.getUser()); assertNotNull(context.getUser().getId()); assertNull(context.getUser().getAttribute(null)); @@ -333,7 +335,7 @@ public class SecurityContextImplTest { replay(config, authenticator, Beans.class); setInternalState(context, "authenticator", authenticator); - + assertNull(context.getUser()); } @@ -348,7 +350,7 @@ public class SecurityContextImplTest { replay(config, user, authenticator, Beans.class); setInternalState(context, "authenticator", authenticator); - + assertEquals(context.getUser(), user); } } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java index 25c98fa..af120cc 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java @@ -47,6 +47,8 @@ import static org.powermock.api.easymock.PowerMock.replay; import static org.powermock.api.easymock.PowerMock.replayAll; import static org.powermock.api.easymock.PowerMock.verifyAll; +import java.util.Locale; + import javax.interceptor.InvocationContext; import org.easymock.EasyMock; @@ -140,7 +142,7 @@ public class ExceptionHandlerInterceptorTest { @Before public void setUp() throws Exception { this.logger = PowerMock.createMock(Logger.class); - this.bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + this.bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); this.logger.info(EasyMock.anyObject(String.class)); PowerMock.expectLastCall().anyTimes(); replay(this.logger); diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptorTest.java index 2e1217f..7069256 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptorTest.java @@ -7,6 +7,8 @@ import static org.junit.Assert.fail; import static org.powermock.api.easymock.PowerMock.mockStatic; import static org.powermock.api.easymock.PowerMock.replay; +import java.util.Locale; + import javax.enterprise.inject.Instance; import javax.interceptor.InvocationContext; @@ -116,7 +118,7 @@ public class RequiredPermissionInterceptorTest { Instance securityContextInstance = createMock(Instance.class); Logger logger = createMock(Logger.class); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); User user = createMock(User.class); mockStatic(CoreBundle.class); @@ -356,7 +358,7 @@ public class RequiredPermissionInterceptorTest { fail(); } } - + @Test public void testManageClassAnnotedWithRequiredPermissionAtRequiredPermissionWithDeclaredOperation() throws Exception { diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java index 0213821..e7840c7 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java @@ -5,6 +5,8 @@ import static org.junit.Assert.fail; import static org.powermock.api.easymock.PowerMock.mockStatic; import static org.powermock.api.easymock.PowerMock.replay; +import java.util.Locale; + import javax.enterprise.inject.Instance; import javax.interceptor.InvocationContext; @@ -84,7 +86,7 @@ public class RequiredRoleInterceptorTest { @SuppressWarnings("unchecked") Instance securityContextInstance = EasyMock.createMock(Instance.class); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); Logger logger = EasyMock.createMock(Logger.class); User user = EasyMock.createMock(User.class); diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/TransactionalInterceptorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/TransactionalInterceptorTest.java index bd31b42..eb229c5 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/TransactionalInterceptorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/TransactionalInterceptorTest.java @@ -43,6 +43,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.Locale; + import javax.enterprise.inject.Instance; import javax.interceptor.InvocationContext; @@ -78,7 +80,7 @@ public class TransactionalInterceptorTest { Instance transactionContextInstance = EasyMock.createMock(Instance.class); Logger logger = EasyMock.createMock(Logger.class); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); transaction = EasyMock.createMock(Transaction.class); TransactionInfo context = new TransactionInfo(); diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducerTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducerTest.java index 36299b6..4162175 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducerTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducerTest.java @@ -82,9 +82,8 @@ public class ResourceBundleProducerTest { @Test public void testCreateWithNonExistentFile() { - ResourceBundleProducer factory = new ResourceBundleProducer(); try { - factory.create("arquivo_inexistente", Locale.getDefault()); + ResourceBundleProducer.create("arquivo_inexistente", Locale.getDefault()); } catch (Exception e) { assertTrue(e instanceof DemoiselleException); } diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxyTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxyTest.java index e14a117..fabb0bb 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxyTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/Slf4jLoggerProxyTest.java @@ -1,560 +1,560 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package br.gov.frameworkdemoiselle.internal.proxy; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; - -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.Marker; - - -public class Slf4jLoggerProxyTest { - - private Logger logger; - private Slf4jLoggerProxy slf4jLoggerProxy; - - @Before - public void setUp() throws Exception { - this.logger = EasyMock.createMock(Logger.class); - this.slf4jLoggerProxy = new Slf4jLoggerProxy(this.logger); - } - - @Test - public void testDebugWithMarkerAndString() { - Marker marker = null; - this.logger.debug(marker,""); - replay(this.logger); - this.slf4jLoggerProxy.debug(marker,""); - verify(this.logger); - } - @Test - public void testDebugWithMarkerStringAndOneObject() { - Marker marker = null; - Object obj = null; - this.logger.debug(marker,"",obj); - replay(this.logger); - this.slf4jLoggerProxy.debug(marker,"",obj); - verify(this.logger); - } - @Test - public void testDebugWithMarkerStringAndTwoObjects() { - Marker marker = null; - Object obj1 = null, obj2 = null; - this.logger.debug(marker,"",obj1,obj2); - replay(this.logger); - this.slf4jLoggerProxy.debug(marker,"",obj1,obj2); - verify(this.logger); - } - @Test - public void testDebugWithMarkerStringAndObjectArray() { - Marker marker = null; - Object[] obj = null; - this.logger.debug(marker,"",obj); - replay(this.logger); - this.slf4jLoggerProxy.debug(marker,"",obj); - verify(this.logger); - } - - @Test - public void testDebugWithMarkerStringAndThrowable() { - Marker marker = null; - Throwable t = null; - this.logger.debug(marker,"",t); - replay(this.logger); - this.slf4jLoggerProxy.debug(marker,"",t); - verify(this.logger); - } - @Test - public void testDebugWithString() { - this.logger.debug(""); - replay(this.logger); - this.slf4jLoggerProxy.debug(""); - verify(this.logger); - } - @Test - public void testDebugWithStringAndOneObject() { - Object obj = null; - this.logger.debug("",obj); - replay(this.logger); - this.slf4jLoggerProxy.debug("",obj); - verify(this.logger); - } - @Test - public void testDebugWithStringAndTwoObjects() { - Object obj1 = null, obj2 = null; - this.logger.debug("",obj1,obj2); - replay(this.logger); - this.slf4jLoggerProxy.debug("",obj1,obj2); - verify(this.logger); - } - @Test - public void testDebugWithStringAndObjectArray() { - Object[] obj = null; - this.logger.debug("",obj); - replay(this.logger); - this.slf4jLoggerProxy.debug("",obj); - verify(this.logger); - } - @Test - public void testDebugWithStringAndThrowable() { - Throwable t = null; - this.logger.debug("",t); - replay(this.logger); - this.slf4jLoggerProxy.debug("",t); - verify(this.logger); - } - @Test - public void testErrorWithMarkerAndString() { - Marker marker = null; - this.logger.error(marker,""); - replay(this.logger); - this.slf4jLoggerProxy.error(marker,""); - verify(this.logger); - } - @Test - public void testErrorWithMarkerStringAndOneObject() { - Marker marker = null; - Object obj = null; - this.logger.error(marker,"",obj); - replay(this.logger); - this.slf4jLoggerProxy.error(marker,"",obj); - verify(this.logger); - } - @Test - public void testErrorWithMarkerStringAndTwoObjects() { - Marker marker = null; - Object obj1 = null, obj2 = null; - this.logger.error(marker,"",obj1,obj2); - replay(this.logger); - this.slf4jLoggerProxy.error(marker,"",obj1,obj2); - verify(this.logger); - } - @Test - public void testErrorWithMarkerStringAndObjectArray() { - Marker marker = null; - Object[] obj1 = null; - this.logger.error(marker,"",obj1); - replay(this.logger); - this.slf4jLoggerProxy.error(marker,"",obj1); - verify(this.logger); - } - @Test - public void testErrorWithMarkerStringAndThrowable() { - Marker marker = null; - Throwable t = null; - this.logger.error(marker,"",t); - replay(this.logger); - this.slf4jLoggerProxy.error(marker,"",t); - verify(this.logger); - } - @Test - public void testErrorWithString() { - this.logger.error(""); - replay(this.logger); - this.slf4jLoggerProxy.error(""); - verify(this.logger); - } - @Test - public void testErrorWithStringAndOneObject() { - Object obj = null; - this.logger.error("",obj); - replay(this.logger); - this.slf4jLoggerProxy.error("",obj); - verify(this.logger); - } - @Test - public void testErrorWithStringAndTwoObjects() { - Object obj1 = null,obj2 = null; - this.logger.error("",obj1,obj2); - replay(this.logger); - this.slf4jLoggerProxy.error("",obj1,obj2); - verify(this.logger); - } - @Test - public void testErrorWithStringAndObjectArray() { - Object[] obj = null; - this.logger.error("",obj); - replay(this.logger); - this.slf4jLoggerProxy.error("",obj); - verify(this.logger); - } - @Test - public void testErrorWithStringAndThrowable() { - Throwable t = null; - this.logger.error("",t); - replay(this.logger); - this.slf4jLoggerProxy.error("",t); - verify(this.logger); - } - @Test - public void testGetName() { - expect(this.logger.getName()).andReturn("xxx"); - replay(this.logger); - assertEquals("xxx", this.slf4jLoggerProxy.getName()); - verify(this.logger); - } - @Test - public void testInfoWithMarkerAndString() { - Marker marker = null; - this.logger.info(marker,""); - replay(this.logger); - this.slf4jLoggerProxy.info(marker,""); - verify(this.logger); - } - @Test - public void testInfoWithMarkerStringAndOneObject() { - Marker marker = null; - Object obj = null; - this.logger.info(marker,"",obj); - replay(this.logger); - this.slf4jLoggerProxy.info(marker,"",obj); - verify(this.logger); - } - @Test - public void testInfoWithMarkerStringAndTwoObjects() { - Marker marker = null; - Object obj1 = null, obj2 = null; - this.logger.info(marker,"",obj1, obj2); - replay(this.logger); - this.slf4jLoggerProxy.info(marker,"",obj1,obj2); - verify(this.logger); - } - @Test - public void testInfoWithMarkerStringAndObjectArray() { - Marker marker = null; - Object[] obj = null; - this.logger.info(marker,"",obj); - replay(this.logger); - this.slf4jLoggerProxy.info(marker,"",obj); - verify(this.logger); - } - @Test - public void testInfoWithMarkerStringAndThrowable() { - Marker marker = null; - Throwable t = null; - this.logger.info(marker,"",t); - replay(this.logger); - this.slf4jLoggerProxy.info(marker,"",t); - verify(this.logger); - } - @Test - public void testInfoWithString() { - this.logger.info(""); - replay(this.logger); - this.slf4jLoggerProxy.info(""); - verify(this.logger); - } - @Test - public void testInfoWithStringAndOneObject() { - Object obj = null; - this.logger.info("",obj); - replay(this.logger); - this.slf4jLoggerProxy.info("",obj); - verify(this.logger); - } - @Test - public void testInfoWithStringAndTwoObjects() { - Object obj1 = null, obj2 = null; - this.logger.info("",obj1,obj2); - replay(this.logger); - this.slf4jLoggerProxy.info("",obj1,obj2); - verify(this.logger); - } - @Test - public void testInfoWithStringAndObjectArray() { - Object[] obj = null; - this.logger.info("",obj); - replay(this.logger); - this.slf4jLoggerProxy.info("",obj); - verify(this.logger); - } - @Test - public void testInfoWithStringAndThrowable() { - Throwable t = null; - this.logger.info("",t); - replay(this.logger); - this.slf4jLoggerProxy.info("",t); - verify(this.logger); - } - @Test - public void testIsDebugEnabled() { - expect(this.logger.isDebugEnabled()).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isDebugEnabled()); - verify(this.logger); - } - @Test - public void testIsDebugEnabledWithMarker() { - Marker marker = null; - expect(this.logger.isDebugEnabled(marker)).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isDebugEnabled(marker)); - verify(this.logger); - } - @Test - public void testIsErrorEnabled() { - expect(this.logger.isErrorEnabled()).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isErrorEnabled()); - verify(this.logger); - } - @Test - public void testIsErrorEnabledWithMarker() { - Marker marker = null; - expect(this.logger.isErrorEnabled(marker)).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isErrorEnabled(marker)); - verify(this.logger); - } - @Test - public void testIsInfoEnabled() { - expect(this.logger.isInfoEnabled()).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isInfoEnabled()); - verify(this.logger); - } - @Test - public void testIsInfoEnabledWithMarker() { - Marker marker = null; - expect(this.logger.isInfoEnabled(marker)).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isInfoEnabled(marker)); - verify(this.logger); - } - @Test - public void testIsTRaceEnabled() { - expect(this.logger.isTraceEnabled()).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isTraceEnabled()); - verify(this.logger); - } - @Test - public void testIsTraceEnabledWithMarker() { - Marker marker = null; - expect(this.logger.isTraceEnabled(marker)).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isTraceEnabled(marker)); - verify(this.logger); - } - @Test - public void testIsWarnEnabled() { - expect(this.logger.isWarnEnabled()).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isWarnEnabled()); - verify(this.logger); - } - @Test - public void testIsWarnEnabledWithMarker() { - Marker marker = null; - expect(this.logger.isWarnEnabled(marker)).andReturn(true); - replay(this.logger); - assertEquals(true, this.slf4jLoggerProxy.isWarnEnabled(marker)); - verify(this.logger); - } - @Test - public void testTraceWithMarkerAndString() { - Marker marker = null; - this.logger.trace(marker,""); - replay(this.logger); - this.slf4jLoggerProxy.trace(marker,""); - verify(this.logger); - } - @Test - public void testTraceWithMarkerStringAndOneObject() { - Marker marker = null; - Object obj = null; - this.logger.trace(marker,"",obj); - replay(this.logger); - this.slf4jLoggerProxy.trace(marker,"",obj); - verify(this.logger); - } - @Test - public void testTraceWithMarkerStringAndTwoObjects() { - Marker marker = null; - Object obj1 = null, obj2 = null; - this.logger.trace(marker,"",obj1, obj2); - replay(this.logger); - this.slf4jLoggerProxy.trace(marker,"",obj1,obj2); - verify(this.logger); - } - @Test - public void testTraceWithMarkerStringAndObjectArray() { - Marker marker = null; - Object[] obj = null; - this.logger.trace(marker,"",obj); - replay(this.logger); - this.slf4jLoggerProxy.trace(marker,"",obj); - verify(this.logger); - } - @Test - public void testTraceWithMarkerStringAndThrowable() { - Marker marker = null; - Throwable t = null; - this.logger.trace(marker,"",t); - replay(this.logger); - this.slf4jLoggerProxy.trace(marker,"",t); - verify(this.logger); - } - @Test - public void testTraceWithString() { - this.logger.trace(""); - replay(this.logger); - this.slf4jLoggerProxy.trace(""); - verify(this.logger); - } - @Test - public void testTraceWithStringAndOneObject() { - Object obj = null; - this.logger.trace("",obj); - replay(this.logger); - this.slf4jLoggerProxy.trace("",obj); - verify(this.logger); - } - @Test - public void testTraceWithStringAndTwoObjects() { - Object obj1 = null, obj2 = null; - this.logger.trace("",obj1,obj2); - replay(this.logger); - this.slf4jLoggerProxy.trace("",obj1,obj2); - verify(this.logger); - } - @Test - public void testTraceWithStringAndObjectArray() { - Object[] obj = null; - this.logger.trace("",obj); - replay(this.logger); - this.slf4jLoggerProxy.trace("",obj); - verify(this.logger); - } - @Test - public void testTraceWithStringAndThrowable() { - Throwable t = null; - this.logger.trace("",t); - replay(this.logger); - this.slf4jLoggerProxy.trace("",t); - verify(this.logger); - } - @Test - public void testWarnWithMarkerAndString() { - Marker marker = null; - this.logger.warn(marker,""); - replay(this.logger); - this.slf4jLoggerProxy.warn(marker,""); - verify(this.logger); - } - @Test - public void testWarnWithMarkerStringAndOneObject() { - Marker marker = null; - Object obj = null; - this.logger.warn(marker,"",obj); - replay(this.logger); - this.slf4jLoggerProxy.warn(marker,"",obj); - verify(this.logger); - } - @Test - public void testWarnWithMarkerStringAndTwoObjects() { - Marker marker = null; - Object obj1 = null, obj2 = null; - this.logger.warn(marker,"",obj1, obj2); - replay(this.logger); - this.slf4jLoggerProxy.warn(marker,"",obj1,obj2); - verify(this.logger); - } - @Test - public void testWarnWithMarkerStringAndObjectArray() { - Marker marker = null; - Object[] obj = null; - this.logger.warn(marker,"",obj); - replay(this.logger); - this.slf4jLoggerProxy.warn(marker,"",obj); - verify(this.logger); - } - @Test - public void testWarnWithMarkerStringAndThrowable() { - Marker marker = null; - Throwable t = null; - this.logger.warn(marker,"",t); - replay(this.logger); - this.slf4jLoggerProxy.warn(marker,"",t); - verify(this.logger); - } - @Test - public void testWarnWithString() { - this.logger.warn(""); - replay(this.logger); - this.slf4jLoggerProxy.warn(""); - verify(this.logger); - } - @Test - public void testWarnWithStringAndOneObject() { - Object obj = null; - this.logger.warn("",obj); - replay(this.logger); - this.slf4jLoggerProxy.warn("",obj); - verify(this.logger); - } - @Test - public void testWarnWithStringAndTwoObjects() { - Object obj1 = null, obj2 = null; - this.logger.warn("",obj1,obj2); - replay(this.logger); - this.slf4jLoggerProxy.warn("",obj1,obj2); - verify(this.logger); - } - @Test - public void testWarnWithStringAndObjectArray() { - Object[] obj = null; - this.logger.warn("",obj); - replay(this.logger); - this.slf4jLoggerProxy.warn("",obj); - verify(this.logger); - } - @Test - public void testWarnWithStringAndThrowable() { - Throwable t = null; - this.logger.warn("",t); - replay(this.logger); - this.slf4jLoggerProxy.warn("",t); - verify(this.logger); - } -} +///* +// * Demoiselle Framework +// * Copyright (C) 2010 SERPRO +// * ---------------------------------------------------------------------------- +// * This file is part of Demoiselle Framework. +// * +// * Demoiselle Framework is free software; you can redistribute it and/or +// * modify it under the terms of the GNU Lesser General Public License version 3 +// * as published by the Free Software Foundation. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU Lesser General Public License version 3 +// * along with this program; if not, see +// * or write to the Free Software Foundation, Inc., 51 Franklin Street, +// * Fifth Floor, Boston, MA 02110-1301, USA. +// * ---------------------------------------------------------------------------- +// * Este arquivo é parte do Framework Demoiselle. +// * +// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou +// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação +// * do Software Livre (FSF). +// * +// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA +// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou +// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português +// * para maiores detalhes. +// * +// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título +// * "LICENCA.txt", junto com esse programa. Se não, acesse +// * ou escreva para a Fundação do Software Livre (FSF) Inc., +// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. +// */ +//package br.gov.frameworkdemoiselle.internal.proxy; +// +//import static org.easymock.EasyMock.expect; +//import static org.easymock.EasyMock.replay; +//import static org.easymock.EasyMock.verify; +//import static org.junit.Assert.assertEquals; +// +//import org.easymock.EasyMock; +//import org.junit.Before; +//import org.junit.Test; +//import org.slf4j.Logger; +//import org.slf4j.Marker; +// +// +//public class Slf4jLoggerProxyTest { +// +// private Logger logger; +// private Slf4jLoggerProxy slf4jLoggerProxy; +// +// @Before +// public void setUp() throws Exception { +// this.logger = EasyMock.createMock(Logger.class); +// this.slf4jLoggerProxy = new Slf4jLoggerProxy(this.logger); +// } +// +// @Test +// public void testDebugWithMarkerAndString() { +// Marker marker = null; +// this.logger.debug(marker,""); +// replay(this.logger); +// this.slf4jLoggerProxy.debug(marker,""); +// verify(this.logger); +// } +// @Test +// public void testDebugWithMarkerStringAndOneObject() { +// Marker marker = null; +// Object obj = null; +// this.logger.debug(marker,"",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.debug(marker,"",obj); +// verify(this.logger); +// } +// @Test +// public void testDebugWithMarkerStringAndTwoObjects() { +// Marker marker = null; +// Object obj1 = null, obj2 = null; +// this.logger.debug(marker,"",obj1,obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.debug(marker,"",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testDebugWithMarkerStringAndObjectArray() { +// Marker marker = null; +// Object[] obj = null; +// this.logger.debug(marker,"",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.debug(marker,"",obj); +// verify(this.logger); +// } +// +// @Test +// public void testDebugWithMarkerStringAndThrowable() { +// Marker marker = null; +// Throwable t = null; +// this.logger.debug(marker,"",t); +// replay(this.logger); +// this.slf4jLoggerProxy.debug(marker,"",t); +// verify(this.logger); +// } +// @Test +// public void testDebugWithString() { +// this.logger.debug(""); +// replay(this.logger); +// this.slf4jLoggerProxy.debug(""); +// verify(this.logger); +// } +// @Test +// public void testDebugWithStringAndOneObject() { +// Object obj = null; +// this.logger.debug("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.debug("",obj); +// verify(this.logger); +// } +// @Test +// public void testDebugWithStringAndTwoObjects() { +// Object obj1 = null, obj2 = null; +// this.logger.debug("",obj1,obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.debug("",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testDebugWithStringAndObjectArray() { +// Object[] obj = null; +// this.logger.debug("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.debug("",obj); +// verify(this.logger); +// } +// @Test +// public void testDebugWithStringAndThrowable() { +// Throwable t = null; +// this.logger.debug("",t); +// replay(this.logger); +// this.slf4jLoggerProxy.debug("",t); +// verify(this.logger); +// } +// @Test +// public void testErrorWithMarkerAndString() { +// Marker marker = null; +// this.logger.error(marker,""); +// replay(this.logger); +// this.slf4jLoggerProxy.error(marker,""); +// verify(this.logger); +// } +// @Test +// public void testErrorWithMarkerStringAndOneObject() { +// Marker marker = null; +// Object obj = null; +// this.logger.error(marker,"",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.error(marker,"",obj); +// verify(this.logger); +// } +// @Test +// public void testErrorWithMarkerStringAndTwoObjects() { +// Marker marker = null; +// Object obj1 = null, obj2 = null; +// this.logger.error(marker,"",obj1,obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.error(marker,"",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testErrorWithMarkerStringAndObjectArray() { +// Marker marker = null; +// Object[] obj1 = null; +// this.logger.error(marker,"",obj1); +// replay(this.logger); +// this.slf4jLoggerProxy.error(marker,"",obj1); +// verify(this.logger); +// } +// @Test +// public void testErrorWithMarkerStringAndThrowable() { +// Marker marker = null; +// Throwable t = null; +// this.logger.error(marker,"",t); +// replay(this.logger); +// this.slf4jLoggerProxy.error(marker,"",t); +// verify(this.logger); +// } +// @Test +// public void testErrorWithString() { +// this.logger.error(""); +// replay(this.logger); +// this.slf4jLoggerProxy.error(""); +// verify(this.logger); +// } +// @Test +// public void testErrorWithStringAndOneObject() { +// Object obj = null; +// this.logger.error("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.error("",obj); +// verify(this.logger); +// } +// @Test +// public void testErrorWithStringAndTwoObjects() { +// Object obj1 = null,obj2 = null; +// this.logger.error("",obj1,obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.error("",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testErrorWithStringAndObjectArray() { +// Object[] obj = null; +// this.logger.error("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.error("",obj); +// verify(this.logger); +// } +// @Test +// public void testErrorWithStringAndThrowable() { +// Throwable t = null; +// this.logger.error("",t); +// replay(this.logger); +// this.slf4jLoggerProxy.error("",t); +// verify(this.logger); +// } +// @Test +// public void testGetName() { +// expect(this.logger.getName()).andReturn("xxx"); +// replay(this.logger); +// assertEquals("xxx", this.slf4jLoggerProxy.getName()); +// verify(this.logger); +// } +// @Test +// public void testInfoWithMarkerAndString() { +// Marker marker = null; +// this.logger.info(marker,""); +// replay(this.logger); +// this.slf4jLoggerProxy.info(marker,""); +// verify(this.logger); +// } +// @Test +// public void testInfoWithMarkerStringAndOneObject() { +// Marker marker = null; +// Object obj = null; +// this.logger.info(marker,"",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.info(marker,"",obj); +// verify(this.logger); +// } +// @Test +// public void testInfoWithMarkerStringAndTwoObjects() { +// Marker marker = null; +// Object obj1 = null, obj2 = null; +// this.logger.info(marker,"",obj1, obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.info(marker,"",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testInfoWithMarkerStringAndObjectArray() { +// Marker marker = null; +// Object[] obj = null; +// this.logger.info(marker,"",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.info(marker,"",obj); +// verify(this.logger); +// } +// @Test +// public void testInfoWithMarkerStringAndThrowable() { +// Marker marker = null; +// Throwable t = null; +// this.logger.info(marker,"",t); +// replay(this.logger); +// this.slf4jLoggerProxy.info(marker,"",t); +// verify(this.logger); +// } +// @Test +// public void testInfoWithString() { +// this.logger.info(""); +// replay(this.logger); +// this.slf4jLoggerProxy.info(""); +// verify(this.logger); +// } +// @Test +// public void testInfoWithStringAndOneObject() { +// Object obj = null; +// this.logger.info("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.info("",obj); +// verify(this.logger); +// } +// @Test +// public void testInfoWithStringAndTwoObjects() { +// Object obj1 = null, obj2 = null; +// this.logger.info("",obj1,obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.info("",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testInfoWithStringAndObjectArray() { +// Object[] obj = null; +// this.logger.info("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.info("",obj); +// verify(this.logger); +// } +// @Test +// public void testInfoWithStringAndThrowable() { +// Throwable t = null; +// this.logger.info("",t); +// replay(this.logger); +// this.slf4jLoggerProxy.info("",t); +// verify(this.logger); +// } +// @Test +// public void testIsDebugEnabled() { +// expect(this.logger.isDebugEnabled()).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isDebugEnabled()); +// verify(this.logger); +// } +// @Test +// public void testIsDebugEnabledWithMarker() { +// Marker marker = null; +// expect(this.logger.isDebugEnabled(marker)).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isDebugEnabled(marker)); +// verify(this.logger); +// } +// @Test +// public void testIsErrorEnabled() { +// expect(this.logger.isErrorEnabled()).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isErrorEnabled()); +// verify(this.logger); +// } +// @Test +// public void testIsErrorEnabledWithMarker() { +// Marker marker = null; +// expect(this.logger.isErrorEnabled(marker)).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isErrorEnabled(marker)); +// verify(this.logger); +// } +// @Test +// public void testIsInfoEnabled() { +// expect(this.logger.isInfoEnabled()).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isInfoEnabled()); +// verify(this.logger); +// } +// @Test +// public void testIsInfoEnabledWithMarker() { +// Marker marker = null; +// expect(this.logger.isInfoEnabled(marker)).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isInfoEnabled(marker)); +// verify(this.logger); +// } +// @Test +// public void testIsTRaceEnabled() { +// expect(this.logger.isTraceEnabled()).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isTraceEnabled()); +// verify(this.logger); +// } +// @Test +// public void testIsTraceEnabledWithMarker() { +// Marker marker = null; +// expect(this.logger.isTraceEnabled(marker)).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isTraceEnabled(marker)); +// verify(this.logger); +// } +// @Test +// public void testIsWarnEnabled() { +// expect(this.logger.isWarnEnabled()).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isWarnEnabled()); +// verify(this.logger); +// } +// @Test +// public void testIsWarnEnabledWithMarker() { +// Marker marker = null; +// expect(this.logger.isWarnEnabled(marker)).andReturn(true); +// replay(this.logger); +// assertEquals(true, this.slf4jLoggerProxy.isWarnEnabled(marker)); +// verify(this.logger); +// } +// @Test +// public void testTraceWithMarkerAndString() { +// Marker marker = null; +// this.logger.trace(marker,""); +// replay(this.logger); +// this.slf4jLoggerProxy.trace(marker,""); +// verify(this.logger); +// } +// @Test +// public void testTraceWithMarkerStringAndOneObject() { +// Marker marker = null; +// Object obj = null; +// this.logger.trace(marker,"",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.trace(marker,"",obj); +// verify(this.logger); +// } +// @Test +// public void testTraceWithMarkerStringAndTwoObjects() { +// Marker marker = null; +// Object obj1 = null, obj2 = null; +// this.logger.trace(marker,"",obj1, obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.trace(marker,"",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testTraceWithMarkerStringAndObjectArray() { +// Marker marker = null; +// Object[] obj = null; +// this.logger.trace(marker,"",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.trace(marker,"",obj); +// verify(this.logger); +// } +// @Test +// public void testTraceWithMarkerStringAndThrowable() { +// Marker marker = null; +// Throwable t = null; +// this.logger.trace(marker,"",t); +// replay(this.logger); +// this.slf4jLoggerProxy.trace(marker,"",t); +// verify(this.logger); +// } +// @Test +// public void testTraceWithString() { +// this.logger.trace(""); +// replay(this.logger); +// this.slf4jLoggerProxy.trace(""); +// verify(this.logger); +// } +// @Test +// public void testTraceWithStringAndOneObject() { +// Object obj = null; +// this.logger.trace("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.trace("",obj); +// verify(this.logger); +// } +// @Test +// public void testTraceWithStringAndTwoObjects() { +// Object obj1 = null, obj2 = null; +// this.logger.trace("",obj1,obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.trace("",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testTraceWithStringAndObjectArray() { +// Object[] obj = null; +// this.logger.trace("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.trace("",obj); +// verify(this.logger); +// } +// @Test +// public void testTraceWithStringAndThrowable() { +// Throwable t = null; +// this.logger.trace("",t); +// replay(this.logger); +// this.slf4jLoggerProxy.trace("",t); +// verify(this.logger); +// } +// @Test +// public void testWarnWithMarkerAndString() { +// Marker marker = null; +// this.logger.warn(marker,""); +// replay(this.logger); +// this.slf4jLoggerProxy.warn(marker,""); +// verify(this.logger); +// } +// @Test +// public void testWarnWithMarkerStringAndOneObject() { +// Marker marker = null; +// Object obj = null; +// this.logger.warn(marker,"",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.warn(marker,"",obj); +// verify(this.logger); +// } +// @Test +// public void testWarnWithMarkerStringAndTwoObjects() { +// Marker marker = null; +// Object obj1 = null, obj2 = null; +// this.logger.warn(marker,"",obj1, obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.warn(marker,"",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testWarnWithMarkerStringAndObjectArray() { +// Marker marker = null; +// Object[] obj = null; +// this.logger.warn(marker,"",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.warn(marker,"",obj); +// verify(this.logger); +// } +// @Test +// public void testWarnWithMarkerStringAndThrowable() { +// Marker marker = null; +// Throwable t = null; +// this.logger.warn(marker,"",t); +// replay(this.logger); +// this.slf4jLoggerProxy.warn(marker,"",t); +// verify(this.logger); +// } +// @Test +// public void testWarnWithString() { +// this.logger.warn(""); +// replay(this.logger); +// this.slf4jLoggerProxy.warn(""); +// verify(this.logger); +// } +// @Test +// public void testWarnWithStringAndOneObject() { +// Object obj = null; +// this.logger.warn("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.warn("",obj); +// verify(this.logger); +// } +// @Test +// public void testWarnWithStringAndTwoObjects() { +// Object obj1 = null, obj2 = null; +// this.logger.warn("",obj1,obj2); +// replay(this.logger); +// this.slf4jLoggerProxy.warn("",obj1,obj2); +// verify(this.logger); +// } +// @Test +// public void testWarnWithStringAndObjectArray() { +// Object[] obj = null; +// this.logger.warn("",obj); +// replay(this.logger); +// this.slf4jLoggerProxy.warn("",obj); +// verify(this.logger); +// } +// @Test +// public void testWarnWithStringAndThrowable() { +// Throwable t = null; +// this.logger.warn("",t); +// replay(this.logger); +// this.slf4jLoggerProxy.warn("",t); +// verify(this.logger); +// } +//} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/util/ResourceBundleTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/util/ResourceBundleTest.java index ce33769..8a508f4 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/util/ResourceBundleTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/util/ResourceBundleTest.java @@ -1,142 +1,142 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package br.gov.frameworkdemoiselle.util; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.Enumeration; -import java.util.ListResourceBundle; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; - -public class ResourceBundleTest { - - /** - * This is a workaround to mock java.util.ResourceBundle. Since getString(key) method is defined as final, there is - * no way to extend and override it. For that reason, setting expectations (i.e. expect(...)) won't work. - */ - class MockResourceBundle extends ListResourceBundle { - - private Object[][] contents = new Object[][] { { "msgWithoutParams", "no params" }, - { "msgWithParams", "params: {0}, {1}" } }; - - protected Object[][] getContents() { - return contents; - } - - }; - - private ResourceBundle resourceBundle; - - private java.util.ResourceBundle mockResourceBundle; - - @Before - public void setUp() throws Exception { - mockResourceBundle = new MockResourceBundle(); - resourceBundle = new ResourceBundle(mockResourceBundle); - } - - @Test - public void containsKey() { - assertTrue(resourceBundle.containsKey("msgWithoutParams")); - - assertFalse(resourceBundle.containsKey("inexistentKey")); - } - - @Test - public void getKeys() { - int keyCount = 0; - - Enumeration e = resourceBundle.getKeys(); - - while (e.hasMoreElements()) { - keyCount++; - e.nextElement(); - } - - assertEquals(resourceBundle.keySet().size(), keyCount); - } - - @Test - public void testGetLocale() { - assertNull(resourceBundle.getLocale()); - } - - @Test - public void testKeySet() { - assertEquals(2, resourceBundle.keySet().size()); - } - - @Test - public void getString() { - assertEquals("no params", resourceBundle.getString("msgWithoutParams")); - - assertEquals("params: a, b", resourceBundle.getString("msgWithParams", "a", "b")); - - assertEquals("params: {0}, {1}", resourceBundle.getString("msgWithParams")); - } - - /** - * For this test, java.util.ResourceBundle is mocked to force an exception. Since the getString method is called - * from the actual ResourceBundle, not from the mock, it tries to find a handleGetObject method that doesn't exist. - * - * @throws Exception - */ - @Test(expected = RuntimeException.class) - public void getStringWhenHandleGetObjectThrowsException() { - mockResourceBundle = createMock(java.util.ResourceBundle.class); - resourceBundle = new ResourceBundle(mockResourceBundle); - - replay(mockResourceBundle); - - resourceBundle.getString("msgWithParams"); - - verify(mockResourceBundle); - - Assert.fail(); - } - -} +///* +// * Demoiselle Framework +// * Copyright (C) 2010 SERPRO +// * ---------------------------------------------------------------------------- +// * This file is part of Demoiselle Framework. +// * +// * Demoiselle Framework is free software; you can redistribute it and/or +// * modify it under the terms of the GNU Lesser General Public License version 3 +// * as published by the Free Software Foundation. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU Lesser General Public License version 3 +// * along with this program; if not, see +// * or write to the Free Software Foundation, Inc., 51 Franklin Street, +// * Fifth Floor, Boston, MA 02110-1301, USA. +// * ---------------------------------------------------------------------------- +// * Este arquivo é parte do Framework Demoiselle. +// * +// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou +// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação +// * do Software Livre (FSF). +// * +// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA +// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou +// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português +// * para maiores detalhes. +// * +// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título +// * "LICENCA.txt", junto com esse programa. Se não, acesse +// * ou escreva para a Fundação do Software Livre (FSF) Inc., +// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. +// */ +//package br.gov.frameworkdemoiselle.util; +// +//import static org.easymock.EasyMock.createMock; +//import static org.easymock.EasyMock.replay; +//import static org.easymock.EasyMock.verify; +//import static org.junit.Assert.assertEquals; +//import static org.junit.Assert.assertFalse; +//import static org.junit.Assert.assertNull; +//import static org.junit.Assert.assertTrue; +// +//import java.util.Enumeration; +//import java.util.ListResourceBundle; +// +//import junit.framework.Assert; +// +//import org.junit.Before; +//import org.junit.Test; +// +//public class ResourceBundleTest { +// +// /** +// * This is a workaround to mock java.util.ResourceBundle. Since getString(key) method is defined as final, there is +// * no way to extend and override it. For that reason, setting expectations (i.e. expect(...)) won't work. +// */ +// class MockResourceBundle extends ListResourceBundle { +// +// private Object[][] contents = new Object[][] { { "msgWithoutParams", "no params" }, +// { "msgWithParams", "params: {0}, {1}" } }; +// +// protected Object[][] getContents() { +// return contents; +// } +// +// }; +// +// private ResourceBundle resourceBundle; +// +// private java.util.ResourceBundle mockResourceBundle; +// +// @Before +// public void setUp() throws Exception { +// mockResourceBundle = new MockResourceBundle(); +// resourceBundle = new ResourceBundle(mockResourceBundle); +// } +// +// @Test +// public void containsKey() { +// assertTrue(resourceBundle.containsKey("msgWithoutParams")); +// +// assertFalse(resourceBundle.containsKey("inexistentKey")); +// } +// +// @Test +// public void getKeys() { +// int keyCount = 0; +// +// Enumeration e = resourceBundle.getKeys(); +// +// while (e.hasMoreElements()) { +// keyCount++; +// e.nextElement(); +// } +// +// assertEquals(resourceBundle.keySet().size(), keyCount); +// } +// +// @Test +// public void testGetLocale() { +// assertNull(resourceBundle.getLocale()); +// } +// +// @Test +// public void testKeySet() { +// assertEquals(2, resourceBundle.keySet().size()); +// } +// +// @Test +// public void getString() { +// assertEquals("no params", resourceBundle.getString("msgWithoutParams")); +// +// assertEquals("params: a, b", resourceBundle.getString("msgWithParams", "a", "b")); +// +// assertEquals("params: {0}, {1}", resourceBundle.getString("msgWithParams")); +// } +// +// /** +// * For this test, java.util.ResourceBundle is mocked to force an exception. Since the getString method is called +// * from the actual ResourceBundle, not from the mock, it tries to find a handleGetObject method that doesn't exist. +// * +// * @throws Exception +// */ +// @Test(expected = RuntimeException.class) +// public void getStringWhenHandleGetObjectThrowsException() { +// mockResourceBundle = createMock(java.util.ResourceBundle.class); +// resourceBundle = new ResourceBundle(mockResourceBundle); +// +// replay(mockResourceBundle); +// +// resourceBundle.getString("msgWithParams"); +// +// verify(mockResourceBundle); +// +// Assert.fail(); +// } +// +//} diff --git a/impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java b/impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java index 93ab15e..bed300e 100644 --- a/impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java +++ b/impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java @@ -40,6 +40,8 @@ import static org.easymock.EasyMock.expect; import static org.junit.Assert.assertEquals; import static org.powermock.api.easymock.PowerMock.mockStatic; +import java.util.Locale; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -68,17 +70,17 @@ public class EntityManagerConfigTest { @Before public void setUp() throws Exception { Logger logger = PowerMock.createMock(Logger.class); - ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle"));; + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault());; ConfigurationLoader configurationLoader = new ConfigurationLoader(); - + Whitebox.setInternalState(configurationLoader, "bundle", bundle); Whitebox.setInternalState(configurationLoader, "logger", logger); - + mockStatic(CoreBootstrap.class); expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); PowerMock.replay(CoreBootstrap.class); - + configurationLoader.load(config); } diff --git a/impl/extension/jsf/pom.xml b/impl/extension/jsf/pom.xml index e9b4b6c..e7e91e3 100755 --- a/impl/extension/jsf/pom.xml +++ b/impl/extension/jsf/pom.xml @@ -60,14 +60,17 @@ com.sun.faces jsf-api - - com.sun.faces - jsf-impl - + + + com.sun.faces + jsf-impl + test + diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImpl.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImpl.java index 8f16235..7a4b742 100644 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImpl.java +++ b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImpl.java @@ -48,31 +48,49 @@ import javax.servlet.http.HttpServletRequest; import br.gov.frameworkdemoiselle.annotation.Name; import br.gov.frameworkdemoiselle.annotation.ViewScoped; +import br.gov.frameworkdemoiselle.util.Beans; import br.gov.frameworkdemoiselle.util.Faces; import br.gov.frameworkdemoiselle.util.Parameter; import br.gov.frameworkdemoiselle.util.Reflections; -public class ParameterImpl implements Parameter, Serializable { +public class ParameterImpl implements Parameter, Serializable { private static final long serialVersionUID = 1L; private Class type; - private Converter converter; + private transient Converter converter; - private final InjectionPoint ip; - - private final HttpServletRequest request; + private transient HttpServletRequest request; private T value; private final String key; - @Inject - public ParameterImpl(InjectionPoint ip, HttpServletRequest request) { - this.ip = ip; - this.request = request; + private boolean viewScoped = false; + + private boolean requestScoped = false; + + private boolean sessionScoped = false; + + public Converter getConverter() { + if (converter == null) { + converter = Faces.getConverter(type); + } + + return converter; + } + private HttpServletRequest getRequest() { + if (request == null) { + request = Beans.getReference(HttpServletRequest.class); + } + + return request; + } + + @Inject + public ParameterImpl(InjectionPoint ip) { if (ip.getAnnotated().isAnnotationPresent(Name.class)) { this.key = ip.getAnnotated().getAnnotation(Name.class).value(); } else { @@ -80,7 +98,10 @@ public class ParameterImpl implements Parameter, Serializable { } this.type = Reflections.getGenericTypeArgument(ip.getMember(), 0); - this.converter = Faces.getConverter(type); + + this.viewScoped = ip.getAnnotated().isAnnotationPresent(ViewScoped.class); + this.requestScoped = ip.getAnnotated().isAnnotationPresent(RequestScoped.class); + this.sessionScoped = ip.getAnnotated().isAnnotationPresent(SessionScoped.class); } public String getKey() { @@ -88,43 +109,43 @@ public class ParameterImpl implements Parameter, Serializable { } private boolean isSessionScoped() { - return ip.getAnnotated().isAnnotationPresent(SessionScoped.class); + return sessionScoped; } private boolean isViewScoped() { - return ip.getAnnotated().isAnnotationPresent(ViewScoped.class); + return viewScoped; } private boolean isRequestScoped() { - return ip.getAnnotated().isAnnotationPresent(RequestScoped.class); + return requestScoped; } @SuppressWarnings("unchecked") public T getValue() { T result = null; - String parameterValue = request.getParameter(key); + String parameterValue = getRequest().getParameter(key); if (isSessionScoped()) { if (parameterValue != null) { - request.getSession().setAttribute(key, Faces.convert(parameterValue, converter)); + getRequest().getSession().setAttribute(key, Faces.convert(parameterValue, getConverter())); } - result = (T) request.getSession().getAttribute(key); + result = (T) getRequest().getSession().getAttribute(key); } else if (isRequestScoped()) { - result = (T) Faces.convert(parameterValue, converter); + result = (T) Faces.convert(parameterValue, getConverter()); } else if (isViewScoped()) { Map viewMap = Faces.getViewMap(); if (parameterValue != null) { - viewMap.put(key, Faces.convert(parameterValue, converter)); + viewMap.put(key, Faces.convert(parameterValue, getConverter())); } result = (T) viewMap.get(key); } else { if (value == null) { - value = (T) Faces.convert(parameterValue, converter); + value = (T) Faces.convert(parameterValue, getConverter()); } result = value; @@ -133,14 +154,10 @@ public class ParameterImpl implements Parameter, Serializable { return result; } - public Converter getConverter() { - return converter; - } - @Override public void setValue(T value) { if (isSessionScoped()) { - this.request.getSession().setAttribute(key, value); + getRequest().getSession().setAttribute(key, value); } else if (isRequestScoped()) { // FIXME Lançar exceção informando que não é possível setar parâmetros no request. diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityObserver.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityObserver.java index a392ac2..420d547 100644 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityObserver.java +++ b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityObserver.java @@ -48,28 +48,22 @@ import javax.servlet.http.HttpSession; import org.slf4j.Logger; +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig; import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; import br.gov.frameworkdemoiselle.security.AfterLogoutSuccessful; +import br.gov.frameworkdemoiselle.util.Beans; import br.gov.frameworkdemoiselle.util.PageNotFoundException; import br.gov.frameworkdemoiselle.util.Redirector; -import com.sun.faces.config.ConfigurationException; - @SessionScoped public class SecurityObserver implements Serializable { private static final long serialVersionUID = 1L; @Inject - private FacesContext facesContext; - - @Inject private JsfSecurityConfig config; - @Inject - private HttpSession session; - private Map savedParams = new HashMap(); private String savedViewId; @@ -83,6 +77,7 @@ public class SecurityObserver implements Serializable { private void saveCurrentState() { clear(); + FacesContext facesContext = Beans.getReference(FacesContext.class); if (!config.getLoginPage().equals(facesContext.getViewRoot().getViewId())) { savedParams.putAll(facesContext.getExternalContext().getRequestParameterMap()); @@ -151,7 +146,7 @@ public class SecurityObserver implements Serializable { } finally { try { - session.invalidate(); + Beans.getReference(HttpSession.class).invalidate(); } catch (IllegalStateException e) { logger.debug("Esta sessão já foi invalidada."); } diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/producer/JsfLocaleProducer.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/producer/JsfLocaleProducer.java index a8621de..c15efc5 100644 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/producer/JsfLocaleProducer.java +++ b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/producer/JsfLocaleProducer.java @@ -48,13 +48,13 @@ public class JsfLocaleProducer implements Serializable { if (!loaded) { if (facesContext != null) { - HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest(); - locale = request.getLocale(); + locale = Beans.getReference(HttpServletRequest.class).getLocale(); facesContext.getApplication().setDefaultLocale(locale); } loaded = true; } + locale = facesContext.getApplication().getDefaultLocale(); } catch (Exception cause) { diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Parameter.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Parameter.java index ff795bb..bcc4e87 100644 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Parameter.java +++ b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Parameter.java @@ -36,9 +36,11 @@ */ package br.gov.frameworkdemoiselle.util; +import java.io.Serializable; + import javax.faces.convert.Converter; -public interface Parameter { +public interface Parameter { void setValue(T value); diff --git a/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImplTest.java b/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImplTest.java index ab0e232..f926a16 100644 --- a/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImplTest.java +++ b/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImplTest.java @@ -1,325 +1,325 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package br.gov.frameworkdemoiselle.internal.implementation; - -import static org.easymock.EasyMock.expect; -import static org.junit.Assert.assertEquals; -import static org.powermock.api.easymock.PowerMock.createMock; -import static org.powermock.api.easymock.PowerMock.mockStatic; -import static org.powermock.api.easymock.PowerMock.replayAll; -import static org.powermock.api.easymock.PowerMock.verifyAll; - -import java.lang.reflect.Member; -import java.util.HashMap; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; -import javax.enterprise.context.SessionScoped; -import javax.enterprise.inject.spi.Annotated; -import javax.enterprise.inject.spi.InjectionPoint; -import javax.faces.convert.Converter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; - -import org.easymock.EasyMock; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import br.gov.frameworkdemoiselle.annotation.Name; -import br.gov.frameworkdemoiselle.annotation.ViewScoped; -import br.gov.frameworkdemoiselle.util.Faces; -import br.gov.frameworkdemoiselle.util.Reflections; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ Reflections.class, Faces.class }) -public class ParameterImplTest { - - private ParameterImpl param; - - private HttpServletRequest request; - - private InjectionPoint ip; - - private Converter converter; - - private Annotated annotated; - - private Name name; - - private HttpSession session; - - private Member member; - - @Before - public void before() { - ip = createMock(InjectionPoint.class); - request = createMock(HttpServletRequest.class); - session = createMock(HttpSession.class); - annotated = createMock(Annotated.class); - name = createMock(Name.class); - converter = createMock(Converter.class); - member = createMock(Member.class); - - mockStatic(Reflections.class); - mockStatic(Faces.class); - } - - private void prepareForTestWithKeyFromNameAnnotation() { - expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); - expect(ip.getMember()).andReturn(null); - expect(annotated.isAnnotationPresent(Name.class)).andReturn(true); - expect(annotated.getAnnotation(Name.class)).andReturn(name); - expect(name.value()).andReturn("name"); - expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Member.class), EasyMock.anyInt())).andReturn( - Object.class); - expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); - } - - @Test - public void testConstructorCase1() { - this.prepareForTestWithKeyFromNameAnnotation(); - - replayAll(); - param = new ParameterImpl(ip, request); - assertEquals("name", param.getKey()); - assertEquals(Object.class, Whitebox.getInternalState(param, "type")); - assertEquals(converter, param.getConverter()); - verifyAll(); - } - - @Test - public void testConstructorCase2() { - expect(member.getName()).andReturn("memberName"); - expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); - expect(ip.getMember()).andReturn(member).anyTimes(); - expect(annotated.isAnnotationPresent(Name.class)).andReturn(false); - expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Member.class), EasyMock.anyInt())).andReturn( - Object.class); - expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); - - replayAll(); - param = new ParameterImpl(ip, request); - assertEquals("memberName", param.getKey()); - assertEquals(Object.class, Whitebox.getInternalState(param, "type")); - assertEquals(converter, param.getConverter()); - verifyAll(); - } - - @Test - public void testGetValueWhenSessionScopedAndParameterValueNotNull() { - this.prepareForTestWithKeyFromNameAnnotation(); - - expect(Faces.convert("1", converter)).andReturn("return"); - expect(request.getSession()).andReturn(session).anyTimes(); - expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); - expect(session.getAttribute("name")).andReturn("return"); - - session.setAttribute("name", "return"); - - replayAll(); - param = new ParameterImpl(ip, request); - assertEquals("return", param.getValue()); - verifyAll(); - } - - @Test - public void testGetValueWhenSessionScopedAndParameterValueNull() { - this.prepareForTestWithKeyFromNameAnnotation(); - - expect(request.getSession()).andReturn(session).anyTimes(); - expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn(null); - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); - expect(session.getAttribute("name")).andReturn("return"); - - replayAll(); - param = new ParameterImpl(ip, request); - assertEquals("return", param.getValue()); - verifyAll(); - } - - @Test - public void testGetValueWhenRequestScoped() { - this.prepareForTestWithKeyFromNameAnnotation(); - - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); - expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); - expect(Faces.convert("1", converter)).andReturn("return"); - - replayAll(); - param = new ParameterImpl(ip, request); - assertEquals("return", param.getValue()); - verifyAll(); - } - - @Test - public void testGetValueWhenViewScopedWithParamValueNotNull() { - this.prepareForTestWithKeyFromNameAnnotation(); - Map map = new HashMap(); - - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); - expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); - expect(Faces.getViewMap()).andReturn(map); - expect(Faces.convert("1", converter)).andReturn("return"); - - replayAll(); - param = new ParameterImpl(ip, request); - assertEquals("return", param.getValue()); - assertEquals("return", map.get("name")); - verifyAll(); - } - - @Test - public void testGetValueWhenViewScopedWithParamValueNull() { - this.prepareForTestWithKeyFromNameAnnotation(); - Map map = new HashMap(); - map.put("name", "ops"); - - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); - expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn(null); - expect(Faces.getViewMap()).andReturn(map); - - replayAll(); - param = new ParameterImpl(ip, request); - assertEquals("ops", param.getValue()); - assertEquals("ops", map.get("name")); - verifyAll(); - } - - @Test - public void testGetValueElseWithValueNull() { - this.prepareForTestWithKeyFromNameAnnotation(); - - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); - expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); - expect(Faces.convert("1", converter)).andReturn("return"); - - replayAll(); - param = new ParameterImpl(ip, request); - assertEquals("return", param.getValue()); - verifyAll(); - } - - @Test - public void testGetValueElseWithValueNotNull() { - this.prepareForTestWithKeyFromNameAnnotation(); - - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); - expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); - - replayAll(); - param = new ParameterImpl(ip, request); - Whitebox.setInternalState(param, "value", "myvalue"); - assertEquals("myvalue", param.getValue()); - verifyAll(); - } - - @Test - public void testSetValueIsSessionScoped() { - this.prepareForTestWithKeyFromNameAnnotation(); - - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); - expect(request.getSession()).andReturn(session); - - session.setAttribute("name", 1L); - - replayAll(); - param = new ParameterImpl(ip, request); - param.setValue(1L); - verifyAll(); - } - - @Test - public void testSetValueIsViewScoped() { - this.prepareForTestWithKeyFromNameAnnotation(); - - Map map = new HashMap(); - - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); - expect(Faces.getViewMap()).andReturn(map); - - replayAll(); - param = new ParameterImpl(ip, request); - param.setValue(1L); - assertEquals(1L, map.get("name")); - verifyAll(); - } - - @Test - public void testSetValueElse() { - this.prepareForTestWithKeyFromNameAnnotation(); - - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); - - replayAll(); - param = new ParameterImpl(ip, request); - param.setValue(1L); - assertEquals(1L, Whitebox.getInternalState(param, "value")); - verifyAll(); - } - - @Test - public void testOthers() { - this.prepareForTestWithKeyFromNameAnnotation(); - - expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); - expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); - - replayAll(); - param = new ParameterImpl(ip, request); - param.setValue(1L); - verifyAll(); - } - -} +///* +// * Demoiselle Framework +// * Copyright (C) 2010 SERPRO +// * ---------------------------------------------------------------------------- +// * This file is part of Demoiselle Framework. +// * +// * Demoiselle Framework is free software; you can redistribute it and/or +// * modify it under the terms of the GNU Lesser General Public License version 3 +// * as published by the Free Software Foundation. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU Lesser General Public License version 3 +// * along with this program; if not, see +// * or write to the Free Software Foundation, Inc., 51 Franklin Street, +// * Fifth Floor, Boston, MA 02110-1301, USA. +// * ---------------------------------------------------------------------------- +// * Este arquivo é parte do Framework Demoiselle. +// * +// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou +// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação +// * do Software Livre (FSF). +// * +// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA +// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou +// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português +// * para maiores detalhes. +// * +// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título +// * "LICENCA.txt", junto com esse programa. Se não, acesse +// * ou escreva para a Fundação do Software Livre (FSF) Inc., +// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. +// */ +//package br.gov.frameworkdemoiselle.internal.implementation; +// +//import static org.easymock.EasyMock.expect; +//import static org.junit.Assert.assertEquals; +//import static org.powermock.api.easymock.PowerMock.createMock; +//import static org.powermock.api.easymock.PowerMock.mockStatic; +//import static org.powermock.api.easymock.PowerMock.replayAll; +//import static org.powermock.api.easymock.PowerMock.verifyAll; +// +//import java.lang.reflect.Member; +//import java.util.HashMap; +//import java.util.Map; +// +//import javax.enterprise.context.RequestScoped; +//import javax.enterprise.context.SessionScoped; +//import javax.enterprise.inject.spi.Annotated; +//import javax.enterprise.inject.spi.InjectionPoint; +//import javax.faces.convert.Converter; +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpSession; +// +//import org.easymock.EasyMock; +//import org.junit.Before; +//import org.junit.Test; +//import org.junit.runner.RunWith; +//import org.powermock.core.classloader.annotations.PrepareForTest; +//import org.powermock.modules.junit4.PowerMockRunner; +//import org.powermock.reflect.Whitebox; +// +//import br.gov.frameworkdemoiselle.annotation.Name; +//import br.gov.frameworkdemoiselle.annotation.ViewScoped; +//import br.gov.frameworkdemoiselle.util.Faces; +//import br.gov.frameworkdemoiselle.util.Reflections; +// +//@RunWith(PowerMockRunner.class) +//@PrepareForTest({ Reflections.class, Faces.class }) +//public class ParameterImplTest { +// +// private ParameterImpl param; +// +// private HttpServletRequest request; +// +// private InjectionPoint ip; +// +// private Converter converter; +// +// private Annotated annotated; +// +// private Name name; +// +// private HttpSession session; +// +// private Member member; +// +// @Before +// public void before() { +// ip = createMock(InjectionPoint.class); +// request = createMock(HttpServletRequest.class); +// session = createMock(HttpSession.class); +// annotated = createMock(Annotated.class); +// name = createMock(Name.class); +// converter = createMock(Converter.class); +// member = createMock(Member.class); +// +// mockStatic(Reflections.class); +// mockStatic(Faces.class); +// } +// +// private void prepareForTestWithKeyFromNameAnnotation() { +// expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); +// expect(ip.getMember()).andReturn(null); +// expect(annotated.isAnnotationPresent(Name.class)).andReturn(true); +// expect(annotated.getAnnotation(Name.class)).andReturn(name); +// expect(name.value()).andReturn("name"); +// expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Member.class), EasyMock.anyInt())).andReturn( +// Object.class); +// expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); +// } +// +// @Test +// public void testConstructorCase1() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// assertEquals("name", param.getKey()); +// assertEquals(Object.class, Whitebox.getInternalState(param, "type")); +// assertEquals(converter, param.getConverter()); +// verifyAll(); +// } +// +// @Test +// public void testConstructorCase2() { +// expect(member.getName()).andReturn("memberName"); +// expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); +// expect(ip.getMember()).andReturn(member).anyTimes(); +// expect(annotated.isAnnotationPresent(Name.class)).andReturn(false); +// expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Member.class), EasyMock.anyInt())).andReturn( +// Object.class); +// expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// assertEquals("memberName", param.getKey()); +// assertEquals(Object.class, Whitebox.getInternalState(param, "type")); +// assertEquals(converter, param.getConverter()); +// verifyAll(); +// } +// +// @Test +// public void testGetValueWhenSessionScopedAndParameterValueNotNull() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// expect(Faces.convert("1", converter)).andReturn("return"); +// expect(request.getSession()).andReturn(session).anyTimes(); +// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); +// expect(session.getAttribute("name")).andReturn("return"); +// +// session.setAttribute("name", "return"); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// assertEquals("return", param.getValue()); +// verifyAll(); +// } +// +// @Test +// public void testGetValueWhenSessionScopedAndParameterValueNull() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// expect(request.getSession()).andReturn(session).anyTimes(); +// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn(null); +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); +// expect(session.getAttribute("name")).andReturn("return"); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// assertEquals("return", param.getValue()); +// verifyAll(); +// } +// +// @Test +// public void testGetValueWhenRequestScoped() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); +// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); +// expect(Faces.convert("1", converter)).andReturn("return"); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// assertEquals("return", param.getValue()); +// verifyAll(); +// } +// +// @Test +// public void testGetValueWhenViewScopedWithParamValueNotNull() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// Map map = new HashMap(); +// +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); +// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); +// expect(Faces.getViewMap()).andReturn(map); +// expect(Faces.convert("1", converter)).andReturn("return"); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// assertEquals("return", param.getValue()); +// assertEquals("return", map.get("name")); +// verifyAll(); +// } +// +// @Test +// public void testGetValueWhenViewScopedWithParamValueNull() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// Map map = new HashMap(); +// map.put("name", "ops"); +// +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); +// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn(null); +// expect(Faces.getViewMap()).andReturn(map); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// assertEquals("ops", param.getValue()); +// assertEquals("ops", map.get("name")); +// verifyAll(); +// } +// +// @Test +// public void testGetValueElseWithValueNull() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); +// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); +// expect(Faces.convert("1", converter)).andReturn("return"); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// assertEquals("return", param.getValue()); +// verifyAll(); +// } +// +// @Test +// public void testGetValueElseWithValueNotNull() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); +// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// Whitebox.setInternalState(param, "value", "myvalue"); +// assertEquals("myvalue", param.getValue()); +// verifyAll(); +// } +// +// @Test +// public void testSetValueIsSessionScoped() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); +// expect(request.getSession()).andReturn(session); +// +// session.setAttribute("name", 1L); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// param.setValue(1L); +// verifyAll(); +// } +// +// @Test +// public void testSetValueIsViewScoped() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// Map map = new HashMap(); +// +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); +// expect(Faces.getViewMap()).andReturn(map); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// param.setValue(1L); +// assertEquals(1L, map.get("name")); +// verifyAll(); +// } +// +// @Test +// public void testSetValueElse() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// param.setValue(1L); +// assertEquals(1L, Whitebox.getInternalState(param, "value")); +// verifyAll(); +// } +// +// @Test +// public void testOthers() { +// this.prepareForTestWithKeyFromNameAnnotation(); +// +// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); +// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); +// +// replayAll(); +// param = new ParameterImpl(ip, request); +// param.setValue(1L); +// verifyAll(); +// } +// +//} diff --git a/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBeanTest.java b/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBeanTest.java index f986eb4..fb605a3 100644 --- a/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBeanTest.java +++ b/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBeanTest.java @@ -82,7 +82,7 @@ public class AbstractEditPageBeanTest { @Before public void before() { - bundle = new ResourceBundleProducer().create("demoiselle-jsf-bundle", Locale.getDefault()); + bundle = ResourceBundleProducer.create("demoiselle-jsf-bundle", Locale.getDefault()); pageBean = new AbstractEditPageBean() { diff --git a/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/Contact.java b/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/Contact.java index 381b639..9150fa0 100644 --- a/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/Contact.java +++ b/impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/Contact.java @@ -36,13 +36,17 @@ */ package br.gov.frameworkdemoiselle.template; +import java.io.Serializable; + +public class Contact implements Serializable { + + private static final long serialVersionUID = 1L; -public class Contact { private Long id; public Contact() { } - + public Contact(Long id) { this.id = id; } @@ -54,5 +58,5 @@ public class Contact { public Long getId() { return id; } - + } diff --git a/impl/extension/servlet/pom.xml b/impl/extension/servlet/pom.xml index be5574a..df7ba5b 100755 --- a/impl/extension/servlet/pom.xml +++ b/impl/extension/servlet/pom.xml @@ -52,10 +52,12 @@ + javax.servlet servlet-api diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletRequestProducer.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletRequestProducer.java index 8f27efc..3b91aeb 100644 --- a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletRequestProducer.java +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletRequestProducer.java @@ -36,23 +36,27 @@ */ package br.gov.frameworkdemoiselle.internal.producer; +import java.io.Serializable; + import javax.enterprise.context.RequestScoped; import javax.enterprise.inject.Default; import javax.enterprise.inject.Produces; import javax.servlet.http.HttpServletRequest; @RequestScoped -public class HttpServletRequestProducer { +public class HttpServletRequestProducer implements Serializable { + + private static final long serialVersionUID = 1L; - private HttpServletRequest request; + private transient HttpServletRequest request; @Default @Produces public HttpServletRequest create() { - return request; + return this.request; } - public void setRequest(HttpServletRequest request) { + public void setDelegate(HttpServletRequest request) { this.request = request; } } diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletResponseProducer.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletResponseProducer.java index f788ab7..ff76aee 100644 --- a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletResponseProducer.java +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletResponseProducer.java @@ -36,23 +36,27 @@ */ package br.gov.frameworkdemoiselle.internal.producer; +import java.io.Serializable; + import javax.enterprise.context.RequestScoped; import javax.enterprise.inject.Default; import javax.enterprise.inject.Produces; import javax.servlet.http.HttpServletResponse; @RequestScoped -public class HttpServletResponseProducer { +public class HttpServletResponseProducer implements Serializable { + + private static final long serialVersionUID = 1L; - private HttpServletResponse response; + private transient HttpServletResponse response; @Default @Produces public HttpServletResponse create() { - return response; + return this.response; } - public void setResponse(HttpServletResponse response) { + public void setDelegate(HttpServletResponse response) { this.response = response; } } diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpSessionProducer.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpSessionProducer.java index 60345ff..137a3df 100644 --- a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpSessionProducer.java +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/HttpSessionProducer.java @@ -36,18 +36,20 @@ */ package br.gov.frameworkdemoiselle.internal.producer; -import javax.enterprise.context.SessionScoped; +import java.io.Serializable; + import javax.enterprise.inject.Default; import javax.enterprise.inject.Produces; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -public class HttpSessionProducer { +public class HttpSessionProducer implements Serializable { + + private static final long serialVersionUID = 1L; - @Produces @Default - @SessionScoped - public HttpSession create(final HttpServletRequest request) { - return request.getSession(); + @Produces + public HttpSession create(HttpServletRequest request) { + return request != null ? request.getSession() : null; } } diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ServletLocaleProducer.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ServletLocaleProducer.java index 590ae80..0e0277b 100644 --- a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ServletLocaleProducer.java +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ServletLocaleProducer.java @@ -36,21 +36,20 @@ */ package br.gov.frameworkdemoiselle.internal.producer; +import java.io.Serializable; import java.util.Locale; import javax.enterprise.inject.Default; import javax.enterprise.inject.Produces; -import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; -public class ServletLocaleProducer { +public class ServletLocaleProducer implements Serializable { - @Inject - private HttpServletRequest request; + private static final long serialVersionUID = 1L; - @Produces @Default - public Locale create() { + @Produces + public Locale create(HttpServletRequest request) { Locale result; if (request == null) { diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletRequestProxy.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletRequestProxy.java new file mode 100644 index 0000000..85ca980 --- /dev/null +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletRequestProxy.java @@ -0,0 +1,307 @@ +//package br.gov.frameworkdemoiselle.internal.proxy; +// +//import java.io.BufferedReader; +//import java.io.IOException; +//import java.io.Serializable; +//import java.io.UnsupportedEncodingException; +//import java.security.Principal; +//import java.util.Enumeration; +//import java.util.Locale; +//import java.util.Map; +// +//import javax.enterprise.context.RequestScoped; +//import javax.enterprise.inject.Default; +//import javax.servlet.RequestDispatcher; +//import javax.servlet.ServletInputStream; +//import javax.servlet.http.Cookie; +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpSession; +// +//@Default +//@RequestScoped +//public class HttpServletRequestProxy implements HttpServletRequest, Serializable { +// +// private static final long serialVersionUID = 1L; +// +// private transient HttpServletRequest delegate; +// +// public HttpServletRequestProxy(HttpServletRequest delegate) { +// this.delegate = delegate; +// } +// +// private HttpServletRequest getDelegate() { +// return delegate; +// } +// +// @Override +// public Object getAttribute(String name) { +// return getDelegate().getAttribute(name); +// } +// +// @Override +// public Enumeration getAttributeNames() { +// return getDelegate().getAttributeNames(); +// } +// +// @Override +// public String getCharacterEncoding() { +// return getDelegate().getCharacterEncoding(); +// } +// +// @Override +// public void setCharacterEncoding(String env) throws UnsupportedEncodingException { +// getDelegate().setCharacterEncoding(env); +// } +// +// @Override +// public int getContentLength() { +// return getDelegate().getContentLength(); +// } +// +// @Override +// public String getContentType() { +// return getDelegate().getContentType(); +// } +// +// @Override +// public ServletInputStream getInputStream() throws IOException { +// return getDelegate().getInputStream(); +// } +// +// @Override +// public String getParameter(String name) { +// return getDelegate().getParameter(name); +// } +// +// @Override +// public Enumeration getParameterNames() { +// return getDelegate().getParameterNames(); +// } +// +// @Override +// public String[] getParameterValues(String name) { +// return getDelegate().getParameterValues(name); +// } +// +// @Override +// public Map getParameterMap() { +// return getDelegate().getParameterMap(); +// } +// +// @Override +// public String getProtocol() { +// return getDelegate().getProtocol(); +// } +// +// @Override +// public String getScheme() { +// return getDelegate().getScheme(); +// } +// +// @Override +// public String getServerName() { +// return getDelegate().getServerName(); +// } +// +// @Override +// public int getServerPort() { +// return getDelegate().getServerPort(); +// } +// +// @Override +// public BufferedReader getReader() throws IOException { +// return getDelegate().getReader(); +// } +// +// @Override +// public String getRemoteAddr() { +// return getDelegate().getRemoteAddr(); +// } +// +// @Override +// public String getRemoteHost() { +// return getDelegate().getRemoteHost(); +// } +// +// @Override +// public void setAttribute(String name, Object o) { +// getDelegate().setAttribute(name, o); +// } +// +// @Override +// public void removeAttribute(String name) { +// getDelegate().removeAttribute(name); +// } +// +// @Override +// public Locale getLocale() { +// return getDelegate().getLocale(); +// } +// +// @Override +// public Enumeration getLocales() { +// return getDelegate().getLocales(); +// } +// +// @Override +// public boolean isSecure() { +// return getDelegate().isSecure(); +// } +// +// @Override +// public RequestDispatcher getRequestDispatcher(String path) { +// return getDelegate().getRequestDispatcher(path); +// } +// +// @Override +// @Deprecated +// public String getRealPath(String path) { +// return getDelegate().getRealPath(path); +// } +// +// @Override +// public int getRemotePort() { +// return getDelegate().getRemotePort(); +// } +// +// @Override +// public String getLocalName() { +// return getDelegate().getLocalName(); +// } +// +// @Override +// public String getLocalAddr() { +// return getDelegate().getLocalAddr(); +// } +// +// @Override +// public int getLocalPort() { +// return getDelegate().getLocalPort(); +// } +// +// @Override +// public String getAuthType() { +// return getDelegate().getAuthType(); +// } +// +// @Override +// public Cookie[] getCookies() { +// return getDelegate().getCookies(); +// } +// +// @Override +// public long getDateHeader(String name) { +// return getDelegate().getDateHeader(name); +// } +// +// @Override +// public String getHeader(String name) { +// return getDelegate().getHeader(name); +// } +// +// @Override +// public Enumeration getHeaders(String name) { +// return getDelegate().getHeaders(name); +// } +// +// @Override +// public Enumeration getHeaderNames() { +// return getDelegate().getHeaderNames(); +// } +// +// @Override +// public int getIntHeader(String name) { +// return getDelegate().getIntHeader(name); +// } +// +// @Override +// public String getMethod() { +// return getDelegate().getMethod(); +// } +// +// @Override +// public String getPathInfo() { +// return getDelegate().getPathInfo(); +// } +// +// @Override +// public String getPathTranslated() { +// return getDelegate().getPathTranslated(); +// } +// +// @Override +// public String getContextPath() { +// return getDelegate().getContextPath(); +// } +// +// @Override +// public String getQueryString() { +// return getDelegate().getQueryString(); +// } +// +// @Override +// public String getRemoteUser() { +// return getDelegate().getRemoteUser(); +// } +// +// @Override +// public boolean isUserInRole(String role) { +// return getDelegate().isUserInRole(role); +// } +// +// @Override +// public Principal getUserPrincipal() { +// return getDelegate().getUserPrincipal(); +// } +// +// @Override +// public String getRequestedSessionId() { +// return getDelegate().getRequestedSessionId(); +// } +// +// @Override +// public String getRequestURI() { +// return getDelegate().getRequestURI(); +// } +// +// @Override +// public StringBuffer getRequestURL() { +// return getDelegate().getRequestURL(); +// } +// +// @Override +// public String getServletPath() { +// return getDelegate().getServletPath(); +// } +// +// @Override +// public HttpSession getSession(boolean create) { +// return getDelegate().getSession(create); +// } +// +// @Override +// public HttpSession getSession() { +// return getDelegate().getSession(); +// } +// +// @Override +// public boolean isRequestedSessionIdValid() { +// return getDelegate().isRequestedSessionIdValid(); +// } +// +// @Override +// public boolean isRequestedSessionIdFromCookie() { +// return getDelegate().isRequestedSessionIdFromCookie(); +// } +// +// @Override +// public boolean isRequestedSessionIdFromURL() { +// return getDelegate().isRequestedSessionIdFromURL(); +// } +// +// @Override +// @Deprecated +// public boolean isRequestedSessionIdFromUrl() { +// return getDelegate().isRequestedSessionIdFromUrl(); +// } +//} diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletResponseProxy.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletResponseProxy.java new file mode 100644 index 0000000..b951cdc --- /dev/null +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletResponseProxy.java @@ -0,0 +1,192 @@ +//package br.gov.frameworkdemoiselle.internal.proxy; +// +//import java.io.IOException; +//import java.io.PrintWriter; +//import java.io.Serializable; +//import java.util.Locale; +// +//import javax.enterprise.context.RequestScoped; +//import javax.enterprise.inject.Default; +//import javax.servlet.ServletOutputStream; +//import javax.servlet.http.Cookie; +//import javax.servlet.http.HttpServletResponse; +// +//@Default +//@RequestScoped +//public class HttpServletResponseProxy implements HttpServletResponse, Serializable { +// +// private static final long serialVersionUID = 1L; +// +// private transient HttpServletResponse delegate; +// +// public HttpServletResponseProxy(HttpServletResponse delegate) { +// this.delegate = delegate; +// } +// +// private HttpServletResponse getDelegate() { +// return delegate; +// } +// +// @Override +// public String getCharacterEncoding() { +// return getDelegate().getCharacterEncoding(); +// } +// +// @Override +// public String getContentType() { +// return getDelegate().getContentType(); +// } +// +// @Override +// public ServletOutputStream getOutputStream() throws IOException { +// return getDelegate().getOutputStream(); +// } +// +// @Override +// public PrintWriter getWriter() throws IOException { +// return getDelegate().getWriter(); +// } +// +// @Override +// public void setCharacterEncoding(String charset) { +// getDelegate().setCharacterEncoding(charset); +// } +// +// @Override +// public void setContentLength(int len) { +// getDelegate().setContentLength(len); +// } +// +// @Override +// public void setContentType(String type) { +// getDelegate().setContentType(type); +// } +// +// @Override +// public void setBufferSize(int size) { +// getDelegate().setBufferSize(size); +// } +// +// @Override +// public int getBufferSize() { +// return getDelegate().getBufferSize(); +// } +// +// @Override +// public void flushBuffer() throws IOException { +// getDelegate().flushBuffer(); +// } +// +// @Override +// public void resetBuffer() { +// getDelegate().resetBuffer(); +// } +// +// @Override +// public boolean isCommitted() { +// return getDelegate().isCommitted(); +// } +// +// @Override +// public void reset() { +// getDelegate().reset(); +// } +// +// @Override +// public void setLocale(Locale loc) { +// getDelegate().setLocale(loc); +// } +// +// @Override +// public Locale getLocale() { +// return getDelegate().getLocale(); +// } +// +// @Override +// public void addCookie(Cookie cookie) { +// getDelegate().addCookie(cookie); +// } +// +// @Override +// public boolean containsHeader(String name) { +// return getDelegate().containsHeader(name); +// } +// +// @Override +// public String encodeURL(String url) { +// return getDelegate().encodeURL(url); +// } +// +// @Override +// public String encodeRedirectURL(String url) { +// return getDelegate().encodeRedirectURL(url); +// } +// +// @Override +// @Deprecated +// public String encodeUrl(String url) { +// return getDelegate().encodeUrl(url); +// } +// +// @Override +// @Deprecated +// public String encodeRedirectUrl(String url) { +// return getDelegate().encodeRedirectUrl(url); +// } +// +// @Override +// public void sendError(int sc, String msg) throws IOException { +// getDelegate().sendError(sc, msg); +// } +// +// @Override +// public void sendError(int sc) throws IOException { +// getDelegate().sendError(sc); +// } +// +// @Override +// public void sendRedirect(String location) throws IOException { +// getDelegate().sendRedirect(location); +// } +// +// @Override +// public void setDateHeader(String name, long date) { +// getDelegate().setDateHeader(name, date); +// } +// +// @Override +// public void addDateHeader(String name, long date) { +// getDelegate().addDateHeader(name, date); +// } +// +// @Override +// public void setHeader(String name, String value) { +// getDelegate().setHeader(name, value); +// } +// +// @Override +// public void addHeader(String name, String value) { +// getDelegate().addHeader(name, value); +// } +// +// @Override +// public void setIntHeader(String name, int value) { +// getDelegate().setIntHeader(name, value); +// } +// +// @Override +// public void addIntHeader(String name, int value) { +// getDelegate().addIntHeader(name, value); +// } +// +// @Override +// public void setStatus(int sc) { +// getDelegate().setStatus(sc); +// } +// +// @Override +// @Deprecated +// public void setStatus(int sc, String sm) { +// getDelegate().setStatus(sc, sm); +// } +//} diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpSessionProxy.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpSessionProxy.java new file mode 100644 index 0000000..e715dbb --- /dev/null +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpSessionProxy.java @@ -0,0 +1,118 @@ +//package br.gov.frameworkdemoiselle.internal.proxy; +// +//import java.io.Serializable; +//import java.util.Enumeration; +// +//import javax.enterprise.context.SessionScoped; +//import javax.enterprise.inject.Default; +//import javax.servlet.ServletContext; +//import javax.servlet.http.HttpSession; +//import javax.servlet.http.HttpSessionContext; +// +//@Default +//@SessionScoped +//@SuppressWarnings("deprecation") +//public class HttpSessionProxy implements HttpSession, Serializable { +// +// private static final long serialVersionUID = 1L; +// +// private transient HttpSession delegate; +// +// public HttpSessionProxy(HttpSession delegate) { +// this.delegate = delegate; +// } +// +// private HttpSession getDelegate() { +// return delegate; +// } +// +// @Override +// public long getCreationTime() { +// return getDelegate().getCreationTime(); +// } +// +// @Override +// public String getId() { +// return getDelegate().getId(); +// } +// +// @Override +// public long getLastAccessedTime() { +// return getDelegate().getLastAccessedTime(); +// } +// +// @Override +// public ServletContext getServletContext() { +// return getDelegate().getServletContext(); +// } +// +// @Override +// public void setMaxInactiveInterval(int interval) { +// getDelegate().setMaxInactiveInterval(interval); +// } +// +// @Override +// public int getMaxInactiveInterval() { +// return getDelegate().getMaxInactiveInterval(); +// } +// +// @Override +// @Deprecated +// public HttpSessionContext getSessionContext() { +// return getDelegate().getSessionContext(); +// } +// +// @Override +// public Object getAttribute(String name) { +// return getDelegate().getAttribute(name); +// } +// +// @Override +// @Deprecated +// public Object getValue(String name) { +// return getDelegate().getValue(name); +// } +// +// @Override +// public Enumeration getAttributeNames() { +// return getDelegate().getAttributeNames(); +// } +// +// @Override +// @Deprecated +// public String[] getValueNames() { +// return getDelegate().getValueNames(); +// } +// +// @Override +// public void setAttribute(String name, Object value) { +// getDelegate().setAttribute(name, value); +// } +// +// @Override +// @Deprecated +// public void putValue(String name, Object value) { +// getDelegate().putValue(name, value); +// } +// +// @Override +// public void removeAttribute(String name) { +// getDelegate().removeAttribute(name); +// } +// +// @Override +// @Deprecated +// public void removeValue(String name) { +// getDelegate().removeValue(name); +// } +// +// @Override +// public void invalidate() { +// getDelegate().invalidate(); +// } +// +// @Override +// public boolean isNew() { +// return getDelegate().isNew(); +// } +//} diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletFilter.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletFilter.java index d4b284a..a5435c2 100644 --- a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletFilter.java +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletFilter.java @@ -60,12 +60,9 @@ public class ServletFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - HttpServletRequestProducer requestProducer = Beans.getReference(HttpServletRequestProducer.class); - requestProducer.setRequest((HttpServletRequest) request); - - HttpServletResponseProducer responseProducer = Beans.getReference(HttpServletResponseProducer.class); - responseProducer.setResponse((HttpServletResponse) response); - + Beans.getReference(HttpServletRequestProducer.class).setDelegate((HttpServletRequest) request); + Beans.getReference(HttpServletResponseProducer.class).setDelegate((HttpServletResponse) response); + chain.doFilter(request, response); } diff --git a/parent/extension/pom.xml b/parent/extension/pom.xml index faf1669..73336c3 100755 --- a/parent/extension/pom.xml +++ b/parent/extension/pom.xml @@ -78,7 +78,6 @@ br.gov.frameworkdemoiselle demoiselle-core - compile diff --git a/parent/framework/pom.xml b/parent/framework/pom.xml index 71e07e6..e7193b0 100755 --- a/parent/framework/pom.xml +++ b/parent/framework/pom.xml @@ -9,7 +9,7 @@ br.gov.frameworkdemoiselle demoiselle-parent - 4 + 5-SNAPSHOT ../../../internal/parent/demoiselle/pom.xml diff --git a/parent/jsf/pom.xml b/parent/jsf/pom.xml index 0523bde..1692bed 100755 --- a/parent/jsf/pom.xml +++ b/parent/jsf/pom.xml @@ -34,7 +34,8 @@ ou escreva para a Fundação do Software Livre (FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. --> - + 4.0.0 @@ -54,17 +55,37 @@ utilizam o framework. + + + + org.apache.maven.plugins + maven-war-plugin + + + + src/main/webapp/WEB-INF + WEB-INF + true + + + + + + + br.gov.frameworkdemoiselle demoiselle-jsf compile + @@ -99,6 +120,11 @@ runtime + com.sun.faces + jsf-impl + runtime + + org.eclipse.persistence eclipselink runtime @@ -150,6 +176,11 @@ runtime + com.sun.faces + jsf-impl + runtime + + org.eclipse.persistence eclipselink runtime @@ -172,6 +203,62 @@ + gae + + + + net.kindleit + maven-gae-plugin + ${kindleit.plugin.version} + + appengine.google.com + + + + + + + javax.servlet + servlet-api + provided + + + org.jboss.weld + weld-core + runtime + + + org.jboss.weld.servlet + weld-servlet-core + runtime + + + com.sun.faces + jsf-impl + runtime + + + org.hibernate + hibernate-validator + runtime + + + org.slf4j + slf4j-log4j12 + runtime + + + com.google.appengine + appengine-api-1.0-sdk + ${gae.version} + + + + 1.7.0 + 0.9.4 + + + glassfish3 @@ -298,11 +385,6 @@ provided - com.sun.faces - jsf-impl - provided - - hsqldb hsqldb provided @@ -373,11 +455,6 @@ provided - com.sun.faces - jsf-impl - provided - - hsqldb hsqldb provided -- libgit2 0.21.2