Commit f5c6bf55d0fef61ec2938d8edc99bb40519d1fd3
1 parent
d6f83053
Exists in
master
Comentando os testes quebrados que serão substituidos pelos novos testes
Showing
6 changed files
with
1490 additions
and
1490 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ConfigurationLoader.java
... | ... | @@ -163,7 +163,7 @@ public class ConfigurationLoader implements Serializable { |
163 | 163 | |
164 | 164 | if (url != null) { |
165 | 165 | result = new DataConfiguration(new PropertiesConfiguration(url)); |
166 | - }else{ | |
166 | + } else { | |
167 | 167 | getLogger().warn(getBundle().getString("resource-not-found", resource + ".properties")); |
168 | 168 | } |
169 | 169 | |
... | ... | @@ -174,7 +174,7 @@ public class ConfigurationLoader implements Serializable { |
174 | 174 | |
175 | 175 | if (url != null) { |
176 | 176 | result = new DataConfiguration(new XMLConfiguration(url)); |
177 | - }else{ | |
177 | + } else { | |
178 | 178 | getLogger().warn(getBundle().getString("resource-not-found", resource + ".xml")); |
179 | 179 | } |
180 | 180 | |
... | ... | @@ -448,9 +448,9 @@ public class ConfigurationLoader implements Serializable { |
448 | 448 | } |
449 | 449 | |
450 | 450 | this.key = this.prefix + this.name; |
451 | - | |
452 | - if(!config.containsKey(key.toString())){ | |
453 | - getLogger().debug(getBundle().getString("key-not-found", key)); | |
451 | + | |
452 | + if (!config.containsKey(this.key)) { | |
453 | + getLogger().debug(getBundle().getString("key-not-found", this.key)); | |
454 | 454 | } |
455 | 455 | } |
456 | 456 | |
... | ... | @@ -484,4 +484,4 @@ public class ConfigurationLoader implements Serializable { |
484 | 484 | return this.key; |
485 | 485 | } |
486 | 486 | } |
487 | -} | |
488 | 487 | \ No newline at end of file |
488 | +} | ... | ... |
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 java.util.Locale; | |
47 | -import java.util.Properties; | |
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.internal.bootstrap.CoreBootstrap; | |
64 | -import br.gov.frameworkdemoiselle.util.Beans; | |
65 | - | |
66 | -@RunWith(PowerMockRunner.class) | |
67 | -@PrepareForTest(Beans.class) | |
68 | -public class ConfigurationLoaderTest { | |
69 | - | |
70 | - private ConfigurationLoader configurationLoader; | |
71 | - | |
72 | - private CoreBootstrap coreBootstrap; | |
73 | - | |
74 | - @Configuration | |
75 | - public class ConfigurationSuccessfulPropertiesWithClassField { | |
76 | - | |
77 | - protected Class<?> classe; | |
78 | - | |
79 | - } | |
80 | - | |
81 | - @Configuration | |
82 | - public class ConfigurationSuccessfulPropertiesWithPropertiesField { | |
83 | - | |
84 | - protected Properties properties; | |
85 | - | |
86 | - } | |
87 | - | |
88 | - @Configuration | |
89 | - public class ConfigurationSuccessfulProperties { | |
90 | - | |
91 | - @Name("frameworkdemoiselle.configurationtest.nameConfiguration") | |
92 | - protected String nameConfiguration; | |
93 | - | |
94 | - } | |
95 | - | |
96 | - @Configuration | |
97 | - public class ConfigurationSuccessfulProperties2 { | |
98 | - | |
99 | - @Name("frameworkdemoiselle.configurationtest.name") | |
100 | - protected String name; | |
101 | - | |
102 | - } | |
103 | - | |
104 | - @Configuration(resource = "absentFile") | |
105 | - public class ConfigurationPropertiesWithAbsentFile { | |
106 | - | |
107 | - @Name("frameworkdemoiselle.configurationtest.nameConfiguration") | |
108 | - protected String nameConfiguration; | |
109 | - | |
110 | - } | |
111 | - | |
112 | - @Configuration | |
113 | - public class ConfigurationWithEmptyName { | |
114 | - | |
115 | - @Name("") | |
116 | - protected String nameConfiguration; | |
117 | - | |
118 | - } | |
119 | - | |
120 | - @Configuration | |
121 | - public class ConfigurationWithoutNameAnnotation { | |
122 | - | |
123 | - protected String nameConfiguration; | |
124 | - | |
125 | - } | |
126 | - | |
127 | - @Configuration | |
128 | - public class ConfigurationWithIgnoreAnnotation { | |
129 | - | |
130 | - @Ignore | |
131 | - protected String nameConfiguration; | |
132 | - | |
133 | - } | |
134 | - | |
135 | - @Configuration(prefix = "frameworkdemoiselle.configurationtest.") | |
136 | - public class ConfigurationWithPrefix { | |
137 | - | |
138 | - @Name("nameConfiguration") | |
139 | - protected String nameConfiguration; | |
140 | - | |
141 | - } | |
142 | - | |
143 | - @Configuration | |
144 | - public class ConfigurationWithKeyNotFoundInProperties { | |
145 | - | |
146 | - protected Integer notExistKey; | |
147 | - } | |
148 | - | |
149 | - @Configuration | |
150 | - public class ConfigurationWithNotNullFieldButValueIsNull { | |
151 | - | |
152 | - @Name("notexistKey") | |
153 | - @NotNull | |
154 | - protected int nameConfiguration; | |
155 | - | |
156 | - } | |
157 | - | |
158 | - @Configuration | |
159 | - public class ConfigurationWithNotNullFieldAndValueIsNotNull { | |
160 | - | |
161 | - @Name("nameConfiguration") | |
162 | - @NotNull | |
163 | - protected String nameConfiguration; | |
164 | - | |
165 | - } | |
166 | - | |
167 | - @Configuration | |
168 | - public class ConfigurationWithNonPrimitiveFieldValueNull { | |
169 | - | |
170 | - @Name("notexistKey") | |
171 | - protected String nameConfiguration; | |
172 | - | |
173 | - } | |
174 | - | |
175 | - @Configuration | |
176 | - public class ConfigurationWithPrimitiveFieldValueNull { | |
177 | - | |
178 | - @Name("notexistKey") | |
179 | - protected int nameConfiguration = 1; | |
180 | - | |
181 | - } | |
182 | - | |
183 | - @Configuration(type = ConfigType.SYSTEM) | |
184 | - public class ConfigurationWithKeyFromSystem { | |
185 | - | |
186 | - @Name("os.name") | |
187 | - protected String nameConfiguration; | |
188 | - | |
189 | - } | |
190 | - | |
191 | - @Configuration(type = ConfigType.XML) | |
192 | - public class ConfigurationWithKeyFromXML { | |
193 | - | |
194 | - @Name("nameConfiguration") | |
195 | - protected String nameConfiguration; | |
196 | - | |
197 | - } | |
198 | - | |
199 | - @Configuration(type = ConfigType.XML, prefix = "br.gov.frameworkdemoiselle") | |
200 | - public class ConfigurationFromXMLWithPrefix { | |
201 | - | |
202 | - @Name("nameConfiguration") | |
203 | - protected String nameConfiguration; | |
204 | - | |
205 | - } | |
206 | - | |
207 | - @Configuration | |
208 | - public class ConfigurationWithConventionAllUpperCase { | |
209 | - | |
210 | - protected String conventionAllUpperCase; | |
211 | - | |
212 | - } | |
213 | - | |
214 | - @Configuration(type = ConfigType.XML) | |
215 | - public class ConfigurationXMLWithConventionAllUpperCase { | |
216 | - | |
217 | - protected String conventionAllUpperCase; | |
218 | - | |
219 | - } | |
220 | - | |
221 | - @Configuration | |
222 | - public class ConfigurationWithConventionAllLowerCase { | |
223 | - | |
224 | - protected String conventionAllLowerCase; | |
225 | - | |
226 | - } | |
227 | - | |
228 | - @Configuration(type = ConfigType.XML) | |
229 | - public class ConfigurationXMLWithConventionAllLowerCase { | |
230 | - | |
231 | - protected String conventionAllLowerCase; | |
232 | - | |
233 | - } | |
234 | - | |
235 | - @Configuration(prefix = "br.gov.frameworkdemoiselle.") | |
236 | - public class ConfigurationPropertiesSuccessWithPrefixNonAmbiguous { | |
237 | - | |
238 | - protected String success; | |
239 | - | |
240 | - } | |
241 | - | |
242 | - @Configuration | |
243 | - public class ConfigurationPropertiesErrorWithComplexObject { | |
244 | - | |
245 | - protected ConfigurationWithConventionAllLowerCase complexObject; | |
246 | - } | |
247 | - | |
248 | - @Before | |
249 | - public void setUp() throws Exception { | |
250 | - this.configurationLoader = new ConfigurationLoader(); | |
251 | - mockStatic(Beans.class); | |
252 | - this.coreBootstrap = PowerMock.createMock(CoreBootstrap.class); | |
253 | - | |
254 | - expect(Beans.getReference(CoreBootstrap.class)).andReturn(coreBootstrap); | |
255 | - expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | |
256 | - } | |
257 | - | |
258 | - @After | |
259 | - public void tearDown() throws Exception { | |
260 | - } | |
261 | - | |
262 | - @Test | |
263 | - public void testConfigurationSuccessfulPropertiesWithClassField() { | |
264 | - ConfigurationSuccessfulPropertiesWithClassField config = new ConfigurationSuccessfulPropertiesWithClassField(); | |
265 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
266 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
267 | - configurationLoader.load(config); | |
268 | - assertEquals(ConfigurationLoaderTest.class, config.classe); | |
269 | - } | |
270 | - | |
271 | - @Test | |
272 | - public void testConfigurationSuccessfulPropertiesWithPropertiesField() { | |
273 | - ConfigurationSuccessfulPropertiesWithPropertiesField config = new ConfigurationSuccessfulPropertiesWithPropertiesField(); | |
274 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
275 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
276 | - configurationLoader.load(config); | |
277 | - assertEquals("teste1", config.properties.getProperty("1")); | |
278 | - assertEquals("teste2", config.properties.getProperty("2")); | |
279 | - assertTrue(config.properties.containsKey("1")); | |
280 | - assertTrue(config.properties.containsKey("2")); | |
281 | - } | |
282 | - | |
283 | - @Test | |
284 | - public void testConfigurationSuccessfulPropertiesPossibleConventions() { | |
285 | - ConfigurationSuccessfulProperties config = new ConfigurationSuccessfulProperties(); | |
286 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
287 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
288 | - configurationLoader.load(config); | |
289 | - assertEquals("ConfigurationTest", config.nameConfiguration); | |
290 | - | |
291 | - } | |
292 | - | |
293 | - @Test | |
294 | - public void testConfigurationSuccessfulPropertiesNoConventions() { | |
295 | - ConfigurationSuccessfulProperties2 config = new ConfigurationSuccessfulProperties2(); | |
296 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
297 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
298 | - configurationLoader.load(config); | |
299 | - assertEquals("ConfigurationTest2", config.name); | |
300 | - } | |
301 | - | |
302 | - // @Test | |
303 | - // public void ConfigurationPropertiesWithAbsentFile() { | |
304 | - // ConfigurationPropertiesWithAbsentFile config = new ConfigurationPropertiesWithAbsentFile(); | |
305 | - // | |
306 | - // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
307 | - // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
308 | - // | |
309 | - // try { | |
310 | - // configurationLoader.load(config); | |
311 | - // fail(); | |
312 | - // } catch (Exception e) { | |
313 | - // } | |
314 | - // } | |
315 | - | |
316 | - @Test | |
317 | - public void testConfigurationProcessorWithNameEmpty() { | |
318 | - ConfigurationWithEmptyName config = new ConfigurationWithEmptyName(); | |
319 | - | |
320 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
321 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
322 | - | |
323 | - try { | |
324 | - configurationLoader.load(config); | |
325 | - fail(); | |
326 | - } catch (Exception e) { | |
327 | - } | |
328 | - } | |
329 | - | |
330 | - @Test | |
331 | - public void testConfigurationWithoutNameAnnotation() { | |
332 | - ConfigurationWithoutNameAnnotation config = new ConfigurationWithoutNameAnnotation(); | |
333 | - | |
334 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
335 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
336 | - | |
337 | - configurationLoader.load(config); | |
338 | - assertEquals("ConfigurationTest", config.nameConfiguration); | |
339 | - } | |
340 | - | |
341 | - @Test | |
342 | - public void testConfigurationWithIgnoreAnnotation() { | |
343 | - ConfigurationWithIgnoreAnnotation config = new ConfigurationWithIgnoreAnnotation(); | |
344 | - | |
345 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
346 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
347 | - | |
348 | - configurationLoader.load(config); | |
349 | - assertNull(config.nameConfiguration); | |
350 | - } | |
351 | - | |
352 | - @Test | |
353 | - public void testConfigurationWithPrefix() { | |
354 | - ConfigurationWithPrefix config = new ConfigurationWithPrefix(); | |
355 | - | |
356 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
357 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
358 | - | |
359 | - configurationLoader.load(config); | |
360 | - assertEquals("ConfigurationTest", config.nameConfiguration); | |
361 | - } | |
362 | - | |
363 | - @Test | |
364 | - public void testConfigurationWithKeyNotFoundInProperties() { | |
365 | - ConfigurationWithKeyNotFoundInProperties config = new ConfigurationWithKeyNotFoundInProperties(); | |
366 | - | |
367 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
368 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
369 | - | |
370 | - configurationLoader.load(config); | |
371 | - assertNull(config.notExistKey); | |
372 | - } | |
373 | - | |
374 | - @Test | |
375 | - public void testConfigurationWithNotNullFieldButValueIsNull() { | |
376 | - ConfigurationWithNotNullFieldButValueIsNull config = new ConfigurationWithNotNullFieldButValueIsNull(); | |
377 | - | |
378 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
379 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
380 | - | |
381 | - try { | |
382 | - configurationLoader.load(config); | |
383 | - fail(); | |
384 | - } catch (Exception e) { | |
385 | - assertTrue(true); | |
386 | - } | |
387 | - } | |
388 | - | |
389 | - @Test | |
390 | - public void testConfigurationWithNotNullFieldAndValueIsNotNull() { | |
391 | - ConfigurationWithNotNullFieldAndValueIsNotNull config = new ConfigurationWithNotNullFieldAndValueIsNotNull(); | |
392 | - | |
393 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
394 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
395 | - | |
396 | - configurationLoader.load(config); | |
397 | - assertEquals("ConfigurationTest", config.nameConfiguration); | |
398 | - } | |
399 | - | |
400 | - @Test | |
401 | - public void testConfigurationWithNonPrimitiveFieldValueNull() { | |
402 | - ConfigurationWithNonPrimitiveFieldValueNull config = new ConfigurationWithNonPrimitiveFieldValueNull(); | |
403 | - | |
404 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
405 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
406 | - | |
407 | - configurationLoader.load(config); | |
408 | - assertNull(config.nameConfiguration); | |
409 | - } | |
410 | - | |
411 | - @Test | |
412 | - public void testConfigurationWithPrimitiveFieldValueNull() { | |
413 | - ConfigurationWithPrimitiveFieldValueNull config = new ConfigurationWithPrimitiveFieldValueNull(); | |
414 | - | |
415 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
416 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
417 | - | |
418 | - configurationLoader.load(config); | |
419 | - assertEquals(1, config.nameConfiguration); | |
420 | - } | |
421 | - | |
422 | - @Test | |
423 | - public void testConfigurationWithKeyFromSystem() { | |
424 | - ConfigurationWithKeyFromSystem config = new ConfigurationWithKeyFromSystem(); | |
425 | - | |
426 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
427 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
428 | - | |
429 | - configurationLoader.load(config); | |
430 | - assertEquals(System.getProperty("os.name"), config.nameConfiguration); | |
431 | - } | |
432 | - | |
433 | - @Test | |
434 | - public void testConfigurationWithKeyFromXML() { | |
435 | - ConfigurationWithKeyFromXML config = new ConfigurationWithKeyFromXML(); | |
436 | - | |
437 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
438 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
439 | - | |
440 | - configurationLoader.load(config); | |
441 | - assertEquals("ConfigurationTest", config.nameConfiguration); | |
442 | - } | |
443 | - | |
444 | - @Test | |
445 | - public void testConfigurationWithPrefixNotAmbiguous() { | |
446 | - ConfigurationPropertiesSuccessWithPrefixNonAmbiguous config = new ConfigurationPropertiesSuccessWithPrefixNonAmbiguous(); | |
447 | - | |
448 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
449 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
450 | - | |
451 | - configurationLoader.load(config); | |
452 | - assertEquals("Success", config.success); | |
453 | - } | |
454 | - | |
455 | - // @Test | |
456 | - // public void testConfigurationWithConventionAllLowerCase() { | |
457 | - // ConfigurationWithConventionAllLowerCase config = new ConfigurationWithConventionAllLowerCase(); | |
458 | - // | |
459 | - // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
460 | - // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
461 | - // | |
462 | - // configurationLoader.load(config); | |
463 | - // assertEquals("All LowerCase", config.conventionAllLowerCase); | |
464 | - // } | |
465 | - | |
466 | - // @Test | |
467 | - // public void testConfigurationWithConventionAllUpperCase() { | |
468 | - // ConfigurationWithConventionAllUpperCase config = new ConfigurationWithConventionAllUpperCase(); | |
469 | - // | |
470 | - // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
471 | - // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
472 | - // | |
473 | - // configurationLoader.load(config); | |
474 | - // assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); | |
475 | - // } | |
476 | - | |
477 | - @Test | |
478 | - public void testConfigurationPropertiesErrorWithComplexObject() { | |
479 | - ConfigurationPropertiesErrorWithComplexObject config = new ConfigurationPropertiesErrorWithComplexObject(); | |
480 | - | |
481 | - expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
482 | - PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
483 | - | |
484 | - try { | |
485 | - configurationLoader.load(config); | |
486 | - fail(); | |
487 | - } catch (Throwable throwable) { | |
488 | - } | |
489 | - } | |
490 | - | |
491 | - // @Test | |
492 | - // public void testConfigurationFromXMLWithPrefix() { | |
493 | - // ConfigurationFromXMLWithPrefix config = new ConfigurationFromXMLWithPrefix(); | |
494 | - // | |
495 | - // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
496 | - // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
497 | - // | |
498 | - // configurationLoader.load(config); | |
499 | - // assertEquals("ConfigurationTest", config.nameConfiguration); | |
500 | - // } | |
501 | - | |
502 | - // @Test | |
503 | - // public void testConfigurationXMLWithConventionAllUpperCase() { | |
504 | - // ConfigurationXMLWithConventionAllUpperCase config = new ConfigurationXMLWithConventionAllUpperCase(); | |
505 | - // | |
506 | - // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
507 | - // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
508 | - // | |
509 | - // configurationLoader.load(config); | |
510 | - // assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); | |
511 | - // } | |
512 | - | |
513 | - // @Test | |
514 | - // public void testConfigurationXMLWithConventionAllLowerCase() { | |
515 | - // ConfigurationXMLWithConventionAllLowerCase config = new ConfigurationXMLWithConventionAllLowerCase(); | |
516 | - // | |
517 | - // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
518 | - // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
519 | - // | |
520 | - // configurationLoader.load(config); | |
521 | - // assertEquals("All LowerCase", config.conventionAllLowerCase); | |
522 | - // } | |
523 | -} | |
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 java.util.Locale; | |
47 | +//import java.util.Properties; | |
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.internal.bootstrap.CoreBootstrap; | |
64 | +//import br.gov.frameworkdemoiselle.util.Beans; | |
65 | +// | |
66 | +//@RunWith(PowerMockRunner.class) | |
67 | +//@PrepareForTest(Beans.class) | |
68 | +//public class ConfigurationLoaderTest { | |
69 | +// | |
70 | +// private ConfigurationLoader configurationLoader; | |
71 | +// | |
72 | +// private CoreBootstrap coreBootstrap; | |
73 | +// | |
74 | +// @Configuration | |
75 | +// public class ConfigurationSuccessfulPropertiesWithClassField { | |
76 | +// | |
77 | +// protected Class<?> classe; | |
78 | +// | |
79 | +// } | |
80 | +// | |
81 | +// @Configuration | |
82 | +// public class ConfigurationSuccessfulPropertiesWithPropertiesField { | |
83 | +// | |
84 | +// protected Properties properties; | |
85 | +// | |
86 | +// } | |
87 | +// | |
88 | +// @Configuration | |
89 | +// public class ConfigurationSuccessfulProperties { | |
90 | +// | |
91 | +// @Name("frameworkdemoiselle.configurationtest.nameConfiguration") | |
92 | +// protected String nameConfiguration; | |
93 | +// | |
94 | +// } | |
95 | +// | |
96 | +// @Configuration | |
97 | +// public class ConfigurationSuccessfulProperties2 { | |
98 | +// | |
99 | +// @Name("frameworkdemoiselle.configurationtest.name") | |
100 | +// protected String name; | |
101 | +// | |
102 | +// } | |
103 | +// | |
104 | +// @Configuration(resource = "absentFile") | |
105 | +// public class ConfigurationPropertiesWithAbsentFile { | |
106 | +// | |
107 | +// @Name("frameworkdemoiselle.configurationtest.nameConfiguration") | |
108 | +// protected String nameConfiguration; | |
109 | +// | |
110 | +// } | |
111 | +// | |
112 | +// @Configuration | |
113 | +// public class ConfigurationWithEmptyName { | |
114 | +// | |
115 | +// @Name("") | |
116 | +// protected String nameConfiguration; | |
117 | +// | |
118 | +// } | |
119 | +// | |
120 | +// @Configuration | |
121 | +// public class ConfigurationWithoutNameAnnotation { | |
122 | +// | |
123 | +// protected String nameConfiguration; | |
124 | +// | |
125 | +// } | |
126 | +// | |
127 | +// @Configuration | |
128 | +// public class ConfigurationWithIgnoreAnnotation { | |
129 | +// | |
130 | +// @Ignore | |
131 | +// protected String nameConfiguration; | |
132 | +// | |
133 | +// } | |
134 | +// | |
135 | +// @Configuration(prefix = "frameworkdemoiselle.configurationtest.") | |
136 | +// public class ConfigurationWithPrefix { | |
137 | +// | |
138 | +// @Name("nameConfiguration") | |
139 | +// protected String nameConfiguration; | |
140 | +// | |
141 | +// } | |
142 | +// | |
143 | +// @Configuration | |
144 | +// public class ConfigurationWithKeyNotFoundInProperties { | |
145 | +// | |
146 | +// protected Integer notExistKey; | |
147 | +// } | |
148 | +// | |
149 | +// @Configuration | |
150 | +// public class ConfigurationWithNotNullFieldButValueIsNull { | |
151 | +// | |
152 | +// @Name("notexistKey") | |
153 | +// @NotNull | |
154 | +// protected int nameConfiguration; | |
155 | +// | |
156 | +// } | |
157 | +// | |
158 | +// @Configuration | |
159 | +// public class ConfigurationWithNotNullFieldAndValueIsNotNull { | |
160 | +// | |
161 | +// @Name("nameConfiguration") | |
162 | +// @NotNull | |
163 | +// protected String nameConfiguration; | |
164 | +// | |
165 | +// } | |
166 | +// | |
167 | +// @Configuration | |
168 | +// public class ConfigurationWithNonPrimitiveFieldValueNull { | |
169 | +// | |
170 | +// @Name("notexistKey") | |
171 | +// protected String nameConfiguration; | |
172 | +// | |
173 | +// } | |
174 | +// | |
175 | +// @Configuration | |
176 | +// public class ConfigurationWithPrimitiveFieldValueNull { | |
177 | +// | |
178 | +// @Name("notexistKey") | |
179 | +// protected int nameConfiguration = 1; | |
180 | +// | |
181 | +// } | |
182 | +// | |
183 | +// @Configuration(type = ConfigType.SYSTEM) | |
184 | +// public class ConfigurationWithKeyFromSystem { | |
185 | +// | |
186 | +// @Name("os.name") | |
187 | +// protected String nameConfiguration; | |
188 | +// | |
189 | +// } | |
190 | +// | |
191 | +// @Configuration(type = ConfigType.XML) | |
192 | +// public class ConfigurationWithKeyFromXML { | |
193 | +// | |
194 | +// @Name("nameConfiguration") | |
195 | +// protected String nameConfiguration; | |
196 | +// | |
197 | +// } | |
198 | +// | |
199 | +// @Configuration(type = ConfigType.XML, prefix = "br.gov.frameworkdemoiselle") | |
200 | +// public class ConfigurationFromXMLWithPrefix { | |
201 | +// | |
202 | +// @Name("nameConfiguration") | |
203 | +// protected String nameConfiguration; | |
204 | +// | |
205 | +// } | |
206 | +// | |
207 | +// @Configuration | |
208 | +// public class ConfigurationWithConventionAllUpperCase { | |
209 | +// | |
210 | +// protected String conventionAllUpperCase; | |
211 | +// | |
212 | +// } | |
213 | +// | |
214 | +// @Configuration(type = ConfigType.XML) | |
215 | +// public class ConfigurationXMLWithConventionAllUpperCase { | |
216 | +// | |
217 | +// protected String conventionAllUpperCase; | |
218 | +// | |
219 | +// } | |
220 | +// | |
221 | +// @Configuration | |
222 | +// public class ConfigurationWithConventionAllLowerCase { | |
223 | +// | |
224 | +// protected String conventionAllLowerCase; | |
225 | +// | |
226 | +// } | |
227 | +// | |
228 | +// @Configuration(type = ConfigType.XML) | |
229 | +// public class ConfigurationXMLWithConventionAllLowerCase { | |
230 | +// | |
231 | +// protected String conventionAllLowerCase; | |
232 | +// | |
233 | +// } | |
234 | +// | |
235 | +// @Configuration(prefix = "br.gov.frameworkdemoiselle.") | |
236 | +// public class ConfigurationPropertiesSuccessWithPrefixNonAmbiguous { | |
237 | +// | |
238 | +// protected String success; | |
239 | +// | |
240 | +// } | |
241 | +// | |
242 | +// @Configuration | |
243 | +// public class ConfigurationPropertiesErrorWithComplexObject { | |
244 | +// | |
245 | +// protected ConfigurationWithConventionAllLowerCase complexObject; | |
246 | +// } | |
247 | +// | |
248 | +// @Before | |
249 | +// public void setUp() throws Exception { | |
250 | +// this.configurationLoader = new ConfigurationLoader(); | |
251 | +// mockStatic(Beans.class); | |
252 | +// this.coreBootstrap = PowerMock.createMock(CoreBootstrap.class); | |
253 | +// | |
254 | +// expect(Beans.getReference(CoreBootstrap.class)).andReturn(coreBootstrap); | |
255 | +// expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | |
256 | +// } | |
257 | +// | |
258 | +// @After | |
259 | +// public void tearDown() throws Exception { | |
260 | +// } | |
261 | +// | |
262 | +// @Test | |
263 | +// public void testConfigurationSuccessfulPropertiesWithClassField() { | |
264 | +// ConfigurationSuccessfulPropertiesWithClassField config = new ConfigurationSuccessfulPropertiesWithClassField(); | |
265 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
266 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
267 | +// configurationLoader.load(config); | |
268 | +// assertEquals(ConfigurationLoaderTest.class, config.classe); | |
269 | +// } | |
270 | +// | |
271 | +// @Test | |
272 | +// public void testConfigurationSuccessfulPropertiesWithPropertiesField() { | |
273 | +// ConfigurationSuccessfulPropertiesWithPropertiesField config = new ConfigurationSuccessfulPropertiesWithPropertiesField(); | |
274 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
275 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
276 | +// configurationLoader.load(config); | |
277 | +// assertEquals("teste1", config.properties.getProperty("1")); | |
278 | +// assertEquals("teste2", config.properties.getProperty("2")); | |
279 | +// assertTrue(config.properties.containsKey("1")); | |
280 | +// assertTrue(config.properties.containsKey("2")); | |
281 | +// } | |
282 | +// | |
283 | +// @Test | |
284 | +// public void testConfigurationSuccessfulPropertiesPossibleConventions() { | |
285 | +// ConfigurationSuccessfulProperties config = new ConfigurationSuccessfulProperties(); | |
286 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
287 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
288 | +// configurationLoader.load(config); | |
289 | +// assertEquals("ConfigurationTest", config.nameConfiguration); | |
290 | +// | |
291 | +// } | |
292 | +// | |
293 | +// @Test | |
294 | +// public void testConfigurationSuccessfulPropertiesNoConventions() { | |
295 | +// ConfigurationSuccessfulProperties2 config = new ConfigurationSuccessfulProperties2(); | |
296 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
297 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
298 | +// configurationLoader.load(config); | |
299 | +// assertEquals("ConfigurationTest2", config.name); | |
300 | +// } | |
301 | +// | |
302 | +// // @Test | |
303 | +// // public void ConfigurationPropertiesWithAbsentFile() { | |
304 | +// // ConfigurationPropertiesWithAbsentFile config = new ConfigurationPropertiesWithAbsentFile(); | |
305 | +// // | |
306 | +// // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
307 | +// // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
308 | +// // | |
309 | +// // try { | |
310 | +// // configurationLoader.load(config); | |
311 | +// // fail(); | |
312 | +// // } catch (Exception e) { | |
313 | +// // } | |
314 | +// // } | |
315 | +// | |
316 | +// @Test | |
317 | +// public void testConfigurationProcessorWithNameEmpty() { | |
318 | +// ConfigurationWithEmptyName config = new ConfigurationWithEmptyName(); | |
319 | +// | |
320 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
321 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
322 | +// | |
323 | +// try { | |
324 | +// configurationLoader.load(config); | |
325 | +// fail(); | |
326 | +// } catch (Exception e) { | |
327 | +// } | |
328 | +// } | |
329 | +// | |
330 | +// @Test | |
331 | +// public void testConfigurationWithoutNameAnnotation() { | |
332 | +// ConfigurationWithoutNameAnnotation config = new ConfigurationWithoutNameAnnotation(); | |
333 | +// | |
334 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
335 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
336 | +// | |
337 | +// configurationLoader.load(config); | |
338 | +// assertEquals("ConfigurationTest", config.nameConfiguration); | |
339 | +// } | |
340 | +// | |
341 | +// @Test | |
342 | +// public void testConfigurationWithIgnoreAnnotation() { | |
343 | +// ConfigurationWithIgnoreAnnotation config = new ConfigurationWithIgnoreAnnotation(); | |
344 | +// | |
345 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
346 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
347 | +// | |
348 | +// configurationLoader.load(config); | |
349 | +// assertNull(config.nameConfiguration); | |
350 | +// } | |
351 | +// | |
352 | +// @Test | |
353 | +// public void testConfigurationWithPrefix() { | |
354 | +// ConfigurationWithPrefix config = new ConfigurationWithPrefix(); | |
355 | +// | |
356 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
357 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
358 | +// | |
359 | +// configurationLoader.load(config); | |
360 | +// assertEquals("ConfigurationTest", config.nameConfiguration); | |
361 | +// } | |
362 | +// | |
363 | +// @Test | |
364 | +// public void testConfigurationWithKeyNotFoundInProperties() { | |
365 | +// ConfigurationWithKeyNotFoundInProperties config = new ConfigurationWithKeyNotFoundInProperties(); | |
366 | +// | |
367 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
368 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
369 | +// | |
370 | +// configurationLoader.load(config); | |
371 | +// assertNull(config.notExistKey); | |
372 | +// } | |
373 | +// | |
374 | +// @Test | |
375 | +// public void testConfigurationWithNotNullFieldButValueIsNull() { | |
376 | +// ConfigurationWithNotNullFieldButValueIsNull config = new ConfigurationWithNotNullFieldButValueIsNull(); | |
377 | +// | |
378 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
379 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
380 | +// | |
381 | +// try { | |
382 | +// configurationLoader.load(config); | |
383 | +// fail(); | |
384 | +// } catch (Exception e) { | |
385 | +// assertTrue(true); | |
386 | +// } | |
387 | +// } | |
388 | +// | |
389 | +// @Test | |
390 | +// public void testConfigurationWithNotNullFieldAndValueIsNotNull() { | |
391 | +// ConfigurationWithNotNullFieldAndValueIsNotNull config = new ConfigurationWithNotNullFieldAndValueIsNotNull(); | |
392 | +// | |
393 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
394 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
395 | +// | |
396 | +// configurationLoader.load(config); | |
397 | +// assertEquals("ConfigurationTest", config.nameConfiguration); | |
398 | +// } | |
399 | +// | |
400 | +// @Test | |
401 | +// public void testConfigurationWithNonPrimitiveFieldValueNull() { | |
402 | +// ConfigurationWithNonPrimitiveFieldValueNull config = new ConfigurationWithNonPrimitiveFieldValueNull(); | |
403 | +// | |
404 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
405 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
406 | +// | |
407 | +// configurationLoader.load(config); | |
408 | +// assertNull(config.nameConfiguration); | |
409 | +// } | |
410 | +// | |
411 | +// @Test | |
412 | +// public void testConfigurationWithPrimitiveFieldValueNull() { | |
413 | +// ConfigurationWithPrimitiveFieldValueNull config = new ConfigurationWithPrimitiveFieldValueNull(); | |
414 | +// | |
415 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
416 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
417 | +// | |
418 | +// configurationLoader.load(config); | |
419 | +// assertEquals(1, config.nameConfiguration); | |
420 | +// } | |
421 | +// | |
422 | +// @Test | |
423 | +// public void testConfigurationWithKeyFromSystem() { | |
424 | +// ConfigurationWithKeyFromSystem config = new ConfigurationWithKeyFromSystem(); | |
425 | +// | |
426 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
427 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
428 | +// | |
429 | +// configurationLoader.load(config); | |
430 | +// assertEquals(System.getProperty("os.name"), config.nameConfiguration); | |
431 | +// } | |
432 | +// | |
433 | +// @Test | |
434 | +// public void testConfigurationWithKeyFromXML() { | |
435 | +// ConfigurationWithKeyFromXML config = new ConfigurationWithKeyFromXML(); | |
436 | +// | |
437 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
438 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
439 | +// | |
440 | +// configurationLoader.load(config); | |
441 | +// assertEquals("ConfigurationTest", config.nameConfiguration); | |
442 | +// } | |
443 | +// | |
444 | +// @Test | |
445 | +// public void testConfigurationWithPrefixNotAmbiguous() { | |
446 | +// ConfigurationPropertiesSuccessWithPrefixNonAmbiguous config = new ConfigurationPropertiesSuccessWithPrefixNonAmbiguous(); | |
447 | +// | |
448 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
449 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
450 | +// | |
451 | +// configurationLoader.load(config); | |
452 | +// assertEquals("Success", config.success); | |
453 | +// } | |
454 | +// | |
455 | +// // @Test | |
456 | +// // public void testConfigurationWithConventionAllLowerCase() { | |
457 | +// // ConfigurationWithConventionAllLowerCase config = new ConfigurationWithConventionAllLowerCase(); | |
458 | +// // | |
459 | +// // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
460 | +// // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
461 | +// // | |
462 | +// // configurationLoader.load(config); | |
463 | +// // assertEquals("All LowerCase", config.conventionAllLowerCase); | |
464 | +// // } | |
465 | +// | |
466 | +// // @Test | |
467 | +// // public void testConfigurationWithConventionAllUpperCase() { | |
468 | +// // ConfigurationWithConventionAllUpperCase config = new ConfigurationWithConventionAllUpperCase(); | |
469 | +// // | |
470 | +// // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
471 | +// // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
472 | +// // | |
473 | +// // configurationLoader.load(config); | |
474 | +// // assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); | |
475 | +// // } | |
476 | +// | |
477 | +// @Test | |
478 | +// public void testConfigurationPropertiesErrorWithComplexObject() { | |
479 | +// ConfigurationPropertiesErrorWithComplexObject config = new ConfigurationPropertiesErrorWithComplexObject(); | |
480 | +// | |
481 | +// expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
482 | +// PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
483 | +// | |
484 | +// try { | |
485 | +// configurationLoader.load(config); | |
486 | +// fail(); | |
487 | +// } catch (Throwable throwable) { | |
488 | +// } | |
489 | +// } | |
490 | +// | |
491 | +// // @Test | |
492 | +// // public void testConfigurationFromXMLWithPrefix() { | |
493 | +// // ConfigurationFromXMLWithPrefix config = new ConfigurationFromXMLWithPrefix(); | |
494 | +// // | |
495 | +// // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
496 | +// // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
497 | +// // | |
498 | +// // configurationLoader.load(config); | |
499 | +// // assertEquals("ConfigurationTest", config.nameConfiguration); | |
500 | +// // } | |
501 | +// | |
502 | +// // @Test | |
503 | +// // public void testConfigurationXMLWithConventionAllUpperCase() { | |
504 | +// // ConfigurationXMLWithConventionAllUpperCase config = new ConfigurationXMLWithConventionAllUpperCase(); | |
505 | +// // | |
506 | +// // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
507 | +// // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
508 | +// // | |
509 | +// // configurationLoader.load(config); | |
510 | +// // assertEquals("ALL UPPERCASE", config.conventionAllUpperCase); | |
511 | +// // } | |
512 | +// | |
513 | +// // @Test | |
514 | +// // public void testConfigurationXMLWithConventionAllLowerCase() { | |
515 | +// // ConfigurationXMLWithConventionAllLowerCase config = new ConfigurationXMLWithConventionAllLowerCase(); | |
516 | +// // | |
517 | +// // expect(coreBootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
518 | +// // PowerMock.replayAll(CoreBootstrap.class, Beans.class); | |
519 | +// // | |
520 | +// // configurationLoader.load(config); | |
521 | +// // assertEquals("All LowerCase", config.conventionAllLowerCase); | |
522 | +// // } | |
523 | +//} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.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.interceptor; | |
38 | - | |
39 | -import static org.easymock.EasyMock.expect; | |
40 | -import static org.easymock.EasyMock.verify; | |
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 | -import static org.powermock.api.easymock.PowerMock.replay; | |
47 | -import static org.powermock.api.easymock.PowerMock.replayAll; | |
48 | -import static org.powermock.api.easymock.PowerMock.verifyAll; | |
49 | - | |
50 | -import java.util.Locale; | |
51 | - | |
52 | -import javax.interceptor.InvocationContext; | |
53 | - | |
54 | -import org.easymock.EasyMock; | |
55 | -import org.junit.Before; | |
56 | -import org.junit.Test; | |
57 | -import org.junit.runner.RunWith; | |
58 | -import org.powermock.api.easymock.PowerMock; | |
59 | -import org.powermock.core.classloader.annotations.PrepareForTest; | |
60 | -import org.powermock.modules.junit4.PowerMockRunner; | |
61 | -import org.slf4j.Logger; | |
62 | - | |
63 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
64 | -import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | |
65 | -import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; | |
66 | -import br.gov.frameworkdemoiselle.util.Beans; | |
67 | - | |
68 | -@RunWith(PowerMockRunner.class) | |
69 | -@PrepareForTest(Beans.class) | |
70 | -public class ExceptionHandlerInterceptorTest { | |
71 | - | |
72 | - private ExceptionHandlerInterceptor interceptor; | |
73 | - | |
74 | - private InvocationContext context; | |
75 | - | |
76 | - private Logger logger; | |
77 | - | |
78 | - private CoreBootstrap coreBootstrap; | |
79 | - | |
80 | - class TestException extends DemoiselleException { | |
81 | - | |
82 | - private static final long serialVersionUID = 1L; | |
83 | - | |
84 | - public TestException(String message) { | |
85 | - super(message); | |
86 | - } | |
87 | - } | |
88 | - | |
89 | - class ClassWithMethodsAnnotatedWithExceptionHandler { | |
90 | - | |
91 | - int times = 0; | |
92 | - | |
93 | - @ExceptionHandler | |
94 | - public void methodWithExceptionHandlerAnotation(DemoiselleException cause) { | |
95 | - times++; | |
96 | - } | |
97 | - | |
98 | - @ExceptionHandler | |
99 | - public void methodWithExceptionHandlerAnotationAndGenericException(Exception cause) { | |
100 | - times++; | |
101 | - } | |
102 | - | |
103 | - } | |
104 | - | |
105 | - class ClassWithoutMethodsAnnotatedWithExceptionHandler { | |
106 | - | |
107 | - public void methodWithoutExceptionHandlerAnotation(DemoiselleException cause) { | |
108 | - } | |
109 | - } | |
110 | - | |
111 | - class ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException { | |
112 | - | |
113 | - int times = 0; | |
114 | - | |
115 | - @ExceptionHandler | |
116 | - public void methodWithExceptionHandlerAnotation(DemoiselleException cause) { | |
117 | - times++; | |
118 | - throw new RuntimeException(); | |
119 | - } | |
120 | - } | |
121 | - | |
122 | - class ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler { | |
123 | - | |
124 | - @ExceptionHandler | |
125 | - public void methodWithExceptionHandlerAnotation() { | |
126 | - } | |
127 | - | |
128 | - } | |
129 | - | |
130 | - class ClassWithExceptionHandlerMethodThatRethrowException { | |
131 | - | |
132 | - int times = 0; | |
133 | - | |
134 | - @ExceptionHandler | |
135 | - public void methodThatRethrowException(TestException cause) { | |
136 | - times++; | |
137 | - throw cause; | |
138 | - } | |
139 | - | |
140 | - } | |
141 | - | |
142 | - @Before | |
143 | - public void setUp() throws Exception { | |
144 | - | |
145 | - this.interceptor = new ExceptionHandlerInterceptor(); | |
146 | - this.context = PowerMock.createMock(InvocationContext.class); | |
147 | - this.coreBootstrap = PowerMock.createMock(CoreBootstrap.class); | |
148 | - | |
149 | - mockStatic(Beans.class); | |
150 | - expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()).anyTimes(); | |
151 | - expect(Beans.getReference(CoreBootstrap.class)).andReturn(this.coreBootstrap).anyTimes(); | |
152 | - | |
153 | - } | |
154 | - | |
155 | - @Test | |
156 | - public void manageSuccessfully() throws Throwable { | |
157 | - expect(this.context.proceed()).andReturn(null); | |
158 | - expect(this.context.getTarget()).andReturn(null); | |
159 | - replayAll(); | |
160 | - assertEquals(null, this.interceptor.manage(this.context)); | |
161 | - verify(); | |
162 | - } | |
163 | - | |
164 | - @Test | |
165 | - public void manageWithClassThatDoesNotContainHandleMethod() throws Exception { | |
166 | - ClassWithoutMethodsAnnotatedWithExceptionHandler classWithoutException = new ClassWithoutMethodsAnnotatedWithExceptionHandler(); | |
167 | - | |
168 | - expect(this.context.getTarget()).andReturn(classWithoutException); | |
169 | - expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
170 | - expect(this.coreBootstrap.isAnnotatedType(ClassWithoutMethodsAnnotatedWithExceptionHandler.class)).andReturn( | |
171 | - true); | |
172 | - | |
173 | - replayAll(this.context, this.coreBootstrap, Beans.class); | |
174 | - | |
175 | - try { | |
176 | - this.interceptor.manage(this.context); | |
177 | - fail(); | |
178 | - } catch (DemoiselleException e) { | |
179 | - assertTrue(true); | |
180 | - } | |
181 | - | |
182 | - verifyAll(); | |
183 | - } | |
184 | - | |
185 | - @Test | |
186 | - public void manageWithClassThatContainsHandleMethod() throws Exception { | |
187 | - ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); | |
188 | - expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
189 | - expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
190 | - expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); | |
191 | - | |
192 | - replayAll(this.context, this.coreBootstrap, Beans.class); | |
193 | - | |
194 | - assertNull(this.interceptor.manage(this.context)); | |
195 | - assertEquals(1, classWithException.times); | |
196 | - verifyAll(); | |
197 | - } | |
198 | - | |
199 | - @Test | |
200 | - public void manageWithClassThatContainsParentExceptionHandleMethod() throws Exception { | |
201 | - ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); | |
202 | - expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
203 | - expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
204 | - expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); | |
205 | - replayAll(this.context, this.coreBootstrap, Beans.class); | |
206 | - | |
207 | - assertNull(this.interceptor.manage(this.context)); | |
208 | - assertEquals(1, classWithException.times); | |
209 | - verifyAll(); | |
210 | - } | |
211 | - | |
212 | - @Test | |
213 | - public void manageWithClassThatContainsHandleMethodWithDiferentException() throws Exception { | |
214 | - ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); | |
215 | - expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
216 | - expect(this.context.proceed()).andThrow(new TestException("")); | |
217 | - replay(this.context); | |
218 | - expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); | |
219 | - replayAll(this.context, this.coreBootstrap, Beans.class); | |
220 | - | |
221 | - try { | |
222 | - this.interceptor.manage(this.context); | |
223 | - fail(); | |
224 | - } catch (TestException e) { | |
225 | - assertEquals(0, classWithException.times); | |
226 | - } | |
227 | - | |
228 | - verify(); | |
229 | - } | |
230 | - | |
231 | - @Test | |
232 | - public void manageWithClassThatContainsHandleMethodThatThrowsAnotherException() throws Exception { | |
233 | - ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException classWithException = new ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException(); | |
234 | - expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
235 | - expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
236 | - expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException.class)) | |
237 | - .andReturn(true); | |
238 | - replayAll(this.context, this.coreBootstrap, Beans.class); | |
239 | - | |
240 | - try { | |
241 | - this.interceptor.manage(this.context); | |
242 | - fail(); | |
243 | - } catch (RuntimeException e) { | |
244 | - assertEquals(1, classWithException.times); | |
245 | - } | |
246 | - | |
247 | - verifyAll(); | |
248 | - } | |
249 | - | |
250 | - @Test | |
251 | - public void manageWithClassThatContainsHandleMethodsAndIsInvokedTwice() throws Exception { | |
252 | - ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); | |
253 | - expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
254 | - expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
255 | - expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true) | |
256 | - .anyTimes(); | |
257 | - replayAll(this.context, this.coreBootstrap, Beans.class); | |
258 | - | |
259 | - assertNull(this.interceptor.manage(this.context)); | |
260 | - assertEquals(1, classWithException.times); | |
261 | - | |
262 | - this.context = PowerMock.createMock(InvocationContext.class); | |
263 | - expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
264 | - expect(this.context.proceed()).andThrow(new Exception("")); | |
265 | - replayAll(this.context); | |
266 | - | |
267 | - assertNull(this.interceptor.manage(this.context)); | |
268 | - assertEquals(2, classWithException.times); | |
269 | - verifyAll(); | |
270 | - | |
271 | - } | |
272 | - | |
273 | - @Test | |
274 | - public void manageWithClassThatContainsHandleMethodWithoutParameter() throws Exception { | |
275 | - ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler classWithException = new ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler(); | |
276 | - expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
277 | - expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
278 | - expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler.class)) | |
279 | - .andReturn(true); | |
280 | - replayAll(this.context, this.coreBootstrap, Beans.class); | |
281 | - | |
282 | - try { | |
283 | - this.interceptor.manage(this.context); | |
284 | - fail(); | |
285 | - } catch (DemoiselleException e) { | |
286 | - assertTrue(true); | |
287 | - } | |
288 | - | |
289 | - verifyAll(); | |
290 | - } | |
291 | - | |
292 | - @Test | |
293 | - public void manageHandlerMethodThatRethrowExpectedException() throws Exception { | |
294 | - ClassWithExceptionHandlerMethodThatRethrowException testClass = new ClassWithExceptionHandlerMethodThatRethrowException(); | |
295 | - expect(this.context.getTarget()).andReturn(testClass).anyTimes(); | |
296 | - expect(this.context.proceed()).andThrow(new TestException("")); | |
297 | - expect(this.coreBootstrap.isAnnotatedType(ClassWithExceptionHandlerMethodThatRethrowException.class)) | |
298 | - .andReturn(true); | |
299 | - replayAll(this.context, this.coreBootstrap, Beans.class); | |
300 | - | |
301 | - try { | |
302 | - this.interceptor.manage(this.context); | |
303 | - fail(); | |
304 | - } catch (TestException e) { | |
305 | - assertEquals(1, testClass.times); | |
306 | - } | |
307 | - | |
308 | - verifyAll(); | |
309 | - } | |
310 | - | |
311 | - /** | |
312 | - * Tests an exception handler when the class that contains the method is a proxy. This is the case when using | |
313 | - * injection. | |
314 | - * | |
315 | - * @throws Exception | |
316 | - */ | |
317 | - @Test | |
318 | - public void manageHandlerMethodInsideProxyClass() throws Exception { | |
319 | - // creates a proxy class | |
320 | - ClassWithExceptionHandlerMethodThatRethrowException testClass = PowerMock | |
321 | - .createNicePartialMockForAllMethodsExcept(ClassWithExceptionHandlerMethodThatRethrowException.class, | |
322 | - "methodThatRethrowException"); | |
323 | - expect(this.context.getTarget()).andReturn(testClass).anyTimes(); | |
324 | - expect(this.context.proceed()).andThrow(new TestException("")); | |
325 | - expect(this.coreBootstrap.isAnnotatedType(testClass.getClass())).andReturn(false); | |
326 | - | |
327 | - this.logger = PowerMock.createMock(Logger.class); | |
328 | - this.logger.info(EasyMock.anyObject(String.class)); | |
329 | - this.logger.debug(EasyMock.anyObject(String.class)); | |
330 | - replayAll(testClass, this.context, this.coreBootstrap, logger, Beans.class); | |
331 | - | |
332 | - this.interceptor = new ExceptionHandlerInterceptor(); | |
333 | - | |
334 | - try { | |
335 | - this.interceptor.manage(this.context); | |
336 | - fail(); | |
337 | - } catch (TestException e) { | |
338 | - assertEquals(1, testClass.times); | |
339 | - } | |
340 | - } | |
341 | -} | |
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.interceptor; | |
38 | +// | |
39 | +//import static org.easymock.EasyMock.expect; | |
40 | +//import static org.easymock.EasyMock.verify; | |
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 | +//import static org.powermock.api.easymock.PowerMock.replay; | |
47 | +//import static org.powermock.api.easymock.PowerMock.replayAll; | |
48 | +//import static org.powermock.api.easymock.PowerMock.verifyAll; | |
49 | +// | |
50 | +//import java.util.Locale; | |
51 | +// | |
52 | +//import javax.interceptor.InvocationContext; | |
53 | +// | |
54 | +//import org.easymock.EasyMock; | |
55 | +//import org.junit.Before; | |
56 | +//import org.junit.Test; | |
57 | +//import org.junit.runner.RunWith; | |
58 | +//import org.powermock.api.easymock.PowerMock; | |
59 | +//import org.powermock.core.classloader.annotations.PrepareForTest; | |
60 | +//import org.powermock.modules.junit4.PowerMockRunner; | |
61 | +//import org.slf4j.Logger; | |
62 | +// | |
63 | +//import br.gov.frameworkdemoiselle.DemoiselleException; | |
64 | +//import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | |
65 | +//import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; | |
66 | +//import br.gov.frameworkdemoiselle.util.Beans; | |
67 | +// | |
68 | +//@RunWith(PowerMockRunner.class) | |
69 | +//@PrepareForTest(Beans.class) | |
70 | +//public class ExceptionHandlerInterceptorTest { | |
71 | +// | |
72 | +// private ExceptionHandlerInterceptor interceptor; | |
73 | +// | |
74 | +// private InvocationContext context; | |
75 | +// | |
76 | +// private Logger logger; | |
77 | +// | |
78 | +// private CoreBootstrap coreBootstrap; | |
79 | +// | |
80 | +// class TestException extends DemoiselleException { | |
81 | +// | |
82 | +// private static final long serialVersionUID = 1L; | |
83 | +// | |
84 | +// public TestException(String message) { | |
85 | +// super(message); | |
86 | +// } | |
87 | +// } | |
88 | +// | |
89 | +// class ClassWithMethodsAnnotatedWithExceptionHandler { | |
90 | +// | |
91 | +// int times = 0; | |
92 | +// | |
93 | +// @ExceptionHandler | |
94 | +// public void methodWithExceptionHandlerAnotation(DemoiselleException cause) { | |
95 | +// times++; | |
96 | +// } | |
97 | +// | |
98 | +// @ExceptionHandler | |
99 | +// public void methodWithExceptionHandlerAnotationAndGenericException(Exception cause) { | |
100 | +// times++; | |
101 | +// } | |
102 | +// | |
103 | +// } | |
104 | +// | |
105 | +// class ClassWithoutMethodsAnnotatedWithExceptionHandler { | |
106 | +// | |
107 | +// public void methodWithoutExceptionHandlerAnotation(DemoiselleException cause) { | |
108 | +// } | |
109 | +// } | |
110 | +// | |
111 | +// class ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException { | |
112 | +// | |
113 | +// int times = 0; | |
114 | +// | |
115 | +// @ExceptionHandler | |
116 | +// public void methodWithExceptionHandlerAnotation(DemoiselleException cause) { | |
117 | +// times++; | |
118 | +// throw new RuntimeException(); | |
119 | +// } | |
120 | +// } | |
121 | +// | |
122 | +// class ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler { | |
123 | +// | |
124 | +// @ExceptionHandler | |
125 | +// public void methodWithExceptionHandlerAnotation() { | |
126 | +// } | |
127 | +// | |
128 | +// } | |
129 | +// | |
130 | +// class ClassWithExceptionHandlerMethodThatRethrowException { | |
131 | +// | |
132 | +// int times = 0; | |
133 | +// | |
134 | +// @ExceptionHandler | |
135 | +// public void methodThatRethrowException(TestException cause) { | |
136 | +// times++; | |
137 | +// throw cause; | |
138 | +// } | |
139 | +// | |
140 | +// } | |
141 | +// | |
142 | +// @Before | |
143 | +// public void setUp() throws Exception { | |
144 | +// | |
145 | +// this.interceptor = new ExceptionHandlerInterceptor(); | |
146 | +// this.context = PowerMock.createMock(InvocationContext.class); | |
147 | +// this.coreBootstrap = PowerMock.createMock(CoreBootstrap.class); | |
148 | +// | |
149 | +// mockStatic(Beans.class); | |
150 | +// expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()).anyTimes(); | |
151 | +// expect(Beans.getReference(CoreBootstrap.class)).andReturn(this.coreBootstrap).anyTimes(); | |
152 | +// | |
153 | +// } | |
154 | +// | |
155 | +// @Test | |
156 | +// public void manageSuccessfully() throws Throwable { | |
157 | +// expect(this.context.proceed()).andReturn(null); | |
158 | +// expect(this.context.getTarget()).andReturn(null); | |
159 | +// replayAll(); | |
160 | +// assertEquals(null, this.interceptor.manage(this.context)); | |
161 | +// verify(); | |
162 | +// } | |
163 | +// | |
164 | +// @Test | |
165 | +// public void manageWithClassThatDoesNotContainHandleMethod() throws Exception { | |
166 | +// ClassWithoutMethodsAnnotatedWithExceptionHandler classWithoutException = new ClassWithoutMethodsAnnotatedWithExceptionHandler(); | |
167 | +// | |
168 | +// expect(this.context.getTarget()).andReturn(classWithoutException); | |
169 | +// expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
170 | +// expect(this.coreBootstrap.isAnnotatedType(ClassWithoutMethodsAnnotatedWithExceptionHandler.class)).andReturn( | |
171 | +// true); | |
172 | +// | |
173 | +// replayAll(this.context, this.coreBootstrap, Beans.class); | |
174 | +// | |
175 | +// try { | |
176 | +// this.interceptor.manage(this.context); | |
177 | +// fail(); | |
178 | +// } catch (DemoiselleException e) { | |
179 | +// assertTrue(true); | |
180 | +// } | |
181 | +// | |
182 | +// verifyAll(); | |
183 | +// } | |
184 | +// | |
185 | +// @Test | |
186 | +// public void manageWithClassThatContainsHandleMethod() throws Exception { | |
187 | +// ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); | |
188 | +// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
189 | +// expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
190 | +// expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); | |
191 | +// | |
192 | +// replayAll(this.context, this.coreBootstrap, Beans.class); | |
193 | +// | |
194 | +// assertNull(this.interceptor.manage(this.context)); | |
195 | +// assertEquals(1, classWithException.times); | |
196 | +// verifyAll(); | |
197 | +// } | |
198 | +// | |
199 | +// @Test | |
200 | +// public void manageWithClassThatContainsParentExceptionHandleMethod() throws Exception { | |
201 | +// ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); | |
202 | +// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
203 | +// expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
204 | +// expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); | |
205 | +// replayAll(this.context, this.coreBootstrap, Beans.class); | |
206 | +// | |
207 | +// assertNull(this.interceptor.manage(this.context)); | |
208 | +// assertEquals(1, classWithException.times); | |
209 | +// verifyAll(); | |
210 | +// } | |
211 | +// | |
212 | +// @Test | |
213 | +// public void manageWithClassThatContainsHandleMethodWithDiferentException() throws Exception { | |
214 | +// ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); | |
215 | +// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
216 | +// expect(this.context.proceed()).andThrow(new TestException("")); | |
217 | +// replay(this.context); | |
218 | +// expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); | |
219 | +// replayAll(this.context, this.coreBootstrap, Beans.class); | |
220 | +// | |
221 | +// try { | |
222 | +// this.interceptor.manage(this.context); | |
223 | +// fail(); | |
224 | +// } catch (TestException e) { | |
225 | +// assertEquals(0, classWithException.times); | |
226 | +// } | |
227 | +// | |
228 | +// verify(); | |
229 | +// } | |
230 | +// | |
231 | +// @Test | |
232 | +// public void manageWithClassThatContainsHandleMethodThatThrowsAnotherException() throws Exception { | |
233 | +// ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException classWithException = new ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException(); | |
234 | +// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
235 | +// expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
236 | +// expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException.class)) | |
237 | +// .andReturn(true); | |
238 | +// replayAll(this.context, this.coreBootstrap, Beans.class); | |
239 | +// | |
240 | +// try { | |
241 | +// this.interceptor.manage(this.context); | |
242 | +// fail(); | |
243 | +// } catch (RuntimeException e) { | |
244 | +// assertEquals(1, classWithException.times); | |
245 | +// } | |
246 | +// | |
247 | +// verifyAll(); | |
248 | +// } | |
249 | +// | |
250 | +// @Test | |
251 | +// public void manageWithClassThatContainsHandleMethodsAndIsInvokedTwice() throws Exception { | |
252 | +// ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); | |
253 | +// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
254 | +// expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
255 | +// expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true) | |
256 | +// .anyTimes(); | |
257 | +// replayAll(this.context, this.coreBootstrap, Beans.class); | |
258 | +// | |
259 | +// assertNull(this.interceptor.manage(this.context)); | |
260 | +// assertEquals(1, classWithException.times); | |
261 | +// | |
262 | +// this.context = PowerMock.createMock(InvocationContext.class); | |
263 | +// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
264 | +// expect(this.context.proceed()).andThrow(new Exception("")); | |
265 | +// replayAll(this.context); | |
266 | +// | |
267 | +// assertNull(this.interceptor.manage(this.context)); | |
268 | +// assertEquals(2, classWithException.times); | |
269 | +// verifyAll(); | |
270 | +// | |
271 | +// } | |
272 | +// | |
273 | +// @Test | |
274 | +// public void manageWithClassThatContainsHandleMethodWithoutParameter() throws Exception { | |
275 | +// ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler classWithException = new ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler(); | |
276 | +// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); | |
277 | +// expect(this.context.proceed()).andThrow(new DemoiselleException("")); | |
278 | +// expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler.class)) | |
279 | +// .andReturn(true); | |
280 | +// replayAll(this.context, this.coreBootstrap, Beans.class); | |
281 | +// | |
282 | +// try { | |
283 | +// this.interceptor.manage(this.context); | |
284 | +// fail(); | |
285 | +// } catch (DemoiselleException e) { | |
286 | +// assertTrue(true); | |
287 | +// } | |
288 | +// | |
289 | +// verifyAll(); | |
290 | +// } | |
291 | +// | |
292 | +// @Test | |
293 | +// public void manageHandlerMethodThatRethrowExpectedException() throws Exception { | |
294 | +// ClassWithExceptionHandlerMethodThatRethrowException testClass = new ClassWithExceptionHandlerMethodThatRethrowException(); | |
295 | +// expect(this.context.getTarget()).andReturn(testClass).anyTimes(); | |
296 | +// expect(this.context.proceed()).andThrow(new TestException("")); | |
297 | +// expect(this.coreBootstrap.isAnnotatedType(ClassWithExceptionHandlerMethodThatRethrowException.class)) | |
298 | +// .andReturn(true); | |
299 | +// replayAll(this.context, this.coreBootstrap, Beans.class); | |
300 | +// | |
301 | +// try { | |
302 | +// this.interceptor.manage(this.context); | |
303 | +// fail(); | |
304 | +// } catch (TestException e) { | |
305 | +// assertEquals(1, testClass.times); | |
306 | +// } | |
307 | +// | |
308 | +// verifyAll(); | |
309 | +// } | |
310 | +// | |
311 | +// /** | |
312 | +// * Tests an exception handler when the class that contains the method is a proxy. This is the case when using | |
313 | +// * injection. | |
314 | +// * | |
315 | +// * @throws Exception | |
316 | +// */ | |
317 | +// @Test | |
318 | +// public void manageHandlerMethodInsideProxyClass() throws Exception { | |
319 | +// // creates a proxy class | |
320 | +// ClassWithExceptionHandlerMethodThatRethrowException testClass = PowerMock | |
321 | +// .createNicePartialMockForAllMethodsExcept(ClassWithExceptionHandlerMethodThatRethrowException.class, | |
322 | +// "methodThatRethrowException"); | |
323 | +// expect(this.context.getTarget()).andReturn(testClass).anyTimes(); | |
324 | +// expect(this.context.proceed()).andThrow(new TestException("")); | |
325 | +// expect(this.coreBootstrap.isAnnotatedType(testClass.getClass())).andReturn(false); | |
326 | +// | |
327 | +// this.logger = PowerMock.createMock(Logger.class); | |
328 | +// this.logger.info(EasyMock.anyObject(String.class)); | |
329 | +// this.logger.debug(EasyMock.anyObject(String.class)); | |
330 | +// replayAll(testClass, this.context, this.coreBootstrap, logger, Beans.class); | |
331 | +// | |
332 | +// this.interceptor = new ExceptionHandlerInterceptor(); | |
333 | +// | |
334 | +// try { | |
335 | +// this.interceptor.manage(this.context); | |
336 | +// fail(); | |
337 | +// } catch (TestException e) { | |
338 | +// assertEquals(1, testClass.times); | |
339 | +// } | |
340 | +// } | |
341 | +//} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java
1 | -package br.gov.frameworkdemoiselle.internal.interceptor; | |
2 | - | |
3 | -import static org.easymock.EasyMock.expect; | |
4 | -import static org.junit.Assert.fail; | |
5 | -import static org.powermock.api.easymock.PowerMock.mockStatic; | |
6 | -import static org.powermock.api.easymock.PowerMock.replay; | |
7 | - | |
8 | -import java.util.Locale; | |
9 | - | |
10 | -import javax.enterprise.inject.Instance; | |
11 | -import javax.interceptor.InvocationContext; | |
12 | - | |
13 | -import org.easymock.EasyMock; | |
14 | -import org.junit.Before; | |
15 | -import org.junit.Test; | |
16 | -import org.junit.runner.RunWith; | |
17 | -import org.powermock.core.classloader.annotations.PrepareForTest; | |
18 | -import org.powermock.modules.junit4.PowerMockRunner; | |
19 | - | |
20 | -import br.gov.frameworkdemoiselle.security.AuthorizationException; | |
21 | -import br.gov.frameworkdemoiselle.security.NotLoggedInException; | |
22 | -import br.gov.frameworkdemoiselle.security.RequiredRole; | |
23 | -import br.gov.frameworkdemoiselle.security.SecurityContext; | |
24 | -import br.gov.frameworkdemoiselle.security.User; | |
25 | -import br.gov.frameworkdemoiselle.util.Beans; | |
26 | - | |
27 | -@RunWith(PowerMockRunner.class) | |
28 | -@PrepareForTest(Beans.class) | |
29 | -public class RequiredRoleInterceptorTest { | |
30 | - | |
31 | - private RequiredRoleInterceptor interceptor; | |
32 | - | |
33 | - private InvocationContext ic; | |
34 | - | |
35 | - private SecurityContext securityContext; | |
36 | - | |
37 | - class ClassNotAnnoted { | |
38 | - | |
39 | - @RequiredRole("simpleRoleName") | |
40 | - public void requiredRoleWithSingleRole() { | |
41 | - } | |
42 | - | |
43 | - @RequiredRole({ "firstRole", "secondRole", "thirdRole", "fourthRole", "fifthRole" }) | |
44 | - public void requiredRoleWithArrayOfRoles() { | |
45 | - } | |
46 | - | |
47 | - @RequiredRole({ "firstRole, secondRole" }) | |
48 | - public void requiredRoleWithArrayOfSingleRoleComma() { | |
49 | - } | |
50 | - | |
51 | - @RequiredRole("firstRole, secondRole") | |
52 | - public void requiredRoleWithSingleRoleComma() { | |
53 | - } | |
54 | - | |
55 | - @RequiredRole("") | |
56 | - public void requiredRoleWithEmptyValue() { | |
57 | - } | |
58 | - | |
59 | - @RequiredRole({}) | |
60 | - public void requiredRoleWithEmptyArray() { | |
61 | - } | |
62 | - | |
63 | - @RequiredRole({ "" }) | |
64 | - public void requiredRoleWithArrayOfEmptyString() { | |
65 | - } | |
66 | - | |
67 | - public void methodNotAnnoted() { | |
68 | - } | |
69 | - } | |
70 | - | |
71 | - @RequiredRole("classRole") | |
72 | - class ClassAnnotedWithRequiredRole { | |
73 | - | |
74 | - public void withoutRole() { | |
75 | - } | |
76 | - | |
77 | - @RequiredRole("simpleRoleName") | |
78 | - public void requiredRoleWithSingleRole() { | |
79 | - } | |
80 | - } | |
81 | - | |
82 | - @Before | |
83 | - public void setUp() throws Exception { | |
84 | - | |
85 | - @SuppressWarnings("unchecked") | |
86 | - Instance<SecurityContext> securityContextInstance = EasyMock.createMock(Instance.class); | |
87 | - User user = EasyMock.createMock(User.class); | |
88 | - | |
89 | - this.securityContext = EasyMock.createMock(SecurityContext.class); | |
90 | - this.ic = EasyMock.createMock(InvocationContext.class); | |
91 | - | |
92 | - mockStatic(Beans.class); | |
93 | - expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | |
94 | - expect(Beans.getReference(SecurityContext.class)).andReturn(this.securityContext); | |
95 | - | |
96 | - expect(user.getId()).andReturn("UserName").anyTimes(); | |
97 | - expect(this.securityContext.getUser()).andReturn(user).anyTimes(); | |
98 | - expect(securityContextInstance.get()).andReturn(securityContext).anyTimes(); | |
99 | - expect(this.ic.proceed()).andReturn(null); | |
100 | - replay(securityContextInstance, user, Beans.class); | |
101 | - | |
102 | - this.interceptor = new RequiredRoleInterceptor(); | |
103 | - } | |
104 | - | |
105 | - private void prepareMock(Object target, String methodName, String[] expectedRoles, boolean hasHole, | |
106 | - boolean isLoggedUser) throws Exception { | |
107 | - | |
108 | - expect(this.securityContext.isLoggedIn()).andReturn(isLoggedUser).anyTimes(); | |
109 | - | |
110 | - for (String role : expectedRoles) { | |
111 | - this.securityContext.hasRole(role); | |
112 | - if (isLoggedUser) { | |
113 | - EasyMock.expectLastCall().andReturn(hasHole); | |
114 | - } else { | |
115 | - EasyMock.expectLastCall().andThrow(new NotLoggedInException("")); | |
116 | - } | |
117 | - } | |
118 | - | |
119 | - expect(this.ic.getTarget()).andReturn(target).anyTimes(); | |
120 | - expect(this.ic.getMethod()).andReturn(target.getClass().getMethod(methodName)).anyTimes(); | |
121 | - replay(this.ic, this.securityContext); | |
122 | - } | |
123 | - | |
124 | - // @Test | |
125 | - // public void testManageClassNotAnnotedAtRequiredRoleWithSingleRole() throws Exception { | |
126 | - // Object target = new ClassNotAnnoted(); | |
127 | - // String methodName = "requiredRoleWithSingleRole"; | |
128 | - // String[] expectedRoles = { "simpleRoleName" }; | |
129 | - // prepareMock(target, methodName, expectedRoles, true, true); | |
130 | - // | |
131 | - // interceptor.manage(this.ic); | |
132 | - // } | |
133 | - | |
134 | - // @Test | |
135 | - // public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfRoles() throws Exception { | |
136 | - // Object target = new ClassNotAnnoted(); | |
137 | - // String methodName = "requiredRoleWithArrayOfRoles"; | |
138 | - // String[] expectedRoles = { "firstRole", "secondRole", "thirdRole", "fourthRole", "fifthRole" }; | |
139 | - // prepareMock(target, methodName, expectedRoles, true, true); | |
140 | - // | |
141 | - // interceptor.manage(this.ic); | |
142 | - // } | |
143 | - | |
144 | - // @Test | |
145 | - // public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfSingleRoleComma() throws Exception { | |
146 | - // Object target = new ClassNotAnnoted(); | |
147 | - // String methodName = "requiredRoleWithArrayOfSingleRoleComma"; | |
148 | - // String[] expectedRoles = { "firstRole, secondRole" }; | |
149 | - // prepareMock(target, methodName, expectedRoles, true, true); | |
150 | - // | |
151 | - // interceptor.manage(this.ic); | |
152 | - // } | |
153 | - | |
154 | - // @Test | |
155 | - // public void testManageClassNotAnnotedAtRequiredRoleWithSingleRoleComma() throws Exception { | |
156 | - // Object target = new ClassNotAnnoted(); | |
157 | - // String methodName = "requiredRoleWithSingleRoleComma"; | |
158 | - // String[] expectedRoles = { "firstRole, secondRole" }; | |
159 | - // prepareMock(target, methodName, expectedRoles, true, true); | |
160 | - // | |
161 | - // interceptor.manage(this.ic); | |
162 | - // } | |
163 | - | |
164 | - // @Test | |
165 | - // public void testManageClassNotAnnotedAtRequiredRoleWithEmptyValue() throws Exception { | |
166 | - // try { | |
167 | - // Object target = new ClassNotAnnoted(); | |
168 | - // String methodName = "requiredRoleWithEmptyValue"; | |
169 | - // String[] expectedRoles = { "" }; | |
170 | - // prepareMock(target, methodName, expectedRoles, false, true); | |
171 | - // | |
172 | - // interceptor.manage(this.ic); | |
173 | - // fail(); | |
174 | - // } catch (AuthorizationException cause) { | |
175 | - // } | |
176 | - // } | |
177 | - | |
178 | - // @Test | |
179 | - // public void testManageClassNotAnnotedAtRequiredRoleWithEmptyArray() throws Exception { | |
180 | - // try { | |
181 | - // Object target = new ClassNotAnnoted(); | |
182 | - // String methodName = "requiredRoleWithEmptyArray"; | |
183 | - // String[] expectedRoles = { "" }; | |
184 | - // prepareMock(target, methodName, expectedRoles, false, true); | |
185 | - // | |
186 | - // interceptor.manage(this.ic); | |
187 | - // fail(); | |
188 | - // } catch (AuthorizationException cause) { | |
189 | - // } | |
190 | - // } | |
191 | - | |
192 | - // @Test | |
193 | - // public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfEmptyString() throws Exception { | |
194 | - // try { | |
195 | - // Object target = new ClassNotAnnoted(); | |
196 | - // String methodName = "requiredRoleWithArrayOfEmptyString"; | |
197 | - // String[] expectedRoles = { "" }; | |
198 | - // prepareMock(target, methodName, expectedRoles, false, true); | |
199 | - // | |
200 | - // interceptor.manage(this.ic); | |
201 | - // fail(); | |
202 | - // } catch (AuthorizationException cause) { | |
203 | - // } | |
204 | - // } | |
205 | - | |
206 | - // @Test | |
207 | - // public void testManageClassNotAnnotedAtMethodNotAnnoted() throws Exception { | |
208 | - // try { | |
209 | - // Object target = new ClassNotAnnoted(); | |
210 | - // String methodName = "methodNotAnnoted"; | |
211 | - // String[] expectedRoles = { "" }; | |
212 | - // prepareMock(target, methodName, expectedRoles, false, true); | |
213 | - // | |
214 | - // interceptor.manage(this.ic); | |
215 | - // fail(); | |
216 | - // } catch (AuthorizationException cause) { | |
217 | - // } | |
218 | - // } | |
219 | - | |
220 | - // @Test | |
221 | - // public void testManageClassAnnotedWithRequiredRoleAtWithoutRole() throws Exception { | |
222 | - // Object target = new ClassAnnotedWithRequiredRole(); | |
223 | - // String methodName = "withoutRole"; | |
224 | - // String[] expectedRoles = { "classRole" }; | |
225 | - // prepareMock(target, methodName, expectedRoles, true, true); | |
226 | - // | |
227 | - // interceptor.manage(this.ic); | |
228 | - // } | |
229 | - | |
230 | - // @Test | |
231 | - // public void testManageClassAnnotedWithRequiredRoleAtRequiredRoleWithSingleRole() throws Exception { | |
232 | - // Object target = new ClassAnnotedWithRequiredRole(); | |
233 | - // String methodName = "requiredRoleWithSingleRole"; | |
234 | - // String[] expectedRoles = { "simpleRoleName" }; | |
235 | - // prepareMock(target, methodName, expectedRoles, true, true); | |
236 | - // | |
237 | - // interceptor.manage(this.ic); | |
238 | - // } | |
239 | - | |
240 | - // @Test | |
241 | - // public void testDoesNotHaveSingleRole() throws Exception { | |
242 | - // try { | |
243 | - // Object target = new ClassNotAnnoted(); | |
244 | - // String methodName = "requiredRoleWithSingleRole"; | |
245 | - // String[] expectedRoles = { "simpleRoleName" }; | |
246 | - // prepareMock(target, methodName, expectedRoles, false, true); | |
247 | - // | |
248 | - // interceptor.manage(this.ic); | |
249 | - // fail(); | |
250 | - // } catch (AuthorizationException cause) { | |
251 | - // } | |
252 | - // } | |
253 | - | |
254 | - @Test | |
255 | - public void testUserNotLoggedIn() throws Exception { | |
256 | - try { | |
257 | - Object target = new ClassNotAnnoted(); | |
258 | - String methodName = "requiredRoleWithSingleRole"; | |
259 | - String[] expectedRoles = { "simpleRoleName" }; | |
260 | - prepareMock(target, methodName, expectedRoles, true, false); | |
261 | - | |
262 | - interceptor.manage(this.ic); | |
263 | - fail(); | |
264 | - } catch (NotLoggedInException cause) { | |
265 | - } | |
266 | - } | |
267 | - | |
268 | - // @Test | |
269 | - // public void testDoesNotHaveOneOrMoreRolesOfArray() throws Exception { | |
270 | - // Object target = new ClassNotAnnoted(); | |
271 | - // String methodName = "requiredRoleWithArrayOfRoles"; | |
272 | - // String[] expectedRoles = { "thirdRole", "fourthRole", "fifthRole" }; | |
273 | - // | |
274 | - // expect(this.securityContext.hasRole("firstRole")).andReturn(false); | |
275 | - // expect(this.securityContext.hasRole("secondRole")).andReturn(false); | |
276 | - // | |
277 | - // prepareMock(target, methodName, expectedRoles, true, true); | |
278 | - // | |
279 | - // interceptor.manage(this.ic); | |
280 | - // } | |
281 | - | |
282 | - // @Test | |
283 | - // public void testHasMoreRolesThenArray() throws Exception { | |
284 | - // Object target = new ClassNotAnnoted(); | |
285 | - // String methodName = "requiredRoleWithArrayOfRoles"; | |
286 | - // String[] expectedRoles = { "thirdRole", "fourthRole", "fifthRole" }; | |
287 | - // | |
288 | - // expect(this.securityContext.hasRole("firstRole")).andReturn(false); | |
289 | - // expect(this.securityContext.hasRole("secondRole")).andReturn(false); | |
290 | - // expect(this.securityContext.hasRole("sixthRole")).andReturn(true); | |
291 | - // | |
292 | - // prepareMock(target, methodName, expectedRoles, true, true); | |
293 | - // | |
294 | - // interceptor.manage(this.ic); | |
295 | - // } | |
296 | -} | |
1 | +//package br.gov.frameworkdemoiselle.internal.interceptor; | |
2 | +// | |
3 | +//import static org.easymock.EasyMock.expect; | |
4 | +//import static org.junit.Assert.fail; | |
5 | +//import static org.powermock.api.easymock.PowerMock.mockStatic; | |
6 | +//import static org.powermock.api.easymock.PowerMock.replay; | |
7 | +// | |
8 | +//import java.util.Locale; | |
9 | +// | |
10 | +//import javax.enterprise.inject.Instance; | |
11 | +//import javax.interceptor.InvocationContext; | |
12 | +// | |
13 | +//import org.easymock.EasyMock; | |
14 | +//import org.junit.Before; | |
15 | +//import org.junit.Test; | |
16 | +//import org.junit.runner.RunWith; | |
17 | +//import org.powermock.core.classloader.annotations.PrepareForTest; | |
18 | +//import org.powermock.modules.junit4.PowerMockRunner; | |
19 | +// | |
20 | +//import br.gov.frameworkdemoiselle.security.AuthorizationException; | |
21 | +//import br.gov.frameworkdemoiselle.security.NotLoggedInException; | |
22 | +//import br.gov.frameworkdemoiselle.security.RequiredRole; | |
23 | +//import br.gov.frameworkdemoiselle.security.SecurityContext; | |
24 | +//import br.gov.frameworkdemoiselle.security.User; | |
25 | +//import br.gov.frameworkdemoiselle.util.Beans; | |
26 | +// | |
27 | +//@RunWith(PowerMockRunner.class) | |
28 | +//@PrepareForTest(Beans.class) | |
29 | +//public class RequiredRoleInterceptorTest { | |
30 | +// | |
31 | +// private RequiredRoleInterceptor interceptor; | |
32 | +// | |
33 | +// private InvocationContext ic; | |
34 | +// | |
35 | +// private SecurityContext securityContext; | |
36 | +// | |
37 | +// class ClassNotAnnoted { | |
38 | +// | |
39 | +// @RequiredRole("simpleRoleName") | |
40 | +// public void requiredRoleWithSingleRole() { | |
41 | +// } | |
42 | +// | |
43 | +// @RequiredRole({ "firstRole", "secondRole", "thirdRole", "fourthRole", "fifthRole" }) | |
44 | +// public void requiredRoleWithArrayOfRoles() { | |
45 | +// } | |
46 | +// | |
47 | +// @RequiredRole({ "firstRole, secondRole" }) | |
48 | +// public void requiredRoleWithArrayOfSingleRoleComma() { | |
49 | +// } | |
50 | +// | |
51 | +// @RequiredRole("firstRole, secondRole") | |
52 | +// public void requiredRoleWithSingleRoleComma() { | |
53 | +// } | |
54 | +// | |
55 | +// @RequiredRole("") | |
56 | +// public void requiredRoleWithEmptyValue() { | |
57 | +// } | |
58 | +// | |
59 | +// @RequiredRole({}) | |
60 | +// public void requiredRoleWithEmptyArray() { | |
61 | +// } | |
62 | +// | |
63 | +// @RequiredRole({ "" }) | |
64 | +// public void requiredRoleWithArrayOfEmptyString() { | |
65 | +// } | |
66 | +// | |
67 | +// public void methodNotAnnoted() { | |
68 | +// } | |
69 | +// } | |
70 | +// | |
71 | +// @RequiredRole("classRole") | |
72 | +// class ClassAnnotedWithRequiredRole { | |
73 | +// | |
74 | +// public void withoutRole() { | |
75 | +// } | |
76 | +// | |
77 | +// @RequiredRole("simpleRoleName") | |
78 | +// public void requiredRoleWithSingleRole() { | |
79 | +// } | |
80 | +// } | |
81 | +// | |
82 | +// @Before | |
83 | +// public void setUp() throws Exception { | |
84 | +// | |
85 | +// @SuppressWarnings("unchecked") | |
86 | +// Instance<SecurityContext> securityContextInstance = EasyMock.createMock(Instance.class); | |
87 | +// User user = EasyMock.createMock(User.class); | |
88 | +// | |
89 | +// this.securityContext = EasyMock.createMock(SecurityContext.class); | |
90 | +// this.ic = EasyMock.createMock(InvocationContext.class); | |
91 | +// | |
92 | +// mockStatic(Beans.class); | |
93 | +// expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | |
94 | +// expect(Beans.getReference(SecurityContext.class)).andReturn(this.securityContext); | |
95 | +// | |
96 | +// expect(user.getId()).andReturn("UserName").anyTimes(); | |
97 | +// expect(this.securityContext.getUser()).andReturn(user).anyTimes(); | |
98 | +// expect(securityContextInstance.get()).andReturn(securityContext).anyTimes(); | |
99 | +// expect(this.ic.proceed()).andReturn(null); | |
100 | +// replay(securityContextInstance, user, Beans.class); | |
101 | +// | |
102 | +// this.interceptor = new RequiredRoleInterceptor(); | |
103 | +// } | |
104 | +// | |
105 | +// private void prepareMock(Object target, String methodName, String[] expectedRoles, boolean hasHole, | |
106 | +// boolean isLoggedUser) throws Exception { | |
107 | +// | |
108 | +// expect(this.securityContext.isLoggedIn()).andReturn(isLoggedUser).anyTimes(); | |
109 | +// | |
110 | +// for (String role : expectedRoles) { | |
111 | +// this.securityContext.hasRole(role); | |
112 | +// if (isLoggedUser) { | |
113 | +// EasyMock.expectLastCall().andReturn(hasHole); | |
114 | +// } else { | |
115 | +// EasyMock.expectLastCall().andThrow(new NotLoggedInException("")); | |
116 | +// } | |
117 | +// } | |
118 | +// | |
119 | +// expect(this.ic.getTarget()).andReturn(target).anyTimes(); | |
120 | +// expect(this.ic.getMethod()).andReturn(target.getClass().getMethod(methodName)).anyTimes(); | |
121 | +// replay(this.ic, this.securityContext); | |
122 | +// } | |
123 | +// | |
124 | +// // @Test | |
125 | +// // public void testManageClassNotAnnotedAtRequiredRoleWithSingleRole() throws Exception { | |
126 | +// // Object target = new ClassNotAnnoted(); | |
127 | +// // String methodName = "requiredRoleWithSingleRole"; | |
128 | +// // String[] expectedRoles = { "simpleRoleName" }; | |
129 | +// // prepareMock(target, methodName, expectedRoles, true, true); | |
130 | +// // | |
131 | +// // interceptor.manage(this.ic); | |
132 | +// // } | |
133 | +// | |
134 | +// // @Test | |
135 | +// // public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfRoles() throws Exception { | |
136 | +// // Object target = new ClassNotAnnoted(); | |
137 | +// // String methodName = "requiredRoleWithArrayOfRoles"; | |
138 | +// // String[] expectedRoles = { "firstRole", "secondRole", "thirdRole", "fourthRole", "fifthRole" }; | |
139 | +// // prepareMock(target, methodName, expectedRoles, true, true); | |
140 | +// // | |
141 | +// // interceptor.manage(this.ic); | |
142 | +// // } | |
143 | +// | |
144 | +// // @Test | |
145 | +// // public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfSingleRoleComma() throws Exception { | |
146 | +// // Object target = new ClassNotAnnoted(); | |
147 | +// // String methodName = "requiredRoleWithArrayOfSingleRoleComma"; | |
148 | +// // String[] expectedRoles = { "firstRole, secondRole" }; | |
149 | +// // prepareMock(target, methodName, expectedRoles, true, true); | |
150 | +// // | |
151 | +// // interceptor.manage(this.ic); | |
152 | +// // } | |
153 | +// | |
154 | +// // @Test | |
155 | +// // public void testManageClassNotAnnotedAtRequiredRoleWithSingleRoleComma() throws Exception { | |
156 | +// // Object target = new ClassNotAnnoted(); | |
157 | +// // String methodName = "requiredRoleWithSingleRoleComma"; | |
158 | +// // String[] expectedRoles = { "firstRole, secondRole" }; | |
159 | +// // prepareMock(target, methodName, expectedRoles, true, true); | |
160 | +// // | |
161 | +// // interceptor.manage(this.ic); | |
162 | +// // } | |
163 | +// | |
164 | +// // @Test | |
165 | +// // public void testManageClassNotAnnotedAtRequiredRoleWithEmptyValue() throws Exception { | |
166 | +// // try { | |
167 | +// // Object target = new ClassNotAnnoted(); | |
168 | +// // String methodName = "requiredRoleWithEmptyValue"; | |
169 | +// // String[] expectedRoles = { "" }; | |
170 | +// // prepareMock(target, methodName, expectedRoles, false, true); | |
171 | +// // | |
172 | +// // interceptor.manage(this.ic); | |
173 | +// // fail(); | |
174 | +// // } catch (AuthorizationException cause) { | |
175 | +// // } | |
176 | +// // } | |
177 | +// | |
178 | +// // @Test | |
179 | +// // public void testManageClassNotAnnotedAtRequiredRoleWithEmptyArray() throws Exception { | |
180 | +// // try { | |
181 | +// // Object target = new ClassNotAnnoted(); | |
182 | +// // String methodName = "requiredRoleWithEmptyArray"; | |
183 | +// // String[] expectedRoles = { "" }; | |
184 | +// // prepareMock(target, methodName, expectedRoles, false, true); | |
185 | +// // | |
186 | +// // interceptor.manage(this.ic); | |
187 | +// // fail(); | |
188 | +// // } catch (AuthorizationException cause) { | |
189 | +// // } | |
190 | +// // } | |
191 | +// | |
192 | +// // @Test | |
193 | +// // public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfEmptyString() throws Exception { | |
194 | +// // try { | |
195 | +// // Object target = new ClassNotAnnoted(); | |
196 | +// // String methodName = "requiredRoleWithArrayOfEmptyString"; | |
197 | +// // String[] expectedRoles = { "" }; | |
198 | +// // prepareMock(target, methodName, expectedRoles, false, true); | |
199 | +// // | |
200 | +// // interceptor.manage(this.ic); | |
201 | +// // fail(); | |
202 | +// // } catch (AuthorizationException cause) { | |
203 | +// // } | |
204 | +// // } | |
205 | +// | |
206 | +// // @Test | |
207 | +// // public void testManageClassNotAnnotedAtMethodNotAnnoted() throws Exception { | |
208 | +// // try { | |
209 | +// // Object target = new ClassNotAnnoted(); | |
210 | +// // String methodName = "methodNotAnnoted"; | |
211 | +// // String[] expectedRoles = { "" }; | |
212 | +// // prepareMock(target, methodName, expectedRoles, false, true); | |
213 | +// // | |
214 | +// // interceptor.manage(this.ic); | |
215 | +// // fail(); | |
216 | +// // } catch (AuthorizationException cause) { | |
217 | +// // } | |
218 | +// // } | |
219 | +// | |
220 | +// // @Test | |
221 | +// // public void testManageClassAnnotedWithRequiredRoleAtWithoutRole() throws Exception { | |
222 | +// // Object target = new ClassAnnotedWithRequiredRole(); | |
223 | +// // String methodName = "withoutRole"; | |
224 | +// // String[] expectedRoles = { "classRole" }; | |
225 | +// // prepareMock(target, methodName, expectedRoles, true, true); | |
226 | +// // | |
227 | +// // interceptor.manage(this.ic); | |
228 | +// // } | |
229 | +// | |
230 | +// // @Test | |
231 | +// // public void testManageClassAnnotedWithRequiredRoleAtRequiredRoleWithSingleRole() throws Exception { | |
232 | +// // Object target = new ClassAnnotedWithRequiredRole(); | |
233 | +// // String methodName = "requiredRoleWithSingleRole"; | |
234 | +// // String[] expectedRoles = { "simpleRoleName" }; | |
235 | +// // prepareMock(target, methodName, expectedRoles, true, true); | |
236 | +// // | |
237 | +// // interceptor.manage(this.ic); | |
238 | +// // } | |
239 | +// | |
240 | +// // @Test | |
241 | +// // public void testDoesNotHaveSingleRole() throws Exception { | |
242 | +// // try { | |
243 | +// // Object target = new ClassNotAnnoted(); | |
244 | +// // String methodName = "requiredRoleWithSingleRole"; | |
245 | +// // String[] expectedRoles = { "simpleRoleName" }; | |
246 | +// // prepareMock(target, methodName, expectedRoles, false, true); | |
247 | +// // | |
248 | +// // interceptor.manage(this.ic); | |
249 | +// // fail(); | |
250 | +// // } catch (AuthorizationException cause) { | |
251 | +// // } | |
252 | +// // } | |
253 | +// | |
254 | +// @Test | |
255 | +// public void testUserNotLoggedIn() throws Exception { | |
256 | +// try { | |
257 | +// Object target = new ClassNotAnnoted(); | |
258 | +// String methodName = "requiredRoleWithSingleRole"; | |
259 | +// String[] expectedRoles = { "simpleRoleName" }; | |
260 | +// prepareMock(target, methodName, expectedRoles, true, false); | |
261 | +// | |
262 | +// interceptor.manage(this.ic); | |
263 | +// fail(); | |
264 | +// } catch (NotLoggedInException cause) { | |
265 | +// } | |
266 | +// } | |
267 | +// | |
268 | +// // @Test | |
269 | +// // public void testDoesNotHaveOneOrMoreRolesOfArray() throws Exception { | |
270 | +// // Object target = new ClassNotAnnoted(); | |
271 | +// // String methodName = "requiredRoleWithArrayOfRoles"; | |
272 | +// // String[] expectedRoles = { "thirdRole", "fourthRole", "fifthRole" }; | |
273 | +// // | |
274 | +// // expect(this.securityContext.hasRole("firstRole")).andReturn(false); | |
275 | +// // expect(this.securityContext.hasRole("secondRole")).andReturn(false); | |
276 | +// // | |
277 | +// // prepareMock(target, methodName, expectedRoles, true, true); | |
278 | +// // | |
279 | +// // interceptor.manage(this.ic); | |
280 | +// // } | |
281 | +// | |
282 | +// // @Test | |
283 | +// // public void testHasMoreRolesThenArray() throws Exception { | |
284 | +// // Object target = new ClassNotAnnoted(); | |
285 | +// // String methodName = "requiredRoleWithArrayOfRoles"; | |
286 | +// // String[] expectedRoles = { "thirdRole", "fourthRole", "fifthRole" }; | |
287 | +// // | |
288 | +// // expect(this.securityContext.hasRole("firstRole")).andReturn(false); | |
289 | +// // expect(this.securityContext.hasRole("secondRole")).andReturn(false); | |
290 | +// // expect(this.securityContext.hasRole("sixthRole")).andReturn(true); | |
291 | +// // | |
292 | +// // prepareMock(target, methodName, expectedRoles, true, true); | |
293 | +// // | |
294 | +// // interceptor.manage(this.ic); | |
295 | +// // } | |
296 | +//} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/template/DelegateCrudTest.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.template; | |
38 | - | |
39 | -import static org.easymock.EasyMock.expect; | |
40 | -import static org.junit.Assert.assertEquals; | |
41 | -import static org.powermock.api.easymock.PowerMock.mockStatic; | |
42 | -import static org.powermock.api.easymock.PowerMock.replayAll; | |
43 | -import static org.powermock.api.easymock.PowerMock.verifyAll; | |
44 | - | |
45 | -import java.util.ArrayList; | |
46 | -import java.util.List; | |
47 | - | |
48 | -import org.easymock.EasyMock; | |
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 | - | |
57 | -import br.gov.frameworkdemoiselle.util.Beans; | |
58 | -import br.gov.frameworkdemoiselle.util.Reflections; | |
59 | - | |
60 | -@RunWith(PowerMockRunner.class) | |
61 | -@PrepareForTest({ Crud.class, Beans.class, Reflections.class }) | |
62 | -public class DelegateCrudTest { | |
63 | - | |
64 | - private DelegateCrud<Contact, Long, Delegated> delegateCrud; | |
65 | - | |
66 | - private Crud<Contact, Long> mockCrud; | |
67 | - | |
68 | - @SuppressWarnings("unchecked") | |
69 | - @Before | |
70 | - public void before() { | |
71 | - delegateCrud = new DelegateCrud<Contact, Long, Delegated>(); | |
72 | - mockCrud = PowerMock.createMock(Crud.class); | |
73 | - } | |
74 | - | |
75 | - @SuppressWarnings("unchecked") | |
76 | - @Test | |
77 | - public void testDelete() { | |
78 | - mockStatic(Beans.class); | |
79 | - mockStatic(Reflections.class); | |
80 | - | |
81 | - expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Class.class), EasyMock.anyInt())).andReturn(null); | |
82 | - expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud).times(2); | |
83 | - | |
84 | - mockCrud.delete(1L); | |
85 | - PowerMock.expectLastCall(); | |
86 | - | |
87 | - PowerMock.replay(Reflections.class, Beans.class, mockCrud); | |
88 | - | |
89 | - delegateCrud.delete(1L); | |
90 | - | |
91 | - PowerMock.verify(); | |
92 | - } | |
93 | - | |
94 | - @SuppressWarnings("unchecked") | |
95 | - @Test | |
96 | - public void testUpdate() { | |
97 | - Whitebox.setInternalState(delegateCrud, "delegate", mockCrud); | |
98 | - | |
99 | - mockStatic(Beans.class); | |
100 | - | |
101 | - expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud); | |
102 | - | |
103 | - Contact update = new Contact(); | |
104 | - mockCrud.update(update); | |
105 | - replayAll(Beans.class, mockCrud); | |
106 | - | |
107 | - delegateCrud.update(update); | |
108 | - | |
109 | - verifyAll(); | |
110 | - } | |
111 | - | |
112 | - @SuppressWarnings("unchecked") | |
113 | - @Test | |
114 | - public void testInsert() { | |
115 | - Whitebox.setInternalState(delegateCrud, "delegate", mockCrud); | |
116 | - | |
117 | - mockStatic(Beans.class); | |
118 | - | |
119 | - expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud); | |
120 | - | |
121 | - Contact insert = new Contact(); | |
122 | - mockCrud.insert(insert); | |
123 | - replayAll(mockCrud); | |
124 | - | |
125 | - delegateCrud.insert(insert); | |
126 | - | |
127 | - verifyAll(); | |
128 | - } | |
129 | - | |
130 | - @SuppressWarnings("unchecked") | |
131 | - @Test | |
132 | - public void testFindAll() { | |
133 | - mockStatic(Beans.class); | |
134 | - mockStatic(Reflections.class); | |
135 | - | |
136 | - expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Class.class), EasyMock.anyInt())).andReturn(null); | |
137 | - expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud); | |
138 | - | |
139 | - List<Contact> returned = new ArrayList<Contact>(); | |
140 | - expect(mockCrud.findAll()).andReturn(returned); | |
141 | - replayAll(Reflections.class, Beans.class, mockCrud); | |
142 | - | |
143 | - assertEquals(returned, delegateCrud.findAll()); | |
144 | - | |
145 | - verifyAll(); | |
146 | - } | |
147 | - | |
148 | - @SuppressWarnings("unchecked") | |
149 | - @Test | |
150 | - public void testLoad() { | |
151 | - mockStatic(Beans.class); | |
152 | - | |
153 | - expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud); | |
154 | - | |
155 | - Contact contact = new Contact(); | |
156 | - expect(mockCrud.load(1L)).andReturn(contact); | |
157 | - replayAll(Beans.class, mockCrud); | |
158 | - | |
159 | - Whitebox.setInternalState(delegateCrud, "delegateClass", delegateCrud.getClass(), delegateCrud.getClass()); | |
160 | - | |
161 | - assertEquals(contact, delegateCrud.load(1L)); | |
162 | - verifyAll(); | |
163 | - } | |
164 | - | |
165 | - class Contact { | |
166 | - | |
167 | - private Long id; | |
168 | - | |
169 | - public Long getId() { | |
170 | - return id; | |
171 | - } | |
172 | - | |
173 | - public void setId(Long id) { | |
174 | - this.id = id; | |
175 | - } | |
176 | - } | |
177 | - | |
178 | - @SuppressWarnings("serial") | |
179 | - class Delegated implements Crud<Contact, Long> { | |
180 | - | |
181 | - @Override | |
182 | - public void delete(Long id) { | |
183 | - } | |
184 | - | |
185 | - @Override | |
186 | - public List<Contact> findAll() { | |
187 | - return null; | |
188 | - } | |
189 | - | |
190 | - @Override | |
191 | - public void insert(Contact bean) { | |
192 | - } | |
193 | - | |
194 | - @Override | |
195 | - public Contact load(Long id) { | |
196 | - return null; | |
197 | - } | |
198 | - | |
199 | - @Override | |
200 | - public void update(Contact bean) { | |
201 | - } | |
202 | - | |
203 | - } | |
204 | - | |
205 | -} | |
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.template; | |
38 | +// | |
39 | +//import static org.easymock.EasyMock.expect; | |
40 | +//import static org.junit.Assert.assertEquals; | |
41 | +//import static org.powermock.api.easymock.PowerMock.mockStatic; | |
42 | +//import static org.powermock.api.easymock.PowerMock.replayAll; | |
43 | +//import static org.powermock.api.easymock.PowerMock.verifyAll; | |
44 | +// | |
45 | +//import java.util.ArrayList; | |
46 | +//import java.util.List; | |
47 | +// | |
48 | +//import org.easymock.EasyMock; | |
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 | +// | |
57 | +//import br.gov.frameworkdemoiselle.util.Beans; | |
58 | +//import br.gov.frameworkdemoiselle.util.Reflections; | |
59 | +// | |
60 | +//@RunWith(PowerMockRunner.class) | |
61 | +//@PrepareForTest({ Crud.class, Beans.class, Reflections.class }) | |
62 | +//public class DelegateCrudTest { | |
63 | +// | |
64 | +// private DelegateCrud<Contact, Long, Delegated> delegateCrud; | |
65 | +// | |
66 | +// private Crud<Contact, Long> mockCrud; | |
67 | +// | |
68 | +// @SuppressWarnings("unchecked") | |
69 | +// @Before | |
70 | +// public void before() { | |
71 | +// delegateCrud = new DelegateCrud<Contact, Long, Delegated>(); | |
72 | +// mockCrud = PowerMock.createMock(Crud.class); | |
73 | +// } | |
74 | +// | |
75 | +// @SuppressWarnings("unchecked") | |
76 | +// @Test | |
77 | +// public void testDelete() { | |
78 | +// mockStatic(Beans.class); | |
79 | +// mockStatic(Reflections.class); | |
80 | +// | |
81 | +// expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Class.class), EasyMock.anyInt())).andReturn(null); | |
82 | +// expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud).times(2); | |
83 | +// | |
84 | +// mockCrud.delete(1L); | |
85 | +// PowerMock.expectLastCall(); | |
86 | +// | |
87 | +// PowerMock.replay(Reflections.class, Beans.class, mockCrud); | |
88 | +// | |
89 | +// delegateCrud.delete(1L); | |
90 | +// | |
91 | +// PowerMock.verify(); | |
92 | +// } | |
93 | +// | |
94 | +// @SuppressWarnings("unchecked") | |
95 | +// @Test | |
96 | +// public void testUpdate() { | |
97 | +// Whitebox.setInternalState(delegateCrud, "delegate", mockCrud); | |
98 | +// | |
99 | +// mockStatic(Beans.class); | |
100 | +// | |
101 | +// expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud); | |
102 | +// | |
103 | +// Contact update = new Contact(); | |
104 | +// mockCrud.update(update); | |
105 | +// replayAll(Beans.class, mockCrud); | |
106 | +// | |
107 | +// delegateCrud.update(update); | |
108 | +// | |
109 | +// verifyAll(); | |
110 | +// } | |
111 | +// | |
112 | +// @SuppressWarnings("unchecked") | |
113 | +// @Test | |
114 | +// public void testInsert() { | |
115 | +// Whitebox.setInternalState(delegateCrud, "delegate", mockCrud); | |
116 | +// | |
117 | +// mockStatic(Beans.class); | |
118 | +// | |
119 | +// expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud); | |
120 | +// | |
121 | +// Contact insert = new Contact(); | |
122 | +// mockCrud.insert(insert); | |
123 | +// replayAll(mockCrud); | |
124 | +// | |
125 | +// delegateCrud.insert(insert); | |
126 | +// | |
127 | +// verifyAll(); | |
128 | +// } | |
129 | +// | |
130 | +// @SuppressWarnings("unchecked") | |
131 | +// @Test | |
132 | +// public void testFindAll() { | |
133 | +// mockStatic(Beans.class); | |
134 | +// mockStatic(Reflections.class); | |
135 | +// | |
136 | +// expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Class.class), EasyMock.anyInt())).andReturn(null); | |
137 | +// expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud); | |
138 | +// | |
139 | +// List<Contact> returned = new ArrayList<Contact>(); | |
140 | +// expect(mockCrud.findAll()).andReturn(returned); | |
141 | +// replayAll(Reflections.class, Beans.class, mockCrud); | |
142 | +// | |
143 | +// assertEquals(returned, delegateCrud.findAll()); | |
144 | +// | |
145 | +// verifyAll(); | |
146 | +// } | |
147 | +// | |
148 | +// @SuppressWarnings("unchecked") | |
149 | +// @Test | |
150 | +// public void testLoad() { | |
151 | +// mockStatic(Beans.class); | |
152 | +// | |
153 | +// expect(Beans.getReference(EasyMock.anyObject(Class.class))).andReturn(mockCrud); | |
154 | +// | |
155 | +// Contact contact = new Contact(); | |
156 | +// expect(mockCrud.load(1L)).andReturn(contact); | |
157 | +// replayAll(Beans.class, mockCrud); | |
158 | +// | |
159 | +// Whitebox.setInternalState(delegateCrud, "delegateClass", delegateCrud.getClass(), delegateCrud.getClass()); | |
160 | +// | |
161 | +// assertEquals(contact, delegateCrud.load(1L)); | |
162 | +// verifyAll(); | |
163 | +// } | |
164 | +// | |
165 | +// class Contact { | |
166 | +// | |
167 | +// private Long id; | |
168 | +// | |
169 | +// public Long getId() { | |
170 | +// return id; | |
171 | +// } | |
172 | +// | |
173 | +// public void setId(Long id) { | |
174 | +// this.id = id; | |
175 | +// } | |
176 | +// } | |
177 | +// | |
178 | +// @SuppressWarnings("serial") | |
179 | +// class Delegated implements Crud<Contact, Long> { | |
180 | +// | |
181 | +// @Override | |
182 | +// public void delete(Long id) { | |
183 | +// } | |
184 | +// | |
185 | +// @Override | |
186 | +// public List<Contact> findAll() { | |
187 | +// return null; | |
188 | +// } | |
189 | +// | |
190 | +// @Override | |
191 | +// public void insert(Contact bean) { | |
192 | +// } | |
193 | +// | |
194 | +// @Override | |
195 | +// public Contact load(Long id) { | |
196 | +// return null; | |
197 | +// } | |
198 | +// | |
199 | +// @Override | |
200 | +// public void update(Contact bean) { | |
201 | +// } | |
202 | +// | |
203 | +// } | |
204 | +// | |
205 | +//} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/util/BeansTest.java
1 | -/* | |
2 | - * Demoiselle Framework | |
3 | - * Copyright (C) 2010 SERPRO | |
4 | - * ---------------------------------------------------------------------------- | |
5 | - * This file is part of Demoiselle Framework. | |
6 | - * | |
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | - * as published by the Free Software Foundation. | |
10 | - * | |
11 | - * This program is distributed in the hope that it will be useful, | |
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | - * GNU General Public License for more details. | |
15 | - * | |
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | - * ---------------------------------------------------------------------------- | |
21 | - * Este arquivo é parte do Framework Demoiselle. | |
22 | - * | |
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | - * do Software Livre (FSF). | |
26 | - * | |
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | - * para maiores detalhes. | |
31 | - * | |
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | - */ | |
37 | -package br.gov.frameworkdemoiselle.util; | |
38 | - | |
39 | -import static junit.framework.Assert.assertEquals; | |
40 | -import static org.easymock.EasyMock.expect; | |
41 | -import static org.powermock.api.easymock.PowerMock.replayAll; | |
42 | -import static org.powermock.api.easymock.PowerMock.verifyAll; | |
43 | - | |
44 | -import java.util.HashSet; | |
45 | -import java.util.Set; | |
46 | - | |
47 | -import javax.enterprise.context.spi.Contextual; | |
48 | -import javax.enterprise.context.spi.CreationalContext; | |
49 | -import javax.enterprise.inject.spi.Bean; | |
50 | -import javax.enterprise.inject.spi.BeanManager; | |
51 | - | |
52 | -import org.easymock.EasyMock; | |
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 | -@RunWith(PowerMockRunner.class) | |
60 | -@PrepareForTest({ BeanManager.class, Bean.class }) | |
61 | -public class BeansTest { | |
62 | - | |
63 | - @SuppressWarnings("unchecked") | |
64 | - @Test | |
65 | - public void testGetReferenceByClass() { | |
66 | - BeanManager beanManager = PowerMock.createMock(BeanManager.class); | |
67 | - | |
68 | - Set<Bean<?>> collection = new HashSet<Bean<?>>(); | |
69 | - Bean<?> bean = PowerMock.createMock(Bean.class); | |
70 | - collection.add(bean); | |
71 | - | |
72 | - String object = "object"; | |
73 | - | |
74 | - expect(beanManager.createCreationalContext(EasyMock.anyObject(Contextual.class))).andReturn(null); | |
75 | - expect(beanManager.getBeans(EasyMock.anyObject(Class.class))).andReturn(collection); | |
76 | - expect( | |
77 | - beanManager.getReference(EasyMock.anyObject(Bean.class), EasyMock.anyObject(Class.class), | |
78 | - EasyMock.anyObject(CreationalContext.class))).andReturn(object); | |
79 | - | |
80 | - replayAll(beanManager, bean); | |
81 | - | |
82 | - Beans.setBeanManager(beanManager); | |
83 | - String returned = Beans.getReference(String.class); | |
84 | - | |
85 | - assertEquals(returned, object); | |
86 | - assertEquals(beanManager, Beans.getBeanManager()); | |
87 | - | |
88 | - verifyAll(); | |
89 | - } | |
90 | - | |
91 | - @Test | |
92 | - @SuppressWarnings("unchecked") | |
93 | - public void testGetReferenceByString() { | |
94 | - BeanManager beanManager = PowerMock.createMock(BeanManager.class); | |
95 | - | |
96 | - Set<Bean<?>> collection = new HashSet<Bean<?>>(); | |
97 | - Bean<?> bean = PowerMock.createMock(Bean.class); | |
98 | - collection.add(bean); | |
99 | - | |
100 | - String object = "object"; | |
101 | - | |
102 | - expect(bean.getBeanClass()).andReturn(null); | |
103 | - expect(beanManager.createCreationalContext(EasyMock.anyObject(Contextual.class))).andReturn(null); | |
104 | - expect(beanManager.getBeans("something")).andReturn(collection); | |
105 | - expect( | |
106 | - beanManager.getReference(EasyMock.anyObject(Bean.class), EasyMock.anyObject(Class.class), | |
107 | - EasyMock.anyObject(CreationalContext.class))).andReturn(object); | |
108 | - | |
109 | - replayAll(beanManager, bean); | |
110 | - | |
111 | - Beans.setBeanManager(beanManager); | |
112 | - String returned = Beans.getReference("something"); | |
113 | - | |
114 | - assertEquals(returned, object); | |
115 | - assertEquals(beanManager, Beans.getBeanManager()); | |
116 | - | |
117 | - verifyAll(); | |
118 | - } | |
119 | -} | |
1 | +///* | |
2 | +// * Demoiselle Framework | |
3 | +// * Copyright (C) 2010 SERPRO | |
4 | +// * ---------------------------------------------------------------------------- | |
5 | +// * This file is part of Demoiselle Framework. | |
6 | +// * | |
7 | +// * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | +// * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | +// * as published by the Free Software Foundation. | |
10 | +// * | |
11 | +// * This program is distributed in the hope that it will be useful, | |
12 | +// * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | +// * GNU General Public License for more details. | |
15 | +// * | |
16 | +// * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | +// * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | +// * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | +// * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | +// * ---------------------------------------------------------------------------- | |
21 | +// * Este arquivo é parte do Framework Demoiselle. | |
22 | +// * | |
23 | +// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | +// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | +// * do Software Livre (FSF). | |
26 | +// * | |
27 | +// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | +// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | +// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | +// * para maiores detalhes. | |
31 | +// * | |
32 | +// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | +// * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | +// * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | +// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | +// */ | |
37 | +//package br.gov.frameworkdemoiselle.util; | |
38 | +// | |
39 | +//import static junit.framework.Assert.assertEquals; | |
40 | +//import static org.easymock.EasyMock.expect; | |
41 | +//import static org.powermock.api.easymock.PowerMock.replayAll; | |
42 | +//import static org.powermock.api.easymock.PowerMock.verifyAll; | |
43 | +// | |
44 | +//import java.util.HashSet; | |
45 | +//import java.util.Set; | |
46 | +// | |
47 | +//import javax.enterprise.context.spi.Contextual; | |
48 | +//import javax.enterprise.context.spi.CreationalContext; | |
49 | +//import javax.enterprise.inject.spi.Bean; | |
50 | +//import javax.enterprise.inject.spi.BeanManager; | |
51 | +// | |
52 | +//import org.easymock.EasyMock; | |
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 | +//@RunWith(PowerMockRunner.class) | |
60 | +//@PrepareForTest({ BeanManager.class, Bean.class }) | |
61 | +//public class BeansTest { | |
62 | +// | |
63 | +// @SuppressWarnings("unchecked") | |
64 | +// @Test | |
65 | +// public void testGetReferenceByClass() { | |
66 | +// BeanManager beanManager = PowerMock.createMock(BeanManager.class); | |
67 | +// | |
68 | +// Set<Bean<?>> collection = new HashSet<Bean<?>>(); | |
69 | +// Bean<?> bean = PowerMock.createMock(Bean.class); | |
70 | +// collection.add(bean); | |
71 | +// | |
72 | +// String object = "object"; | |
73 | +// | |
74 | +// expect(beanManager.createCreationalContext(EasyMock.anyObject(Contextual.class))).andReturn(null); | |
75 | +// expect(beanManager.getBeans(EasyMock.anyObject(Class.class))).andReturn(collection); | |
76 | +// expect( | |
77 | +// beanManager.getReference(EasyMock.anyObject(Bean.class), EasyMock.anyObject(Class.class), | |
78 | +// EasyMock.anyObject(CreationalContext.class))).andReturn(object); | |
79 | +// | |
80 | +// replayAll(beanManager, bean); | |
81 | +// | |
82 | +// Beans.setBeanManager(beanManager); | |
83 | +// String returned = Beans.getReference(String.class); | |
84 | +// | |
85 | +// assertEquals(returned, object); | |
86 | +// assertEquals(beanManager, Beans.getBeanManager()); | |
87 | +// | |
88 | +// verifyAll(); | |
89 | +// } | |
90 | +// | |
91 | +// @Test | |
92 | +// @SuppressWarnings("unchecked") | |
93 | +// public void testGetReferenceByString() { | |
94 | +// BeanManager beanManager = PowerMock.createMock(BeanManager.class); | |
95 | +// | |
96 | +// Set<Bean<?>> collection = new HashSet<Bean<?>>(); | |
97 | +// Bean<?> bean = PowerMock.createMock(Bean.class); | |
98 | +// collection.add(bean); | |
99 | +// | |
100 | +// String object = "object"; | |
101 | +// | |
102 | +// expect(bean.getBeanClass()).andReturn(null); | |
103 | +// expect(beanManager.createCreationalContext(EasyMock.anyObject(Contextual.class))).andReturn(null); | |
104 | +// expect(beanManager.getBeans("something")).andReturn(collection); | |
105 | +// expect( | |
106 | +// beanManager.getReference(EasyMock.anyObject(Bean.class), EasyMock.anyObject(Class.class), | |
107 | +// EasyMock.anyObject(CreationalContext.class))).andReturn(object); | |
108 | +// | |
109 | +// replayAll(beanManager, bean); | |
110 | +// | |
111 | +// Beans.setBeanManager(beanManager); | |
112 | +// String returned = Beans.getReference("something"); | |
113 | +// | |
114 | +// assertEquals(returned, object); | |
115 | +// assertEquals(beanManager, Beans.getBeanManager()); | |
116 | +// | |
117 | +// verifyAll(); | |
118 | +// } | |
119 | +//} | ... | ... |