Commit e140c1fc011aeca7b7eee9ce64027414f5f3f4ec
Exists in
master
Merge branch '2.3' of ssh://git@github.com/demoiselle/framework.git into 2.3
Showing
16 changed files
with
243 additions
and
203 deletions
Show diff stats
example/security/src/main/resources/demoiselle.properties
... | ... | @@ -32,6 +32,3 @@ |
32 | 32 | # "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> |
33 | 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., |
34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
35 | - | |
36 | -#frameworkdemoiselle.security.authenticator.class=example.MyAuthenticator | |
37 | -#frameworkdemoiselle.security.authorizer.class=example.MyAuthorizer | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
... | ... | @@ -62,7 +62,6 @@ import br.gov.frameworkdemoiselle.internal.context.Contexts; |
62 | 62 | import br.gov.frameworkdemoiselle.internal.context.CustomContext; |
63 | 63 | import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; |
64 | 64 | import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor; |
65 | -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | |
66 | 65 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; |
67 | 66 | import br.gov.frameworkdemoiselle.util.Reflections; |
68 | 67 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
... | ... | @@ -81,24 +80,16 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
81 | 80 | |
82 | 81 | private boolean registered = false; |
83 | 82 | |
84 | - private static Logger logger; | |
83 | + private ResourceBundle bundle; | |
85 | 84 | |
86 | - private static ResourceBundle bundle; | |
85 | + protected abstract Logger getLogger(); | |
87 | 86 | |
88 | - protected static Logger getLogger() { | |
89 | - if (logger == null) { | |
90 | - logger = LoggerProducer.create(AbstractLifecycleBootstrap.class); | |
87 | + protected ResourceBundle getBundle() { | |
88 | + if (this.bundle == null) { | |
89 | + this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | |
91 | 90 | } |
92 | 91 | |
93 | - return logger; | |
94 | - } | |
95 | - | |
96 | - protected static ResourceBundle getBundle() { | |
97 | - if (bundle == null) { | |
98 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | |
99 | - } | |
100 | - | |
101 | - return bundle; | |
92 | + return this.bundle; | |
102 | 93 | } |
103 | 94 | |
104 | 95 | protected <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractStrategyBootstrap.java
... | ... | @@ -11,24 +11,15 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; |
11 | 11 | |
12 | 12 | import org.slf4j.Logger; |
13 | 13 | |
14 | -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | |
15 | 14 | import br.gov.frameworkdemoiselle.util.Reflections; |
16 | 15 | |
17 | -public class AbstractStrategyBootstrap<I> implements Extension { | |
16 | +public abstract class AbstractStrategyBootstrap<I> implements Extension { | |
18 | 17 | |
19 | 18 | private Class<? extends I> strategyClass; |
20 | 19 | |
21 | 20 | private List<Class<? extends I>> cache; |
22 | 21 | |
23 | - private static Logger logger; | |
24 | - | |
25 | - protected static Logger getLogger() { | |
26 | - if (logger == null) { | |
27 | - logger = LoggerProducer.create(AbstractStrategyBootstrap.class); | |
28 | - } | |
29 | - | |
30 | - return logger; | |
31 | - } | |
22 | + protected abstract Logger getLogger(); | |
32 | 23 | |
33 | 24 | protected Class<? extends I> getStrategyClass() { |
34 | 25 | if (this.strategyClass == null) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthenticatorBootstrap.java
... | ... | @@ -43,9 +43,10 @@ import br.gov.frameworkdemoiselle.security.Authenticator; |
43 | 43 | |
44 | 44 | public class AuthenticatorBootstrap extends AbstractStrategyBootstrap<Authenticator> { |
45 | 45 | |
46 | - private static Logger logger; | |
46 | + private Logger logger; | |
47 | 47 | |
48 | - protected static Logger getLogger() { | |
48 | + @Override | |
49 | + protected Logger getLogger() { | |
49 | 50 | if (logger == null) { |
50 | 51 | logger = LoggerProducer.create(AuthenticatorBootstrap.class); |
51 | 52 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AuthorizerBootstrap.java
... | ... | @@ -43,9 +43,10 @@ import br.gov.frameworkdemoiselle.security.Authorizer; |
43 | 43 | |
44 | 44 | public class AuthorizerBootstrap extends AbstractStrategyBootstrap<Authorizer> { |
45 | 45 | |
46 | - private static Logger logger; | |
46 | + private Logger logger; | |
47 | 47 | |
48 | - protected static Logger getLogger() { | |
48 | + @Override | |
49 | + protected Logger getLogger() { | |
49 | 50 | if (logger == null) { |
50 | 51 | logger = LoggerProducer.create(AuthorizerBootstrap.class); |
51 | 52 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
... | ... | @@ -60,24 +60,24 @@ public class CoreBootstrap implements Extension { |
60 | 60 | |
61 | 61 | private final Map<Class<?>, AnnotatedType<?>> beans = new HashMap<Class<?>, AnnotatedType<?>>(); |
62 | 62 | |
63 | - private static Logger logger; | |
63 | + private Logger logger; | |
64 | 64 | |
65 | - private static ResourceBundle bundle; | |
65 | + private ResourceBundle bundle; | |
66 | 66 | |
67 | - private static Logger getLogger() { | |
68 | - if (logger == null) { | |
69 | - logger = LoggerProducer.create(CoreBootstrap.class); | |
67 | + private Logger getLogger() { | |
68 | + if (this.logger == null) { | |
69 | + this.logger = LoggerProducer.create(CoreBootstrap.class); | |
70 | 70 | } |
71 | 71 | |
72 | - return logger; | |
72 | + return this.logger; | |
73 | 73 | } |
74 | 74 | |
75 | - private static ResourceBundle getBundle() { | |
76 | - if (bundle == null) { | |
77 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | |
75 | + private ResourceBundle getBundle() { | |
76 | + if (this.bundle == null) { | |
77 | + this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | |
78 | 78 | } |
79 | 79 | |
80 | - return bundle; | |
80 | + return this.bundle; | |
81 | 81 | } |
82 | 82 | |
83 | 83 | public boolean isAnnotatedType(Class<?> type) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrap.java
... | ... | @@ -38,6 +38,9 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; |
38 | 38 | |
39 | 39 | import javax.enterprise.event.Observes; |
40 | 40 | |
41 | +import org.slf4j.Logger; | |
42 | + | |
43 | +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | |
41 | 44 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
42 | 45 | import br.gov.frameworkdemoiselle.lifecycle.Shutdown; |
43 | 46 | |
... | ... | @@ -46,6 +49,17 @@ import br.gov.frameworkdemoiselle.lifecycle.Shutdown; |
46 | 49 | */ |
47 | 50 | public class ShutdownBootstrap extends AbstractLifecycleBootstrap<Shutdown> { |
48 | 51 | |
52 | + private Logger logger; | |
53 | + | |
54 | + @Override | |
55 | + protected Logger getLogger() { | |
56 | + if (logger == null) { | |
57 | + logger = LoggerProducer.create(ShutdownBootstrap.class); | |
58 | + } | |
59 | + | |
60 | + return logger; | |
61 | + } | |
62 | + | |
49 | 63 | public void shutdown(@Observes AfterShutdownProccess event) { |
50 | 64 | proccessEvent(); |
51 | 65 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrap.java
... | ... | @@ -38,6 +38,9 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; |
38 | 38 | |
39 | 39 | import javax.enterprise.event.Observes; |
40 | 40 | |
41 | +import org.slf4j.Logger; | |
42 | + | |
43 | +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | |
41 | 44 | import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; |
42 | 45 | import br.gov.frameworkdemoiselle.lifecycle.Startup; |
43 | 46 | |
... | ... | @@ -46,6 +49,17 @@ import br.gov.frameworkdemoiselle.lifecycle.Startup; |
46 | 49 | */ |
47 | 50 | public class StartupBootstrap extends AbstractLifecycleBootstrap<Startup> { |
48 | 51 | |
52 | + private Logger logger; | |
53 | + | |
54 | + @Override | |
55 | + protected Logger getLogger() { | |
56 | + if (logger == null) { | |
57 | + logger = LoggerProducer.create(StartupBootstrap.class); | |
58 | + } | |
59 | + | |
60 | + return logger; | |
61 | + } | |
62 | + | |
49 | 63 | public void startup(@Observes AfterStartupProccess event) { |
50 | 64 | proccessEvent(); |
51 | 65 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java
... | ... | @@ -36,7 +36,21 @@ |
36 | 36 | */ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
38 | 38 | |
39 | +import org.slf4j.Logger; | |
40 | + | |
41 | +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | |
39 | 42 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
40 | 43 | |
41 | 44 | public class TransactionBootstrap extends AbstractStrategyBootstrap<Transaction> { |
45 | + | |
46 | + private Logger logger; | |
47 | + | |
48 | + @Override | |
49 | + protected Logger getLogger() { | |
50 | + if (logger == null) { | |
51 | + logger = LoggerProducer.create(TransactionBootstrap.class); | |
52 | + } | |
53 | + | |
54 | + return logger; | |
55 | + } | |
42 | 56 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/template/DelegateCrud.java
... | ... | @@ -53,6 +53,12 @@ public class DelegateCrud<T, I, C extends Crud<T, I>> implements Crud<T, I> { |
53 | 53 | |
54 | 54 | private transient C delegate; |
55 | 55 | |
56 | + /** | |
57 | + * Removes a instance from delegate. | |
58 | + * | |
59 | + * @param id | |
60 | + * Entity with the given identifier | |
61 | + */ | |
56 | 62 | @Override |
57 | 63 | public void delete(final I id) { |
58 | 64 | if (isRunningTransactionalOperations()) { |
... | ... | @@ -71,6 +77,12 @@ public class DelegateCrud<T, I, C extends Crud<T, I>> implements Crud<T, I> { |
71 | 77 | getDelegate().delete(id); |
72 | 78 | } |
73 | 79 | |
80 | + /** | |
81 | + * Removes a list of instances from delegate. | |
82 | + * | |
83 | + * @param ids | |
84 | + * List of entities identifiers | |
85 | + */ | |
74 | 86 | public void delete(final List<I> ids) { |
75 | 87 | if (isRunningTransactionalOperations()) { |
76 | 88 | transactionalDelete(ids); |
... | ... | @@ -91,6 +103,11 @@ public class DelegateCrud<T, I, C extends Crud<T, I>> implements Crud<T, I> { |
91 | 103 | } |
92 | 104 | } |
93 | 105 | |
106 | + /** | |
107 | + * Gets the results from delegate. | |
108 | + * | |
109 | + * @return The list of matched query results. | |
110 | + */ | |
94 | 111 | @Override |
95 | 112 | public List<T> findAll() { |
96 | 113 | return getDelegate().findAll(); |
... | ... | @@ -112,6 +129,12 @@ public class DelegateCrud<T, I, C extends Crud<T, I>> implements Crud<T, I> { |
112 | 129 | return this.delegateClass; |
113 | 130 | } |
114 | 131 | |
132 | + /** | |
133 | + * Delegates the insert operation of the given instance. | |
134 | + * | |
135 | + * @param bean | |
136 | + * A entity to be inserted by the delegate | |
137 | + */ | |
115 | 138 | @Override |
116 | 139 | public void insert(final T bean) { |
117 | 140 | if (isRunningTransactionalOperations()) { |
... | ... | @@ -130,11 +153,22 @@ public class DelegateCrud<T, I, C extends Crud<T, I>> implements Crud<T, I> { |
130 | 153 | getDelegate().insert(bean); |
131 | 154 | } |
132 | 155 | |
156 | + /** | |
157 | + * Returns the instance of the given entity with the given identifier | |
158 | + * | |
159 | + * @return The instance | |
160 | + */ | |
133 | 161 | @Override |
134 | 162 | public T load(final I id) { |
135 | 163 | return getDelegate().load(id); |
136 | 164 | } |
137 | 165 | |
166 | + /** | |
167 | + * Delegates the update operation of the given instance. | |
168 | + * | |
169 | + * @param bean | |
170 | + * The instance containing the updated state. | |
171 | + */ | |
138 | 172 | @Override |
139 | 173 | public void update(final T bean) { |
140 | 174 | if (isRunningTransactionalOperations()) { | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/PaginationContextImplTest.java
... | ... | @@ -35,6 +35,7 @@ |
35 | 35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
36 | 36 | */ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
38 | + | |
38 | 39 | import org.junit.Ignore; |
39 | 40 | import static org.junit.Assert.assertEquals; |
40 | 41 | import static org.junit.Assert.assertNotNull; |
... | ... | @@ -55,7 +56,7 @@ import org.powermock.reflect.Whitebox; |
55 | 56 | import br.gov.frameworkdemoiselle.internal.configuration.PaginationConfig; |
56 | 57 | import br.gov.frameworkdemoiselle.pagination.Pagination; |
57 | 58 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; |
58 | -@Ignore | |
59 | + | |
59 | 60 | @RunWith(PowerMockRunner.class) |
60 | 61 | public class PaginationContextImplTest { |
61 | 62 | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/PaginationImplTest.java
... | ... | @@ -35,6 +35,7 @@ |
35 | 35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
36 | 36 | */ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
38 | + | |
38 | 39 | import org.junit.Ignore; |
39 | 40 | import static org.junit.Assert.assertEquals; |
40 | 41 | import static org.junit.Assert.fail; |
... | ... | @@ -49,7 +50,7 @@ import br.gov.frameworkdemoiselle.util.Strings; |
49 | 50 | /** |
50 | 51 | * @author SERPRO |
51 | 52 | */ |
52 | -@Ignore | |
53 | + | |
53 | 54 | public class PaginationImplTest { |
54 | 55 | |
55 | 56 | private Pagination pagination; |
... | ... | @@ -171,7 +172,7 @@ public class PaginationImplTest { |
171 | 172 | fail(); |
172 | 173 | } catch (IndexOutOfBoundsException cause) { |
173 | 174 | } |
174 | - | |
175 | + | |
175 | 176 | try { |
176 | 177 | pagination.setTotalResults(0); |
177 | 178 | pagination.setFirstResult(0); |
... | ... | @@ -314,7 +315,7 @@ public class PaginationImplTest { |
314 | 315 | pagination.setCurrentPage(9); |
315 | 316 | assertEquals(90, pagination.getFirstResult()); |
316 | 317 | } |
317 | - | |
318 | + | |
318 | 319 | @Test |
319 | 320 | public void testToStringFormat() { |
320 | 321 | assertEquals(Strings.toString(pagination), pagination.toString()); | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/util/ResourceBundleTest.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 org.easymock.EasyMock.createMock; | |
40 | -//import static org.easymock.EasyMock.replay; | |
41 | -//import static org.easymock.EasyMock.verify; | |
42 | -//import static org.junit.Assert.assertEquals; | |
43 | -//import static org.junit.Assert.assertFalse; | |
44 | -//import static org.junit.Assert.assertNull; | |
45 | -//import static org.junit.Assert.assertTrue; | |
46 | -// | |
47 | -//import java.util.Enumeration; | |
48 | -//import java.util.ListResourceBundle; | |
49 | -// | |
50 | -//import junit.framework.Assert; | |
51 | -// | |
52 | -//import org.junit.Before; | |
53 | -//import org.junit.Test; | |
54 | -// | |
55 | -//public class ResourceBundleTest { | |
56 | -// | |
57 | -// /** | |
58 | -// * This is a workaround to mock java.util.ResourceBundle. Since getString(key) method is defined as final, there is | |
59 | -// * no way to extend and override it. For that reason, setting expectations (i.e. expect(...)) won't work. | |
60 | -// */ | |
61 | -// class MockResourceBundle extends ListResourceBundle { | |
62 | -// | |
63 | -// private Object[][] contents = new Object[][] { { "msgWithoutParams", "no params" }, | |
64 | -// { "msgWithParams", "params: {0}, {1}" } }; | |
65 | -// | |
66 | -// protected Object[][] getContents() { | |
67 | -// return contents; | |
68 | -// } | |
69 | -// | |
70 | -// }; | |
71 | -// | |
72 | -// private ResourceBundle resourceBundle; | |
73 | -// | |
74 | -// private java.util.ResourceBundle mockResourceBundle; | |
75 | -// | |
76 | -// @Before | |
77 | -// public void setUp() throws Exception { | |
78 | -// mockResourceBundle = new MockResourceBundle(); | |
79 | -// resourceBundle = new ResourceBundle(mockResourceBundle); | |
80 | -// } | |
81 | -// | |
82 | -// @Test | |
83 | -// public void containsKey() { | |
84 | -// assertTrue(resourceBundle.containsKey("msgWithoutParams")); | |
85 | -// | |
86 | -// assertFalse(resourceBundle.containsKey("inexistentKey")); | |
87 | -// } | |
88 | -// | |
89 | -// @Test | |
90 | -// public void getKeys() { | |
91 | -// int keyCount = 0; | |
92 | -// | |
93 | -// Enumeration<String> e = resourceBundle.getKeys(); | |
94 | -// | |
95 | -// while (e.hasMoreElements()) { | |
96 | -// keyCount++; | |
97 | -// e.nextElement(); | |
98 | -// } | |
99 | -// | |
100 | -// assertEquals(resourceBundle.keySet().size(), keyCount); | |
101 | -// } | |
102 | -// | |
103 | -// @Test | |
104 | -// public void testGetLocale() { | |
105 | -// assertNull(resourceBundle.getLocale()); | |
106 | -// } | |
107 | -// | |
108 | -// @Test | |
109 | -// public void testKeySet() { | |
110 | -// assertEquals(2, resourceBundle.keySet().size()); | |
111 | -// } | |
112 | -// | |
113 | -// @Test | |
114 | -// public void getString() { | |
115 | -// assertEquals("no params", resourceBundle.getString("msgWithoutParams")); | |
116 | -// | |
117 | -// assertEquals("params: a, b", resourceBundle.getString("msgWithParams", "a", "b")); | |
118 | -// | |
119 | -// assertEquals("params: {0}, {1}", resourceBundle.getString("msgWithParams")); | |
120 | -// } | |
121 | -// | |
122 | -// /** | |
123 | -// * For this test, java.util.ResourceBundle is mocked to force an exception. Since the getString method is called | |
124 | -// * from the actual ResourceBundle, not from the mock, it tries to find a handleGetObject method that doesn't exist. | |
125 | -// * | |
126 | -// * @throws Exception | |
127 | -// */ | |
128 | -// @Test(expected = RuntimeException.class) | |
129 | -// public void getStringWhenHandleGetObjectThrowsException() { | |
130 | -// mockResourceBundle = createMock(java.util.ResourceBundle.class); | |
131 | -// resourceBundle = new ResourceBundle(mockResourceBundle); | |
132 | -// | |
133 | -// replay(mockResourceBundle); | |
134 | -// | |
135 | -// resourceBundle.getString("msgWithParams"); | |
136 | -// | |
137 | -// verify(mockResourceBundle); | |
138 | -// | |
139 | -// Assert.fail(); | |
140 | -// } | |
141 | -// | |
142 | -//} | |
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 org.junit.Assert.assertEquals; | |
40 | +import static org.junit.Assert.assertFalse; | |
41 | +import static org.junit.Assert.assertTrue; | |
42 | + | |
43 | +import java.util.Enumeration; | |
44 | +import java.util.Locale; | |
45 | + | |
46 | +import org.junit.Before; | |
47 | +import org.junit.Test; | |
48 | + | |
49 | +public class ResourceBundleTest { | |
50 | + | |
51 | + /** | |
52 | + * This is a workaround to mock java.util.ResourceBundle. Since getString(key) method is defined as final, there is | |
53 | + * no way to extend and override it. For that reason, setting expectations (i.e. expect(...)) won't work. | |
54 | + */ | |
55 | + private ResourceBundle resourceBundle; | |
56 | + | |
57 | + @Before | |
58 | + public void setUp() throws Exception { | |
59 | + resourceBundle = new ResourceBundle("resource-bundle", new Locale("pt")); | |
60 | + } | |
61 | + | |
62 | + @Test | |
63 | + public void containsKey() { | |
64 | + assertTrue(resourceBundle.containsKey("msgWithoutParams")); | |
65 | + | |
66 | + assertFalse(resourceBundle.containsKey("inexistentKey")); | |
67 | + } | |
68 | + | |
69 | + @Test | |
70 | + public void getKeys() { | |
71 | + int keyCount = 0; | |
72 | + | |
73 | + Enumeration<String> e = resourceBundle.getKeys(); | |
74 | + | |
75 | + while (e.hasMoreElements()) { | |
76 | + keyCount++; | |
77 | + e.nextElement(); | |
78 | + } | |
79 | + | |
80 | + assertEquals(resourceBundle.keySet().size(), keyCount); | |
81 | + } | |
82 | + | |
83 | + @Test | |
84 | + public void testGetLocale() { | |
85 | + assertEquals(resourceBundle.getLocale(), new Locale("pt")); | |
86 | + } | |
87 | + | |
88 | + @Test | |
89 | + public void testKeySet() { | |
90 | + assertEquals(2, resourceBundle.keySet().size()); | |
91 | + } | |
92 | + | |
93 | + @Test | |
94 | + public void getString() { | |
95 | + assertEquals("no params", resourceBundle.getString("msgWithoutParams")); | |
96 | + | |
97 | + assertEquals("params: a, b", resourceBundle.getString("msgWithParams", "a", "b")); | |
98 | + | |
99 | + assertEquals("params: {0}, {1}", resourceBundle.getString("msgWithParams")); | |
100 | + } | |
101 | + | |
102 | + /** | |
103 | + * For this test, java.util.ResourceBundle is mocked to force an exception. Since the getString method is called | |
104 | + * from the actual ResourceBundle, not from the mock, it tries to find a handleGetObject method that doesn't exist. | |
105 | + * | |
106 | + * @throws Exception | |
107 | + */ | |
108 | + // @Test(expected = RuntimeException.class) | |
109 | + // public void getStringWhenHandleGetObjectThrowsException() { | |
110 | + // mockResourceBundle = createMock(java.util.ResourceBundle.class); | |
111 | + // resourceBundle = new ResourceBundle(mockResourceBundle); | |
112 | + // | |
113 | + // replay(mockResourceBundle); | |
114 | + // | |
115 | + // resourceBundle.getString("msgWithParams"); | |
116 | + // | |
117 | + // verify(mockResourceBundle); | |
118 | + // | |
119 | + // Assert.fail(); | |
120 | + // } | |
121 | + | |
122 | +} | ... | ... |
impl/core/src/test/resources/resource-bundle_pt.properties
0 → 100644
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/JsfBootstrap.java
... | ... | @@ -56,19 +56,18 @@ public class JsfBootstrap implements Extension { |
56 | 56 | private AfterBeanDiscovery afterBeanDiscoveryEvent; |
57 | 57 | |
58 | 58 | public void storeContexts(@Observes final AfterBeanDiscovery event) { |
59 | - tempContexts.add(new ViewContext()); | |
60 | - | |
61 | - afterBeanDiscoveryEvent = event; | |
59 | + this.tempContexts.add(new ViewContext()); | |
60 | + this.afterBeanDiscoveryEvent = event; | |
62 | 61 | } |
63 | 62 | |
64 | 63 | public void addContexts(@Observes final AfterDeploymentValidation event) { |
65 | - for (CustomContext tempContext : tempContexts) { | |
66 | - Contexts.add(tempContext, afterBeanDiscoveryEvent); | |
64 | + for (CustomContext tempContext : this.tempContexts) { | |
65 | + Contexts.add(tempContext, this.afterBeanDiscoveryEvent); | |
67 | 66 | } |
68 | 67 | } |
69 | 68 | |
70 | 69 | public void removeContexts(@Observes AfterShutdownProccess event) { |
71 | - for (CustomContext tempContext : tempContexts) { | |
70 | + for (CustomContext tempContext : this.tempContexts) { | |
72 | 71 | Contexts.remove(tempContext); |
73 | 72 | } |
74 | 73 | } | ... | ... |
impl/extension/se/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/SeBootstrap.java
... | ... | @@ -60,22 +60,22 @@ public class SeBootstrap implements Extension { |
60 | 60 | private AfterBeanDiscovery afterBeanDiscoveryEvent; |
61 | 61 | |
62 | 62 | public void storeContexts(@Observes final AfterBeanDiscovery event) { |
63 | - tempContexts.add(new ThreadLocalContext(ViewScoped.class)); | |
64 | - tempContexts.add(new ThreadLocalContext(SessionScoped.class)); | |
65 | - tempContexts.add(new ThreadLocalContext(ConversationScoped.class)); | |
66 | - tempContexts.add(new ThreadLocalContext(RequestScoped.class)); | |
63 | + this.tempContexts.add(new ThreadLocalContext(ViewScoped.class)); | |
64 | + this.tempContexts.add(new ThreadLocalContext(SessionScoped.class)); | |
65 | + this.tempContexts.add(new ThreadLocalContext(ConversationScoped.class)); | |
66 | + this.tempContexts.add(new ThreadLocalContext(RequestScoped.class)); | |
67 | 67 | |
68 | - afterBeanDiscoveryEvent = event; | |
68 | + this.afterBeanDiscoveryEvent = event; | |
69 | 69 | } |
70 | 70 | |
71 | 71 | public void addContexts(@Observes final AfterDeploymentValidation event) { |
72 | - for (CustomContext tempContext : tempContexts) { | |
73 | - Contexts.add(tempContext, afterBeanDiscoveryEvent); | |
72 | + for (CustomContext tempContext : this.tempContexts) { | |
73 | + Contexts.add(tempContext, this.afterBeanDiscoveryEvent); | |
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | 77 | public void removeContexts(@Observes AfterShutdownProccess event) { |
78 | - for (CustomContext tempContext : tempContexts) { | |
78 | + for (CustomContext tempContext : this.tempContexts) { | |
79 | 79 | Contexts.remove(tempContext); |
80 | 80 | } |
81 | 81 | } | ... | ... |