Commit 801bb4591e8b2142839f198bd6602b5f1b5bc484
Exists in
master
Merge branch '2.3' of ssh://git@github.com/demoiselle/framework.git into 2.3
Showing
10 changed files
with
732 additions
and
721 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java
@@ -82,7 +82,7 @@ public class ConfigurationLoader implements Serializable { | @@ -82,7 +82,7 @@ public class ConfigurationLoader implements Serializable { | ||
82 | private static ResourceBundle bundle; | 82 | private static ResourceBundle bundle; |
83 | 83 | ||
84 | private static Logger logger; | 84 | private static Logger logger; |
85 | - | 85 | + |
86 | /** | 86 | /** |
87 | * Loads a config class filling it with the corresponding values. | 87 | * Loads a config class filling it with the corresponding values. |
88 | * | 88 | * |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java
@@ -76,14 +76,7 @@ public class ResourceBundleProducer implements Serializable { | @@ -76,14 +76,7 @@ public class ResourceBundleProducer implements Serializable { | ||
76 | */ | 76 | */ |
77 | public static ResourceBundle create(String baseName, Locale locale) { | 77 | public static ResourceBundle create(String baseName, Locale locale) { |
78 | ResourceBundle bundle = null; | 78 | ResourceBundle bundle = null; |
79 | - | ||
80 | - try { | ||
81 | - bundle = new ResourceBundle(baseName, locale); | ||
82 | - | ||
83 | - } catch (MissingResourceException e) { | ||
84 | - throw new DemoiselleException("File " + baseName + " not found!"); | ||
85 | - } | ||
86 | - | 79 | + bundle = new ResourceBundle(baseName, locale); |
87 | return bundle; | 80 | return bundle; |
88 | } | 81 | } |
89 | 82 |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderTest.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.configuration; | ||
38 | -// | ||
39 | -//import static org.easymock.EasyMock.expect; | ||
40 | -//import static org.junit.Assert.assertEquals; | ||
41 | -//import static org.junit.Assert.assertNull; | ||
42 | -//import static org.junit.Assert.assertTrue; | ||
43 | -//import static org.junit.Assert.fail; | ||
44 | -//import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
45 | -// | ||
46 | -//import javax.validation.constraints.NotNull; | ||
47 | -// | ||
48 | -//import org.junit.After; | ||
49 | -//import org.junit.Before; | ||
50 | -//import org.junit.Test; | ||
51 | -//import org.junit.runner.RunWith; | ||
52 | -//import org.powermock.api.easymock.PowerMock; | ||
53 | -//import org.powermock.core.classloader.annotations.PrepareForTest; | ||
54 | -//import org.powermock.modules.junit4.PowerMockRunner; | ||
55 | -//import org.powermock.reflect.Whitebox; | ||
56 | -//import org.slf4j.Logger; | ||
57 | -// | ||
58 | -//import br.gov.frameworkdemoiselle.annotation.Ignore; | ||
59 | -//import br.gov.frameworkdemoiselle.annotation.Name; | ||
60 | -//import br.gov.frameworkdemoiselle.configuration.ConfigType; | ||
61 | -//import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
62 | -//import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | ||
63 | -//import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; | ||
64 | -//import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
65 | -// | ||
66 | -//@RunWith(PowerMockRunner.class) | ||
67 | -//@PrepareForTest(CoreBootstrap.class) | ||
68 | -//public class ConfigurationLoaderTest { | ||
69 | -// | ||
70 | -// private ConfigurationLoader configurationLoader; | ||
71 | -// | ||
72 | -// @Configuration | ||
73 | -// public class ConfigurationSuccessfulProperties { | ||
74 | -// | ||
75 | -// @Name("frameworkdemoiselle.configurationtest.nameConfiguration") | ||
76 | -// protected String nameConfiguration; | ||
77 | -// | ||
78 | -// } | ||
79 | -// | ||
80 | -// @Configuration | ||
81 | -// public class ConfigurationSuccessfulProperties2 { | ||
82 | -// | ||
83 | -// @Name("frameworkdemoiselle.configurationtest.name") | ||
84 | -// protected String name; | ||
85 | -// | ||
86 | -// } | ||
87 | -// | ||
88 | -// @Configuration(resource = "absentFile") | ||
89 | -// public class ConfigurationPropertiesWithAbsentFile { | ||
90 | -// | ||
91 | -// @Name("frameworkdemoiselle.configurationtest.nameConfiguration") | ||
92 | -// protected String nameConfiguration; | ||
93 | -// | ||
94 | -// } | ||
95 | -// | ||
96 | -// @Configuration | ||
97 | -// public class ConfigurationWithEmptyName { | ||
98 | -// | ||
99 | -// @Name("") | ||
100 | -// protected String nameConfiguration; | ||
101 | -// | ||
102 | -// } | ||
103 | -// | ||
104 | -// @Configuration | ||
105 | -// public class ConfigurationWithoutNameAnnotation { | ||
106 | -// | ||
107 | -// protected String nameConfiguration; | ||
108 | -// | ||
109 | -// } | ||
110 | -// | ||
111 | -// @Configuration | ||
112 | -// public class ConfigurationWithIgnoreAnnotation { | ||
113 | -// | ||
114 | -// @Ignore | ||
115 | -// protected String nameConfiguration; | ||
116 | -// | ||
117 | -// } | ||
118 | -// | ||
119 | -// @Configuration(prefix = "frameworkdemoiselle.configurationtest") | ||
120 | -// public class ConfigurationWithPrefix { | ||
121 | -// | ||
122 | -// @Name("nameConfiguration") | ||
123 | -// protected String nameConfiguration; | ||
124 | -// | ||
125 | -// } | ||
126 | -// | ||
127 | -// @Configuration | ||
128 | -// public class ConfigurationWithKeyNotFoundInProperties { | ||
129 | -// | ||
130 | -// protected Integer notExistKey; | ||
131 | -// } | ||
132 | -// | ||
133 | -// @Configuration | ||
134 | -// public class ConfigurationWithNotNullFieldButValueIsNull { | ||
135 | -// | ||
136 | -// @Name("notexistKey") | ||
137 | -// @NotNull | ||
138 | -// protected int nameConfiguration; | ||
139 | -// | ||
140 | -// } | ||
141 | -// | ||
142 | -// @Configuration | ||
143 | -// public class ConfigurationWithNotNullFieldAndValueIsNotNull { | ||
144 | -// | ||
145 | -// @Name("nameConfiguration") | ||
146 | -// @NotNull | ||
147 | -// protected String nameConfiguration; | ||
148 | -// | ||
149 | -// } | ||
150 | -// | ||
151 | -// @Configuration | ||
152 | -// public class ConfigurationWithNonPrimitiveFieldValueNull { | ||
153 | -// | ||
154 | -// @Name("notexistKey") | ||
155 | -// protected String nameConfiguration; | ||
156 | -// | ||
157 | -// } | ||
158 | -// | ||
159 | -// @Configuration | ||
160 | -// public class ConfigurationWithPrimitiveFieldValueNull { | ||
161 | -// | ||
162 | -// @Name("notexistKey") | ||
163 | -// protected int nameConfiguration = 1; | ||
164 | -// | ||
165 | -// } | ||
166 | -// | ||
167 | -// @Configuration(type = ConfigType.SYSTEM) | ||
168 | -// public class ConfigurationWithKeyFromSystem { | ||
169 | -// | ||
170 | -// @Name("os.name") | ||
171 | -// protected String nameConfiguration; | ||
172 | -// | ||
173 | -// } | ||
174 | -// | ||
175 | -// @Configuration(type = ConfigType.XML) | ||
176 | -// public class ConfigurationWithKeyFromXML { | ||
177 | -// | ||
178 | -// @Name("nameConfiguration") | ||
179 | -// protected String nameConfiguration; | ||
180 | -// | ||
181 | -// } | ||
182 | -// | ||
183 | -// @Configuration(type = ConfigType.XML, prefix = "br.gov.frameworkdemoiselle") | ||
184 | -// public class ConfigurationFromXMLWithPrefix { | ||
185 | -// | ||
186 | -// @Name("nameConfiguration") | ||
187 | -// protected String nameConfiguration; | ||
188 | -// | ||
189 | -// } | ||
190 | -// | ||
191 | -// @Configuration | ||
192 | -// public class ConfigurationPropertiesWithTwoAmbiguousKey { | ||
193 | -// | ||
194 | -// protected String twoConfiguration; | ||
195 | -// | ||
196 | -// } | ||
197 | -// | ||
198 | -// @Configuration | ||
199 | -// public class ConfigurationPropertiesWithThreeAmbiguousKey { | ||
200 | -// | ||
201 | -// protected String threeConfiguration; | ||
202 | -// | ||
203 | -// } | ||
204 | -// | ||
205 | -// @Configuration | ||
206 | -// public class ConfigurationPropertiesWithFourAmbiguousKey { | ||
207 | -// | ||
208 | -// protected String fourConfiguration; | ||
209 | -// | ||
210 | -// } | ||
211 | -// | ||
212 | -// @Configuration | ||
213 | -// public class ConfigurationWithConventionUnderline { | ||
214 | -// | ||
215 | -// protected String conventionUnderline; | ||
216 | -// | ||
217 | -// } | ||
218 | -// | ||
219 | -// @Configuration(type = ConfigType.XML) | ||
220 | -// public class ConfigurationXMLWithConventionUnderline { | ||
221 | -// | ||
222 | -// protected String conventionUnderline; | ||
223 | -// | ||
224 | -// } | ||
225 | -// | ||
226 | -// @Configuration | ||
227 | -// public class ConfigurationWithConventionDot { | ||
228 | -// | ||
229 | -// protected String conventionDot; | ||
230 | -// | ||
231 | -// } | ||
232 | -// | ||
233 | -// @Configuration(type = ConfigType.XML) | ||
234 | -// public class ConfigurationXMLWithConventionDot { | ||
235 | -// | ||
236 | -// protected String conventionDot; | ||
237 | -// | ||
238 | -// } | ||
239 | -// | ||
240 | -// @Configuration | ||
241 | -// public class ConfigurationWithConventionAllUpperCase { | ||
242 | -// | ||
243 | -// protected String conventionAllUpperCase; | ||
244 | -// | ||
245 | -// } | ||
246 | -// | ||
247 | -// @Configuration(type = ConfigType.XML) | ||
248 | -// public class ConfigurationXMLWithConventionAllUpperCase { | ||
249 | -// | ||
250 | -// protected String conventionAllUpperCase; | ||
251 | -// | ||
252 | -// } | ||
253 | -// | ||
254 | -// @Configuration | ||
255 | -// public class ConfigurationWithConventionAllLowerCase { | ||
256 | -// | ||
257 | -// protected String conventionAllLowerCase; | ||
258 | -// | ||
259 | -// } | ||
260 | -// | ||
261 | -// @Configuration(type = ConfigType.XML) | ||
262 | -// public class ConfigurationXMLWithConventionAllLowerCase { | ||
263 | -// | ||
264 | -// protected String conventionAllLowerCase; | ||
265 | -// | ||
266 | -// } | ||
267 | -// | ||
268 | -// @Configuration(prefix = "br.gov.frameworkdemoiselle") | ||
269 | -// public class ConfigurationPropertiesSuccessWithPrefixNonAmbiguous { | ||
270 | -// | ||
271 | -// protected String success; | ||
272 | -// | ||
273 | -// } | ||
274 | -// | ||
275 | -// @Configuration | ||
276 | -// public class ConfigurationPropertiesErrorWithComplexObject { | ||
277 | -// | ||
278 | -// protected ConfigurationWithConventionAllLowerCase complexObject; | ||
279 | -// } | ||
280 | -// | ||
281 | -// @Before | ||
282 | -// public void setUp() throws Exception { | ||
283 | -// Logger logger; | ||
284 | -// ResourceBundle bundle; | ||
285 | -// logger = PowerMock.createMock(Logger.class); | ||
286 | -// bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle")); | ||
287 | -// configurationLoader = new ConfigurationLoader(); | ||
288 | -// Whitebox.setInternalState(this.configurationLoader, "bundle", bundle); | ||
289 | -// Whitebox.setInternalState(this.configurationLoader, "logger", logger); | ||
290 | -// } | ||
291 | -// | ||
292 | -// @After | ||
293 | -// public void tearDown() throws Exception { | ||
294 | -// } | ||
295 | -// | ||
296 | -// @Test | ||
297 | -// public void testConfigurationSuccessfulPropertiesPossibleConventions() { | ||
298 | -// ConfigurationSuccessfulProperties config = new ConfigurationSuccessfulProperties(); | ||
299 | -// | ||
300 | -// mockStatic(CoreBootstrap.class); | ||
301 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
302 | -// PowerMock.replay(CoreBootstrap.class); | ||
303 | -// | ||
304 | -// configurationLoader.load(config); | ||
305 | -// assertEquals("ConfigurationTest", config.nameConfiguration); | ||
306 | -// | ||
307 | -// } | ||
308 | -// | ||
309 | -// @Test | ||
310 | -// public void testConfigurationSuccessfulPropertiesNoConventions() { | ||
311 | -// ConfigurationSuccessfulProperties2 config = new ConfigurationSuccessfulProperties2(); | ||
312 | -// | ||
313 | -// mockStatic(CoreBootstrap.class); | ||
314 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
315 | -// PowerMock.replay(CoreBootstrap.class); | ||
316 | -// | ||
317 | -// configurationLoader.load(config); | ||
318 | -// assertEquals("ConfigurationTest2", config.name); | ||
319 | -// } | ||
320 | -// | ||
321 | -// @Test | ||
322 | -// public void ConfigurationPropertiesWithAbsentFile() { | ||
323 | -// ConfigurationPropertiesWithAbsentFile config = new ConfigurationPropertiesWithAbsentFile(); | ||
324 | -// | ||
325 | -// mockStatic(CoreBootstrap.class); | ||
326 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
327 | -// PowerMock.replay(CoreBootstrap.class); | ||
328 | -// | ||
329 | -// try { | ||
330 | -// configurationLoader.load(config); | ||
331 | -// fail(); | ||
332 | -// } catch (Exception e) { | ||
333 | -// } | ||
334 | -// } | ||
335 | -// | ||
336 | -// @Test | ||
337 | -// public void testConfigurationProcessorWithNameEmpty() { | ||
338 | -// ConfigurationWithEmptyName config = new ConfigurationWithEmptyName(); | ||
339 | -// | ||
340 | -// mockStatic(CoreBootstrap.class); | ||
341 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
342 | -// PowerMock.replay(CoreBootstrap.class); | ||
343 | -// | ||
344 | -// try { | ||
345 | -// configurationLoader.load(config); | ||
346 | -// fail(); | ||
347 | -// } catch (Exception e) { | ||
348 | -// } | ||
349 | -// } | ||
350 | -// | ||
351 | -// @Test | ||
352 | -// public void testConfigurationWithoutNameAnnotation() { | ||
353 | -// ConfigurationWithoutNameAnnotation config = new ConfigurationWithoutNameAnnotation(); | ||
354 | -// | ||
355 | -// mockStatic(CoreBootstrap.class); | ||
356 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
357 | -// PowerMock.replay(CoreBootstrap.class); | ||
358 | -// | ||
359 | -// configurationLoader.load(config); | ||
360 | -// assertEquals("ConfigurationTest", config.nameConfiguration); | ||
361 | -// } | ||
362 | -// | ||
363 | -// @Test | ||
364 | -// public void testConfigurationWithIgnoreAnnotation() { | ||
365 | -// ConfigurationWithIgnoreAnnotation config = new ConfigurationWithIgnoreAnnotation(); | ||
366 | -// | ||
367 | -// configurationLoader.load(config); | ||
368 | -// assertNull(config.nameConfiguration); | ||
369 | -// } | ||
370 | -// | ||
371 | -// @Test | ||
372 | -// public void testConfigurationWithPrefix() { | ||
373 | -// ConfigurationWithPrefix config = new ConfigurationWithPrefix(); | ||
374 | -// | ||
375 | -// mockStatic(CoreBootstrap.class); | ||
376 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
377 | -// PowerMock.replay(CoreBootstrap.class); | ||
378 | -// | ||
379 | -// configurationLoader.load(config); | ||
380 | -// assertEquals("ConfigurationTest", config.nameConfiguration); | ||
381 | -// } | ||
382 | -// | ||
383 | -// @Test | ||
384 | -// public void testConfigurationWithKeyNotFoundInProperties() { | ||
385 | -// ConfigurationWithKeyNotFoundInProperties config = new ConfigurationWithKeyNotFoundInProperties(); | ||
386 | -// | ||
387 | -// configurationLoader.load(config); | ||
388 | -// assertNull(config.notExistKey); | ||
389 | -// } | ||
390 | -// | ||
391 | -// @Test | ||
392 | -// public void testConfigurationWithNotNullFieldButValueIsNull() { | ||
393 | -// ConfigurationWithNotNullFieldButValueIsNull config = new ConfigurationWithNotNullFieldButValueIsNull(); | ||
394 | -// | ||
395 | -// mockStatic(CoreBootstrap.class); | ||
396 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
397 | -// PowerMock.replay(CoreBootstrap.class); | ||
398 | -// | ||
399 | -// try { | ||
400 | -// configurationLoader.load(config); | ||
401 | -// fail(); | ||
402 | -// } catch (Exception e) { | ||
403 | -// assertTrue(true); | ||
404 | -// } | ||
405 | -// } | ||
406 | -// | ||
407 | -// @Test | ||
408 | -// public void testConfigurationWithNotNullFieldAndValueIsNotNull() { | ||
409 | -// ConfigurationWithNotNullFieldAndValueIsNotNull config = new ConfigurationWithNotNullFieldAndValueIsNotNull(); | ||
410 | -// | ||
411 | -// mockStatic(CoreBootstrap.class); | ||
412 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
413 | -// PowerMock.replay(CoreBootstrap.class); | ||
414 | -// | ||
415 | -// configurationLoader.load(config); | ||
416 | -// assertEquals("ConfigurationTest", config.nameConfiguration); | ||
417 | -// } | ||
418 | -// | ||
419 | -// @Test | ||
420 | -// public void testConfigurationWithNonPrimitiveFieldValueNull() { | ||
421 | -// ConfigurationWithNonPrimitiveFieldValueNull config = new ConfigurationWithNonPrimitiveFieldValueNull(); | ||
422 | -// | ||
423 | -// configurationLoader.load(config); | ||
424 | -// assertNull(config.nameConfiguration); | ||
425 | -// } | ||
426 | -// | ||
427 | -// @Test | ||
428 | -// public void testConfigurationWithPrimitiveFieldValueNull() { | ||
429 | -// ConfigurationWithPrimitiveFieldValueNull config = new ConfigurationWithPrimitiveFieldValueNull(); | ||
430 | -// | ||
431 | -// configurationLoader.load(config); | ||
432 | -// assertEquals(1, config.nameConfiguration); | ||
433 | -// } | ||
434 | -// | ||
435 | -// @Test | ||
436 | -// public void testConfigurationWithKeyFromSystem() { | ||
437 | -// ConfigurationWithKeyFromSystem config = new ConfigurationWithKeyFromSystem(); | ||
438 | -// | ||
439 | -// mockStatic(CoreBootstrap.class); | ||
440 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
441 | -// PowerMock.replay(CoreBootstrap.class); | ||
442 | -// | ||
443 | -// configurationLoader.load(config); | ||
444 | -// assertEquals(System.getProperty("os.name"), config.nameConfiguration); | ||
445 | -// } | ||
446 | -// | ||
447 | -// @Test | ||
448 | -// public void testConfigurationWithKeyFromXML() { | ||
449 | -// ConfigurationWithKeyFromXML config = new ConfigurationWithKeyFromXML(); | ||
450 | -// | ||
451 | -// mockStatic(CoreBootstrap.class); | ||
452 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
453 | -// PowerMock.replay(CoreBootstrap.class); | ||
454 | -// | ||
455 | -// configurationLoader.load(config); | ||
456 | -// assertEquals("ConfigurationTest", config.nameConfiguration); | ||
457 | -// } | ||
458 | -// | ||
459 | -// @Test | ||
460 | -// public void testConfigurationWithTwoAmbiguousKey() { | ||
461 | -// ConfigurationPropertiesWithTwoAmbiguousKey config = new ConfigurationPropertiesWithTwoAmbiguousKey(); | ||
462 | -// | ||
463 | -// mockStatic(CoreBootstrap.class); | ||
464 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
465 | -// PowerMock.replay(CoreBootstrap.class); | ||
466 | -// | ||
467 | -// try { | ||
468 | -// configurationLoader.load(config); | ||
469 | -// fail(); | ||
470 | -// } catch (Exception e) { | ||
471 | -// assertTrue(e instanceof ConfigurationException); | ||
472 | -// } | ||
473 | -// | ||
474 | -// } | ||
475 | -// | ||
476 | -// @Test | ||
477 | -// public void testConfigurationWithThreeAmbiguousKey() { | ||
478 | -// ConfigurationPropertiesWithThreeAmbiguousKey config = new ConfigurationPropertiesWithThreeAmbiguousKey(); | ||
479 | -// | ||
480 | -// mockStatic(CoreBootstrap.class); | ||
481 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
482 | -// PowerMock.replay(CoreBootstrap.class); | ||
483 | -// | ||
484 | -// try { | ||
485 | -// configurationLoader.load(config); | ||
486 | -// fail(); | ||
487 | -// } catch (Exception e) { | ||
488 | -// assertTrue(e instanceof ConfigurationException); | ||
489 | -// } | ||
490 | -// | ||
491 | -// } | ||
492 | -// | ||
493 | -// @Test | ||
494 | -// public void testConfigurationWithFourAmbiguousKey() { | ||
495 | -// ConfigurationPropertiesWithFourAmbiguousKey config = new ConfigurationPropertiesWithFourAmbiguousKey(); | ||
496 | -// | ||
497 | -// mockStatic(CoreBootstrap.class); | ||
498 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
499 | -// PowerMock.replay(CoreBootstrap.class); | ||
500 | -// | ||
501 | -// try { | ||
502 | -// configurationLoader.load(config); | ||
503 | -// fail(); | ||
504 | -// } catch (Exception e) { | ||
505 | -// assertTrue(e instanceof ConfigurationException); | ||
506 | -// } | ||
507 | -// | ||
508 | -// } | ||
509 | -// | ||
510 | -// @Test | ||
511 | -// public void testConfigurationWithPrefixNotAmbiguous() { | ||
512 | -// ConfigurationPropertiesSuccessWithPrefixNonAmbiguous config = new ConfigurationPropertiesSuccessWithPrefixNonAmbiguous(); | ||
513 | -// | ||
514 | -// mockStatic(CoreBootstrap.class); | ||
515 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
516 | -// PowerMock.replay(CoreBootstrap.class); | ||
517 | -// | ||
518 | -// configurationLoader.load(config); | ||
519 | -// assertEquals("Success", config.success); | ||
520 | -// } | ||
521 | -// | ||
522 | -// @Test | ||
523 | -// public void testConfigurationWithConventionUnderline() { | ||
524 | -// ConfigurationWithConventionUnderline config = new ConfigurationWithConventionUnderline(); | ||
525 | -// | ||
526 | -// mockStatic(CoreBootstrap.class); | ||
527 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
528 | -// PowerMock.replay(CoreBootstrap.class); | ||
529 | -// | ||
530 | -// configurationLoader.load(config); | ||
531 | -// assertEquals("Convention Underline", config.conventionUnderline); | ||
532 | -// } | ||
533 | -// | ||
534 | -// @Test | ||
535 | -// public void testConfigurationWithConventionDot() { | ||
536 | -// ConfigurationWithConventionDot config = new ConfigurationWithConventionDot(); | ||
537 | -// | ||
538 | -// mockStatic(CoreBootstrap.class); | ||
539 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
540 | -// PowerMock.replay(CoreBootstrap.class); | ||
541 | -// | ||
542 | -// configurationLoader.load(config); | ||
543 | -// assertEquals("Convention Dot", config.conventionDot); | ||
544 | -// } | ||
545 | -// | ||
546 | -// @Test | ||
547 | -// public void testConfigurationWithConventionAllLowerCase() { | ||
548 | -// ConfigurationWithConventionAllLowerCase config = new ConfigurationWithConventionAllLowerCase(); | ||
549 | -// | ||
550 | -// mockStatic(CoreBootstrap.class); | ||
551 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
552 | -// PowerMock.replay(CoreBootstrap.class); | ||
553 | -// | ||
554 | -// configurationLoader.load(config); | ||
555 | -// assertEquals("All LowerCase", config.conventionAllLowerCase); | ||
556 | -// } | ||
557 | -// | ||
558 | -// @Test | ||
559 | -// public void testConfigurationWithConventionAllUpperCase() { | ||
560 | -// ConfigurationWithConventionAllUpperCase config = new ConfigurationWithConventionAllUpperCase(); | ||
561 | -// | ||
562 | -// mockStatic(CoreBootstrap.class); | ||
563 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
564 | -// PowerMock.replay(CoreBootstrap.class); | ||
565 | -// | ||
566 | -// configurationLoader.load(config); | ||
567 | -// assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); | ||
568 | -// } | ||
569 | -// | ||
570 | -// @Test | ||
571 | -// public void testConfigurationPropertiesErrorWithComplexObject() { | ||
572 | -// ConfigurationPropertiesErrorWithComplexObject config = new ConfigurationPropertiesErrorWithComplexObject(); | ||
573 | -// | ||
574 | -// try { | ||
575 | -// configurationLoader.load(config); | ||
576 | -// fail(); | ||
577 | -// } catch (Throwable throwable) { | ||
578 | -// } | ||
579 | -// } | ||
580 | -// | ||
581 | -// @Test | ||
582 | -// public void testConfigurationFromXMLWithPrefix() { | ||
583 | -// ConfigurationFromXMLWithPrefix config = new ConfigurationFromXMLWithPrefix(); | ||
584 | -// | ||
585 | -// mockStatic(CoreBootstrap.class); | ||
586 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
587 | -// PowerMock.replay(CoreBootstrap.class); | ||
588 | -// | ||
589 | -// configurationLoader.load(config); | ||
590 | -// assertEquals("ConfigurationTest", config.nameConfiguration); | ||
591 | -// } | ||
592 | -// | ||
593 | -// @Test | ||
594 | -// public void testConfigurationXMLWithConventionDot() { | ||
595 | -// ConfigurationXMLWithConventionDot config = new ConfigurationXMLWithConventionDot(); | ||
596 | -// | ||
597 | -// mockStatic(CoreBootstrap.class); | ||
598 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
599 | -// PowerMock.replay(CoreBootstrap.class); | ||
600 | -// | ||
601 | -// configurationLoader.load(config); | ||
602 | -// assertEquals("convention.dot", config.conventionDot); | ||
603 | -// } | ||
604 | -// | ||
605 | -// @Test | ||
606 | -// public void testConfigurationXMLWithConventionUnderline() { | ||
607 | -// ConfigurationXMLWithConventionUnderline config = new ConfigurationXMLWithConventionUnderline(); | ||
608 | -// | ||
609 | -// mockStatic(CoreBootstrap.class); | ||
610 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
611 | -// PowerMock.replay(CoreBootstrap.class); | ||
612 | -// | ||
613 | -// configurationLoader.load(config); | ||
614 | -// assertEquals("Convention_Underline", config.conventionUnderline); | ||
615 | -// } | ||
616 | -// | ||
617 | -// @Test | ||
618 | -// public void testConfigurationXMLWithConventionAllUpperCase() { | ||
619 | -// ConfigurationXMLWithConventionAllUpperCase config = new ConfigurationXMLWithConventionAllUpperCase(); | ||
620 | -// | ||
621 | -// mockStatic(CoreBootstrap.class); | ||
622 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
623 | -// PowerMock.replay(CoreBootstrap.class); | ||
624 | -// | ||
625 | -// configurationLoader.load(config); | ||
626 | -// assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); | ||
627 | -// } | ||
628 | -// | ||
629 | -// @Test | ||
630 | -// public void testConfigurationXMLWithConventionAllLowerCase() { | ||
631 | -// ConfigurationXMLWithConventionAllLowerCase config = new ConfigurationXMLWithConventionAllLowerCase(); | ||
632 | -// | ||
633 | -// mockStatic(CoreBootstrap.class); | ||
634 | -// expect(CoreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
635 | -// PowerMock.replay(CoreBootstrap.class); | ||
636 | -// | ||
637 | -// configurationLoader.load(config); | ||
638 | -// assertEquals("All LowerCase", config.conventionAllLowerCase); | ||
639 | -// } | ||
640 | -// | ||
641 | -//} | ||
642 | \ No newline at end of file | 1 | \ No newline at end of file |
2 | +/* | ||
3 | + * Demoiselle Framework | ||
4 | + * Copyright (C) 2010 SERPRO | ||
5 | + * ---------------------------------------------------------------------------- | ||
6 | + * This file is part of Demoiselle Framework. | ||
7 | + * | ||
8 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
9 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
10 | + * as published by the Free Software Foundation. | ||
11 | + * | ||
12 | + * This program is distributed in the hope that it will be useful, | ||
13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | + * GNU General Public License for more details. | ||
16 | + * | ||
17 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
18 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
19 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
20 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
21 | + * ---------------------------------------------------------------------------- | ||
22 | + * Este arquivo é parte do Framework Demoiselle. | ||
23 | + * | ||
24 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
25 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
26 | + * do Software Livre (FSF). | ||
27 | + * | ||
28 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
29 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
30 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
31 | + * para maiores detalhes. | ||
32 | + * | ||
33 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
34 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
35 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
36 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
37 | + */ | ||
38 | +package br.gov.frameworkdemoiselle.internal.configuration; | ||
39 | + | ||
40 | +import static org.easymock.EasyMock.expect; | ||
41 | +import static org.junit.Assert.assertEquals; | ||
42 | +import static org.junit.Assert.assertNull; | ||
43 | +import static org.junit.Assert.assertTrue; | ||
44 | +import static org.junit.Assert.fail; | ||
45 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
46 | + | ||
47 | +import java.util.Locale; | ||
48 | + | ||
49 | +import javax.validation.constraints.NotNull; | ||
50 | + | ||
51 | +import org.junit.After; | ||
52 | +import org.junit.Before; | ||
53 | +import org.junit.Test; | ||
54 | +import org.junit.runner.RunWith; | ||
55 | +import org.powermock.api.easymock.PowerMock; | ||
56 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
57 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
58 | + | ||
59 | +import br.gov.frameworkdemoiselle.annotation.Ignore; | ||
60 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
61 | +import br.gov.frameworkdemoiselle.configuration.ConfigType; | ||
62 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
63 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | ||
64 | +import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; | ||
65 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
66 | + | ||
67 | +@RunWith(PowerMockRunner.class) | ||
68 | +@PrepareForTest(Beans.class) | ||
69 | +public class ConfigurationLoaderTest { | ||
70 | + | ||
71 | + private ConfigurationLoader configurationLoader; | ||
72 | + | ||
73 | + private CoreBootstrap coreBootstrap; | ||
74 | + | ||
75 | + @Configuration | ||
76 | + public class ConfigurationSuccessfulProperties { | ||
77 | + | ||
78 | + @Name("frameworkdemoiselle.configurationtest.nameConfiguration") | ||
79 | + protected String nameConfiguration; | ||
80 | + | ||
81 | + } | ||
82 | + | ||
83 | + @Configuration | ||
84 | + public class ConfigurationSuccessfulProperties2 { | ||
85 | + | ||
86 | + @Name("frameworkdemoiselle.configurationtest.name") | ||
87 | + protected String name; | ||
88 | + | ||
89 | + } | ||
90 | + | ||
91 | + @Configuration(resource = "absentFile") | ||
92 | + public class ConfigurationPropertiesWithAbsentFile { | ||
93 | + | ||
94 | + @Name("frameworkdemoiselle.configurationtest.nameConfiguration") | ||
95 | + protected String nameConfiguration; | ||
96 | + | ||
97 | + } | ||
98 | + | ||
99 | + @Configuration | ||
100 | + public class ConfigurationWithEmptyName { | ||
101 | + | ||
102 | + @Name("") | ||
103 | + protected String nameConfiguration; | ||
104 | + | ||
105 | + } | ||
106 | + | ||
107 | + @Configuration | ||
108 | + public class ConfigurationWithoutNameAnnotation { | ||
109 | + | ||
110 | + protected String nameConfiguration; | ||
111 | + | ||
112 | + } | ||
113 | + | ||
114 | + @Configuration | ||
115 | + public class ConfigurationWithIgnoreAnnotation { | ||
116 | + | ||
117 | + @Ignore | ||
118 | + protected String nameConfiguration; | ||
119 | + | ||
120 | + } | ||
121 | + | ||
122 | + @Configuration(prefix = "frameworkdemoiselle.configurationtest") | ||
123 | + public class ConfigurationWithPrefix { | ||
124 | + | ||
125 | + @Name("nameConfiguration") | ||
126 | + protected String nameConfiguration; | ||
127 | + | ||
128 | + } | ||
129 | + | ||
130 | + @Configuration | ||
131 | + public class ConfigurationWithKeyNotFoundInProperties { | ||
132 | + | ||
133 | + protected Integer notExistKey; | ||
134 | + } | ||
135 | + | ||
136 | + @Configuration | ||
137 | + public class ConfigurationWithNotNullFieldButValueIsNull { | ||
138 | + | ||
139 | + @Name("notexistKey") | ||
140 | + @NotNull | ||
141 | + protected int nameConfiguration; | ||
142 | + | ||
143 | + } | ||
144 | + | ||
145 | + @Configuration | ||
146 | + public class ConfigurationWithNotNullFieldAndValueIsNotNull { | ||
147 | + | ||
148 | + @Name("nameConfiguration") | ||
149 | + @NotNull | ||
150 | + protected String nameConfiguration; | ||
151 | + | ||
152 | + } | ||
153 | + | ||
154 | + @Configuration | ||
155 | + public class ConfigurationWithNonPrimitiveFieldValueNull { | ||
156 | + | ||
157 | + @Name("notexistKey") | ||
158 | + protected String nameConfiguration; | ||
159 | + | ||
160 | + } | ||
161 | + | ||
162 | + @Configuration | ||
163 | + public class ConfigurationWithPrimitiveFieldValueNull { | ||
164 | + | ||
165 | + @Name("notexistKey") | ||
166 | + protected int nameConfiguration = 1; | ||
167 | + | ||
168 | + } | ||
169 | + | ||
170 | + @Configuration(type = ConfigType.SYSTEM) | ||
171 | + public class ConfigurationWithKeyFromSystem { | ||
172 | + | ||
173 | + @Name("os.name") | ||
174 | + protected String nameConfiguration; | ||
175 | + | ||
176 | + } | ||
177 | + | ||
178 | + @Configuration(type = ConfigType.XML) | ||
179 | + public class ConfigurationWithKeyFromXML { | ||
180 | + | ||
181 | + @Name("nameConfiguration") | ||
182 | + protected String nameConfiguration; | ||
183 | + | ||
184 | + } | ||
185 | + | ||
186 | + @Configuration(type = ConfigType.XML, prefix = "br.gov.frameworkdemoiselle") | ||
187 | + public class ConfigurationFromXMLWithPrefix { | ||
188 | + | ||
189 | + @Name("nameConfiguration") | ||
190 | + protected String nameConfiguration; | ||
191 | + | ||
192 | + } | ||
193 | + | ||
194 | + @Configuration | ||
195 | + public class ConfigurationPropertiesWithTwoAmbiguousKey { | ||
196 | + | ||
197 | + protected String twoConfiguration; | ||
198 | + | ||
199 | + } | ||
200 | + | ||
201 | + @Configuration | ||
202 | + public class ConfigurationPropertiesWithThreeAmbiguousKey { | ||
203 | + | ||
204 | + protected String threeConfiguration; | ||
205 | + | ||
206 | + } | ||
207 | + | ||
208 | + @Configuration | ||
209 | + public class ConfigurationPropertiesWithFourAmbiguousKey { | ||
210 | + | ||
211 | + protected String fourConfiguration; | ||
212 | + | ||
213 | + } | ||
214 | + | ||
215 | + @Configuration | ||
216 | + public class ConfigurationWithConventionUnderline { | ||
217 | + | ||
218 | + protected String conventionUnderline; | ||
219 | + | ||
220 | + } | ||
221 | + | ||
222 | + @Configuration(type = ConfigType.XML) | ||
223 | + public class ConfigurationXMLWithConventionUnderline { | ||
224 | + | ||
225 | + protected String conventionUnderline; | ||
226 | + | ||
227 | + } | ||
228 | + | ||
229 | + @Configuration | ||
230 | + public class ConfigurationWithConventionDot { | ||
231 | + | ||
232 | + protected String conventionDot; | ||
233 | + | ||
234 | + } | ||
235 | + | ||
236 | + @Configuration(type = ConfigType.XML) | ||
237 | + public class ConfigurationXMLWithConventionDot { | ||
238 | + | ||
239 | + protected String conventionDot; | ||
240 | + | ||
241 | + } | ||
242 | + | ||
243 | + @Configuration | ||
244 | + public class ConfigurationWithConventionAllUpperCase { | ||
245 | + | ||
246 | + protected String conventionAllUpperCase; | ||
247 | + | ||
248 | + } | ||
249 | + | ||
250 | + @Configuration(type = ConfigType.XML) | ||
251 | + public class ConfigurationXMLWithConventionAllUpperCase { | ||
252 | + | ||
253 | + protected String conventionAllUpperCase; | ||
254 | + | ||
255 | + } | ||
256 | + | ||
257 | + @Configuration | ||
258 | + public class ConfigurationWithConventionAllLowerCase { | ||
259 | + | ||
260 | + protected String conventionAllLowerCase; | ||
261 | + | ||
262 | + } | ||
263 | + | ||
264 | + @Configuration(type = ConfigType.XML) | ||
265 | + public class ConfigurationXMLWithConventionAllLowerCase { | ||
266 | + | ||
267 | + protected String conventionAllLowerCase; | ||
268 | + | ||
269 | + } | ||
270 | + | ||
271 | + @Configuration(prefix = "br.gov.frameworkdemoiselle") | ||
272 | + public class ConfigurationPropertiesSuccessWithPrefixNonAmbiguous { | ||
273 | + | ||
274 | + protected String success; | ||
275 | + | ||
276 | + } | ||
277 | + | ||
278 | + @Configuration | ||
279 | + public class ConfigurationPropertiesErrorWithComplexObject { | ||
280 | + | ||
281 | + protected ConfigurationWithConventionAllLowerCase complexObject; | ||
282 | + } | ||
283 | + | ||
284 | + @Before | ||
285 | + public void setUp() throws Exception { | ||
286 | + this.configurationLoader = new ConfigurationLoader(); | ||
287 | + mockStatic(Beans.class); | ||
288 | + this.coreBootstrap = PowerMock.createMock(CoreBootstrap.class); | ||
289 | + | ||
290 | + expect(Beans.getReference(CoreBootstrap.class)).andReturn(coreBootstrap); | ||
291 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
292 | + } | ||
293 | + | ||
294 | + @After | ||
295 | + public void tearDown() throws Exception { | ||
296 | + } | ||
297 | + | ||
298 | + @Test | ||
299 | + public void testConfigurationSuccessfulPropertiesPossibleConventions() { | ||
300 | + ConfigurationSuccessfulProperties config = new ConfigurationSuccessfulProperties(); | ||
301 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
302 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
303 | + configurationLoader.load(config); | ||
304 | + assertEquals("ConfigurationTest", config.nameConfiguration); | ||
305 | + | ||
306 | + } | ||
307 | + | ||
308 | + @Test | ||
309 | + public void testConfigurationSuccessfulPropertiesNoConventions() { | ||
310 | + ConfigurationSuccessfulProperties2 config = new ConfigurationSuccessfulProperties2(); | ||
311 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
312 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
313 | + configurationLoader.load(config); | ||
314 | + assertEquals("ConfigurationTest2", config.name); | ||
315 | + } | ||
316 | + | ||
317 | + @Test | ||
318 | + public void ConfigurationPropertiesWithAbsentFile() { | ||
319 | + ConfigurationPropertiesWithAbsentFile config = new ConfigurationPropertiesWithAbsentFile(); | ||
320 | + | ||
321 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
322 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
323 | + | ||
324 | + try { | ||
325 | + configurationLoader.load(config); | ||
326 | + fail(); | ||
327 | + } catch (Exception e) { | ||
328 | + } | ||
329 | + } | ||
330 | + | ||
331 | + @Test | ||
332 | + public void testConfigurationProcessorWithNameEmpty() { | ||
333 | + ConfigurationWithEmptyName config = new ConfigurationWithEmptyName(); | ||
334 | + | ||
335 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
336 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
337 | + | ||
338 | + try { | ||
339 | + configurationLoader.load(config); | ||
340 | + fail(); | ||
341 | + } catch (Exception e) { | ||
342 | + } | ||
343 | + } | ||
344 | + | ||
345 | + @Test | ||
346 | + public void testConfigurationWithoutNameAnnotation() { | ||
347 | + ConfigurationWithoutNameAnnotation config = new ConfigurationWithoutNameAnnotation(); | ||
348 | + | ||
349 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
350 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
351 | + | ||
352 | + configurationLoader.load(config); | ||
353 | + assertEquals("ConfigurationTest", config.nameConfiguration); | ||
354 | + } | ||
355 | + | ||
356 | + @Test | ||
357 | + public void testConfigurationWithIgnoreAnnotation() { | ||
358 | + ConfigurationWithIgnoreAnnotation config = new ConfigurationWithIgnoreAnnotation(); | ||
359 | + | ||
360 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
361 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
362 | + | ||
363 | + configurationLoader.load(config); | ||
364 | + assertNull(config.nameConfiguration); | ||
365 | + } | ||
366 | + | ||
367 | + @Test | ||
368 | + public void testConfigurationWithPrefix() { | ||
369 | + ConfigurationWithPrefix config = new ConfigurationWithPrefix(); | ||
370 | + | ||
371 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
372 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
373 | + | ||
374 | + configurationLoader.load(config); | ||
375 | + assertEquals("ConfigurationTest", config.nameConfiguration); | ||
376 | + } | ||
377 | + | ||
378 | + @Test | ||
379 | + public void testConfigurationWithKeyNotFoundInProperties() { | ||
380 | + ConfigurationWithKeyNotFoundInProperties config = new ConfigurationWithKeyNotFoundInProperties(); | ||
381 | + | ||
382 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
383 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
384 | + | ||
385 | + configurationLoader.load(config); | ||
386 | + assertNull(config.notExistKey); | ||
387 | + } | ||
388 | + | ||
389 | + @Test | ||
390 | + public void testConfigurationWithNotNullFieldButValueIsNull() { | ||
391 | + ConfigurationWithNotNullFieldButValueIsNull config = new ConfigurationWithNotNullFieldButValueIsNull(); | ||
392 | + | ||
393 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
394 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
395 | + | ||
396 | + try { | ||
397 | + configurationLoader.load(config); | ||
398 | + fail(); | ||
399 | + } catch (Exception e) { | ||
400 | + assertTrue(true); | ||
401 | + } | ||
402 | + } | ||
403 | + | ||
404 | + @Test | ||
405 | + public void testConfigurationWithNotNullFieldAndValueIsNotNull() { | ||
406 | + ConfigurationWithNotNullFieldAndValueIsNotNull config = new ConfigurationWithNotNullFieldAndValueIsNotNull(); | ||
407 | + | ||
408 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
409 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
410 | + | ||
411 | + configurationLoader.load(config); | ||
412 | + assertEquals("ConfigurationTest", config.nameConfiguration); | ||
413 | + } | ||
414 | + | ||
415 | + @Test | ||
416 | + public void testConfigurationWithNonPrimitiveFieldValueNull() { | ||
417 | + ConfigurationWithNonPrimitiveFieldValueNull config = new ConfigurationWithNonPrimitiveFieldValueNull(); | ||
418 | + | ||
419 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
420 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
421 | + | ||
422 | + configurationLoader.load(config); | ||
423 | + assertNull(config.nameConfiguration); | ||
424 | + } | ||
425 | + | ||
426 | + @Test | ||
427 | + public void testConfigurationWithPrimitiveFieldValueNull() { | ||
428 | + ConfigurationWithPrimitiveFieldValueNull config = new ConfigurationWithPrimitiveFieldValueNull(); | ||
429 | + | ||
430 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
431 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
432 | + | ||
433 | + configurationLoader.load(config); | ||
434 | + assertEquals(1, config.nameConfiguration); | ||
435 | + } | ||
436 | + | ||
437 | + @Test | ||
438 | + public void testConfigurationWithKeyFromSystem() { | ||
439 | + ConfigurationWithKeyFromSystem config = new ConfigurationWithKeyFromSystem(); | ||
440 | + | ||
441 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
442 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
443 | + | ||
444 | + configurationLoader.load(config); | ||
445 | + assertEquals(System.getProperty("os.name"), config.nameConfiguration); | ||
446 | + } | ||
447 | + | ||
448 | + @Test | ||
449 | + public void testConfigurationWithKeyFromXML() { | ||
450 | + ConfigurationWithKeyFromXML config = new ConfigurationWithKeyFromXML(); | ||
451 | + | ||
452 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
453 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
454 | + | ||
455 | + configurationLoader.load(config); | ||
456 | + assertEquals("ConfigurationTest", config.nameConfiguration); | ||
457 | + } | ||
458 | + | ||
459 | + @Test | ||
460 | + public void testConfigurationWithTwoAmbiguousKey() { | ||
461 | + ConfigurationPropertiesWithTwoAmbiguousKey config = new ConfigurationPropertiesWithTwoAmbiguousKey(); | ||
462 | + | ||
463 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
464 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
465 | + | ||
466 | + try { | ||
467 | + configurationLoader.load(config); | ||
468 | + fail(); | ||
469 | + } catch (Exception e) { | ||
470 | + assertTrue(e instanceof ConfigurationException); | ||
471 | + } | ||
472 | + | ||
473 | + } | ||
474 | + | ||
475 | + @Test | ||
476 | + public void testConfigurationWithThreeAmbiguousKey() { | ||
477 | + ConfigurationPropertiesWithThreeAmbiguousKey config = new ConfigurationPropertiesWithThreeAmbiguousKey(); | ||
478 | + | ||
479 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
480 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
481 | + | ||
482 | + try { | ||
483 | + configurationLoader.load(config); | ||
484 | + fail(); | ||
485 | + } catch (Exception e) { | ||
486 | + assertTrue(e instanceof ConfigurationException); | ||
487 | + } | ||
488 | + | ||
489 | + } | ||
490 | + | ||
491 | + @Test | ||
492 | + public void testConfigurationWithFourAmbiguousKey() { | ||
493 | + ConfigurationPropertiesWithFourAmbiguousKey config = new ConfigurationPropertiesWithFourAmbiguousKey(); | ||
494 | + | ||
495 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
496 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
497 | + | ||
498 | + try { | ||
499 | + configurationLoader.load(config); | ||
500 | + fail(); | ||
501 | + } catch (Exception e) { | ||
502 | + assertTrue(e instanceof ConfigurationException); | ||
503 | + } | ||
504 | + | ||
505 | + } | ||
506 | + | ||
507 | + @Test | ||
508 | + public void testConfigurationWithPrefixNotAmbiguous() { | ||
509 | + ConfigurationPropertiesSuccessWithPrefixNonAmbiguous config = new ConfigurationPropertiesSuccessWithPrefixNonAmbiguous(); | ||
510 | + | ||
511 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
512 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
513 | + | ||
514 | + configurationLoader.load(config); | ||
515 | + assertEquals("Success", config.success); | ||
516 | + } | ||
517 | + | ||
518 | + @Test | ||
519 | + public void testConfigurationWithConventionUnderline() { | ||
520 | + ConfigurationWithConventionUnderline config = new ConfigurationWithConventionUnderline(); | ||
521 | + | ||
522 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
523 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
524 | + | ||
525 | + configurationLoader.load(config); | ||
526 | + assertEquals("Convention Underline", config.conventionUnderline); | ||
527 | + } | ||
528 | + | ||
529 | + @Test | ||
530 | + public void testConfigurationWithConventionDot() { | ||
531 | + ConfigurationWithConventionDot config = new ConfigurationWithConventionDot(); | ||
532 | + | ||
533 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
534 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
535 | + | ||
536 | + configurationLoader.load(config); | ||
537 | + assertEquals("Convention Dot", config.conventionDot); | ||
538 | + } | ||
539 | + | ||
540 | + @Test | ||
541 | + public void testConfigurationWithConventionAllLowerCase() { | ||
542 | + ConfigurationWithConventionAllLowerCase config = new ConfigurationWithConventionAllLowerCase(); | ||
543 | + | ||
544 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
545 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
546 | + | ||
547 | + configurationLoader.load(config); | ||
548 | + assertEquals("All LowerCase", config.conventionAllLowerCase); | ||
549 | + } | ||
550 | + | ||
551 | + @Test | ||
552 | + public void testConfigurationWithConventionAllUpperCase() { | ||
553 | + ConfigurationWithConventionAllUpperCase config = new ConfigurationWithConventionAllUpperCase(); | ||
554 | + | ||
555 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
556 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
557 | + | ||
558 | + configurationLoader.load(config); | ||
559 | + assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); | ||
560 | + } | ||
561 | + | ||
562 | + @Test | ||
563 | + public void testConfigurationPropertiesErrorWithComplexObject() { | ||
564 | + ConfigurationPropertiesErrorWithComplexObject config = new ConfigurationPropertiesErrorWithComplexObject(); | ||
565 | + | ||
566 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
567 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
568 | + | ||
569 | + try { | ||
570 | + configurationLoader.load(config); | ||
571 | + fail(); | ||
572 | + } catch (Throwable throwable) { | ||
573 | + } | ||
574 | + } | ||
575 | + | ||
576 | + @Test | ||
577 | + public void testConfigurationFromXMLWithPrefix() { | ||
578 | + ConfigurationFromXMLWithPrefix config = new ConfigurationFromXMLWithPrefix(); | ||
579 | + | ||
580 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
581 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
582 | + | ||
583 | + configurationLoader.load(config); | ||
584 | + assertEquals("ConfigurationTest", config.nameConfiguration); | ||
585 | + } | ||
586 | + | ||
587 | + @Test | ||
588 | + public void testConfigurationXMLWithConventionDot() { | ||
589 | + ConfigurationXMLWithConventionDot config = new ConfigurationXMLWithConventionDot(); | ||
590 | + | ||
591 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
592 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
593 | + | ||
594 | + configurationLoader.load(config); | ||
595 | + assertEquals("convention.dot", config.conventionDot); | ||
596 | + } | ||
597 | + | ||
598 | + @Test | ||
599 | + public void testConfigurationXMLWithConventionUnderline() { | ||
600 | + ConfigurationXMLWithConventionUnderline config = new ConfigurationXMLWithConventionUnderline(); | ||
601 | + | ||
602 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
603 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
604 | + | ||
605 | + configurationLoader.load(config); | ||
606 | + assertEquals("Convention_Underline", config.conventionUnderline); | ||
607 | + } | ||
608 | + | ||
609 | + @Test | ||
610 | + public void testConfigurationXMLWithConventionAllUpperCase() { | ||
611 | + ConfigurationXMLWithConventionAllUpperCase config = new ConfigurationXMLWithConventionAllUpperCase(); | ||
612 | + | ||
613 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
614 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
615 | + | ||
616 | + configurationLoader.load(config); | ||
617 | + assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); | ||
618 | + } | ||
619 | + | ||
620 | + @Test | ||
621 | + public void testConfigurationXMLWithConventionAllLowerCase() { | ||
622 | + ConfigurationXMLWithConventionAllLowerCase config = new ConfigurationXMLWithConventionAllLowerCase(); | ||
623 | + | ||
624 | + expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | ||
625 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); | ||
626 | + | ||
627 | + configurationLoader.load(config); | ||
628 | + assertEquals("All LowerCase", config.conventionAllLowerCase); | ||
629 | + } | ||
630 | + | ||
631 | +} | ||
643 | \ No newline at end of file | 632 | \ No newline at end of file |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithArrayTest.java
@@ -36,10 +36,9 @@ | @@ -36,10 +36,9 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.configuration; | 37 | package br.gov.frameworkdemoiselle.internal.configuration; |
38 | 38 | ||
39 | -import static org.easymock.EasyMock.createMock; | ||
40 | import static org.easymock.EasyMock.expect; | 39 | import static org.easymock.EasyMock.expect; |
41 | import static org.junit.Assert.assertEquals; | 40 | import static org.junit.Assert.assertEquals; |
42 | -import static org.powermock.api.easymock.PowerMock.replay; | 41 | +import static org.powermock.api.easymock.PowerMock.mockStatic; |
43 | 42 | ||
44 | import java.awt.Color; | 43 | import java.awt.Color; |
45 | import java.math.BigDecimal; | 44 | import java.math.BigDecimal; |
@@ -55,16 +54,16 @@ import org.junit.Before; | @@ -55,16 +54,16 @@ import org.junit.Before; | ||
55 | import org.junit.Test; | 54 | import org.junit.Test; |
56 | import org.junit.runner.RunWith; | 55 | import org.junit.runner.RunWith; |
57 | import org.powermock.api.easymock.PowerMock; | 56 | import org.powermock.api.easymock.PowerMock; |
57 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
58 | import org.powermock.modules.junit4.PowerMockRunner; | 58 | import org.powermock.modules.junit4.PowerMockRunner; |
59 | -import org.powermock.reflect.Whitebox; | ||
60 | -import org.slf4j.Logger; | ||
61 | 59 | ||
62 | import br.gov.frameworkdemoiselle.configuration.ConfigType; | 60 | import br.gov.frameworkdemoiselle.configuration.ConfigType; |
63 | import br.gov.frameworkdemoiselle.configuration.Configuration; | 61 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
64 | import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; | 62 | import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; |
65 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | 63 | +import br.gov.frameworkdemoiselle.util.Beans; |
66 | 64 | ||
67 | @RunWith(PowerMockRunner.class) | 65 | @RunWith(PowerMockRunner.class) |
66 | +@PrepareForTest(Beans.class) | ||
68 | public class ConfigurationLoaderWithArrayTest { | 67 | public class ConfigurationLoaderWithArrayTest { |
69 | 68 | ||
70 | private ConfigurationLoader configurationLoader; | 69 | private ConfigurationLoader configurationLoader; |
@@ -149,13 +148,7 @@ public class ConfigurationLoaderWithArrayTest { | @@ -149,13 +148,7 @@ public class ConfigurationLoaderWithArrayTest { | ||
149 | 148 | ||
150 | @Before | 149 | @Before |
151 | public void setUp() throws Exception { | 150 | public void setUp() throws Exception { |
152 | - Logger logger; | ||
153 | - ResourceBundle bundle; | ||
154 | - logger = PowerMock.createMock(Logger.class); | ||
155 | - bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | ||
156 | configurationLoader = new ConfigurationLoader(); | 151 | configurationLoader = new ConfigurationLoader(); |
157 | - Whitebox.setInternalState(this.configurationLoader, "bundle", bundle); | ||
158 | - Whitebox.setInternalState(this.configurationLoader, "logger", logger); | ||
159 | } | 152 | } |
160 | 153 | ||
161 | @After | 154 | @After |
@@ -341,12 +334,16 @@ public class ConfigurationLoaderWithArrayTest { | @@ -341,12 +334,16 @@ public class ConfigurationLoaderWithArrayTest { | ||
341 | } | 334 | } |
342 | 335 | ||
343 | private ConfigurationPropertiesWithArray prepareConfigurationPropertiesWithArray() { | 336 | private ConfigurationPropertiesWithArray prepareConfigurationPropertiesWithArray() { |
337 | + mockStatic(Beans.class); | ||
344 | ConfigurationPropertiesWithArray config = new ConfigurationPropertiesWithArray(); | 338 | ConfigurationPropertiesWithArray config = new ConfigurationPropertiesWithArray(); |
345 | - | ||
346 | - CoreBootstrap coreBootstrap = createMock(CoreBootstrap.class); | 339 | + CoreBootstrap coreBootstrap = PowerMock.createMock(CoreBootstrap.class); |
340 | + | ||
341 | + expect(Beans.getReference(CoreBootstrap.class)).andReturn(coreBootstrap); | ||
342 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
343 | + | ||
347 | expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | 344 | expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); |
348 | 345 | ||
349 | - replay(coreBootstrap); | 346 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); |
350 | 347 | ||
351 | configurationLoader.load(config); | 348 | configurationLoader.load(config); |
352 | return config; | 349 | return config; |
@@ -531,13 +528,17 @@ public class ConfigurationLoaderWithArrayTest { | @@ -531,13 +528,17 @@ public class ConfigurationLoaderWithArrayTest { | ||
531 | } | 528 | } |
532 | 529 | ||
533 | private ConfigurationXMLWithArray prepareConfigurationXMLWithArray() { | 530 | private ConfigurationXMLWithArray prepareConfigurationXMLWithArray() { |
531 | + mockStatic(Beans.class); | ||
534 | ConfigurationXMLWithArray config = new ConfigurationXMLWithArray(); | 532 | ConfigurationXMLWithArray config = new ConfigurationXMLWithArray(); |
535 | - | ||
536 | - CoreBootstrap coreBootstrap = createMock(CoreBootstrap.class); | 533 | + CoreBootstrap coreBootstrap = PowerMock.createMock(CoreBootstrap.class); |
534 | + | ||
535 | + expect(Beans.getReference(CoreBootstrap.class)).andReturn(coreBootstrap); | ||
536 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
537 | + | ||
537 | expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | 538 | expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); |
538 | 539 | ||
539 | - replay(CoreBootstrap.class); | ||
540 | - | 540 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); |
541 | + | ||
541 | configurationLoader.load(config); | 542 | configurationLoader.load(config); |
542 | return config; | 543 | return config; |
543 | } | 544 | } |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoaderWithListTest.java
@@ -36,10 +36,9 @@ | @@ -36,10 +36,9 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.configuration; | 37 | package br.gov.frameworkdemoiselle.internal.configuration; |
38 | 38 | ||
39 | -import static org.easymock.EasyMock.createMock; | ||
40 | import static org.easymock.EasyMock.expect; | 39 | import static org.easymock.EasyMock.expect; |
41 | import static org.junit.Assert.assertEquals; | 40 | import static org.junit.Assert.assertEquals; |
42 | -import static org.powermock.api.easymock.PowerMock.replay; | 41 | +import static org.powermock.api.easymock.PowerMock.mockStatic; |
43 | 42 | ||
44 | import java.awt.Color; | 43 | import java.awt.Color; |
45 | import java.math.BigDecimal; | 44 | import java.math.BigDecimal; |
@@ -53,21 +52,19 @@ import java.util.Locale; | @@ -53,21 +52,19 @@ import java.util.Locale; | ||
53 | 52 | ||
54 | import org.junit.After; | 53 | import org.junit.After; |
55 | import org.junit.Before; | 54 | import org.junit.Before; |
56 | -import org.junit.Ignore; | ||
57 | import org.junit.Test; | 55 | import org.junit.Test; |
58 | import org.junit.runner.RunWith; | 56 | import org.junit.runner.RunWith; |
59 | import org.powermock.api.easymock.PowerMock; | 57 | import org.powermock.api.easymock.PowerMock; |
58 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
60 | import org.powermock.modules.junit4.PowerMockRunner; | 59 | import org.powermock.modules.junit4.PowerMockRunner; |
61 | -import org.powermock.reflect.Whitebox; | ||
62 | -import org.slf4j.Logger; | ||
63 | 60 | ||
64 | import br.gov.frameworkdemoiselle.configuration.ConfigType; | 61 | import br.gov.frameworkdemoiselle.configuration.ConfigType; |
65 | import br.gov.frameworkdemoiselle.configuration.Configuration; | 62 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
66 | import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; | 63 | import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; |
67 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | 64 | +import br.gov.frameworkdemoiselle.util.Beans; |
68 | 65 | ||
69 | -@Ignore | ||
70 | @RunWith(PowerMockRunner.class) | 66 | @RunWith(PowerMockRunner.class) |
67 | +@PrepareForTest(Beans.class) | ||
71 | public class ConfigurationLoaderWithListTest { | 68 | public class ConfigurationLoaderWithListTest { |
72 | 69 | ||
73 | private ConfigurationLoader configurationLoader; | 70 | private ConfigurationLoader configurationLoader; |
@@ -150,13 +147,7 @@ public class ConfigurationLoaderWithListTest { | @@ -150,13 +147,7 @@ public class ConfigurationLoaderWithListTest { | ||
150 | 147 | ||
151 | @Before | 148 | @Before |
152 | public void setUp() throws Exception { | 149 | public void setUp() throws Exception { |
153 | - Logger logger; | ||
154 | - ResourceBundle bundle; | ||
155 | - logger = PowerMock.createMock(Logger.class); | ||
156 | - bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | ||
157 | configurationLoader = new ConfigurationLoader(); | 150 | configurationLoader = new ConfigurationLoader(); |
158 | - Whitebox.setInternalState(this.configurationLoader, "bundle", bundle); | ||
159 | - Whitebox.setInternalState(this.configurationLoader, "logger", logger); | ||
160 | } | 151 | } |
161 | 152 | ||
162 | @After | 153 | @After |
@@ -342,12 +333,17 @@ public class ConfigurationLoaderWithListTest { | @@ -342,12 +333,17 @@ public class ConfigurationLoaderWithListTest { | ||
342 | } | 333 | } |
343 | 334 | ||
344 | private ConfigurationPropertiesWithList prepareConfigurationPropertiesWithList() { | 335 | private ConfigurationPropertiesWithList prepareConfigurationPropertiesWithList() { |
336 | + mockStatic(Beans.class); | ||
337 | + CoreBootstrap coreBootstrap = PowerMock.createMock(CoreBootstrap.class); | ||
338 | + | ||
339 | + expect(Beans.getReference(CoreBootstrap.class)).andReturn(coreBootstrap); | ||
340 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
341 | + | ||
345 | ConfigurationPropertiesWithList config = new ConfigurationPropertiesWithList(); | 342 | ConfigurationPropertiesWithList config = new ConfigurationPropertiesWithList(); |
346 | 343 | ||
347 | - CoreBootstrap coreBootstrap = createMock(CoreBootstrap.class); | ||
348 | expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | 344 | expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); |
349 | 345 | ||
350 | - replay(coreBootstrap); | 346 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); |
351 | 347 | ||
352 | configurationLoader.load(config); | 348 | configurationLoader.load(config); |
353 | return config; | 349 | return config; |
@@ -532,12 +528,17 @@ public class ConfigurationLoaderWithListTest { | @@ -532,12 +528,17 @@ public class ConfigurationLoaderWithListTest { | ||
532 | } | 528 | } |
533 | 529 | ||
534 | private ConfigurationXMLWithList prepareConfigurationXMLWithList() { | 530 | private ConfigurationXMLWithList prepareConfigurationXMLWithList() { |
531 | + mockStatic(Beans.class); | ||
532 | + CoreBootstrap coreBootstrap = PowerMock.createMock(CoreBootstrap.class); | ||
533 | + | ||
534 | + expect(Beans.getReference(CoreBootstrap.class)).andReturn(coreBootstrap); | ||
535 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
536 | + | ||
535 | ConfigurationXMLWithList config = new ConfigurationXMLWithList(); | 537 | ConfigurationXMLWithList config = new ConfigurationXMLWithList(); |
536 | 538 | ||
537 | - CoreBootstrap coreBootstrap = createMock(CoreBootstrap.class); | ||
538 | expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | 539 | expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); |
539 | 540 | ||
540 | - replay(coreBootstrap); | 541 | + PowerMock.replayAll(CoreBootstrap.class,Beans.class); |
541 | 542 | ||
542 | configurationLoader.load(config); | 543 | configurationLoader.load(config); |
543 | return config; | 544 | return config; |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/PaginationConfigTest.java
@@ -37,7 +37,7 @@ | @@ -37,7 +37,7 @@ | ||
37 | package br.gov.frameworkdemoiselle.internal.configuration; | 37 | package br.gov.frameworkdemoiselle.internal.configuration; |
38 | 38 | ||
39 | import static org.junit.Assert.assertEquals; | 39 | import static org.junit.Assert.assertEquals; |
40 | -import org.junit.Ignore; | 40 | + |
41 | import org.junit.Before; | 41 | import org.junit.Before; |
42 | import org.junit.Test; | 42 | import org.junit.Test; |
43 | 43 |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfigTest.java
1 | package br.gov.frameworkdemoiselle.internal.configuration; | 1 | package br.gov.frameworkdemoiselle.internal.configuration; |
2 | 2 | ||
3 | -import org.junit.Ignore; | ||
4 | import static org.junit.Assert.assertEquals; | 3 | import static org.junit.Assert.assertEquals; |
5 | 4 | ||
6 | import org.junit.Before; | 5 | import org.junit.Before; |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/context/ContextsTest.java
@@ -37,14 +37,18 @@ | @@ -37,14 +37,18 @@ | ||
37 | package br.gov.frameworkdemoiselle.internal.context; | 37 | package br.gov.frameworkdemoiselle.internal.context; |
38 | 38 | ||
39 | import static org.easymock.EasyMock.createMock; | 39 | import static org.easymock.EasyMock.createMock; |
40 | +import static org.easymock.EasyMock.expect; | ||
40 | import static org.easymock.EasyMock.expectLastCall; | 41 | import static org.easymock.EasyMock.expectLastCall; |
41 | -import static org.easymock.EasyMock.replay; | 42 | +//import static org.easymock.EasyMock.replay; |
43 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
44 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
42 | import static org.junit.Assert.assertEquals; | 45 | import static org.junit.Assert.assertEquals; |
43 | import static org.junit.Assert.assertFalse; | 46 | import static org.junit.Assert.assertFalse; |
44 | import static org.junit.Assert.assertTrue; | 47 | import static org.junit.Assert.assertTrue; |
45 | 48 | ||
46 | import java.util.ArrayList; | 49 | import java.util.ArrayList; |
47 | import java.util.List; | 50 | import java.util.List; |
51 | +import java.util.Locale; | ||
48 | 52 | ||
49 | import javax.enterprise.context.ApplicationScoped; | 53 | import javax.enterprise.context.ApplicationScoped; |
50 | import javax.enterprise.context.RequestScoped; | 54 | import javax.enterprise.context.RequestScoped; |
@@ -53,9 +57,15 @@ import javax.enterprise.inject.spi.AfterBeanDiscovery; | @@ -53,9 +57,15 @@ import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
53 | 57 | ||
54 | import org.junit.Before; | 58 | import org.junit.Before; |
55 | import org.junit.Test; | 59 | import org.junit.Test; |
60 | +import org.junit.runner.RunWith; | ||
61 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
62 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
56 | 63 | ||
57 | import br.gov.frameworkdemoiselle.annotation.ViewScoped; | 64 | import br.gov.frameworkdemoiselle.annotation.ViewScoped; |
65 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
58 | 66 | ||
67 | +@RunWith(PowerMockRunner.class) | ||
68 | +@PrepareForTest(Beans.class) | ||
59 | public class ContextsTest { | 69 | public class ContextsTest { |
60 | 70 | ||
61 | private AfterBeanDiscovery event; | 71 | private AfterBeanDiscovery event; |
@@ -63,6 +73,11 @@ public class ContextsTest { | @@ -63,6 +73,11 @@ public class ContextsTest { | ||
63 | @Before | 73 | @Before |
64 | public void setUp() throws Exception { | 74 | public void setUp() throws Exception { |
65 | Contexts.clear(); | 75 | Contexts.clear(); |
76 | + mockStatic(Beans.class); | ||
77 | + | ||
78 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
79 | + | ||
80 | + replay(Beans.class); | ||
66 | } | 81 | } |
67 | 82 | ||
68 | @Test | 83 | @Test |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducerTest.java
@@ -35,6 +35,7 @@ | @@ -35,6 +35,7 @@ | ||
35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | 35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.producer; | 37 | package br.gov.frameworkdemoiselle.internal.producer; |
38 | + | ||
38 | import org.junit.Ignore; | 39 | import org.junit.Ignore; |
39 | import static org.easymock.EasyMock.createMock; | 40 | import static org.easymock.EasyMock.createMock; |
40 | import static org.easymock.EasyMock.expect; | 41 | import static org.easymock.EasyMock.expect; |
@@ -47,7 +48,7 @@ import javax.enterprise.inject.spi.InjectionPoint; | @@ -47,7 +48,7 @@ import javax.enterprise.inject.spi.InjectionPoint; | ||
47 | 48 | ||
48 | import org.junit.Test; | 49 | import org.junit.Test; |
49 | import org.slf4j.Logger; | 50 | import org.slf4j.Logger; |
50 | -@Ignore | 51 | + |
51 | public class LoggerProducerTest { | 52 | public class LoggerProducerTest { |
52 | 53 | ||
53 | private Logger logger; | 54 | private Logger logger; |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducerTest.java
@@ -35,20 +35,35 @@ | @@ -35,20 +35,35 @@ | ||
35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | 35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.producer; | 37 | package br.gov.frameworkdemoiselle.internal.producer; |
38 | -import org.junit.Ignore; | 38 | + |
39 | +import static org.easymock.EasyMock.expect; | ||
39 | import static org.junit.Assert.assertTrue; | 40 | import static org.junit.Assert.assertTrue; |
41 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
42 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
40 | 43 | ||
41 | import java.util.Locale; | 44 | import java.util.Locale; |
42 | 45 | ||
46 | +import javax.enterprise.inject.spi.Annotated; | ||
47 | +import javax.enterprise.inject.spi.InjectionPoint; | ||
48 | + | ||
49 | +import org.easymock.EasyMock; | ||
43 | import org.junit.After; | 50 | import org.junit.After; |
44 | import org.junit.AfterClass; | 51 | import org.junit.AfterClass; |
45 | import org.junit.Assert; | 52 | import org.junit.Assert; |
46 | import org.junit.Before; | 53 | import org.junit.Before; |
47 | import org.junit.BeforeClass; | 54 | import org.junit.BeforeClass; |
48 | import org.junit.Test; | 55 | import org.junit.Test; |
56 | +import org.junit.runner.RunWith; | ||
57 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
58 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
49 | 59 | ||
50 | import br.gov.frameworkdemoiselle.DemoiselleException; | 60 | import br.gov.frameworkdemoiselle.DemoiselleException; |
51 | -@Ignore | 61 | +import br.gov.frameworkdemoiselle.annotation.Name; |
62 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
63 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
64 | + | ||
65 | +@RunWith(PowerMockRunner.class) | ||
66 | +@PrepareForTest(Beans.class) | ||
52 | public class ResourceBundleProducerTest { | 67 | public class ResourceBundleProducerTest { |
53 | 68 | ||
54 | @BeforeClass | 69 | @BeforeClass |
@@ -61,6 +76,11 @@ public class ResourceBundleProducerTest { | @@ -61,6 +76,11 @@ public class ResourceBundleProducerTest { | ||
61 | 76 | ||
62 | @Before | 77 | @Before |
63 | public void setUp() throws Exception { | 78 | public void setUp() throws Exception { |
79 | + mockStatic(Beans.class); | ||
80 | + | ||
81 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
82 | + | ||
83 | + replay(Beans.class); | ||
64 | } | 84 | } |
65 | 85 | ||
66 | @After | 86 | @After |
@@ -73,39 +93,31 @@ public class ResourceBundleProducerTest { | @@ -73,39 +93,31 @@ public class ResourceBundleProducerTest { | ||
73 | Assert.assertNotNull(factory); | 93 | Assert.assertNotNull(factory); |
74 | } | 94 | } |
75 | 95 | ||
96 | + @Test | ||
97 | + public void testCreateNullInjectionPoint() { | ||
98 | + ResourceBundleProducer factory = new ResourceBundleProducer(); | ||
99 | + ResourceBundle resourceBundle = factory.create((InjectionPoint) null); | ||
100 | + Assert.assertNotNull(resourceBundle); | ||
101 | + } | ||
102 | + | ||
76 | @Test | 103 | @Test |
77 | - public void testCreateWithNonExistentFile() { | ||
78 | - try { | ||
79 | - ResourceBundleProducer.create("arquivo_inexistente", Locale.getDefault()); | ||
80 | - } catch (Exception e) { | ||
81 | - assertTrue(e instanceof DemoiselleException); | ||
82 | - } | ||
83 | - } | 104 | + public void testCreateInjectionPointNameAnnoted() { |
105 | + Name name = EasyMock.createMock(Name.class); | ||
106 | + expect(name.value()).andReturn("demoiselle-core-bundle"); | ||
107 | + replay(name); | ||
84 | 108 | ||
85 | - // @Test | ||
86 | - // public void testCreateNullInjectionPoint() { | ||
87 | - // ResourceBundleProducer factory = new ResourceBundleProducer(); | ||
88 | - // Assert.assertNotNull(factory.create((InjectionPoint) null, Locale.getDefault())); | ||
89 | - // } | 109 | + Annotated annotated = EasyMock.createMock(Annotated.class); |
110 | + expect(annotated.getAnnotation(Name.class)).andReturn(name).anyTimes(); | ||
111 | + expect(annotated.isAnnotationPresent(Name.class)).andReturn(true).anyTimes(); | ||
112 | + replay(annotated); | ||
90 | 113 | ||
91 | - // @Test | ||
92 | - // public void testCreateInjectionPointNameAnnoted() { | ||
93 | - // Name name = EasyMock.createMock(Name.class); | ||
94 | - // expect(name.value()).andReturn("demoiselle-core-bundle"); | ||
95 | - // replay(name); | ||
96 | - // | ||
97 | - // Annotated annotated = EasyMock.createMock(Annotated.class); | ||
98 | - // expect(annotated.getAnnotation(Name.class)).andReturn(name).anyTimes(); | ||
99 | - // expect(annotated.isAnnotationPresent(Name.class)).andReturn(true).anyTimes(); | ||
100 | - // replay(annotated); | ||
101 | - // | ||
102 | - // InjectionPoint ip = EasyMock.createMock(InjectionPoint.class); | ||
103 | - // expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | ||
104 | - // replay(ip); | ||
105 | - // | ||
106 | - // ResourceBundleProducer factory = new ResourceBundleProducer(); | ||
107 | - // Assert.assertNotNull(factory.create(ip, Locale.getDefault())); | ||
108 | - // } | 114 | + InjectionPoint ip = EasyMock.createMock(InjectionPoint.class); |
115 | + expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | ||
116 | + replay(ip); | ||
117 | + | ||
118 | + ResourceBundleProducer factory = new ResourceBundleProducer(); | ||
119 | + Assert.assertNotNull(factory.create(ip)); | ||
120 | + } | ||
109 | 121 | ||
110 | // @Test | 122 | // @Test |
111 | // public void testCreateInjectionPointNameUnannoted() { | 123 | // public void testCreateInjectionPointNameUnannoted() { |