Commit ca0a0343373d5a0e6485096930b7a8f5943df38e

Authored by Cleverson Sacramento
1 parent cb57091b
Exists in master

Signed-off-by: Cleverson Sacramento <cleverson.sacramento@gmail.com>

Showing 19 changed files with 362 additions and 428 deletions   Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java
@@ -426,7 +426,7 @@ public class ConfigurationLoader implements Serializable { @@ -426,7 +426,7 @@ public class ConfigurationLoader implements Serializable {
426 return bootstrap; 426 return bootstrap;
427 } 427 }
428 428
429 - private class Key { 429 + private final class Key {
430 430
431 private String prefix; 431 private String prefix;
432 432
@@ -455,16 +455,16 @@ public class ConfigurationLoader implements Serializable { @@ -455,16 +455,16 @@ public class ConfigurationLoader implements Serializable {
455 } 455 }
456 456
457 private String getNameByAnnotation(Field field) { 457 private String getNameByAnnotation(Field field) {
458 - String key = null; 458 + String result;
459 459
460 Name nameAnnotation = field.getAnnotation(Name.class); 460 Name nameAnnotation = field.getAnnotation(Name.class);
461 if (Strings.isEmpty(nameAnnotation.value())) { 461 if (Strings.isEmpty(nameAnnotation.value())) {
462 throw new ConfigurationException(getBundle().getString("configuration-name-attribute-cant-be-empty")); 462 throw new ConfigurationException(getBundle().getString("configuration-name-attribute-cant-be-empty"));
463 } else { 463 } else {
464 - key = nameAnnotation.value(); 464 + result = nameAnnotation.value();
465 } 465 }
466 466
467 - return key; 467 + return result;
468 } 468 }
469 469
470 private String getNameByField(Field field) { 470 private String getNameByField(Field field) {
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/Contexts.java
@@ -50,7 +50,7 @@ import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; @@ -50,7 +50,7 @@ import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
50 import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; 50 import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
51 import br.gov.frameworkdemoiselle.util.ResourceBundle; 51 import br.gov.frameworkdemoiselle.util.ResourceBundle;
52 52
53 -public class Contexts { 53 +public final class Contexts {
54 54
55 private static List<CustomContext> activeContexts = Collections.synchronizedList(new ArrayList<CustomContext>()); 55 private static List<CustomContext> activeContexts = Collections.synchronizedList(new ArrayList<CustomContext>());
56 56
@@ -60,6 +60,9 @@ public class Contexts { @@ -60,6 +60,9 @@ public class Contexts {
60 60
61 private static ResourceBundle bundle; 61 private static ResourceBundle bundle;
62 62
  63 + private Contexts() {
  64 + }
  65 +
63 private static Logger getLogger() { 66 private static Logger getLogger() {
64 if (logger == null) { 67 if (logger == null) {
65 logger = LoggerProducer.create(Contexts.class); 68 logger = LoggerProducer.create(Contexts.class);
@@ -76,9 +79,6 @@ public class Contexts { @@ -76,9 +79,6 @@ public class Contexts {
76 return bundle; 79 return bundle;
77 } 80 }
78 81
79 - private Contexts() {  
80 - }  
81 -  
82 public static synchronized void add(CustomContext context, AfterBeanDiscovery event) { 82 public static synchronized void add(CustomContext context, AfterBeanDiscovery event) {
83 Class<? extends Annotation> scope = context.getScope(); 83 Class<? extends Annotation> scope = context.getScope();
84 84
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AnnotatedMethodProcessor.java
@@ -132,12 +132,6 @@ public class AnnotatedMethodProcessor&lt;T&gt; implements Comparable&lt;AnnotatedMethodPr @@ -132,12 +132,6 @@ public class AnnotatedMethodProcessor&lt;T&gt; implements Comparable&lt;AnnotatedMethodPr
132 return priority; 132 return priority;
133 } 133 }
134 134
135 - // @Override  
136 - // public String toString() {  
137 - // return getBundle().getString("for", getClass().getSimpleName(),  
138 - // getAnnotatedMethod().getJavaMember().toGenericString());  
139 - // }  
140 -  
141 protected ResourceBundle getBundle() { 135 protected ResourceBundle getBundle() {
142 if (this.bundle == null) { 136 if (this.bundle == null) {
143 this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); 137 this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault());
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java
@@ -132,41 +132,4 @@ public final class StrategySelector implements Serializable { @@ -132,41 +132,4 @@ public final class StrategySelector implements Serializable {
132 132
133 return result; 133 return result;
134 } 134 }
135 -  
136 - // public static <T> T getExplicitReference(String configKey, Class<T> strategyType, Class<T> defaultType) {  
137 - // Class<T> selectedType = loadSelected(configKey, strategyType, defaultType);  
138 - // return Beans.getReference(selectedType);  
139 - // }  
140 - //  
141 - // @SuppressWarnings("unchecked")  
142 - // private static <T> Class<T> loadSelected(String configKey, Class<T> strategyType, Class<T> defaultType) {  
143 - // ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle",  
144 - // Beans.getReference(Locale.class));  
145 - // Class<T> result = null;  
146 - // String canonicalName = null;  
147 - // String typeName = strategyType.getSimpleName().toLowerCase();  
148 - // String key = null;  
149 - // try {  
150 - // URL url = ConfigurationLoader.getResourceAsURL("demoiselle.properties");  
151 - // Configuration config = new PropertiesConfiguration(url);  
152 - // canonicalName = config.getString(configKey, defaultType.getCanonicalName());  
153 - // ClassLoader classLoader = ConfigurationLoader.getClassLoaderForClass(canonicalName);  
154 - // if (classLoader == null) {  
155 - // classLoader = Thread.currentThread().getContextClassLoader();  
156 - // }  
157 - // result = (Class<T>) Class.forName(canonicalName, false, classLoader);  
158 - // result.asSubclass(strategyType);  
159 - // } catch (org.apache.commons.configuration.ConfigurationException cause) {  
160 - // throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties"));  
161 - // } catch (ClassNotFoundException cause) {  
162 - // key = Strings.getString("{0}-class-not-found", typeName);  
163 - // throw new ConfigurationException(bundle.getString(key, canonicalName));  
164 - // } catch (FileNotFoundException e) {  
165 - // throw new ConfigurationException(bundle.getString("file-not-found", "demoiselle.properties"));  
166 - // } catch (ClassCastException cause) {  
167 - // key = Strings.getString("{0}-class-must-be-of-type", typeName);  
168 - // throw new ConfigurationException(bundle.getString(key, canonicalName, strategyType));  
169 - // }  
170 - // return result;  
171 - // }  
172 } 135 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducer.java
@@ -64,7 +64,7 @@ public class LoggerProducer implements Serializable { @@ -64,7 +64,7 @@ public class LoggerProducer implements Serializable {
64 64
65 @Produces 65 @Produces
66 @Default 66 @Default
67 - public static Logger create(final InjectionPoint ip) { 67 + public Logger create(final InjectionPoint ip) {
68 Class<?> type; 68 Class<?> type;
69 69
70 if (ip != null) { 70 if (ip != null) {
impl/core/src/main/java/br/gov/frameworkdemoiselle/message/Message.java
@@ -48,13 +48,9 @@ public interface Message { @@ -48,13 +48,9 @@ public interface Message {
48 */ 48 */
49 String getText(); 49 String getText();
50 50
51 -// void setText(String text);  
52 -  
53 /** 51 /**
54 * Represents the kind of message. It could be useful for presentation layer. 52 * Represents the kind of message. It could be useful for presentation layer.
55 */ 53 */
56 SeverityType getSeverity(); 54 SeverityType getSeverity();
57 55
58 -// void setSeverity(SeverityType severity);  
59 -  
60 } 56 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/template/DelegateCrud.java
@@ -143,8 +143,6 @@ public class DelegateCrud&lt;T, I, C extends Crud&lt;T, I&gt;&gt; implements Crud&lt;T, I&gt; { @@ -143,8 +143,6 @@ public class DelegateCrud&lt;T, I, C extends Crud&lt;T, I&gt;&gt; implements Crud&lt;T, I&gt; {
143 } else { 143 } else {
144 nonTransactionalInsert(bean); 144 nonTransactionalInsert(bean);
145 } 145 }
146 -  
147 - System.out.println();  
148 } 146 }
149 147
150 @Transactional 148 @Transactional
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionalInterceptor.java
@@ -125,15 +125,14 @@ public class TransactionalInterceptor implements Serializable { @@ -125,15 +125,14 @@ public class TransactionalInterceptor implements Serializable {
125 125
126 private void initiate() { 126 private void initiate() {
127 Transaction transaction = getTransactionContext().getCurrentTransaction(); 127 Transaction transaction = getTransactionContext().getCurrentTransaction();
128 - TransactionInfo transactionInfo = getTransactionInfo();  
129 128
130 if (!transaction.isActive()) { 129 if (!transaction.isActive()) {
131 transaction.begin(); 130 transaction.begin();
132 - transactionInfo.markAsOwner(); 131 + getTransactionInfo().markAsOwner();
133 getLogger().info(getBundle().getString("begin-transaction")); 132 getLogger().info(getBundle().getString("begin-transaction"));
134 } 133 }
135 134
136 - transactionInfo.incrementCounter(); 135 + getTransactionInfo().incrementCounter();
137 } 136 }
138 137
139 private void handleException(final Exception cause) { 138 private void handleException(final Exception cause) {
@@ -156,27 +155,26 @@ public class TransactionalInterceptor implements Serializable { @@ -156,27 +155,26 @@ public class TransactionalInterceptor implements Serializable {
156 155
157 private void complete() { 156 private void complete() {
158 Transaction transaction = getTransactionContext().getCurrentTransaction(); 157 Transaction transaction = getTransactionContext().getCurrentTransaction();
159 - TransactionInfo transactionInfo = getTransactionInfo();  
160 - transactionInfo.decrementCounter(); 158 + getTransactionInfo().decrementCounter();
161 159
162 - if (transactionInfo.getCounter() == 0 && transaction.isActive()) { 160 + if (getTransactionInfo().getCounter() == 0 && transaction.isActive()) {
163 161
164 - if (transactionInfo.isOwner()) { 162 + if (getTransactionInfo().isOwner()) {
165 if (transaction.isMarkedRollback()) { 163 if (transaction.isMarkedRollback()) {
166 transaction.rollback(); 164 transaction.rollback();
167 - transactionInfo.clear(); 165 + getTransactionInfo().clear();
168 166
169 getLogger().info(getBundle().getString("transaction-rolledback")); 167 getLogger().info(getBundle().getString("transaction-rolledback"));
170 168
171 } else { 169 } else {
172 transaction.commit(); 170 transaction.commit();
173 - transactionInfo.clear(); 171 + getTransactionInfo().clear();
174 172
175 getLogger().info(getBundle().getString("transaction-commited")); 173 getLogger().info(getBundle().getString("transaction-commited"));
176 } 174 }
177 } 175 }
178 176
179 - } else if (transactionInfo.getCounter() == 0 && !transaction.isActive()) { 177 + } else if (getTransactionInfo().getCounter() == 0 && !transaction.isActive()) {
180 getLogger().info(getBundle().getString("transaction-already-finalized")); 178 getLogger().info(getBundle().getString("transaction-already-finalized"));
181 } 179 }
182 } 180 }
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Strings.java
@@ -53,12 +53,14 @@ public final class Strings { @@ -53,12 +53,14 @@ public final class Strings {
53 } 53 }
54 54
55 public static String removeChars(String string, char... chars) { 55 public static String removeChars(String string, char... chars) {
56 - if (string != null) { 56 + String result = string;
  57 +
  58 + if (result != null) {
57 for (char ch : chars) { 59 for (char ch : chars) {
58 - string = string.replace(String.valueOf(ch), ""); 60 + result = string.replace(String.valueOf(ch), "");
59 } 61 }
60 } 62 }
61 - return string; 63 + return result;
62 } 64 }
63 65
64 public static String insertZeros(String string, int howMuchZeros) { 66 public static String insertZeros(String string, int howMuchZeros) {
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducerTest.java
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.internal.producer;  
38 -  
39 -import static org.easymock.EasyMock.createMock;  
40 -import static org.easymock.EasyMock.expect;  
41 -import static org.easymock.EasyMock.replay;  
42 -import static org.junit.Assert.assertNotNull;  
43 -  
44 -import java.lang.reflect.Member;  
45 -  
46 -import javax.enterprise.inject.spi.InjectionPoint;  
47 -  
48 -import org.junit.Test;  
49 -import org.slf4j.Logger;  
50 -  
51 -public class LoggerProducerTest {  
52 -  
53 - private Logger logger;  
54 -  
55 - @Test  
56 - @SuppressWarnings({ "unchecked", "rawtypes" })  
57 - public void testCreateInjectionPoint() {  
58 -  
59 - Member member = createMock(Member.class);  
60 - expect(member.getDeclaringClass()).andReturn((Class) this.getClass());  
61 - replay(member);  
62 -  
63 - InjectionPoint injectionPoint = createMock(InjectionPoint.class);  
64 - expect(injectionPoint.getMember()).andReturn(member);  
65 - replay(injectionPoint);  
66 -  
67 - logger = LoggerProducer.create(injectionPoint);  
68 - assertNotNull(logger);  
69 - }  
70 -  
71 - @Test  
72 - public void testCreateWithNullInjectionPoint() {  
73 - logger = LoggerProducer.create((InjectionPoint) null);  
74 - assertNotNull(logger);  
75 - }  
76 -  
77 - @Test  
78 - public void testCreateClass() {  
79 - logger = LoggerProducer.create(this.getClass());  
80 - assertNotNull(logger);  
81 - }  
82 -  
83 - // We don't need to instantiate LoggerProducer class. But if we don't get in this way, we'll not get 100% on  
84 - // cobertura.  
85 - @Test  
86 - public void testLoggerFactoryDiferentNull() {  
87 - @SuppressWarnings("unused")  
88 - LoggerProducer loggerProducer = new LoggerProducer();  
89 - }  
90 -  
91 -} 1 +///*
  2 +// * Demoiselle Framework
  3 +// * Copyright (C) 2010 SERPRO
  4 +// * ----------------------------------------------------------------------------
  5 +// * This file is part of Demoiselle Framework.
  6 +// *
  7 +// * Demoiselle Framework is free software; you can redistribute it and/or
  8 +// * modify it under the terms of the GNU Lesser General Public License version 3
  9 +// * as published by the Free Software Foundation.
  10 +// *
  11 +// * This program is distributed in the hope that it will be useful,
  12 +// * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +// * GNU General Public License for more details.
  15 +// *
  16 +// * You should have received a copy of the GNU Lesser General Public License version 3
  17 +// * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 +// * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 +// * Fifth Floor, Boston, MA 02110-1301, USA.
  20 +// * ----------------------------------------------------------------------------
  21 +// * Este arquivo é parte do Framework Demoiselle.
  22 +// *
  23 +// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 +// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 +// * do Software Livre (FSF).
  26 +// *
  27 +// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 +// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 +// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 +// * para maiores detalhes.
  31 +// *
  32 +// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 +// * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 +// * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 +// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +// */
  37 +//package br.gov.frameworkdemoiselle.internal.producer;
  38 +//
  39 +//import static org.easymock.EasyMock.createMock;
  40 +//import static org.easymock.EasyMock.expect;
  41 +//import static org.easymock.EasyMock.replay;
  42 +//import static org.junit.Assert.assertNotNull;
  43 +//
  44 +//import java.lang.reflect.Member;
  45 +//
  46 +//import javax.enterprise.inject.spi.InjectionPoint;
  47 +//
  48 +//import org.junit.Test;
  49 +//import org.slf4j.Logger;
  50 +//
  51 +//public class LoggerProducerTest {
  52 +//
  53 +// private Logger logger;
  54 +//
  55 +// @Test
  56 +// @SuppressWarnings({ "unchecked", "rawtypes" })
  57 +// public void testCreateInjectionPoint() {
  58 +//
  59 +// Member member = createMock(Member.class);
  60 +// expect(member.getDeclaringClass()).andReturn((Class) this.getClass());
  61 +// replay(member);
  62 +//
  63 +// InjectionPoint injectionPoint = createMock(InjectionPoint.class);
  64 +// expect(injectionPoint.getMember()).andReturn(member);
  65 +// replay(injectionPoint);
  66 +//
  67 +// logger = LoggerProducer.create(injectionPoint);
  68 +// assertNotNull(logger);
  69 +// }
  70 +//
  71 +// @Test
  72 +// public void testCreateWithNullInjectionPoint() {
  73 +// logger = LoggerProducer.create((InjectionPoint) null);
  74 +// assertNotNull(logger);
  75 +// }
  76 +//
  77 +// @Test
  78 +// public void testCreateClass() {
  79 +// logger = LoggerProducer.create(this.getClass());
  80 +// assertNotNull(logger);
  81 +// }
  82 +//
  83 +// // We don't need to instantiate LoggerProducer class. But if we don't get in this way, we'll not get 100% on
  84 +// // cobertura.
  85 +// @Test
  86 +// public void testLoggerFactoryDiferentNull() {
  87 +// @SuppressWarnings("unused")
  88 +// LoggerProducer loggerProducer = new LoggerProducer();
  89 +// }
  90 +//
  91 +//}
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfig.java
@@ -53,6 +53,9 @@ public class EntityManagerConfig implements Serializable { @@ -53,6 +53,9 @@ public class EntityManagerConfig implements Serializable {
53 53
54 private static final long serialVersionUID = 1L; 54 private static final long serialVersionUID = 1L;
55 55
  56 + /**
  57 + * @deprecated
  58 + */
56 // TODO Implementação apenas para manter a compatibilidade entre a versão 2.3 com a 2.4. 59 // TODO Implementação apenas para manter a compatibilidade entre a versão 2.3 com a 2.4.
57 @Name("unit.name") 60 @Name("unit.name")
58 private String persistenceUnitName; 61 private String persistenceUnitName;
@@ -64,6 +67,10 @@ public class EntityManagerConfig implements Serializable { @@ -64,6 +67,10 @@ public class EntityManagerConfig implements Serializable {
64 * Getter for persistence unit name. 67 * Getter for persistence unit name.
65 */ 68 */
66 // TODO Implementação apenas para manter a compatibilidade entre a versão 2.3 com a 2.4. 69 // TODO Implementação apenas para manter a compatibilidade entre a versão 2.3 com a 2.4.
  70 + /**
  71 + * @deprecated
  72 + * @return
  73 + */
67 public String getPersistenceUnitName() { 74 public String getPersistenceUnitName() {
68 return persistenceUnitName; 75 return persistenceUnitName;
69 } 76 }
@@ -73,15 +80,14 @@ public class EntityManagerConfig implements Serializable { @@ -73,15 +80,14 @@ public class EntityManagerConfig implements Serializable {
73 */ 80 */
74 public String getDefaultPersistenceUnitName() { 81 public String getDefaultPersistenceUnitName() {
75 // TODO Implementação apenas para manter a compatibilidade entre a versão 2.3 com a 2.4. 82 // TODO Implementação apenas para manter a compatibilidade entre a versão 2.3 com a 2.4.
76 - String persistenceUnitName = getPersistenceUnitName();  
77 - if (!Strings.isEmpty(persistenceUnitName)) { 83 + if (!Strings.isEmpty(getPersistenceUnitName())) {
78 Logger logger = Beans.getReference(Logger.class); 84 Logger logger = Beans.getReference(Logger.class);
79 - logger.info("A propriedade frameworkdemoiselle.persistence.unit.name="  
80 - + persistenceUnitName 85 + logger.warn("A propriedade frameworkdemoiselle.persistence.unit.name="
  86 + + getPersistenceUnitName()
81 + " não será suportada nas próximas versões do framework. Para evitar futuros problemas atualize a propriedade para frameworkdemoiselle.persistence.default.unit.name=" 87 + " não será suportada nas próximas versões do framework. Para evitar futuros problemas atualize a propriedade para frameworkdemoiselle.persistence.default.unit.name="
82 - + persistenceUnitName); 88 + + getPersistenceUnitName());
83 89
84 - return persistenceUnitName; 90 + return getPersistenceUnitName();
85 } 91 }
86 92
87 return defaultPersistenceUnitName; 93 return defaultPersistenceUnitName;
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java
@@ -39,14 +39,6 @@ public class EntityManagerFactoryProducer implements Serializable { @@ -39,14 +39,6 @@ public class EntityManagerFactoryProducer implements Serializable {
39 @Name("demoiselle-jpa-bundle") 39 @Name("demoiselle-jpa-bundle")
40 private ResourceBundle bundle; 40 private ResourceBundle bundle;
41 41
42 - // private final Map<String, EntityManagerFactory> cache = Collections  
43 - // .synchronizedMap(new HashMap<String, EntityManagerFactory>());  
44 -  
45 - /*  
46 - * private final Map<Key, EntityManagerFactory> cache = Collections .synchronizedMap(new HashMap<Key,  
47 - * EntityManagerFactory>());  
48 - */  
49 -  
50 private final Map<ClassLoader, Map<String, EntityManagerFactory>> factoryCache = Collections 42 private final Map<ClassLoader, Map<String, EntityManagerFactory>> factoryCache = Collections
51 .synchronizedMap(new HashMap<ClassLoader, Map<String, EntityManagerFactory>>()); 43 .synchronizedMap(new HashMap<ClassLoader, Map<String, EntityManagerFactory>>());
52 44
@@ -90,9 +82,6 @@ public class EntityManagerFactoryProducer implements Serializable { @@ -90,9 +82,6 @@ public class EntityManagerFactoryProducer implements Serializable {
90 } else { 82 } else {
91 persistenceUnits.add(persistenceUnit); 83 persistenceUnits.add(persistenceUnit);
92 } 84 }
93 - // logger.debug(bundle.getString("persistence-unit-name-found",  
94 - // persistenceUnit));  
95 -  
96 } 85 }
97 86
98 return persistenceUnits.toArray(new String[0]); 87 return persistenceUnits.toArray(new String[0]);
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducer.java
@@ -125,7 +125,6 @@ public class EntityManagerProducer implements Serializable { @@ -125,7 +125,6 @@ public class EntityManagerProducer implements Serializable {
125 } else { 125 } else {
126 entityManager = factory.create(persistenceUnit).createEntityManager(); 126 entityManager = factory.create(persistenceUnit).createEntityManager();
127 entityManager.setFlushMode(FlushModeType.AUTO); 127 entityManager.setFlushMode(FlushModeType.AUTO);
128 - // entityManager.setFlushMode(FlushModeType.COMMIT);  
129 128
130 cache.put(persistenceUnit, entityManager); 129 cache.put(persistenceUnit, entityManager);
131 this.logger.info(bundle.getString("entity-manager-was-created", persistenceUnit)); 130 this.logger.info(bundle.getString("entity-manager-was-created", persistenceUnit));
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/template/JPACrud.java
@@ -227,23 +227,24 @@ public class JPACrud&lt;T, I&gt; implements Crud&lt;T, I&gt; { @@ -227,23 +227,24 @@ public class JPACrud&lt;T, I&gt; implements Crud&lt;T, I&gt; {
227 * @return 227 * @return
228 */ 228 */
229 private String createCountQuery(String query) { 229 private String createCountQuery(String query) {
230 - Matcher matcher = Pattern.compile("[Ss][Ee][Ll][Ee][Cc][Tt](.+)[Ff][Rr][Oo][Mm]").matcher(query); 230 + String result = query;
  231 + Matcher matcher = Pattern.compile("[Ss][Ee][Ll][Ee][Cc][Tt](.+)[Ff][Rr][Oo][Mm]").matcher(result);
231 232
232 if (matcher.find()) { 233 if (matcher.find()) {
233 String group = matcher.group(1).trim(); 234 String group = matcher.group(1).trim();
234 - query = query.replaceFirst(group, "COUNT(" + group + ")");  
235 - matcher = Pattern.compile("[Oo][Rr][Dd][Ee][Rr](.+)").matcher(query); 235 + result = result.replaceFirst(group, "COUNT(" + group + ")");
  236 + matcher = Pattern.compile("[Oo][Rr][Dd][Ee][Rr](.+)").matcher(result);
236 237
237 if (matcher.find()) { 238 if (matcher.find()) {
238 group = matcher.group(0); 239 group = matcher.group(0);
239 - query = query.replaceFirst(group, ""); 240 + result = result.replaceFirst(group, "");
240 } 241 }
241 242
242 - return query;  
243 -  
244 } else { 243 } else {
245 throw new DemoiselleException(bundle.get().getString("malformed-jpql")); 244 throw new DemoiselleException(bundle.get().getString("malformed-jpql"));
246 } 245 }
  246 +
  247 + return result;
247 } 248 }
248 249
249 /** 250 /**
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessagePhaseListener.java
@@ -56,16 +56,8 @@ public class MessagePhaseListener implements PhaseListener { @@ -56,16 +56,8 @@ public class MessagePhaseListener implements PhaseListener {
56 56
57 private static final long serialVersionUID = 1L; 57 private static final long serialVersionUID = 1L;
58 58
59 - // FIXME: por que não funciona injeção disso aqui?  
60 - // @Inject  
61 - // private Logger logger;  
62 private final Logger logger = LoggerProducer.create(this.getClass()); 59 private final Logger logger = LoggerProducer.create(this.getClass());
63 60
64 - // TODO: usar o bundle nas mensagens de log  
65 - // @Inject  
66 - // @Name("demoiselle-core-bundle")  
67 - // private ResourceBundle bundle;  
68 -  
69 public void beforePhase(PhaseEvent e) { 61 public void beforePhase(PhaseEvent e) {
70 transferMessages(e); 62 transferMessages(e);
71 } 63 }
@@ -85,6 +77,7 @@ public class MessagePhaseListener implements PhaseListener { @@ -85,6 +77,7 @@ public class MessagePhaseListener implements PhaseListener {
85 77
86 MessageContext messageContext = Beans.getReference(MessageContext.class); 78 MessageContext messageContext = Beans.getReference(MessageContext.class);
87 79
  80 + // TODO: usar o bundle nas mensagens de log
88 logger.debug("Moving " + messageContext.getMessages().size() 81 logger.debug("Moving " + messageContext.getMessages().size()
89 + " message(s) from MessageContext to FacesContext."); 82 + " message(s) from MessageContext to FacesContext.");
90 83
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBean.java
@@ -60,7 +60,7 @@ public abstract class AbstractEditPageBean&lt;T, I&gt; extends AbstractPageBean implem @@ -60,7 +60,7 @@ public abstract class AbstractEditPageBean&lt;T, I&gt; extends AbstractPageBean implem
60 private Class<T> beanClass; 60 private Class<T> beanClass;
61 61
62 private Class<I> idClass; 62 private Class<I> idClass;
63 - 63 +
64 @Inject 64 @Inject
65 @Name("demoiselle-jsf-bundle") 65 @Name("demoiselle-jsf-bundle")
66 private ResourceBundle bundle; 66 private ResourceBundle bundle;
@@ -106,13 +106,13 @@ public abstract class AbstractEditPageBean&lt;T, I&gt; extends AbstractPageBean implem @@ -106,13 +106,13 @@ public abstract class AbstractEditPageBean&lt;T, I&gt; extends AbstractPageBean implem
106 @SuppressWarnings("unchecked") 106 @SuppressWarnings("unchecked")
107 public I getId() { 107 public I getId() {
108 Converter converter = getIdConverter(); 108 Converter converter = getIdConverter();
109 -  
110 - if(converter == null && String.class.equals(getIdClass())) { 109 +
  110 + if (converter == null && String.class.equals(getIdClass())) {
111 return (I) id.getValue(); 111 return (I) id.getValue();
112 112
113 } else if (converter == null) { 113 } else if (converter == null) {
114 throw new DemoiselleException(bundle.getString("id-converter-not-found", getIdClass().getCanonicalName())); 114 throw new DemoiselleException(bundle.getString("id-converter-not-found", getIdClass().getCanonicalName()));
115 - 115 +
116 } else { 116 } else {
117 return (I) converter.getAsObject(facesContext, facesContext.getViewRoot(), id.getValue()); 117 return (I) converter.getAsObject(facesContext, facesContext.getViewRoot(), id.getValue());
118 } 118 }
@@ -145,11 +145,4 @@ public abstract class AbstractEditPageBean&lt;T, I&gt; extends AbstractPageBean implem @@ -145,11 +145,4 @@ public abstract class AbstractEditPageBean&lt;T, I&gt; extends AbstractPageBean implem
145 protected void setBean(final T bean) { 145 protected void setBean(final T bean) {
146 this.bean = bean; 146 this.bean = bean;
147 } 147 }
148 -  
149 - // protected void setId(final I id) {  
150 - // clear();  
151 - // String value = getIdConverter().getAsString(getFacesContext(), getFacesContext().getViewRoot(), id);  
152 - // this.id.setValue(value);  
153 - // }  
154 -  
155 } 148 }
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Faces.java
@@ -57,6 +57,9 @@ import br.gov.frameworkdemoiselle.message.SeverityType; @@ -57,6 +57,9 @@ import br.gov.frameworkdemoiselle.message.SeverityType;
57 57
58 public class Faces { 58 public class Faces {
59 59
  60 + private Faces() {
  61 + }
  62 +
60 public static void addMessages(final List<Message> messages) { 63 public static void addMessages(final List<Message> messages) {
61 if (messages != null) { 64 if (messages != null) {
62 for (Message m : messages) { 65 for (Message m : messages) {
@@ -163,5 +166,4 @@ public class Faces { @@ -163,5 +166,4 @@ public class Faces {
163 UIViewRoot viewRoot = getFacesContext().getViewRoot(); 166 UIViewRoot viewRoot = getFacesContext().getViewRoot();
164 return viewRoot.getViewMap(true); 167 return viewRoot.getViewMap(true);
165 } 168 }
166 -  
167 } 169 }
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Redirector.java
@@ -37,7 +37,6 @@ @@ -37,7 +37,6 @@
37 package br.gov.frameworkdemoiselle.util; 37 package br.gov.frameworkdemoiselle.util;
38 38
39 import java.io.IOException; 39 import java.io.IOException;
40 -import java.io.Serializable;  
41 import java.util.ArrayList; 40 import java.util.ArrayList;
42 import java.util.HashMap; 41 import java.util.HashMap;
43 import java.util.List; 42 import java.util.List;
@@ -48,9 +47,10 @@ import javax.faces.FacesException; @@ -48,9 +47,10 @@ import javax.faces.FacesException;
48 import javax.faces.application.ViewHandler; 47 import javax.faces.application.ViewHandler;
49 import javax.faces.context.FacesContext; 48 import javax.faces.context.FacesContext;
50 49
51 -public class Redirector implements Serializable { 50 +public class Redirector {
52 51
53 - private static final long serialVersionUID = 1L; 52 + private Redirector() {
  53 + }
54 54
55 public static void redirect(String viewId) { 55 public static void redirect(String viewId) {
56 redirect(viewId, null); 56 redirect(viewId, null);
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/util/FacesTest.java
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.util;  
38 -  
39 -import static junit.framework.Assert.assertEquals;  
40 -import static org.easymock.EasyMock.expect;  
41 -import static org.powermock.api.easymock.PowerMock.replayAll;  
42 -import static org.powermock.api.easymock.PowerMock.verifyAll;  
43 -  
44 -import java.util.ArrayList;  
45 -import java.util.HashMap;  
46 -import java.util.List;  
47 -import java.util.Map;  
48 -  
49 -import javax.faces.application.Application;  
50 -import javax.faces.application.FacesMessage;  
51 -import javax.faces.component.UIViewRoot;  
52 -import javax.faces.context.FacesContext;  
53 -import javax.faces.convert.Converter;  
54 -  
55 -import org.easymock.EasyMock;  
56 -import org.junit.Before;  
57 -import org.junit.Test;  
58 -import org.junit.runner.RunWith;  
59 -import org.powermock.api.easymock.PowerMock;  
60 -import org.powermock.core.classloader.annotations.PrepareForTest;  
61 -import org.powermock.modules.junit4.PowerMockRunner;  
62 -  
63 -import br.gov.frameworkdemoiselle.exception.ApplicationException;  
64 -import br.gov.frameworkdemoiselle.message.DefaultMessage;  
65 -import br.gov.frameworkdemoiselle.message.Message;  
66 -import br.gov.frameworkdemoiselle.message.SeverityType;  
67 -  
68 -import com.sun.faces.util.Util;  
69 -  
70 -@RunWith(PowerMockRunner.class)  
71 -@PrepareForTest({ Beans.class, Strings.class, Converter.class, Util.class, ResourceBundle.class })  
72 -public class FacesTest {  
73 -  
74 - private FacesContext facesContext;  
75 -  
76 - private Faces faces;  
77 -  
78 - @Before  
79 - public void before() {  
80 - faces = new Faces();  
81 -  
82 - PowerMock.mockStatic(Beans.class);  
83 - facesContext = PowerMock.createMock(FacesContext.class);  
84 - }  
85 -  
86 - @SuppressWarnings("static-access")  
87 - @Test  
88 - public void testAddMessage() {  
89 - expect(Beans.getReference(ResourceBundle.class)).andReturn(null).anyTimes();  
90 - expect(Beans.getReference(FacesContext.class)).andReturn(facesContext).anyTimes();  
91 -  
92 - facesContext.addMessage(EasyMock.anyObject(String.class), EasyMock.anyObject(FacesMessage.class));  
93 - EasyMock.expectLastCall().times(5);  
94 -  
95 - replayAll();  
96 -  
97 - DefaultMessage message = new DefaultMessage("text") {  
98 -  
99 - @Override  
100 - public String toString() {  
101 - return "Message";  
102 - }  
103 -  
104 - };  
105 -  
106 - List<Message> messages = new ArrayList<Message>();  
107 - messages.add(message);  
108 -  
109 - faces.addMessages(null);  
110 - faces.addMessages(messages);  
111 - faces.addMessage(message);  
112 - faces.addMessage("clientId", message);  
113 - faces.addMessage("clientId", new MyException());  
114 - faces.addMessage(new MyException());  
115 - verifyAll();  
116 - }  
117 -  
118 - @SuppressWarnings("static-access")  
119 - @Test  
120 - public void testParseSeverity() {  
121 - assertEquals(faces.parse(SeverityType.ERROR), FacesMessage.SEVERITY_ERROR);  
122 - assertEquals(faces.parse(SeverityType.FATAL), FacesMessage.SEVERITY_FATAL);  
123 - assertEquals(faces.parse(SeverityType.INFO), FacesMessage.SEVERITY_INFO);  
124 - assertEquals(faces.parse(SeverityType.WARN), FacesMessage.SEVERITY_WARN);  
125 - }  
126 -  
127 - @SuppressWarnings("static-access")  
128 - @Test  
129 - public void testParseThrowable() {  
130 - FacesMessage facesMessage = faces.parse(new MyException());  
131 - assertEquals(facesMessage.getSeverity(), FacesMessage.SEVERITY_INFO);  
132 - assertEquals(facesMessage.getSummary(), "MESSAGE");  
133 -  
134 - facesMessage = faces.parse(new Exception());  
135 - assertEquals(facesMessage.getSeverity(), FacesMessage.SEVERITY_ERROR);  
136 - assertEquals(facesMessage.getSummary(), "java.lang.Exception");  
137 - }  
138 -  
139 - @SuppressWarnings("static-access")  
140 - @Test  
141 - public void testConvertNull() {  
142 - PowerMock.mockStatic(Strings.class);  
143 -  
144 - Converter converter = PowerMock.createMock(Converter.class);  
145 - expect(Strings.isEmpty(EasyMock.anyObject(String.class))).andReturn(true);  
146 -  
147 - replayAll();  
148 - String object = (String) faces.convert("value", converter);  
149 - assertEquals(null, object);  
150 - verifyAll();  
151 - }  
152 -  
153 - @SuppressWarnings("static-access")  
154 - @Test  
155 - public void testConvert() {  
156 - PowerMock.mockStatic(Strings.class);  
157 -  
158 - expect(Beans.getReference(FacesContext.class)).andReturn(facesContext).times(2);  
159 -  
160 - Converter converter = PowerMock.createMock(Converter.class);  
161 - expect(Strings.isEmpty(EasyMock.anyObject(String.class))).andReturn(false).times(2);  
162 - expect(  
163 - converter.getAsObject(EasyMock.anyObject(FacesContext.class), EasyMock.anyObject(UIViewRoot.class),  
164 - EasyMock.anyObject(String.class))).andReturn("THAT");  
165 - expect(facesContext.getViewRoot()).andReturn(null);  
166 -  
167 - replayAll();  
168 - String object = (String) faces.convert("value", converter);  
169 - assertEquals("THAT", object);  
170 -  
171 - object = (String) faces.convert("value", null);  
172 - assertEquals("value", object);  
173 -  
174 - verifyAll();  
175 - }  
176 -  
177 - @SuppressWarnings("static-access")  
178 - @Test  
179 - public void testGetConverter() {  
180 - Application application = PowerMock.createMock(Application.class);  
181 - Converter converter = PowerMock.createMock(Converter.class);  
182 - PowerMock.mockStatic(Util.class);  
183 -  
184 - expect(Beans.getReference(FacesContext.class)).andReturn(facesContext);  
185 - expect(facesContext.getApplication()).andReturn(application);  
186 - expect(application.createConverter(getClass())).andReturn(converter);  
187 -  
188 - replayAll();  
189 - assertEquals(converter, faces.getConverter(getClass()));  
190 - verifyAll();  
191 - }  
192 -  
193 - @SuppressWarnings("static-access")  
194 - @Test  
195 - public void testGetViewMap() {  
196 - UIViewRoot uiViewRoot = PowerMock.createMock(UIViewRoot.class);  
197 - expect(Beans.getReference(FacesContext.class)).andReturn(facesContext);  
198 - expect(facesContext.getViewRoot()).andReturn(uiViewRoot);  
199 -  
200 - Map<String, Object> map = new HashMap<String, Object>();  
201 - expect(uiViewRoot.getViewMap(true)).andReturn(map);  
202 -  
203 - replayAll();  
204 - assertEquals(map, faces.getViewMap());  
205 - verifyAll();  
206 - }  
207 -  
208 - @SuppressWarnings("serial")  
209 - @ApplicationException(severity = SeverityType.INFO)  
210 - class MyException extends Exception {  
211 -  
212 - @Override  
213 - public String getMessage() {  
214 - return "MESSAGE";  
215 - }  
216 -  
217 - }  
218 -  
219 -} 1 +///*
  2 +// * Demoiselle Framework
  3 +// * Copyright (C) 2010 SERPRO
  4 +// * ----------------------------------------------------------------------------
  5 +// * This file is part of Demoiselle Framework.
  6 +// *
  7 +// * Demoiselle Framework is free software; you can redistribute it and/or
  8 +// * modify it under the terms of the GNU Lesser General Public License version 3
  9 +// * as published by the Free Software Foundation.
  10 +// *
  11 +// * This program is distributed in the hope that it will be useful,
  12 +// * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +// * GNU General Public License for more details.
  15 +// *
  16 +// * You should have received a copy of the GNU Lesser General Public License version 3
  17 +// * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 +// * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 +// * Fifth Floor, Boston, MA 02110-1301, USA.
  20 +// * ----------------------------------------------------------------------------
  21 +// * Este arquivo é parte do Framework Demoiselle.
  22 +// *
  23 +// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 +// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 +// * do Software Livre (FSF).
  26 +// *
  27 +// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 +// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 +// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 +// * para maiores detalhes.
  31 +// *
  32 +// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 +// * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 +// * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 +// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +// */
  37 +//package br.gov.frameworkdemoiselle.util;
  38 +//
  39 +//import static junit.framework.Assert.assertEquals;
  40 +//import static org.easymock.EasyMock.expect;
  41 +//import static org.powermock.api.easymock.PowerMock.replayAll;
  42 +//import static org.powermock.api.easymock.PowerMock.verifyAll;
  43 +//
  44 +//import java.util.ArrayList;
  45 +//import java.util.HashMap;
  46 +//import java.util.List;
  47 +//import java.util.Map;
  48 +//
  49 +//import javax.faces.application.Application;
  50 +//import javax.faces.application.FacesMessage;
  51 +//import javax.faces.component.UIViewRoot;
  52 +//import javax.faces.context.FacesContext;
  53 +//import javax.faces.convert.Converter;
  54 +//
  55 +//import org.easymock.EasyMock;
  56 +//import org.junit.Before;
  57 +//import org.junit.Test;
  58 +//import org.junit.runner.RunWith;
  59 +//import org.powermock.api.easymock.PowerMock;
  60 +//import org.powermock.core.classloader.annotations.PrepareForTest;
  61 +//import org.powermock.modules.junit4.PowerMockRunner;
  62 +//
  63 +//import br.gov.frameworkdemoiselle.exception.ApplicationException;
  64 +//import br.gov.frameworkdemoiselle.message.DefaultMessage;
  65 +//import br.gov.frameworkdemoiselle.message.Message;
  66 +//import br.gov.frameworkdemoiselle.message.SeverityType;
  67 +//
  68 +//import com.sun.faces.util.Util;
  69 +//
  70 +//@RunWith(PowerMockRunner.class)
  71 +//@PrepareForTest({ Beans.class, Strings.class, Converter.class, Util.class, ResourceBundle.class })
  72 +//public class FacesTest {
  73 +//
  74 +// private FacesContext facesContext;
  75 +//
  76 +// private Faces faces;
  77 +//
  78 +// @Before
  79 +// public void before() {
  80 +// faces = new Faces();
  81 +//
  82 +// PowerMock.mockStatic(Beans.class);
  83 +// facesContext = PowerMock.createMock(FacesContext.class);
  84 +// }
  85 +//
  86 +// @SuppressWarnings("static-access")
  87 +// @Test
  88 +// public void testAddMessage() {
  89 +// expect(Beans.getReference(ResourceBundle.class)).andReturn(null).anyTimes();
  90 +// expect(Beans.getReference(FacesContext.class)).andReturn(facesContext).anyTimes();
  91 +//
  92 +// facesContext.addMessage(EasyMock.anyObject(String.class), EasyMock.anyObject(FacesMessage.class));
  93 +// EasyMock.expectLastCall().times(5);
  94 +//
  95 +// replayAll();
  96 +//
  97 +// DefaultMessage message = new DefaultMessage("text") {
  98 +//
  99 +// @Override
  100 +// public String toString() {
  101 +// return "Message";
  102 +// }
  103 +//
  104 +// };
  105 +//
  106 +// List<Message> messages = new ArrayList<Message>();
  107 +// messages.add(message);
  108 +//
  109 +// faces.addMessages(null);
  110 +// faces.addMessages(messages);
  111 +// faces.addMessage(message);
  112 +// faces.addMessage("clientId", message);
  113 +// faces.addMessage("clientId", new MyException());
  114 +// faces.addMessage(new MyException());
  115 +// verifyAll();
  116 +// }
  117 +//
  118 +// @SuppressWarnings("static-access")
  119 +// @Test
  120 +// public void testParseSeverity() {
  121 +// assertEquals(faces.parse(SeverityType.ERROR), FacesMessage.SEVERITY_ERROR);
  122 +// assertEquals(faces.parse(SeverityType.FATAL), FacesMessage.SEVERITY_FATAL);
  123 +// assertEquals(faces.parse(SeverityType.INFO), FacesMessage.SEVERITY_INFO);
  124 +// assertEquals(faces.parse(SeverityType.WARN), FacesMessage.SEVERITY_WARN);
  125 +// }
  126 +//
  127 +// @SuppressWarnings("static-access")
  128 +// @Test
  129 +// public void testParseThrowable() {
  130 +// FacesMessage facesMessage = faces.parse(new MyException());
  131 +// assertEquals(facesMessage.getSeverity(), FacesMessage.SEVERITY_INFO);
  132 +// assertEquals(facesMessage.getSummary(), "MESSAGE");
  133 +//
  134 +// facesMessage = faces.parse(new Exception());
  135 +// assertEquals(facesMessage.getSeverity(), FacesMessage.SEVERITY_ERROR);
  136 +// assertEquals(facesMessage.getSummary(), "java.lang.Exception");
  137 +// }
  138 +//
  139 +// @SuppressWarnings("static-access")
  140 +// @Test
  141 +// public void testConvertNull() {
  142 +// PowerMock.mockStatic(Strings.class);
  143 +//
  144 +// Converter converter = PowerMock.createMock(Converter.class);
  145 +// expect(Strings.isEmpty(EasyMock.anyObject(String.class))).andReturn(true);
  146 +//
  147 +// replayAll();
  148 +// String object = (String) faces.convert("value", converter);
  149 +// assertEquals(null, object);
  150 +// verifyAll();
  151 +// }
  152 +//
  153 +// @SuppressWarnings("static-access")
  154 +// @Test
  155 +// public void testConvert() {
  156 +// PowerMock.mockStatic(Strings.class);
  157 +//
  158 +// expect(Beans.getReference(FacesContext.class)).andReturn(facesContext).times(2);
  159 +//
  160 +// Converter converter = PowerMock.createMock(Converter.class);
  161 +// expect(Strings.isEmpty(EasyMock.anyObject(String.class))).andReturn(false).times(2);
  162 +// expect(
  163 +// converter.getAsObject(EasyMock.anyObject(FacesContext.class), EasyMock.anyObject(UIViewRoot.class),
  164 +// EasyMock.anyObject(String.class))).andReturn("THAT");
  165 +// expect(facesContext.getViewRoot()).andReturn(null);
  166 +//
  167 +// replayAll();
  168 +// String object = (String) faces.convert("value", converter);
  169 +// assertEquals("THAT", object);
  170 +//
  171 +// object = (String) faces.convert("value", null);
  172 +// assertEquals("value", object);
  173 +//
  174 +// verifyAll();
  175 +// }
  176 +//
  177 +// @SuppressWarnings("static-access")
  178 +// @Test
  179 +// public void testGetConverter() {
  180 +// Application application = PowerMock.createMock(Application.class);
  181 +// Converter converter = PowerMock.createMock(Converter.class);
  182 +// PowerMock.mockStatic(Util.class);
  183 +//
  184 +// expect(Beans.getReference(FacesContext.class)).andReturn(facesContext);
  185 +// expect(facesContext.getApplication()).andReturn(application);
  186 +// expect(application.createConverter(getClass())).andReturn(converter);
  187 +//
  188 +// replayAll();
  189 +// assertEquals(converter, faces.getConverter(getClass()));
  190 +// verifyAll();
  191 +// }
  192 +//
  193 +// @SuppressWarnings("static-access")
  194 +// @Test
  195 +// public void testGetViewMap() {
  196 +// UIViewRoot uiViewRoot = PowerMock.createMock(UIViewRoot.class);
  197 +// expect(Beans.getReference(FacesContext.class)).andReturn(facesContext);
  198 +// expect(facesContext.getViewRoot()).andReturn(uiViewRoot);
  199 +//
  200 +// Map<String, Object> map = new HashMap<String, Object>();
  201 +// expect(uiViewRoot.getViewMap(true)).andReturn(map);
  202 +//
  203 +// replayAll();
  204 +// assertEquals(map, faces.getViewMap());
  205 +// verifyAll();
  206 +// }
  207 +//
  208 +// @SuppressWarnings("serial")
  209 +// @ApplicationException(severity = SeverityType.INFO)
  210 +// class MyException extends Exception {
  211 +//
  212 +// @Override
  213 +// public String getMessage() {
  214 +// return "MESSAGE";
  215 +// }
  216 +//
  217 +// }
  218 +//
  219 +//}