Commit 104e4fd0157dcbea034dcc5307301bf5ed5871e7
Exists in
master
Merge branch 'master' of git@github.com:demoiselle/framework.git
Showing
108 changed files
with
2476 additions
and
1070 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 108 files displayed.
documentation/reference/pt-BR/bookinfo.xml
@@ -3,11 +3,11 @@ | @@ -3,11 +3,11 @@ | ||
3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []> | 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []> |
4 | <bookinfo> | 4 | <bookinfo> |
5 | 5 | ||
6 | - <title>Framework Demoiselle &version;</title> | 6 | + <title>Framework Demoiselle 2.4.0-RC2</title> |
7 | <subtitle>Guia de Referência</subtitle> | 7 | <subtitle>Guia de Referência</subtitle> |
8 | 8 | ||
9 | - <abstract>Demoiselle &version;: Framework de Código Aberto para o Desenvolvimento de Aplicações Java EE 6</abstract> | ||
10 | - <titleabbrev>Demoiselle &version; - Guia de Referência</titleabbrev> | 9 | + <abstract>Demoiselle 2.4.0-RC2: Framework de Código Aberto para o Desenvolvimento de Aplicações Java EE 6</abstract> |
10 | + <titleabbrev>Demoiselle 2.4.0-RC2 - Guia de Referência</titleabbrev> | ||
11 | 11 | ||
12 | <xi:include href="authorgroup.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> | 12 | <xi:include href="authorgroup.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> |
13 | 13 |
documentation/reference/pt-BR/configuracao.xml
@@ -14,15 +14,14 @@ | @@ -14,15 +14,14 @@ | ||
14 | <listitem> | 14 | <listitem> |
15 | <para> | 15 | <para> |
16 | <emphasis>arquivo de propriedades</emphasis>: tratam-se de simples arquivos de texto nomeados com a | 16 | <emphasis>arquivo de propriedades</emphasis>: tratam-se de simples arquivos de texto nomeados com a |
17 | - extensão <filename>.properties</filename>, os quais são escritos com a sintaxe <literal>chave=valor | ||
18 | - </literal>, armazenando uma única chave por linha; | 17 | + extensão <filename>.properties</filename>, os quais são escritos com a sintaxe <literal>chave=valor</literal>, |
18 | + armazenando uma única chave por linha; | ||
19 | </para> | 19 | </para> |
20 | </listitem> | 20 | </listitem> |
21 | <listitem> | 21 | <listitem> |
22 | <para> | 22 | <para> |
23 | <emphasis>arquivo XML</emphasis>: são arquivos de texto altamente estruturados com a sintaxe de tags e | 23 | <emphasis>arquivo XML</emphasis>: são arquivos de texto altamente estruturados com a sintaxe de tags e |
24 | - que permitem uma maior validação dos seus valores, sendo geralmente nomeados com a extensão | ||
25 | - <filename>.xml</filename>; | 24 | + que permitem uma maior validação dos seus valores, sendo geralmente nomeados com a extensão<filename>.xml</filename>; |
26 | </para> | 25 | </para> |
27 | </listitem> | 26 | </listitem> |
28 | <listitem> | 27 | <listitem> |
@@ -35,7 +34,7 @@ | @@ -35,7 +34,7 @@ | ||
35 | </para> | 34 | </para> |
36 | <para> | 35 | <para> |
37 | Esse capítulo mostra de que maneira o <emphasis>Demoiselle Framework</emphasis> pode facilitar a utilização dessas | 36 | Esse capítulo mostra de que maneira o <emphasis>Demoiselle Framework</emphasis> pode facilitar a utilização dessas |
38 | - formas de configuração, oferencendo vários recursos interessantes e poderosos para a sua aplicação. | 37 | + formas de configuração, oferencendo vários recursos interessantes para a sua aplicação. |
39 | </para> | 38 | </para> |
40 | 39 | ||
41 | </section> | 40 | </section> |
@@ -161,15 +160,15 @@ public class BookmarkConfig { | @@ -161,15 +160,15 @@ public class BookmarkConfig { | ||
161 | <section> | 160 | <section> |
162 | <title>Especificando os parâmetros</title> | 161 | <title>Especificando os parâmetros</title> |
163 | <para> | 162 | <para> |
164 | - Atualmente são suportados nativamente pelo <emphasis>Demoiselle Framework</emphasis> parâmetros de cinco tipos | ||
165 | - diferentes, são eles: <emphasis>primitivo</emphasis>, <emphasis>wrapped</emphasis>, <emphasis>String</emphasis>, | ||
166 | - <emphasis>class</emphasis>, <emphasis>map</emphasis> e <emphasis>array</emphasis>, sendo que os três últimos | ||
167 | - são suportados a partir da versão 2.4.0. A seguir vamos explicar e exemplificar como utilizar cada um desses | 163 | + Atualmente são suportados nativamente pelo <emphasis>Demoiselle Framework</emphasis> parâmetros de sete categorias |
164 | + diferentes. São eles: tipos primitivos (<emphasis>int, float, boolean, etc</emphasis>), classes <emphasis>wrapper</emphasis> (<emphasis>Integer, Float, Boolean, etc.</emphasis>) | ||
165 | + , <emphasis>String</emphasis>, <emphasis>Class</emphasis>, <emphasis>Map</emphasis>, <emphasis>Array</emphasis> e instâncias de <emphasis>Enum</emphasis>. | ||
166 | + A seguir vamos explicar e exemplificar como utilizar cada um desses | ||
168 | tipos, e alertar para as possíveis exceções que poderão ser lançadas para sua aplicação. | 167 | tipos, e alertar para as possíveis exceções que poderão ser lançadas para sua aplicação. |
169 | </para> | 168 | </para> |
170 | <caution> | 169 | <caution> |
171 | <para> | 170 | <para> |
172 | - A partir da versão 2.4.0 não são mais reconhecidas as convenções. Os parâmetros serão procurados exatamente | 171 | + A partir da versão 2.4.0 não são mais reconhecidas as convenções de substituição de nomes. Os parâmetros serão procurados exatamente |
173 | como foram definidos na classe de configuração. | 172 | como foram definidos na classe de configuração. |
174 | </para> | 173 | </para> |
175 | </caution> | 174 | </caution> |
@@ -333,58 +332,42 @@ untypedClass=package.MyOtherClass | @@ -333,58 +332,42 @@ untypedClass=package.MyOtherClass | ||
333 | <entry> | 332 | <entry> |
334 | <para> | 333 | <para> |
335 | Para utilizar parâmetros do tipo <emphasis>Map</emphasis>, o arquivo de configurações deve usar a seguinte | 334 | Para utilizar parâmetros do tipo <emphasis>Map</emphasis>, o arquivo de configurações deve usar a seguinte |
336 | - estrutura na formação da chave: <emphasis>prefixo+chavedomap+nomedoatributo</emphasis>. Vejamos um exemplo. | 335 | + estrutura na formação da chave: <emphasis>prefixo+nomedoatributo+chavedomap</emphasis>. Vejamos um exemplo. |
337 | Se temos em nossa aplicação uma classe de configuração como a mostrada abaixo: | 336 | Se temos em nossa aplicação uma classe de configuração como a mostrada abaixo: |
338 | </para> | 337 | </para> |
339 | <programlisting role="JAVA"><![CDATA[ | 338 | <programlisting role="JAVA"><![CDATA[ |
340 | @Configuration | 339 | @Configuration |
341 | public class BookmarkConfig { | 340 | public class BookmarkConfig { |
342 | 341 | ||
343 | - private Map<String, String> url; | 342 | + private Map<String, String> connectionConfiguration; |
344 | 343 | ||
345 | - private Map<String, String> driverClass; | ||
346 | - | ||
347 | - public Map<String, String> getUrl() { | ||
348 | - return url; | ||
349 | - } | ||
350 | - | ||
351 | - public Map<String, String> DriverClass() { | ||
352 | - return driverClass; | 344 | + public Map<String, String> getConnectionConfiguration() { |
345 | + return connectionConfiguration; | ||
353 | } | 346 | } |
354 | } | 347 | } |
355 | ]]></programlisting> | 348 | ]]></programlisting> |
356 | <para> | 349 | <para> |
357 | - O arquivo de configuração deverá ser preenchido no formato seguinte (se for do tipo <emphasis>properties</emphasis>): | 350 | + O arquivo de configuração deverá ser preenchido no seguinte formato (se for do tipo <emphasis>properties</emphasis>): |
358 | </para> | 351 | </para> |
359 | - <programlisting role="PROPERTIES"><![CDATA[ | ||
360 | -mapkey1.url=jdbc:postgresql://localhost:5432/app | ||
361 | -mapkey2.url=jdbc:mysql://localhost:3306/app | ||
362 | -mapkey1.driverClass=org.postgresql.Driver | ||
363 | -mapkey2.driverClass=com.mysql.Driver | ||
364 | - ]]></programlisting> | 352 | + <programlisting role="PROPERTIES"><![CDATA[connectionConfiguration.ip=192.168.0.120 |
353 | +connectionConfiguration.gateway=192.168.0.1 | ||
354 | +connectionConfiguration.dns1=200.10.128.99 | ||
355 | +connectionConfiguration.dns2=200.10.128.88]]></programlisting> | ||
365 | <para> | 356 | <para> |
366 | - Dessa forma, ao fazer a chamada <emphasis>url.get("mapkey2");</emphasis>por exemplo, o valor retornado será | ||
367 | - <emphasis>jdbc:mysql://localhost:3306/app</emphasis>. | 357 | + Dessa forma, ao fazer a chamada <emphasis>connectionConfiguration.get("gateway");</emphasis> por exemplo, o valor retornado será |
358 | + <emphasis>192.168.0.1</emphasis>. | ||
368 | </para> | 359 | </para> |
369 | - <note> | ||
370 | - <para> | ||
371 | - O ponto entre a chave do <emphasis>Map</emphasis> e o nome do parâmetro é adicionado automaticamente pelo | ||
372 | - framework. | ||
373 | - </para> | ||
374 | - </note> | 360 | + |
375 | <tip> | 361 | <tip> |
376 | <para> | 362 | <para> |
377 | Você pode utilizar a chave do Map com nome "default" para indicar que, no arquivo de configuração, a chave é formada | 363 | Você pode utilizar a chave do Map com nome "default" para indicar que, no arquivo de configuração, a chave é formada |
378 | - apenas pela junção do prefixo com o atributo, sem utilizar a própria chave do Map. Por exemplo, se na sua classe | ||
379 | - existir um comando como este: | ||
380 | - </para> | ||
381 | - <programlisting role="JAVA"><![CDATA[ | ||
382 | - myMap.get("default"); | ||
383 | - ]]></programlisting> | ||
384 | - <para>o framework irá procurar no arquivo de configuração uma linha como esta:</para> | ||
385 | - <programlisting role="JAVA"><![CDATA[ | ||
386 | - prefix.myMap=Default Value | ||
387 | - ]]></programlisting> | 364 | + apenas pela junção do prefixo com o atributo, sem utilizar a própria chave do Map. Por exemplo, se o seu arquivo de propriedades |
365 | + contiver uma chave: | ||
366 | + </para> | ||
367 | + <programlisting role="JAVA"><![CDATA[prefix.myMap=Default Value]]></programlisting> | ||
368 | + <para>então seu código poderá ter um comando:</para> | ||
369 | + <programlisting role="JAVA"><![CDATA[String value = myMap.get("default");]]></programlisting> | ||
370 | + <para>e o valor de <emphasis>value</emphasis> será <emphasis>"Default Value"</emphasis>.</para> | ||
388 | </tip> | 371 | </tip> |
389 | <para> | 372 | <para> |
390 | Caso a classe de configuração não esteja associada a um arquivo que contenha a chave de um de seus parâmetros | 373 | Caso a classe de configuração não esteja associada a um arquivo que contenha a chave de um de seus parâmetros |
@@ -428,7 +411,66 @@ integerArray=1 | @@ -428,7 +411,66 @@ integerArray=1 | ||
428 | </row> | 411 | </row> |
429 | </tbody> | 412 | </tbody> |
430 | </tgroup> | 413 | </tgroup> |
431 | - </informaltable> | 414 | + </informaltable> |
415 | + | ||
416 | + <informaltable> | ||
417 | + <tgroup cols="1"> | ||
418 | + <colspec colwidth="100*" /> | ||
419 | + <tbody> | ||
420 | + <row> | ||
421 | + <entry> | ||
422 | + <emphasis role="bold">Enum</emphasis> | ||
423 | + </entry> | ||
424 | + </row> | ||
425 | + <row> | ||
426 | + <entry> | ||
427 | + <para> | ||
428 | + É possível criar uma lista de constantes do tipo <emphasis>Enum</emphasis> e carregar um valor de constante | ||
429 | + através de um arquivo de configuração. Por exemplo, caso exista o seguinte <emphasis>Enum</emphasis> | ||
430 | + </para> | ||
431 | + | ||
432 | + <programlisting role="JAVA"><![CDATA[public enum ConfigurationType { | ||
433 | + | ||
434 | + PROPERTIES , XML , SYSTEM; | ||
435 | + | ||
436 | +}]]></programlisting> | ||
437 | + | ||
438 | + <para>e ele seja usado no seguinte arquivo de configuração</para> | ||
439 | + | ||
440 | + <programlisting role="JAVA"><![CDATA[@Configuration | ||
441 | +public class ConfigurationLoader { | ||
442 | + | ||
443 | + private ConfigurationType loadedConfigurationType; | ||
444 | + | ||
445 | + public ConfigurationType getLoadedConfigurationType(){ | ||
446 | + return loadedConfigurationType; | ||
447 | + } | ||
448 | +}]]></programlisting> | ||
449 | + | ||
450 | + <para>O arquivo do tipo <emphasis>properties</emphasis> pode ser criado assim:</para> | ||
451 | + | ||
452 | + <programlisting role="PROPERTIES"><![CDATA[loadedConfigurationType=SYSTEM]]></programlisting> | ||
453 | + | ||
454 | + <note> | ||
455 | + <para> | ||
456 | + O valor definido no arquivo de configuração para atributos do tipo <emphasis>Enum</emphasis> deve | ||
457 | + ser idêntico ao nome da constante definida no <emphasis>Enum</emphasis>, inclusive casando letras maiúsculas e | ||
458 | + minúsculas. De fato, o valor da propriedade deve casar com o valor retornado no código: | ||
459 | + <emphasis>Enum.name()</emphasis>. | ||
460 | + </para> | ||
461 | + | ||
462 | + <para> | ||
463 | + Caso o valor definido no arquivo de configuração não case com nenhuma constante definida no <emphasis>Enum</emphasis>, | ||
464 | + uma exceção de tipo <emphasis>ConfigurationException</emphasis> de causa <emphasis>ConversionException</emphasis> | ||
465 | + será lançada. Já se à propriedade for atribuido um valor vazio, o atributo do tipo <emphasis>Enum</emphasis> receberá | ||
466 | + o valor <emphasis>null</emphasis>. | ||
467 | + </para> | ||
468 | + </note> | ||
469 | + </entry> | ||
470 | + </row> | ||
471 | + </tbody> | ||
472 | + </tgroup> | ||
473 | + </informaltable> | ||
432 | 474 | ||
433 | </section> | 475 | </section> |
434 | 476 | ||
@@ -549,7 +591,7 @@ public class BookmarkConfig { | @@ -549,7 +591,7 @@ public class BookmarkConfig { | ||
549 | o atributo passando como parâmetro o nome pelo qual você deseja que ele seja procurado no arquivo de propriedades, | 591 | o atributo passando como parâmetro o nome pelo qual você deseja que ele seja procurado no arquivo de propriedades, |
550 | como mostra o exemplo abaixo: | 592 | como mostra o exemplo abaixo: |
551 | </para> | 593 | </para> |
552 | - <programlisting role="JAVA"><![CDATA[@Configuration(resource = "bookmark", prefix = "general.") | 594 | + <programlisting role="JAVA"><![CDATA[@Configuration |
553 | public class BookmarkConfig { | 595 | public class BookmarkConfig { |
554 | 596 | ||
555 | @Name("app.title") | 597 | @Name("app.title") |
documentation/reference/pt-BR/master.xml
@@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
14 | </para> | 14 | </para> |
15 | <note> | 15 | <note> |
16 | <para> | 16 | <para> |
17 | - Esta documentação refere-se à release &version; do <emphasis>Demoiselle Framework</emphasis> | 17 | + Esta documentação refere-se à release 2.4.0-RC2 do <emphasis>Demoiselle Framework</emphasis> |
18 | e pode diferir significativamente das versões anteriores. | 18 | e pode diferir significativamente das versões anteriores. |
19 | </para> | 19 | </para> |
20 | </note> | 20 | </note> |
documentation/reference/pt-BR/mensagem.xml
@@ -145,41 +145,15 @@ private MessageContext messageContext;]]></programlisting> | @@ -145,41 +145,15 @@ private MessageContext messageContext;]]></programlisting> | ||
145 | <programlisting role="JAVA"><![CDATA[Message message = new DefaultMessage("Ocorreu um erro ao excluir o aluno!", SeverityType.ERROR); | 145 | <programlisting role="JAVA"><![CDATA[Message message = new DefaultMessage("Ocorreu um erro ao excluir o aluno!", SeverityType.ERROR); |
146 | messageContext.add(message);]]></programlisting> | 146 | messageContext.add(message);]]></programlisting> |
147 | <para> | 147 | <para> |
148 | - Uma vez inseridas no contexto em determinada camada da aplicação, as mensagens podem ser posteriormente | ||
149 | - recuperadas. Para tal, é preciso invocar o método <function>getMessages()</function> da interface | ||
150 | - <literal>MessageContext</literal>, o qual retornará uma coleção de objetos do tipo <literal>Message</literal>. | 148 | + A extensão para <emphasis>demoiselle-jsf</emphasis> |
149 | + transfere automaticamente as mensagens incluídas no <literal>MessageContext</literal> | ||
150 | + para o <literal>FacesContext</literal>. | ||
151 | </para> | 151 | </para> |
152 | - <note> | ||
153 | - <para> | ||
154 | - A extensão para <emphasis>JavaServer Faces</emphasis> no <emphasis>Demoiselle Framework</emphasis> | ||
155 | - transfere automaticamente as mensagens incluídas no <literal>MessageContext</literal> para a apresentação | ||
156 | - durante a renderização da página pelo <emphasis>JSF</emphasis>. | ||
157 | - </para> | ||
158 | - </note> | ||
159 | <para> | 152 | <para> |
160 | - Para remover todas as mensagens existentes no contexto, basta invocar o método <function>clear()</function> da | ||
161 | - interface <literal>MessageContext</literal>. | 153 | + O contexto de mensagens, representado pela interface <literal>MessageContext</literal>, é capaz de |
154 | + armazenar diversas mensagens em uma mesma requisição. Ele não é restrito a aplicações do tipo Web, | ||
155 | + isto é, pode ser usado também para aplicações do tipo desktop (i.e., Swing). | ||
162 | </para> | 156 | </para> |
163 | - <note> | ||
164 | - <para> | ||
165 | - Especificamente para aplicações Java Web, o contexto de mensagens é automaticamente reinicializado a cada | ||
166 | - requisição HTTP. Ou seja, as mensagens incluídas no contexto por uma determinada sessão de usuário não | ||
167 | - interferem nas demais sessões existentes no servidor de aplicações. Além disso, ao final da requisição as | ||
168 | - mensagens existentes são automaticamente excluídas do contexto. | ||
169 | - </para> | ||
170 | - </note> | ||
171 | - <para> | ||
172 | - O contexto de mensagens <literal>MessageContext</literal> tem o seu ciclo de vida gerenciado pelo CDI e pertence | ||
173 | - ao escopo de sessão (i.e., <literal>@SessionScoped</literal>). Ou seja, mensagens incluídas na requisição de um | ||
174 | - determinado usuário não serão exibidas para um outro usuário, pois cada um possuirá a sua sessão. | ||
175 | - </para> | ||
176 | - <note> | ||
177 | - <para> | ||
178 | - O contexto de mensagens, representado pela interface <literal>MessageContext</literal>, é capaz de | ||
179 | - armazenar diversas mensagens em uma mesma requisição. Ele não é restrito a aplicações do tipo Web, | ||
180 | - isto é, pode ser usado também para aplicações do tipo desktop (i.e., Swing). | ||
181 | - </para> | ||
182 | - </note> | ||
183 | </section> | 157 | </section> |
184 | 158 | ||
185 | <section> | 159 | <section> |
@@ -303,6 +277,41 @@ ALUNO_EXCLUIR_OK=L'étudiant {0} a été supprimé avec succès]]></programlisti | @@ -303,6 +277,41 @@ ALUNO_EXCLUIR_OK=L'étudiant {0} a été supprimé avec succès]]></programlisti | ||
303 | </para> | 277 | </para> |
304 | </note> | 278 | </note> |
305 | </section> | 279 | </section> |
280 | + | ||
281 | + <section> | ||
282 | + <title>Destino das mensagens</title> | ||
283 | + | ||
284 | + <para> | ||
285 | + O Framework Demoiselle permite configurar o destino das mensagens enviadas. Por padrão, mensagens enviadas em um ambiente SE (Swing por exemplo) | ||
286 | + são exibidas como registros de log no console, já mensagens enviadas em um ambiente WEB usando JSF 2.0 são redirecionadas para a classe | ||
287 | + <code>FacesContext</code>. Caso esse comportamento padrão não seja suficiente para você, é possível personalizar o mecanismo de redirecionamento | ||
288 | + de mensagens, fazendo-o enviar as mensagens para um local de seu interesse. | ||
289 | + </para> | ||
290 | + | ||
291 | + <para> | ||
292 | + Para isso existe a interface <code>MessageAppender</code>. Para toda mensagem enviada, o Framework Demoiselle vai determinar a implementação | ||
293 | + mais adequada de <code>MessageAppender</code> a utilizar e vai redirecionar qualquer mensagem para essa implementação. | ||
294 | + </para> | ||
295 | + | ||
296 | + <programlisting role="JAVA">public interface MessageAppender extends Serializable { | ||
297 | + | ||
298 | + /** | ||
299 | + * Method that must hold message in an appropriate way and in an appropriate local. | ||
300 | + * Demoiselle holds a message in a Logger or in a FacesContext, depending on the project. | ||
301 | + * | ||
302 | + * @param message | ||
303 | + * message to be stored. | ||
304 | + */ | ||
305 | + void append(Message message); | ||
306 | +}</programlisting> | ||
307 | + | ||
308 | + <para> | ||
309 | + Para criar seu próprio <code>MessageAppender</code>, implemente essa interface e anote-a com a anotação <code>@Priority</code> - o Framework | ||
310 | + Demoiselle irá selecionar a implementação adequada paseada na maior prioridade. Não é necessário configurar mais nada, o Framework Demoiselle | ||
311 | + selecionará a implementação automaticamente. Cabe-lhe então a tarefa de implementar o método <code>append(Message message)</code> para tratar | ||
312 | + a mensagem da forma que melhor se adequar a seu projeto. | ||
313 | + </para> | ||
314 | + </section> | ||
306 | 315 | ||
307 | <section> | 316 | <section> |
308 | <title>Exemplos de implementação</title> | 317 | <title>Exemplos de implementação</title> |
documentation/reference/pt-BR/persistencia.xml
@@ -18,6 +18,181 @@ | @@ -18,6 +18,181 @@ | ||
18 | é apenas injetar o recurso adequado em seu código e o Framework Demoiselle se encarregará de | 18 | é apenas injetar o recurso adequado em seu código e o Framework Demoiselle se encarregará de |
19 | produzi-lo e configurá-lo. | 19 | produzi-lo e configurá-lo. |
20 | </para> | 20 | </para> |
21 | + | ||
22 | + <section> | ||
23 | + <title>JPA</title> | ||
24 | + | ||
25 | + <para> | ||
26 | + O Framework Demoiselle fornece um produtor padrão para contextos de persistência da JPA. Esse produtor lê o arquivo | ||
27 | + de configuração <code>persistence.xml</code> de seu projeto e toma as providências necessárias para fabricar uma instância | ||
28 | + da classe <code>EntityManager</code> que pode ser usada para gerenciar as entidades de sua aplicação. Além disso, instâncias | ||
29 | + de <code>EntityManager</code> produzidas pelo Framework Demoiselle participam automaticamente de transações abertas através da | ||
30 | + anotação <code>@Transactional</code>, conforme apresentado no capítulo sobre <link linkend="transacao">Transações</link>. | ||
31 | + </para> | ||
32 | + | ||
33 | + <tip> | ||
34 | + <para> | ||
35 | + Para acrescentar a dependência à extensão <literal>demoiselle-jpa</literal>, adicione esse código | ||
36 | + em seu arquivo <literal>pom.xml</literal>, na seção <literal>dependencies</literal>. | ||
37 | + </para> | ||
38 | + | ||
39 | + <programlisting role="XML"><![CDATA[<dependency> | ||
40 | + <groupId>br.gov.frameworkdemoiselle</groupId> | ||
41 | + <artifactId>demoiselle-jpa</artifactId> | ||
42 | + <scope>compile</scope> | ||
43 | +</dependency>]]></programlisting> | ||
44 | + </tip> | ||
45 | + | ||
46 | + <section> | ||
47 | + <title>Introdução ao mecanismo</title> | ||
48 | + | ||
49 | + <para> | ||
50 | + Para injetar uma instância de <code>EntityManager</code> em sua aplicação, basta usar a anotação <code>@Inject</code>. | ||
51 | + </para> | ||
52 | + | ||
53 | + <programlisting role="JAVA">@PersistenceController | ||
54 | +public class BookmarkDAO extends JPACrud<Bookmark, Long> { | ||
55 | + | ||
56 | + private static final long serialVersionUID = 1L; | ||
57 | + | ||
58 | + @Inject | ||
59 | + private EntityManager entityManager; | ||
60 | + | ||
61 | + public void persistBookmark(Bookmark bookmark){ | ||
62 | + entityManager.persist(bookmark); | ||
63 | + } | ||
64 | + | ||
65 | +}</programlisting> | ||
66 | + | ||
67 | + <para> | ||
68 | + O produtor padrão injetará o <code>EntityManager</code> configurado no arquivo <code>persistence.xml</code>. Se houver | ||
69 | + mais de um contexto de persistência configurado em <code>persistence.xml</code>, será necessário especificar qual será | ||
70 | + injetado no ponto de injeção. Para isso use a anotação <code>@Name</code>. | ||
71 | + </para> | ||
72 | + | ||
73 | + <programlisting role="JAVA">@PersistenceController | ||
74 | +public class BookmarkDAO extends JPACrud<Bookmark, Long> { | ||
75 | + | ||
76 | + private static final long serialVersionUID = 1L; | ||
77 | + | ||
78 | + @Inject | ||
79 | + @Name("persistence_unit_1") | ||
80 | + private EntityManager entityManager; | ||
81 | + | ||
82 | + public void persistBookmark(Bookmark bookmark){ | ||
83 | + entityManager.persist(bookmark); | ||
84 | + } | ||
85 | + | ||
86 | +}</programlisting> | ||
87 | + | ||
88 | + <para> | ||
89 | + É possível invocar o utilitário <code>Beans</code> para injetar instâncias de <code>EntityManager</code> programaticamente. | ||
90 | + </para> | ||
91 | + | ||
92 | + <programlisting role="JAVA">@PersistenceController | ||
93 | +public class BookmarkDAO extends JPACrud<Bookmark, Long> { | ||
94 | + | ||
95 | + private static final long serialVersionUID = 1L; | ||
96 | + | ||
97 | + public void persistBookmark(Bookmark bookmark){ | ||
98 | + EntityManager entityManager = Beans.getReference(EntityManager.class); | ||
99 | + entityManager.persist(bookmark); | ||
100 | + } | ||
101 | + | ||
102 | + public void persistBookmarkInHistory(Bookmark bookmark){ | ||
103 | + EntityManager entityManager = Beans.getReference(EntityManager.class , new NameQualifier("history_persistence_unit")); | ||
104 | + entityManager.persist(bookmark); | ||
105 | + } | ||
106 | + | ||
107 | +}</programlisting> | ||
108 | + </section> | ||
109 | + | ||
110 | + <section> | ||
111 | + <title>Configuração</title> | ||
112 | + | ||
113 | + <para> | ||
114 | + Alguns comportamentos do produtor podem ser configurados através das propriedades abaixo, que devem ser configuradas | ||
115 | + no arquivo <code>demoiselle.properties</code>. | ||
116 | + </para> | ||
117 | + | ||
118 | + <informaltable width="100%"> | ||
119 | + <tgroup cols="3"> | ||
120 | + <colspec align="left"/> | ||
121 | + <colspec align="left"/> | ||
122 | + <colspec align="right"/> | ||
123 | + | ||
124 | + <thead> | ||
125 | + <row valign="top"> | ||
126 | + <entry><emphasis role="bold">Propriedade</emphasis></entry> | ||
127 | + <entry><emphasis role="bold">Descrição</emphasis></entry> | ||
128 | + <entry><emphasis role="bold">Padrão</emphasis></entry> | ||
129 | + </row> | ||
130 | + </thead> | ||
131 | + | ||
132 | + <tbody> | ||
133 | + <row valign="top"> | ||
134 | + <entry>frameworkdemoiselle.​persistence.​default.​unit.​name</entry> | ||
135 | + <entry> | ||
136 | + <para> | ||
137 | + Define o nome da unidade de persistência padrão (configurada em <code>persistence.xml</code>) que será injetada | ||
138 | + caso a anotação <code>@Name</code> não seja usada. Não é necessário se apenas uma unidade de persistência for configurada. | ||
139 | + </para> | ||
140 | + </entry> | ||
141 | + <entry></entry> | ||
142 | + </row> | ||
143 | + | ||
144 | + <row valign="top"> | ||
145 | + <entry>frameworkdemoiselle.​persistence.​entitymanager.​scope</entry> | ||
146 | + <entry> | ||
147 | + <para> | ||
148 | + Permite determinar o escopo de unidades de persistência injetadas. Dentro do escopo determinado, todos os pontos | ||
149 | + de injeção receberão a mesma instância de <code>EntityManager</code>. | ||
150 | + </para> | ||
151 | + <para> | ||
152 | + Os valores possíveis são: | ||
153 | + <simplelist type="inline"> | ||
154 | + <member>request</member> | ||
155 | + <member>session</member> | ||
156 | + <member>view</member> | ||
157 | + <member>conversation</member> | ||
158 | + <member>application</member> | ||
159 | + <member>noscope</member> | ||
160 | + </simplelist> | ||
161 | + </para> | ||
162 | + </entry> | ||
163 | + <entry>request</entry> | ||
164 | + </row> | ||
165 | + </tbody> | ||
166 | + </tgroup> | ||
167 | + </informaltable> | ||
168 | + | ||
169 | + <tip> | ||
170 | + <para> | ||
171 | + O escopo especial <emphasis>noscope</emphasis> desliga o gerenciamento de escopo de instâncias de <code>EntityManager</code> | ||
172 | + produzidas pelo Framework Demoiselle. Isso permite ao desenvolvedor controlar totalmente o ciclo de vida de um | ||
173 | + <code>EntityManager</code> injetado e ainda reter o recurso do produtor padrão. | ||
174 | + </para> | ||
175 | + <para> | ||
176 | + Note que ao usar a opção <emphasis>noscope</emphasis>, o desenvolvedor é o responsável por controlar o ciclo de vida do gerenciador | ||
177 | + de persistência. Ele não participará de transações JPA abertas através da anotação <code>@Transactional</code> (transações JTA funcionam normalmente) | ||
178 | + e multiplos pontos de injeção durante uma requisição receberão múltiplas instâncias de <code>EntityManager</code>. | ||
179 | + </para> | ||
180 | + </tip> | ||
181 | + | ||
182 | + <caution> | ||
183 | + <para> | ||
184 | + Deve-se usar cautela ao alterar o escopo padrão das instâncias de <code>EntityManager</code>. Na grande maioria dos casos o escopo | ||
185 | + padrão <emphasis>request</emphasis> é o suficiente e alterar esse padrão deve ser feito apenas após extensa análise dos prós e contras | ||
186 | + de cada escopo. | ||
187 | + </para> | ||
188 | + <para> | ||
189 | + Dê especial atenção aos escopos que podem ser serializados pelo servidor de aplicação (<emphasis>session</emphasis>, <emphasis>view</emphasis> | ||
190 | + e <emphasis>conversation</emphasis>) pois a especificação não define o comportamento de instâncias de <code>EntityManager</code> que são | ||
191 | + serializadas. | ||
192 | + </para> | ||
193 | + </caution> | ||
194 | + </section> | ||
195 | + </section> | ||
21 | 196 | ||
22 | <section> | 197 | <section> |
23 | 198 |
documentation/reference/pt-BR/properties.xml
@@ -251,12 +251,34 @@ | @@ -251,12 +251,34 @@ | ||
251 | <entry>frameworkdemoiselle.​persistence.​default.​unit.​name</entry> | 251 | <entry>frameworkdemoiselle.​persistence.​default.​unit.​name</entry> |
252 | <entry> | 252 | <entry> |
253 | <para> | 253 | <para> |
254 | - Define a unidade de persistência padrão para aplicações que possuem mais | ||
255 | - de um persistence-unit definido no arquivo persistence.xml. | 254 | + Define o nome da unidade de persistência padrão (configurada em <code>persistence.xml</code>) que será injetada |
255 | + caso a anotação <code>@Name</code> não seja usada. Não é necessário se apenas uma unidade de persistência for configurada. | ||
256 | </para> | 256 | </para> |
257 | </entry> | 257 | </entry> |
258 | <entry></entry> | 258 | <entry></entry> |
259 | </row> | 259 | </row> |
260 | + | ||
261 | + <row valign="top"> | ||
262 | + <entry>frameworkdemoiselle.​persistence.​entitymanager.​scope</entry> | ||
263 | + <entry> | ||
264 | + <para> | ||
265 | + Permite determinar o escopo de unidades de persistência injetadas. Dentro do escopo determinado, todos os pontos | ||
266 | + de injeção receberão a mesma instância de <code>EntityManager</code>. | ||
267 | + </para> | ||
268 | + <para> | ||
269 | + Os valores possíveis são: | ||
270 | + <simplelist type="inline"> | ||
271 | + <member>request</member> | ||
272 | + <member>session</member> | ||
273 | + <member>view</member> | ||
274 | + <member>conversation</member> | ||
275 | + <member>application</member> | ||
276 | + <member>noscope</member> | ||
277 | + </simplelist> | ||
278 | + </para> | ||
279 | + </entry> | ||
280 | + <entry>request</entry> | ||
281 | + </row> | ||
260 | </tbody> | 282 | </tbody> |
261 | </tgroup> | 283 | </tgroup> |
262 | </table> | 284 | </table> |
documentation/reference/pt-BR/security.xml
@@ -129,11 +129,16 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | @@ -129,11 +129,16 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | ||
129 | comum e exibir uma tela HTML contendo um formulario que solicita as informacoes. | 129 | comum e exibir uma tela HTML contendo um formulario que solicita as informacoes. |
130 | */ | 130 | */ |
131 | 131 | ||
132 | - securityContext.login(); | 132 | + try{ |
133 | + securityContext.login(); | ||
133 | 134 | ||
134 | - //Executa codigo que requer autenticacao | 135 | + //Executa codigo que requer autenticacao |
135 | 136 | ||
136 | - securityContext.logout(); | 137 | + securityContext.logout(); |
138 | + } | ||
139 | + catch(InvalidCredentialsException exception){ | ||
140 | + //Trata credenciais inválidas | ||
141 | + } | ||
137 | 142 | ||
138 | } | 143 | } |
139 | }]]></programlisting> | 144 | }]]></programlisting> |
@@ -503,13 +508,13 @@ class GerenciadorBookmark { | @@ -503,13 +508,13 @@ class GerenciadorBookmark { | ||
503 | <programlisting role="JAVA"><![CDATA[public class MeuAuthenticator implements Authenticator { | 508 | <programlisting role="JAVA"><![CDATA[public class MeuAuthenticator implements Authenticator { |
504 | 509 | ||
505 | @Override | 510 | @Override |
506 | - public boolean authenticate() { | 511 | + public boolean authenticate() throws Exception { |
507 | // Escreva aqui seu codigo de autenticacao e retorne true caso o processo seja um sucesso | 512 | // Escreva aqui seu codigo de autenticacao e retorne true caso o processo seja um sucesso |
508 | return true; | 513 | return true; |
509 | } | 514 | } |
510 | 515 | ||
511 | @Override | 516 | @Override |
512 | - public Principal getUser() { | 517 | + public User getUser(){ |
513 | // Obtenha dados sobre o usuario autenticado e retorne na forma da interface javax.security.Principal | 518 | // Obtenha dados sobre o usuario autenticado e retorne na forma da interface javax.security.Principal |
514 | return new Principal(){ | 519 | return new Principal(){ |
515 | public String getName(){ | 520 | public String getName(){ |
@@ -519,7 +524,7 @@ class GerenciadorBookmark { | @@ -519,7 +524,7 @@ class GerenciadorBookmark { | ||
519 | } | 524 | } |
520 | 525 | ||
521 | @Override | 526 | @Override |
522 | - public void unAuthenticate() { | 527 | + public void unauthenticate() throws Exception { |
523 | // Remova qualquer informacao de autenticacao do usuario, apas o retorno deste metodo o usuario | 528 | // Remova qualquer informacao de autenticacao do usuario, apas o retorno deste metodo o usuario |
524 | // deve ser considerado nao autenticado. | 529 | // deve ser considerado nao autenticado. |
525 | } | 530 | } |
@@ -527,13 +532,13 @@ class GerenciadorBookmark { | @@ -527,13 +532,13 @@ class GerenciadorBookmark { | ||
527 | <programlisting role="JAVA"><![CDATA[public class MeuAuthorizer implements Authorizer { | 532 | <programlisting role="JAVA"><![CDATA[public class MeuAuthorizer implements Authorizer { |
528 | 533 | ||
529 | @Override | 534 | @Override |
530 | - public boolean hasRole(String role) { | 535 | + public boolean hasRole(String role) throws Exception { |
531 | // Verifique se o usuario autenticado tem o papel informado, retorne true em caso positivo | 536 | // Verifique se o usuario autenticado tem o papel informado, retorne true em caso positivo |
532 | return false; | 537 | return false; |
533 | } | 538 | } |
534 | 539 | ||
535 | @Override | 540 | @Override |
536 | - public boolean hasPermission(String resource, String operation) { | 541 | + public boolean hasPermission(String resource, String operation) throws Exception { |
537 | // Escreva aqui seu codigo de verificação de permissao | 542 | // Escreva aqui seu codigo de verificação de permissao |
538 | return false; | 543 | return false; |
539 | } | 544 | } |
documentation/reference/pt-BR/transacao.xml
@@ -135,7 +135,7 @@ public class AbacaxiException { | @@ -135,7 +135,7 @@ public class AbacaxiException { | ||
135 | <para> | 135 | <para> |
136 | Esta estratégia, que está disponível na extensão <literal>demoiselle-jpa</literal>, delega o | 136 | Esta estratégia, que está disponível na extensão <literal>demoiselle-jpa</literal>, delega o |
137 | controle das transações para o <literal>javax.persistence.EntityManager</literal> da | 137 | controle das transações para o <literal>javax.persistence.EntityManager</literal> da |
138 | - especificação JPA. Você deve escolher esta estratégia quando estiver persisteindo dados | 138 | + especificação JPA. Você deve escolher esta estratégia quando estiver persistindo dados |
139 | com JPA e utilizando apenas uma base de dados em sua aplicação. Como um <literal>EntityManager</literal> | 139 | com JPA e utilizando apenas uma base de dados em sua aplicação. Como um <literal>EntityManager</literal> |
140 | acessa apenas uma unidade de persistência, não há como fazer o controle transacional de unidades distintas. | 140 | acessa apenas uma unidade de persistência, não há como fazer o controle transacional de unidades distintas. |
141 | </para> | 141 | </para> |
impl/core/pom.xml
@@ -104,60 +104,7 @@ | @@ -104,60 +104,7 @@ | ||
104 | <groupId>org.codehaus.mojo</groupId> | 104 | <groupId>org.codehaus.mojo</groupId> |
105 | <artifactId>cobertura-maven-plugin</artifactId> | 105 | <artifactId>cobertura-maven-plugin</artifactId> |
106 | </plugin> | 106 | </plugin> |
107 | - | ||
108 | - <!-- | ||
109 | - <plugin> | ||
110 | - <groupId>org.jacoco</groupId> | ||
111 | - <artifactId>jacoco-maven-plugin</artifactId> | ||
112 | - <version>${jacoco.version}</version> | ||
113 | - <executions> | ||
114 | - <execution> | ||
115 | - <goals> | ||
116 | - <goal>prepare-agent</goal> | ||
117 | - </goals> | ||
118 | - </execution> | ||
119 | - <execution> | ||
120 | - <id>report</id> | ||
121 | - <phase>prepare-package</phase> | ||
122 | - <goals> | ||
123 | - <goal>report</goal> | ||
124 | - </goals> | ||
125 | - </execution> | ||
126 | - </executions> | ||
127 | - </plugin> | ||
128 | - --> | ||
129 | </plugins> | 107 | </plugins> |
130 | - | ||
131 | - <!-- | ||
132 | - <pluginManagement> | ||
133 | - <plugins> | ||
134 | - <plugin> | ||
135 | - <groupId>org.eclipse.m2e</groupId> | ||
136 | - <artifactId>lifecycle-mapping</artifactId> | ||
137 | - <version>1.0.0</version> | ||
138 | - <configuration> | ||
139 | - <lifecycleMappingMetadata> | ||
140 | - <pluginExecutions> | ||
141 | - <pluginExecution> | ||
142 | - <pluginExecutionFilter> | ||
143 | - <groupId>org.jacoco</groupId> | ||
144 | - <artifactId>jacoco-maven-plugin</artifactId> | ||
145 | - <versionRange>[${jacoco.version},)</versionRange> | ||
146 | - <goals> | ||
147 | - <goal>prepare-agent</goal> | ||
148 | - </goals> | ||
149 | - </pluginExecutionFilter> | ||
150 | - <action> | ||
151 | - <ignore></ignore> | ||
152 | - </action> | ||
153 | - </pluginExecution> | ||
154 | - </pluginExecutions> | ||
155 | - </lifecycleMappingMetadata> | ||
156 | - </configuration> | ||
157 | - </plugin> | ||
158 | - </plugins> | ||
159 | - </pluginManagement> | ||
160 | - --> | ||
161 | </build> | 108 | </build> |
162 | 109 | ||
163 | <dependencies> | 110 | <dependencies> |
@@ -196,7 +143,7 @@ | @@ -196,7 +143,7 @@ | ||
196 | <dependency> | 143 | <dependency> |
197 | <groupId>org.jboss.arquillian.container</groupId> | 144 | <groupId>org.jboss.arquillian.container</groupId> |
198 | <artifactId>arquillian-weld-se-embedded-1.1</artifactId> | 145 | <artifactId>arquillian-weld-se-embedded-1.1</artifactId> |
199 | - <version>${arquillian.weld.version}</version> | 146 | +<!-- <version>1.0.0.CR7</version> --> |
200 | <scope>test</scope> | 147 | <scope>test</scope> |
201 | </dependency> | 148 | </dependency> |
202 | <dependency> | 149 | <dependency> |
@@ -214,40 +161,6 @@ | @@ -214,40 +161,6 @@ | ||
214 | <artifactId>slf4j-log4j12</artifactId> | 161 | <artifactId>slf4j-log4j12</artifactId> |
215 | <scope>test</scope> | 162 | <scope>test</scope> |
216 | </dependency> | 163 | </dependency> |
217 | - | ||
218 | - <!-- | ||
219 | - <dependency> | ||
220 | - <groupId>javax.servlet</groupId> | ||
221 | - <artifactId>servlet-api</artifactId> | ||
222 | - <scope>test</scope> | ||
223 | - </dependency> | ||
224 | - | ||
225 | - <dependency> | ||
226 | - <groupId>org.jboss.arquillian.extension</groupId> | ||
227 | - <artifactId>arquillian-jacoco</artifactId> | ||
228 | - <version>1.0.0.Alpha5</version> | ||
229 | - <scope>test</scope> | ||
230 | - </dependency> | ||
231 | - <dependency> | ||
232 | - <groupId>org.jacoco</groupId> | ||
233 | - <artifactId>org.jacoco.core</artifactId> | ||
234 | - <version>${jacoco.version}</version> | ||
235 | - <scope>test</scope> | ||
236 | - </dependency> | ||
237 | - | ||
238 | - <dependency> | ||
239 | - <groupId>org.jboss.shrinkwrap.descriptors</groupId> | ||
240 | - <artifactId>shrinkwrap-descriptors-spi</artifactId> | ||
241 | - <version>2.0.0-alpha-4</version> | ||
242 | - <scope>test</scope> | ||
243 | - </dependency> | ||
244 | - | ||
245 | - <dependency> | ||
246 | - <groupId>javax.el</groupId> | ||
247 | - <artifactId>el-api</artifactId> | ||
248 | - <scope>test</scope> | ||
249 | - </dependency> | ||
250 | - --> | ||
251 | </dependencies> | 164 | </dependencies> |
252 | 165 | ||
253 | <repositories> | 166 | <repositories> |
@@ -276,10 +189,7 @@ | @@ -276,10 +189,7 @@ | ||
276 | </repositories> | 189 | </repositories> |
277 | 190 | ||
278 | <properties> | 191 | <properties> |
279 | - <arquillian.bom.version>1.1.1.Final</arquillian.bom.version> | ||
280 | - <arquillian.weld.version>1.0.0.CR7</arquillian.weld.version> | ||
281 | - | ||
282 | - <!-- <jacoco.version>0.6.0.201210061924</jacoco.version> --> | ||
283 | <demoiselle.validation.version>2.4.0-BETA2-SNAPSHOT</demoiselle.validation.version> | 192 | <demoiselle.validation.version>2.4.0-BETA2-SNAPSHOT</demoiselle.validation.version> |
193 | + <arquillian.bom.version>1.1.1.Final</arquillian.bom.version> | ||
284 | </properties> | 194 | </properties> |
285 | </project> | 195 | </project> |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
@@ -130,22 +130,22 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | @@ -130,22 +130,22 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | ||
130 | ViewContext tempViewContext = Beans.getReference(ViewContext.class); | 130 | ViewContext tempViewContext = Beans.getReference(ViewContext.class); |
131 | ConversationContext tempConversationContext = Beans.getReference(ConversationContext.class); | 131 | ConversationContext tempConversationContext = Beans.getReference(ConversationContext.class); |
132 | 132 | ||
133 | - boolean requestActivatedHere = !tempRequestContext.isActive(); | ||
134 | - boolean sessionActivatedHere = !tempSessionContext.isActive(); | ||
135 | - boolean viewActivatedHere = !tempViewContext.isActive(); | ||
136 | - boolean conversationActivatedHere = !tempConversationContext.isActive(); | 133 | + boolean requestActivatedHere = tempRequestContext!=null && !tempRequestContext.isActive(); |
134 | + boolean sessionActivatedHere = tempSessionContext!=null && !tempSessionContext.isActive(); | ||
135 | + boolean viewActivatedHere = tempViewContext!=null && !tempViewContext.isActive(); | ||
136 | + boolean conversationActivatedHere = tempConversationContext!=null && !tempConversationContext.isActive(); | ||
137 | 137 | ||
138 | if (!registered) { | 138 | if (!registered) { |
139 | - if (!tempRequestContext.isActive()) | 139 | + if (tempRequestContext!=null && !tempRequestContext.isActive()) |
140 | tempRequestContext.activate(); | 140 | tempRequestContext.activate(); |
141 | 141 | ||
142 | - if (!tempSessionContext.isActive()) | 142 | + if (tempSessionContext!=null && !tempSessionContext.isActive()) |
143 | tempSessionContext.activate(); | 143 | tempSessionContext.activate(); |
144 | 144 | ||
145 | - if (!tempViewContext.isActive()) | 145 | + if (tempViewContext!=null && !tempViewContext.isActive()) |
146 | tempViewContext.activate(); | 146 | tempViewContext.activate(); |
147 | 147 | ||
148 | - if (!tempConversationContext.isActive()) | 148 | + if (tempConversationContext!=null && !tempConversationContext.isActive()) |
149 | tempConversationContext.activate(); | 149 | tempConversationContext.activate(); |
150 | 150 | ||
151 | registered = true; | 151 | registered = true; |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CustomContextBootstrap.java
@@ -10,11 +10,13 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; | @@ -10,11 +10,13 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; | ||
10 | 10 | ||
11 | import br.gov.frameworkdemoiselle.context.CustomContext; | 11 | import br.gov.frameworkdemoiselle.context.CustomContext; |
12 | import br.gov.frameworkdemoiselle.context.StaticContext; | 12 | import br.gov.frameworkdemoiselle.context.StaticContext; |
13 | -import br.gov.frameworkdemoiselle.internal.context.TemporaryRequestContextImpl; | ||
14 | -import br.gov.frameworkdemoiselle.internal.context.TemporarySessionContextImpl; | 13 | +import br.gov.frameworkdemoiselle.internal.context.ContextualStore; |
15 | import br.gov.frameworkdemoiselle.internal.context.StaticContextImpl; | 14 | import br.gov.frameworkdemoiselle.internal.context.StaticContextImpl; |
16 | import br.gov.frameworkdemoiselle.internal.context.TemporaryConversationContextImpl; | 15 | import br.gov.frameworkdemoiselle.internal.context.TemporaryConversationContextImpl; |
16 | +import br.gov.frameworkdemoiselle.internal.context.TemporaryRequestContextImpl; | ||
17 | +import br.gov.frameworkdemoiselle.internal.context.TemporarySessionContextImpl; | ||
17 | import br.gov.frameworkdemoiselle.internal.context.TemporaryViewContextImpl; | 18 | import br.gov.frameworkdemoiselle.internal.context.TemporaryViewContextImpl; |
19 | +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | ||
18 | 20 | ||
19 | /** | 21 | /** |
20 | * This portable extension registers and starts custom contexts used by | 22 | * This portable extension registers and starts custom contexts used by |
@@ -27,6 +29,8 @@ public class CustomContextBootstrap implements Extension{ | @@ -27,6 +29,8 @@ public class CustomContextBootstrap implements Extension{ | ||
27 | 29 | ||
28 | private List<CustomContext> contexts; | 30 | private List<CustomContext> contexts; |
29 | 31 | ||
32 | + private final ContextualStore contextualStore = new ContextualStore(); | ||
33 | + | ||
30 | public <T extends CustomContext> void vetoCustomContexts(@Observes ProcessAnnotatedType<T> event){ | 34 | public <T extends CustomContext> void vetoCustomContexts(@Observes ProcessAnnotatedType<T> event){ |
31 | //Veta os subtipos de CustomContext, para que não conflitem com o produtor de contextos personalizados. | 35 | //Veta os subtipos de CustomContext, para que não conflitem com o produtor de contextos personalizados. |
32 | if( CustomContext.class.isAssignableFrom( event.getAnnotatedType().getJavaClass() )){ | 36 | if( CustomContext.class.isAssignableFrom( event.getAnnotatedType().getJavaClass() )){ |
@@ -71,13 +75,22 @@ public class CustomContextBootstrap implements Extension{ | @@ -71,13 +75,22 @@ public class CustomContextBootstrap implements Extension{ | ||
71 | } | 75 | } |
72 | } | 76 | } |
73 | 77 | ||
78 | + public void terminateContexts(@Observes AfterShutdownProccess event){ | ||
79 | + if (contexts!=null){ | ||
80 | + for (CustomContext context : contexts){ | ||
81 | + context.deactivate(); | ||
82 | + } | ||
83 | + | ||
84 | + contexts.clear(); | ||
85 | + contextualStore.clear(); | ||
86 | + } | ||
87 | + } | ||
88 | + | ||
74 | public List<CustomContext> getCustomContexts(){ | 89 | public List<CustomContext> getCustomContexts(){ |
75 | return this.contexts; | 90 | return this.contexts; |
76 | } | 91 | } |
77 | 92 | ||
78 | - /*public void storeContexts(@Observes AfterDeploymentValidation event){ | ||
79 | - CustomContextProducer producer = Beans.getReference(CustomContextProducer.class); | ||
80 | - producer.addRegisteredContexts(contexts); | ||
81 | - }*/ | ||
82 | - | 93 | + public ContextualStore getContextualStore(){ |
94 | + return this.contextualStore; | ||
95 | + } | ||
83 | } | 96 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java
@@ -37,10 +37,7 @@ | @@ -37,10 +37,7 @@ | ||
37 | package br.gov.frameworkdemoiselle.internal.context; | 37 | package br.gov.frameworkdemoiselle.internal.context; |
38 | 38 | ||
39 | import java.lang.annotation.Annotation; | 39 | import java.lang.annotation.Annotation; |
40 | -import java.util.Collections; | ||
41 | -import java.util.HashMap; | ||
42 | import java.util.Locale; | 40 | import java.util.Locale; |
43 | -import java.util.Map; | ||
44 | 41 | ||
45 | import javax.enterprise.context.ContextNotActiveException; | 42 | import javax.enterprise.context.ContextNotActiveException; |
46 | import javax.enterprise.context.spi.Context; | 43 | import javax.enterprise.context.spi.Context; |
@@ -51,7 +48,9 @@ import javax.enterprise.inject.spi.BeanManager; | @@ -51,7 +48,9 @@ import javax.enterprise.inject.spi.BeanManager; | ||
51 | 48 | ||
52 | import org.slf4j.Logger; | 49 | import org.slf4j.Logger; |
53 | 50 | ||
51 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
54 | import br.gov.frameworkdemoiselle.context.CustomContext; | 52 | import br.gov.frameworkdemoiselle.context.CustomContext; |
53 | +import br.gov.frameworkdemoiselle.internal.bootstrap.CustomContextBootstrap; | ||
55 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | 54 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
56 | import br.gov.frameworkdemoiselle.util.Beans; | 55 | import br.gov.frameworkdemoiselle.util.Beans; |
57 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 56 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
@@ -62,7 +61,7 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -62,7 +61,7 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
62 | 61 | ||
63 | private final Class<? extends Annotation> scope; | 62 | private final Class<? extends Annotation> scope; |
64 | 63 | ||
65 | - private Logger logger; | 64 | + private transient Logger logger; |
66 | 65 | ||
67 | private transient ResourceBundle bundle; | 66 | private transient ResourceBundle bundle; |
68 | 67 | ||
@@ -71,7 +70,7 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -71,7 +70,7 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
71 | this.active = false; | 70 | this.active = false; |
72 | } | 71 | } |
73 | 72 | ||
74 | - protected abstract Store getStore(); | 73 | + protected abstract BeanStore getStore(); |
75 | 74 | ||
76 | protected abstract boolean isStoreInitialized(); | 75 | protected abstract boolean isStoreInitialized(); |
77 | 76 | ||
@@ -89,23 +88,24 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -89,23 +88,24 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
89 | throw new ContextNotActiveException(); | 88 | throw new ContextNotActiveException(); |
90 | } | 89 | } |
91 | 90 | ||
92 | - Class<?> type = getType(contextual); | ||
93 | - if (getStore().contains(type)) { | ||
94 | - instance = (T) getStore().get(type); | ||
95 | - | ||
96 | - } else if (creationalContext != null) { | ||
97 | - instance = contextual.create(creationalContext); | ||
98 | - getStore().put(type, instance); | 91 | + String id = getContextualStore().putIfAbsentAndGetId(contextual); |
92 | + BeanStore store = getStore(); | ||
93 | + if (store!=null){ | ||
94 | + if (store.contains(id)) { | ||
95 | + instance = (T) store.getInstance(id); | ||
96 | + } | ||
97 | + else if (creationalContext!=null){ | ||
98 | + instance = contextual.create(creationalContext); | ||
99 | + store.put(id, instance,creationalContext); | ||
100 | + } | ||
101 | + } | ||
102 | + else{ | ||
103 | + throw new DemoiselleException(getBundle().getString("store-not-found" , ((Bean<?>)contextual).getBeanClass().getName() , getScope().getName())); | ||
99 | } | 104 | } |
100 | 105 | ||
101 | return instance; | 106 | return instance; |
102 | } | 107 | } |
103 | 108 | ||
104 | - private <T> Class<?> getType(final Contextual<T> contextual) { | ||
105 | - Bean<T> bean = (Bean<T>) contextual; | ||
106 | - return bean.getBeanClass(); | ||
107 | - } | ||
108 | - | ||
109 | @Override | 109 | @Override |
110 | public boolean isActive() { | 110 | public boolean isActive() { |
111 | return this.active; | 111 | return this.active; |
@@ -140,24 +140,47 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -140,24 +140,47 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
140 | public void deactivate(){ | 140 | public void deactivate(){ |
141 | if (this.active){ | 141 | if (this.active){ |
142 | if (isStoreInitialized()){ | 142 | if (isStoreInitialized()){ |
143 | + clearInstances(); | ||
144 | + | ||
143 | getStore().clear(); | 145 | getStore().clear(); |
146 | + getContextualStore().clear(); | ||
144 | } | 147 | } |
145 | - | 148 | + |
146 | this.active = false; | 149 | this.active = false; |
147 | - | 150 | + |
148 | Logger logger = getLogger(); | 151 | Logger logger = getLogger(); |
149 | ResourceBundle bundle = getBundle(); | 152 | ResourceBundle bundle = getBundle(); |
150 | logger.debug( bundle.getString("custom-context-was-deactivated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); | 153 | logger.debug( bundle.getString("custom-context-was-deactivated" , this.getClass().getCanonicalName() , this.getScope().getSimpleName() ) ); |
151 | } | 154 | } |
152 | } | 155 | } |
153 | - | 156 | + |
157 | + @SuppressWarnings({ "rawtypes", "unchecked" }) | ||
158 | + public void clearInstances(){ | ||
159 | + BeanStore store = getStore(); | ||
160 | + if (store!=null){ | ||
161 | + for (String id : store){ | ||
162 | + Contextual contextual = getContextualStore().getContextual(id); | ||
163 | + Object instance = store.getInstance(id); | ||
164 | + CreationalContext creationalContext = store.getCreationalContext(id); | ||
165 | + | ||
166 | + if (contextual!=null && instance!=null){ | ||
167 | + contextual.destroy(instance, creationalContext); | ||
168 | + } | ||
169 | + } | ||
170 | + } | ||
171 | + } | ||
172 | + | ||
154 | @Override | 173 | @Override |
155 | public Class<? extends Annotation> getScope() { | 174 | public Class<? extends Annotation> getScope() { |
156 | return this.scope; | 175 | return this.scope; |
157 | } | 176 | } |
158 | 177 | ||
159 | - protected static Store createStore() { | ||
160 | - return new Store(); | 178 | + protected static BeanStore createStore() { |
179 | + return new BeanStore(); | ||
180 | + } | ||
181 | + | ||
182 | + protected static ContextualStore createContextualStore() { | ||
183 | + return new ContextualStore(); | ||
161 | } | 184 | } |
162 | 185 | ||
163 | private ResourceBundle getBundle(){ | 186 | private ResourceBundle getBundle(){ |
@@ -176,6 +199,11 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -176,6 +199,11 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
176 | return logger; | 199 | return logger; |
177 | } | 200 | } |
178 | 201 | ||
202 | + ContextualStore getContextualStore(){ | ||
203 | + CustomContextBootstrap bootstrap = Beans.getReference(CustomContextBootstrap.class); | ||
204 | + return bootstrap.getContextualStore(); | ||
205 | + } | ||
206 | + | ||
179 | @Override | 207 | @Override |
180 | public boolean equals(Object obj) { | 208 | public boolean equals(Object obj) { |
181 | if (this == obj) | 209 | if (this == obj) |
@@ -192,39 +220,4 @@ public abstract class AbstractCustomContext implements CustomContext { | @@ -192,39 +220,4 @@ public abstract class AbstractCustomContext implements CustomContext { | ||
192 | return false; | 220 | return false; |
193 | return true; | 221 | return true; |
194 | } | 222 | } |
195 | - | ||
196 | - static class Store { | ||
197 | - | ||
198 | - private Map<ClassLoader, Map<Class<?>, Object>> cache = Collections | ||
199 | - .synchronizedMap(new HashMap<ClassLoader, Map<Class<?>, Object>>()); | ||
200 | - | ||
201 | - private Store() { | ||
202 | - } | ||
203 | - | ||
204 | - private boolean contains(final Class<?> type) { | ||
205 | - return this.getMap().containsKey(type); | ||
206 | - } | ||
207 | - | ||
208 | - private Object get(final Class<?> type) { | ||
209 | - return this.getMap().get(type); | ||
210 | - } | ||
211 | - | ||
212 | - private void put(final Class<?> type, final Object instance) { | ||
213 | - this.getMap().put(type, instance); | ||
214 | - } | ||
215 | - | ||
216 | - public void clear() { | ||
217 | - cache.clear(); | ||
218 | - } | ||
219 | - | ||
220 | - private Map<Class<?>, Object> getMap() { | ||
221 | - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
222 | - | ||
223 | - if (!cache.containsKey(classLoader)) { | ||
224 | - cache.put(classLoader, Collections.synchronizedMap(new HashMap<Class<?>, Object>())); | ||
225 | - } | ||
226 | - | ||
227 | - return cache.get(classLoader); | ||
228 | - } | ||
229 | - } | ||
230 | } | 223 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractStaticContext.java
@@ -37,6 +37,9 @@ | @@ -37,6 +37,9 @@ | ||
37 | package br.gov.frameworkdemoiselle.internal.context; | 37 | package br.gov.frameworkdemoiselle.internal.context; |
38 | 38 | ||
39 | import java.lang.annotation.Annotation; | 39 | import java.lang.annotation.Annotation; |
40 | +import java.util.Collections; | ||
41 | +import java.util.HashMap; | ||
42 | +import java.util.Map; | ||
40 | 43 | ||
41 | import br.gov.frameworkdemoiselle.annotation.Priority; | 44 | import br.gov.frameworkdemoiselle.annotation.Priority; |
42 | import br.gov.frameworkdemoiselle.annotation.StaticScoped; | 45 | import br.gov.frameworkdemoiselle.annotation.StaticScoped; |
@@ -58,7 +61,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration; | @@ -58,7 +61,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
58 | @Priority(Priority.MIN_PRIORITY) | 61 | @Priority(Priority.MIN_PRIORITY) |
59 | public abstract class AbstractStaticContext extends AbstractCustomContext { | 62 | public abstract class AbstractStaticContext extends AbstractCustomContext { |
60 | 63 | ||
61 | - private final static Store store = createStore(); | 64 | + private final static Map<String, BeanStore> staticBeanStore = Collections.synchronizedMap(new HashMap<String, BeanStore>()); |
62 | 65 | ||
63 | /** | 66 | /** |
64 | * Constructs this context to control the provided scope | 67 | * Constructs this context to control the provided scope |
@@ -68,12 +71,18 @@ public abstract class AbstractStaticContext extends AbstractCustomContext { | @@ -68,12 +71,18 @@ public abstract class AbstractStaticContext extends AbstractCustomContext { | ||
68 | } | 71 | } |
69 | 72 | ||
70 | @Override | 73 | @Override |
71 | - protected Store getStore() { | 74 | + protected BeanStore getStore() { |
75 | + BeanStore store = staticBeanStore.get( this.getClass().getCanonicalName() ); | ||
76 | + if (store==null){ | ||
77 | + store = createStore(); | ||
78 | + staticBeanStore.put(this.getClass().getCanonicalName(), store); | ||
79 | + } | ||
80 | + | ||
72 | return store; | 81 | return store; |
73 | } | 82 | } |
74 | - | 83 | + |
75 | @Override | 84 | @Override |
76 | protected boolean isStoreInitialized() { | 85 | protected boolean isStoreInitialized() { |
77 | - return store!=null; | 86 | + return staticBeanStore!=null; |
78 | } | 87 | } |
79 | } | 88 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractThreadLocalContext.java
@@ -59,23 +59,23 @@ import java.lang.annotation.Annotation; | @@ -59,23 +59,23 @@ import java.lang.annotation.Annotation; | ||
59 | */ | 59 | */ |
60 | public abstract class AbstractThreadLocalContext extends AbstractCustomContext { | 60 | public abstract class AbstractThreadLocalContext extends AbstractCustomContext { |
61 | 61 | ||
62 | - private final ThreadLocal<Store> threadLocal = new ThreadLocal<Store>(); | ||
63 | - | 62 | + private final ThreadLocal<BeanStore> threadLocalBeans = new ThreadLocal<BeanStore>(); |
63 | + | ||
64 | AbstractThreadLocalContext(final Class<? extends Annotation> scope) { | 64 | AbstractThreadLocalContext(final Class<? extends Annotation> scope) { |
65 | super(scope); | 65 | super(scope); |
66 | } | 66 | } |
67 | 67 | ||
68 | @Override | 68 | @Override |
69 | protected boolean isStoreInitialized() { | 69 | protected boolean isStoreInitialized() { |
70 | - return threadLocal.get()!=null; | 70 | + return threadLocalBeans.get()!=null; |
71 | } | 71 | } |
72 | 72 | ||
73 | @Override | 73 | @Override |
74 | - protected Store getStore() { | ||
75 | - if (this.threadLocal.get() == null) { | ||
76 | - this.threadLocal.set(createStore()); | 74 | + protected BeanStore getStore() { |
75 | + if (this.threadLocalBeans.get() == null) { | ||
76 | + this.threadLocalBeans.set(createStore()); | ||
77 | } | 77 | } |
78 | 78 | ||
79 | - return this.threadLocal.get(); | 79 | + return this.threadLocalBeans.get(); |
80 | } | 80 | } |
81 | } | 81 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/BeanStore.java
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.context; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.util.Iterator; | ||
5 | +import java.util.concurrent.ConcurrentHashMap; | ||
6 | +import java.util.concurrent.ConcurrentMap; | ||
7 | + | ||
8 | +import javax.enterprise.context.spi.CreationalContext; | ||
9 | + | ||
10 | +@SuppressWarnings("rawtypes") | ||
11 | +public class BeanStore implements Iterable<String>,Serializable { | ||
12 | + | ||
13 | + private static final long serialVersionUID = 1L; | ||
14 | + | ||
15 | + private ConcurrentMap<String, Object> instanceCache = new ConcurrentHashMap<String, Object>(); | ||
16 | + private ConcurrentMap<String, CreationalContext> creationalCache = new ConcurrentHashMap<String, CreationalContext>(); | ||
17 | + | ||
18 | + public <T> void put(String id, T instance,CreationalContext<T> creationalContext){ | ||
19 | + instanceCache.putIfAbsent(id, instance); | ||
20 | + creationalCache.putIfAbsent(id, creationalContext); | ||
21 | + } | ||
22 | + | ||
23 | + public Object getInstance(String id){ | ||
24 | + return instanceCache.get(id); | ||
25 | + } | ||
26 | + | ||
27 | + public CreationalContext getCreationalContext(String id){ | ||
28 | + return creationalCache.get(id); | ||
29 | + } | ||
30 | + | ||
31 | + public void clear(){ | ||
32 | + instanceCache.clear(); | ||
33 | + creationalCache.clear(); | ||
34 | + } | ||
35 | + | ||
36 | + public boolean contains(String id){ | ||
37 | + return instanceCache.containsKey(id); | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + public Iterator<String> iterator() { | ||
42 | + return instanceCache.keySet().iterator(); | ||
43 | + } | ||
44 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextualStore.java
0 → 100644
@@ -0,0 +1,90 @@ | @@ -0,0 +1,90 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.context; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.util.concurrent.ConcurrentHashMap; | ||
5 | +import java.util.concurrent.ConcurrentMap; | ||
6 | +import java.util.concurrent.atomic.AtomicInteger; | ||
7 | + | ||
8 | +import javax.enterprise.context.spi.Contextual; | ||
9 | +import javax.enterprise.inject.spi.PassivationCapable; | ||
10 | + | ||
11 | + | ||
12 | +@SuppressWarnings("rawtypes") | ||
13 | +public class ContextualStore implements Serializable { | ||
14 | + | ||
15 | + private static final long serialVersionUID = 1L; | ||
16 | + | ||
17 | + private static final String PREFIX = ContextualStore.class.getCanonicalName() + "#"; | ||
18 | + | ||
19 | + private final AtomicInteger idGenerator = new AtomicInteger(); | ||
20 | + | ||
21 | + /* | ||
22 | + * BASEADO NA IMPLEMENTAÇÃO DE CDI DO WELD | ||
23 | + * | ||
24 | + * Contextuals (instâncias de Bean) implementam a interface PassivationCapable quando são capazes | ||
25 | + * de participar em um cluster de servidores, dessa forma o mesmo Bean pode ser usado para criar instâncias | ||
26 | + * em todos os servidores e o ciclo de vida é síncrono | ||
27 | + * | ||
28 | + * Se o contextual não implementar PassivationCapable esse suporte não é possível. Por isso o WELD armazena | ||
29 | + * separadamente contextuals que implementam PassivationCapable e que não implementam. | ||
30 | + * | ||
31 | + * A implementação abaixo foi baseada nesse comportamento, afim de evitar problemas em aplicações empacotadas em EAR | ||
32 | + * e servidores de aplicação em cluster. | ||
33 | + * | ||
34 | + */ | ||
35 | + private final ConcurrentMap<String, Contextual> idToContextual = new ConcurrentHashMap<String, Contextual>(); | ||
36 | + private final ConcurrentMap<Contextual, String> contextualToId = new ConcurrentHashMap<Contextual, String>(); | ||
37 | + private final ConcurrentMap<String, Contextual> passivableIdToContextual = new ConcurrentHashMap<String, Contextual>(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Return an unique ID for the given contextual. If it's the first time | ||
41 | + * this contextual is accessed, registers the contextual for latter retrieval. | ||
42 | + * | ||
43 | + * @param contextual The contextual to generate an ID | ||
44 | + * @return The unique ID for the contextual | ||
45 | + */ | ||
46 | + public String putIfAbsentAndGetId(Contextual contextual){ | ||
47 | + String returnedId; | ||
48 | + | ||
49 | + if (contextual instanceof PassivationCapable){ | ||
50 | + returnedId = ((PassivationCapable)contextual).getId(); | ||
51 | + passivableIdToContextual.putIfAbsent(returnedId, contextual); | ||
52 | + } | ||
53 | + else{ | ||
54 | + returnedId = contextualToId.get(contextual); | ||
55 | + if (returnedId==null){ | ||
56 | + synchronized (contextual) { | ||
57 | + //Esse código é uma implementação de performance. Se já existia | ||
58 | + //ID para um contextual, retornamos. Do contrário precisamos fazer uma operação threadsafe | ||
59 | + //que será cara. Então separamos a possibilide do ID já existir (a mais comum) fora do bloco | ||
60 | + //synchronized, mas se precisarmos entrar no bloco precisamos perguntar pelo ID | ||
61 | + //novamente, caso outra thread tenha criado o ID entre a primeira pergunta e a geração do ID. | ||
62 | + returnedId = contextualToId.get(contextual); | ||
63 | + if (returnedId==null){ | ||
64 | + returnedId = new StringBuffer().append(PREFIX).append(idGenerator.incrementAndGet()).toString(); | ||
65 | + idToContextual.put(returnedId, contextual); | ||
66 | + contextualToId.put(contextual, returnedId); | ||
67 | + } | ||
68 | + } | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | + return returnedId; | ||
73 | + } | ||
74 | + | ||
75 | + public Contextual getContextual(String id){ | ||
76 | + if (id.startsWith(PREFIX)){ | ||
77 | + return idToContextual.get(id); | ||
78 | + } | ||
79 | + else{ | ||
80 | + return passivableIdToContextual.get(id); | ||
81 | + } | ||
82 | + } | ||
83 | + | ||
84 | + public void clear(){ | ||
85 | + idToContextual.clear(); | ||
86 | + contextualToId.clear(); | ||
87 | + passivableIdToContextual.clear(); | ||
88 | + } | ||
89 | + | ||
90 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/CustomContextProducer.java
@@ -60,6 +60,7 @@ import javax.enterprise.inject.spi.InjectionPoint; | @@ -60,6 +60,7 @@ import javax.enterprise.inject.spi.InjectionPoint; | ||
60 | 60 | ||
61 | import org.slf4j.Logger; | 61 | import org.slf4j.Logger; |
62 | 62 | ||
63 | +import br.gov.frameworkdemoiselle.annotation.Priority; | ||
63 | import br.gov.frameworkdemoiselle.context.ConversationContext; | 64 | import br.gov.frameworkdemoiselle.context.ConversationContext; |
64 | import br.gov.frameworkdemoiselle.context.CustomContext; | 65 | import br.gov.frameworkdemoiselle.context.CustomContext; |
65 | import br.gov.frameworkdemoiselle.context.RequestContext; | 66 | import br.gov.frameworkdemoiselle.context.RequestContext; |
@@ -133,7 +134,7 @@ public class CustomContextProducer { | @@ -133,7 +134,7 @@ public class CustomContextProducer { | ||
133 | /////////////PRODUCERS/////////////////// | 134 | /////////////PRODUCERS/////////////////// |
134 | 135 | ||
135 | @Produces | 136 | @Produces |
136 | - public RequestContext getRequestContext(InjectionPoint ip){ | 137 | + protected RequestContext getRequestContext(InjectionPoint ip){ |
137 | if (ip!=null){ | 138 | if (ip!=null){ |
138 | return getContext(ip); | 139 | return getContext(ip); |
139 | } | 140 | } |
@@ -143,7 +144,7 @@ public class CustomContextProducer { | @@ -143,7 +144,7 @@ public class CustomContextProducer { | ||
143 | } | 144 | } |
144 | 145 | ||
145 | @Produces | 146 | @Produces |
146 | - public SessionContext getSessionContext(InjectionPoint ip){ | 147 | + protected SessionContext getSessionContext(InjectionPoint ip){ |
147 | if (ip!=null){ | 148 | if (ip!=null){ |
148 | return getContext(ip); | 149 | return getContext(ip); |
149 | } | 150 | } |
@@ -153,7 +154,7 @@ public class CustomContextProducer { | @@ -153,7 +154,7 @@ public class CustomContextProducer { | ||
153 | } | 154 | } |
154 | 155 | ||
155 | @Produces | 156 | @Produces |
156 | - public ViewContext getViewContext(InjectionPoint ip){ | 157 | + protected ViewContext getViewContext(InjectionPoint ip){ |
157 | if (ip!=null){ | 158 | if (ip!=null){ |
158 | return getContext(ip); | 159 | return getContext(ip); |
159 | } | 160 | } |
@@ -163,7 +164,7 @@ public class CustomContextProducer { | @@ -163,7 +164,7 @@ public class CustomContextProducer { | ||
163 | } | 164 | } |
164 | 165 | ||
165 | @Produces | 166 | @Produces |
166 | - public StaticContext getStaticContext(InjectionPoint ip){ | 167 | + protected StaticContext getStaticContext(InjectionPoint ip){ |
167 | if (ip!=null){ | 168 | if (ip!=null){ |
168 | return getContext(ip); | 169 | return getContext(ip); |
169 | } | 170 | } |
@@ -173,7 +174,7 @@ public class CustomContextProducer { | @@ -173,7 +174,7 @@ public class CustomContextProducer { | ||
173 | } | 174 | } |
174 | 175 | ||
175 | @Produces | 176 | @Produces |
176 | - public ConversationContext getConversationContext(InjectionPoint ip){ | 177 | + protected ConversationContext getConversationContext(InjectionPoint ip){ |
177 | if (ip!=null){ | 178 | if (ip!=null){ |
178 | return getContext(ip); | 179 | return getContext(ip); |
179 | } | 180 | } |
@@ -184,8 +185,17 @@ public class CustomContextProducer { | @@ -184,8 +185,17 @@ public class CustomContextProducer { | ||
184 | 185 | ||
185 | /////////////END OF PRODUCERS/////////////////// | 186 | /////////////END OF PRODUCERS/////////////////// |
186 | 187 | ||
188 | + /** | ||
189 | + * Obtain a custom context for the provided injection point. | ||
190 | + * | ||
191 | + * @param ip The object containing information about the injection point - most importantly | ||
192 | + * the declared type of the injection point, to decide the context to return | ||
193 | + * | ||
194 | + * @return A context of a type compatible with the type of the injection point, or <code>null</code> if there is | ||
195 | + * no such context. | ||
196 | + */ | ||
187 | @SuppressWarnings("unchecked") | 197 | @SuppressWarnings("unchecked") |
188 | - private <T extends CustomContext> T getContext(InjectionPoint ip){ | 198 | + public <T extends CustomContext> T getContext(InjectionPoint ip){ |
189 | T producedContext = null; | 199 | T producedContext = null; |
190 | 200 | ||
191 | if (ip!=null){ | 201 | if (ip!=null){ |
@@ -200,8 +210,16 @@ public class CustomContextProducer { | @@ -200,8 +210,16 @@ public class CustomContextProducer { | ||
200 | return producedContext; | 210 | return producedContext; |
201 | } | 211 | } |
202 | 212 | ||
213 | + /** | ||
214 | + * Obtain a context compatible with the provided type. | ||
215 | + * | ||
216 | + * @param contextClass The type of the desired context. The returned context will be compatible with this type, if there | ||
217 | + * is more than one compatible type, this method will decide witch one to return based on the {@link Priority} annotation. | ||
218 | + * | ||
219 | + * @return A context of a type compatible with the informed type, or <code>null</code> if there is no such context. | ||
220 | + */ | ||
203 | @SuppressWarnings("unchecked") | 221 | @SuppressWarnings("unchecked") |
204 | - private <T extends CustomContext> T getContext(Class<T> contextClass){ | 222 | + public <T extends CustomContext> T getContext(Class<T> contextClass){ |
205 | CustomContext producedContext = null; | 223 | CustomContext producedContext = null; |
206 | 224 | ||
207 | ArrayList<CustomContext> selectableContexts = new ArrayList<CustomContext>(); | 225 | ArrayList<CustomContext> selectableContexts = new ArrayList<CustomContext>(); |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationEnumValueExtractor.java
@@ -36,6 +36,9 @@ | @@ -36,6 +36,9 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
38 | 38 | ||
39 | +import static br.gov.frameworkdemoiselle.annotation.Priority.L2_PRIORITY; | ||
40 | + | ||
41 | + | ||
39 | import java.lang.reflect.Field; | 42 | import java.lang.reflect.Field; |
40 | import java.util.Locale; | 43 | import java.util.Locale; |
41 | 44 | ||
@@ -46,7 +49,7 @@ import br.gov.frameworkdemoiselle.annotation.Priority; | @@ -46,7 +49,7 @@ import br.gov.frameworkdemoiselle.annotation.Priority; | ||
46 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | 49 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
47 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 50 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
48 | 51 | ||
49 | -@Priority(Priority.L2_PRIORITY) | 52 | +@Priority(L2_PRIORITY) |
50 | public class ConfigurationEnumValueExtractor implements ConfigurationValueExtractor{ | 53 | public class ConfigurationEnumValueExtractor implements ConfigurationValueExtractor{ |
51 | 54 | ||
52 | private transient ResourceBundle bundle; | 55 | private transient ResourceBundle bundle; |
@@ -55,16 +58,15 @@ public class ConfigurationEnumValueExtractor implements ConfigurationValueExtrac | @@ -55,16 +58,15 @@ public class ConfigurationEnumValueExtractor implements ConfigurationValueExtrac | ||
55 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | 58 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { |
56 | String value = configuration.getString(prefix + key); | 59 | String value = configuration.getString(prefix + key); |
57 | 60 | ||
58 | - if (value!=null){ | 61 | + if (value!=null && !value.trim().equals("")){ |
59 | Object enums[] = field.getType().getEnumConstants(); | 62 | Object enums[] = field.getType().getEnumConstants(); |
60 | 63 | ||
61 | for (int i=0; i<enums.length; i++){ | 64 | for (int i=0; i<enums.length; i++){ |
62 | - if ( ((Enum<?>)enums[i]).toString().equalsIgnoreCase(value) ){ | 65 | + if ( ((Enum<?>)enums[i]).name().equals(value) ){ |
63 | return enums[i]; | 66 | return enums[i]; |
64 | } | 67 | } |
65 | } | 68 | } |
66 | - } | ||
67 | - else{ | 69 | + }else{ |
68 | return null; | 70 | return null; |
69 | } | 71 | } |
70 | 72 |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationMapValueExtractor.java
@@ -50,12 +50,6 @@ import org.apache.commons.configuration.Configuration; | @@ -50,12 +50,6 @@ import org.apache.commons.configuration.Configuration; | ||
50 | import br.gov.frameworkdemoiselle.annotation.Priority; | 50 | import br.gov.frameworkdemoiselle.annotation.Priority; |
51 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | 51 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
52 | 52 | ||
53 | -/** | ||
54 | - * | ||
55 | - * TODO Adicionar verificação da existência de duas ou mais configurações JDBC com mesmo nome. Lançar INFO ou Exceção. | ||
56 | - * | ||
57 | - */ | ||
58 | - | ||
59 | @Priority(L2_PRIORITY) | 53 | @Priority(L2_PRIORITY) |
60 | public class ConfigurationMapValueExtractor implements ConfigurationValueExtractor { | 54 | public class ConfigurationMapValueExtractor implements ConfigurationValueExtractor { |
61 | 55 | ||
@@ -63,7 +57,7 @@ public class ConfigurationMapValueExtractor implements ConfigurationValueExtract | @@ -63,7 +57,7 @@ public class ConfigurationMapValueExtractor implements ConfigurationValueExtract | ||
63 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | 57 | public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { |
64 | Map<String, Object> value = null; | 58 | Map<String, Object> value = null; |
65 | 59 | ||
66 | - String regexp = "^(" + prefix + ")((.+)\\.)?(" + key + ")$"; | 60 | + String regexp = "^(" + prefix + ")(" + key + ")(\\.(\\w+))?$"; |
67 | Pattern pattern = Pattern.compile(regexp); | 61 | Pattern pattern = Pattern.compile(regexp); |
68 | 62 | ||
69 | for (Iterator<String> iter = configuration.getKeys(); iter.hasNext();) { | 63 | for (Iterator<String> iter = configuration.getKeys(); iter.hasNext();) { |
@@ -71,14 +65,16 @@ public class ConfigurationMapValueExtractor implements ConfigurationValueExtract | @@ -71,14 +65,16 @@ public class ConfigurationMapValueExtractor implements ConfigurationValueExtract | ||
71 | Matcher matcher = pattern.matcher(iterKey); | 65 | Matcher matcher = pattern.matcher(iterKey); |
72 | 66 | ||
73 | if (matcher.matches()) { | 67 | if (matcher.matches()) { |
74 | - String confKey = matcher.group(1) + (matcher.group(2) == null ? "" : matcher.group(2)) | ||
75 | - + matcher.group(4); | 68 | + String confKey = matcher.group(1) + matcher.group(2) + ( matcher.group(3)!=null ? matcher.group(3) : "" ); |
69 | + | ||
70 | + /*matcher.group(1) + (matcher.group(2) == null ? "" : matcher.group(2)) | ||
71 | + + matcher.group(4);*/ | ||
76 | 72 | ||
77 | if (value == null) { | 73 | if (value == null) { |
78 | value = new HashMap<String, Object>(); | 74 | value = new HashMap<String, Object>(); |
79 | } | 75 | } |
80 | 76 | ||
81 | - String mapKey = matcher.group(3) == null ? "default" : matcher.group(3); | 77 | + String mapKey = matcher.group(4) == null ? "default" : matcher.group(4); |
82 | value.put(mapKey, configuration.getString(confKey)); | 78 | value.put(mapKey, configuration.getString(confKey)); |
83 | } | 79 | } |
84 | } | 80 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/NotLoggedInException.java
@@ -44,7 +44,7 @@ package br.gov.frameworkdemoiselle.security; | @@ -44,7 +44,7 @@ package br.gov.frameworkdemoiselle.security; | ||
44 | public class NotLoggedInException extends AuthenticationException { | 44 | public class NotLoggedInException extends AuthenticationException { |
45 | 45 | ||
46 | private static final long serialVersionUID = 1L; | 46 | private static final long serialVersionUID = 1L; |
47 | - | 47 | + |
48 | /** | 48 | /** |
49 | * Constructs an <code>NotLoggedInException</code> with a message. | 49 | * Constructs an <code>NotLoggedInException</code> with a message. |
50 | */ | 50 | */ |
impl/core/src/main/resources/demoiselle-core-bundle.properties
@@ -39,6 +39,7 @@ key-not-found=A chave {0} n\u00E3o foi encontrada | @@ -39,6 +39,7 @@ key-not-found=A chave {0} n\u00E3o foi encontrada | ||
39 | ambiguous-strategy-resolution=Foi detectada ambiguidade da interface {0} com as seguintes implementa\u00E7\u00F5es\: {1}. Para resolver o conflito, defina explicitamente a implementa\u00E7\u00E3o no demoiselle.properties. | 39 | ambiguous-strategy-resolution=Foi detectada ambiguidade da interface {0} com as seguintes implementa\u00E7\u00F5es\: {1}. Para resolver o conflito, defina explicitamente a implementa\u00E7\u00E3o no demoiselle.properties. |
40 | ambiguous-bean-resolution=Falha ao obter {0} pois foi detectada ambiguidade nas seguintes implementa\u00E7\u00F5es\: {1} | 40 | ambiguous-bean-resolution=Falha ao obter {0} pois foi detectada ambiguidade nas seguintes implementa\u00E7\u00F5es\: {1} |
41 | bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference({0}) | 41 | bean-not-found=Voc\u00EA est\u00E1 tentando obter um objeto n\u00E3o reconhecido pelo CDI via Beans.getReference({0}) |
42 | +store-not-found=O objeto do tipo [{0}] n\u00E3o pode ser armazenado no escopo indicado\: {1} | ||
42 | more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1} | 43 | more-than-one-exceptionhandler-defined-for-same-class=Foi definido mais de um m\u00E9todo na classe {0} para tratar a exce\u00E7\u00E3o {1} |
43 | handling-exception=Tratando a exce\u00E7\u00E3o {0} | 44 | handling-exception=Tratando a exce\u00E7\u00E3o {0} |
44 | taking-off=O Demoiselle ${project.version} decolou | 45 | taking-off=O Demoiselle ${project.version} decolou |
impl/core/src/test/java/configuration/field/enumeration/AbstractEnumValueConfig.java
0 → 100644
@@ -0,0 +1,62 @@ | @@ -0,0 +1,62 @@ | ||
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 configuration.field.enumeration; | ||
38 | + | ||
39 | +import java.io.Serializable; | ||
40 | + | ||
41 | +public abstract class AbstractEnumValueConfig implements Serializable { | ||
42 | + | ||
43 | + private static final long serialVersionUID = 1L; | ||
44 | + | ||
45 | + private ListOfEnum enumValue; | ||
46 | + | ||
47 | + private ListOfEnum anotherValue; | ||
48 | + | ||
49 | + private ListOfEnum emptyValue; | ||
50 | + | ||
51 | + public ListOfEnum getEnumValue() { | ||
52 | + return enumValue; | ||
53 | + } | ||
54 | + | ||
55 | + public ListOfEnum getAnotherValue() { | ||
56 | + return anotherValue; | ||
57 | + } | ||
58 | + | ||
59 | + public ListOfEnum getEmptyValue() { | ||
60 | + return emptyValue; | ||
61 | + } | ||
62 | +} |
impl/core/src/test/java/configuration/field/enumeration/ConfigurationEnumValueTest.java
0 → 100644
@@ -0,0 +1,84 @@ | @@ -0,0 +1,84 @@ | ||
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 configuration.field.enumeration; | ||
38 | + | ||
39 | +import javax.inject.Inject; | ||
40 | + | ||
41 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
42 | +import org.jboss.arquillian.junit.Arquillian; | ||
43 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
44 | +import org.junit.Assert; | ||
45 | +import org.junit.Test; | ||
46 | +import org.junit.runner.RunWith; | ||
47 | + | ||
48 | +import test.Tests; | ||
49 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | ||
50 | + | ||
51 | +@RunWith(Arquillian.class) | ||
52 | +public class ConfigurationEnumValueTest { | ||
53 | + | ||
54 | + private static final String PATH = "src/test/resources/configuration/field/enumeration"; | ||
55 | + | ||
56 | + @Inject | ||
57 | + private PropertiesEnumConfig propertiesEnumConfig; | ||
58 | + | ||
59 | + @Inject | ||
60 | + private XmlEnumConfig xmlEnumConfig; | ||
61 | + | ||
62 | + @Inject | ||
63 | + private WrongPropertyEnumConfig wrongPropertyEnumConfig; | ||
64 | + | ||
65 | + @Deployment | ||
66 | + public static JavaArchive createDeployment() { | ||
67 | + JavaArchive deployment = Tests.createDeployment(ConfigurationEnumValueTest.class); | ||
68 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
69 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.xml"), "demoiselle.xml"); | ||
70 | + return deployment; | ||
71 | + } | ||
72 | + | ||
73 | + @Test | ||
74 | + public void loadEnumConfig(){ | ||
75 | + Assert.assertEquals(ListOfEnum.VALUE_2, propertiesEnumConfig.getEnumValue()); | ||
76 | + Assert.assertEquals(ListOfEnum.VALUE_2, xmlEnumConfig.getEnumValue()); | ||
77 | + Assert.assertNull(propertiesEnumConfig.getEmptyValue()); | ||
78 | + } | ||
79 | + | ||
80 | + @Test(expected=ConfigurationException.class) | ||
81 | + public void checkConverstionException(){ | ||
82 | + wrongPropertyEnumConfig.getAnotherValue(); | ||
83 | + } | ||
84 | +} |
impl/core/src/test/java/configuration/field/enumeration/ListOfEnum.java
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
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 configuration.field.enumeration; | ||
38 | + | ||
39 | + | ||
40 | +public enum ListOfEnum { | ||
41 | + | ||
42 | + VALUE_1 , VALUE_2 , VALUE_3; | ||
43 | + | ||
44 | +} |
impl/core/src/test/java/configuration/field/enumeration/PropertiesEnumConfig.java
0 → 100644
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
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 configuration.field.enumeration; | ||
38 | + | ||
39 | +import br.gov.frameworkdemoiselle.configuration.ConfigType; | ||
40 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
41 | + | ||
42 | +@Configuration(resource="demoiselle" , type=ConfigType.PROPERTIES , prefix="prefix1") | ||
43 | +public class PropertiesEnumConfig extends AbstractEnumValueConfig { | ||
44 | + | ||
45 | + private static final long serialVersionUID = 1L; | ||
46 | + | ||
47 | +} |
impl/core/src/test/java/configuration/field/enumeration/WrongPropertyEnumConfig.java
0 → 100644
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
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 configuration.field.enumeration; | ||
38 | + | ||
39 | +import br.gov.frameworkdemoiselle.configuration.ConfigType; | ||
40 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
41 | + | ||
42 | +@Configuration(resource="demoiselle" , type=ConfigType.PROPERTIES , prefix="prefix2") | ||
43 | +public class WrongPropertyEnumConfig extends AbstractEnumValueConfig { | ||
44 | + | ||
45 | + private static final long serialVersionUID = 1L; | ||
46 | + | ||
47 | +} |
impl/core/src/test/java/configuration/field/enumeration/XmlEnumConfig.java
0 → 100644
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
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 configuration.field.enumeration; | ||
38 | + | ||
39 | +import br.gov.frameworkdemoiselle.configuration.ConfigType; | ||
40 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
41 | + | ||
42 | +@Configuration(resource="demoiselle" , type=ConfigType.XML , prefix="prefix1") | ||
43 | +public class XmlEnumConfig extends AbstractEnumValueConfig { | ||
44 | + | ||
45 | + private static final long serialVersionUID = 1L; | ||
46 | + | ||
47 | +} |
impl/core/src/test/java/configuration/field/map/PropertiesMapFieldConfig.java
@@ -39,6 +39,6 @@ package configuration.field.map; | @@ -39,6 +39,6 @@ package configuration.field.map; | ||
39 | import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; | 39 | import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; |
40 | import br.gov.frameworkdemoiselle.configuration.Configuration; | 40 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
41 | 41 | ||
42 | -@Configuration(type = PROPERTIES) | 42 | +@Configuration(type = PROPERTIES,prefix="configuration.test") |
43 | public class PropertiesMapFieldConfig extends AbstractMapFieldConfig { | 43 | public class PropertiesMapFieldConfig extends AbstractMapFieldConfig { |
44 | } | 44 | } |
impl/core/src/test/java/context/staticcontext/ConversationBean.java
0 → 100644
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +package context.staticcontext; | ||
2 | + | ||
3 | +import javax.enterprise.context.ConversationScoped; | ||
4 | +import java.io.Serializable; | ||
5 | + | ||
6 | +@ConversationScoped | ||
7 | +public class ConversationBean implements Serializable { | ||
8 | + | ||
9 | + private static final long serialVersionUID = 1L; | ||
10 | + | ||
11 | + private String data = "test"; | ||
12 | + | ||
13 | + | ||
14 | + public String getData() { | ||
15 | + return data; | ||
16 | + } | ||
17 | + | ||
18 | + | ||
19 | + public void setData(String data) { | ||
20 | + this.data = data; | ||
21 | + } | ||
22 | + | ||
23 | + | ||
24 | + | ||
25 | +} |
impl/core/src/test/java/context/staticcontext/SessionBean.java
0 → 100644
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +package context.staticcontext; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | + | ||
5 | +import javax.enterprise.context.SessionScoped; | ||
6 | + | ||
7 | +@SessionScoped | ||
8 | +public class SessionBean implements Serializable{ | ||
9 | + | ||
10 | + private static final long serialVersionUID = 1L; | ||
11 | + | ||
12 | + private String data = "test"; | ||
13 | + | ||
14 | + | ||
15 | + public String getData() { | ||
16 | + return data; | ||
17 | + } | ||
18 | + | ||
19 | + | ||
20 | + public void setData(String data) { | ||
21 | + this.data = data; | ||
22 | + } | ||
23 | + | ||
24 | + | ||
25 | + | ||
26 | +} |
impl/core/src/test/java/context/staticcontext/StaticContextTest.java
0 → 100644
@@ -0,0 +1,88 @@ | @@ -0,0 +1,88 @@ | ||
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 context.staticcontext; | ||
38 | + | ||
39 | +import javax.enterprise.inject.spi.Bean; | ||
40 | + | ||
41 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
42 | +import org.jboss.arquillian.junit.Arquillian; | ||
43 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
44 | +import org.junit.Assert; | ||
45 | +import org.junit.Test; | ||
46 | +import org.junit.runner.RunWith; | ||
47 | + | ||
48 | +import br.gov.frameworkdemoiselle.context.ConversationContext; | ||
49 | +import br.gov.frameworkdemoiselle.context.SessionContext; | ||
50 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
51 | +import test.Tests; | ||
52 | + | ||
53 | +@RunWith(Arquillian.class) | ||
54 | +public class StaticContextTest { | ||
55 | + | ||
56 | + @Deployment | ||
57 | + public static JavaArchive createDeployment() { | ||
58 | + JavaArchive deployment = Tests.createDeployment(StaticContextTest.class); | ||
59 | + return deployment; | ||
60 | + } | ||
61 | + | ||
62 | + @Test | ||
63 | + public void checkSeparatedStores(){ | ||
64 | + | ||
65 | + ConversationContext conversationContext = Beans.getReference(ConversationContext.class); | ||
66 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | ||
67 | + | ||
68 | + conversationContext.activate(); | ||
69 | + sessionContext.activate(); | ||
70 | + | ||
71 | + ConversationBean conversationBean = Beans.getReference(ConversationBean.class); | ||
72 | + conversationBean.getData(); | ||
73 | + | ||
74 | + SessionBean sessionBean = Beans.getReference(SessionBean.class); | ||
75 | + sessionBean.getData(); | ||
76 | + | ||
77 | + Bean<?> conversationContextual = Beans.getBeanManager().getBeans(ConversationBean.class).iterator().next(); | ||
78 | + Bean<?> sessionContextual = Beans.getBeanManager().getBeans(SessionBean.class).iterator().next(); | ||
79 | + | ||
80 | + Assert.assertNotNull( conversationContext.get(conversationContextual) ); | ||
81 | + Assert.assertNull( conversationContext.get(sessionContextual) ); | ||
82 | + | ||
83 | + Assert.assertNotNull( sessionContext.get(sessionContextual) ); | ||
84 | + Assert.assertNull( sessionContext.get(conversationContextual) ); | ||
85 | + | ||
86 | + } | ||
87 | + | ||
88 | +} |
impl/core/src/test/java/security/authorization/custom/CustomAuthorizer.java
@@ -51,7 +51,4 @@ public class CustomAuthorizer implements Authorizer { | @@ -51,7 +51,4 @@ public class CustomAuthorizer implements Authorizer { | ||
51 | public boolean hasPermission(String resource, String operation) { | 51 | public boolean hasPermission(String resource, String operation) { |
52 | return "resource".equals(resource) && "operation".equals(operation); | 52 | return "resource".equals(resource) && "operation".equals(operation); |
53 | } | 53 | } |
54 | - | ||
55 | - | ||
56 | - | ||
57 | } | 54 | } |
impl/core/src/test/java/security/authorization/custom/CustomAuthorizerTest.java
@@ -36,9 +36,10 @@ | @@ -36,9 +36,10 @@ | ||
36 | */ | 36 | */ |
37 | package security.authorization.custom; | 37 | package security.authorization.custom; |
38 | 38 | ||
39 | -import javax.inject.Inject; | 39 | +import static junit.framework.Assert.assertFalse; |
40 | +import static junit.framework.Assert.assertTrue; | ||
40 | 41 | ||
41 | -import junit.framework.Assert; | 42 | +import javax.inject.Inject; |
42 | 43 | ||
43 | import org.jboss.arquillian.container.test.api.Deployment; | 44 | import org.jboss.arquillian.container.test.api.Deployment; |
44 | import org.jboss.arquillian.junit.Arquillian; | 45 | import org.jboss.arquillian.junit.Arquillian; |
@@ -66,44 +67,43 @@ public class CustomAuthorizerTest { | @@ -66,44 +67,43 @@ public class CustomAuthorizerTest { | ||
66 | deployment.addClass(CustomAuthorizer.class); | 67 | deployment.addClass(CustomAuthorizer.class); |
67 | return deployment; | 68 | return deployment; |
68 | } | 69 | } |
69 | - | 70 | + |
70 | @Before | 71 | @Before |
71 | - public void loginToTest(){ | 72 | + public void loginToTest() { |
72 | context.login(); | 73 | context.login(); |
73 | } | 74 | } |
74 | 75 | ||
75 | @Test | 76 | @Test |
76 | - public void hasPermission(){ | ||
77 | - Assert.assertTrue(context.hasPermission("resource", "operation")); | 77 | + public void hasPermission() { |
78 | + assertTrue(context.hasPermission("resource", "operation")); | ||
78 | } | 79 | } |
79 | - | 80 | + |
80 | @Test | 81 | @Test |
81 | - public void hasRole(){ | ||
82 | - Assert.assertTrue(context.hasRole("role")); | 82 | + public void hasRole() { |
83 | + assertTrue(context.hasRole("role")); | ||
83 | } | 84 | } |
84 | - | 85 | + |
85 | /** | 86 | /** |
86 | * Verify if when already exist an authorizer, the things keeps working fine. | 87 | * Verify if when already exist an authorizer, the things keeps working fine. |
87 | */ | 88 | */ |
88 | @Test | 89 | @Test |
89 | - public void hasPermitionAndHasRole(){ | ||
90 | - Assert.assertTrue(context.hasPermission("resource", "operation")); | ||
91 | - Assert.assertTrue(context.hasRole("role")); | 90 | + public void hasPermitionAndHasRole() { |
91 | + assertTrue(context.hasPermission("resource", "operation")); | ||
92 | + assertTrue(context.hasRole("role")); | ||
92 | } | 93 | } |
93 | - | 94 | + |
94 | @Test | 95 | @Test |
95 | - public void denyPermission(){ | ||
96 | - Assert.assertFalse(context.hasPermission("falseresource", "falseoperation")); | 96 | + public void denyPermission() { |
97 | + assertFalse(context.hasPermission("falseresource", "falseoperation")); | ||
97 | } | 98 | } |
98 | - | 99 | + |
99 | @Test | 100 | @Test |
100 | - public void denyRole(){ | ||
101 | - Assert.assertFalse(context.hasRole("falserole")); | 101 | + public void denyRole() { |
102 | + assertFalse(context.hasRole("falserole")); | ||
102 | } | 103 | } |
103 | - | 104 | + |
104 | @After | 105 | @After |
105 | - public void logoutAfterTest(){ | 106 | + public void logoutAfterTest() { |
106 | context.logout(); | 107 | context.logout(); |
107 | } | 108 | } |
108 | - | ||
109 | } | 109 | } |
impl/core/src/test/java/security/authorization/disable/DisabledAuthorizationTest.java
@@ -36,14 +36,13 @@ | @@ -36,14 +36,13 @@ | ||
36 | */ | 36 | */ |
37 | package security.authorization.disable; | 37 | package security.authorization.disable; |
38 | 38 | ||
39 | +import static junit.framework.Assert.assertTrue; | ||
39 | import static org.junit.Assert.assertNull; | 40 | import static org.junit.Assert.assertNull; |
40 | 41 | ||
41 | import javax.enterprise.context.RequestScoped; | 42 | import javax.enterprise.context.RequestScoped; |
42 | import javax.enterprise.event.Observes; | 43 | import javax.enterprise.event.Observes; |
43 | import javax.inject.Inject; | 44 | import javax.inject.Inject; |
44 | 45 | ||
45 | -import junit.framework.Assert; | ||
46 | - | ||
47 | import org.jboss.arquillian.container.test.api.Deployment; | 46 | import org.jboss.arquillian.container.test.api.Deployment; |
48 | import org.jboss.arquillian.junit.Arquillian; | 47 | import org.jboss.arquillian.junit.Arquillian; |
49 | import org.jboss.shrinkwrap.api.spec.JavaArchive; | 48 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
@@ -69,10 +68,8 @@ public class DisabledAuthorizationTest { | @@ -69,10 +68,8 @@ public class DisabledAuthorizationTest { | ||
69 | 68 | ||
70 | @Deployment | 69 | @Deployment |
71 | public static JavaArchive createDeployment() { | 70 | public static JavaArchive createDeployment() { |
72 | - JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | ||
73 | - deployment.addClass(CustomAuthorizer.class); | ||
74 | - deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
75 | - return deployment; | 71 | + return Tests.createDeployment(ConfigurationResourceTest.class).addClasses(CustomAuthorizer.class) |
72 | + .addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
76 | } | 73 | } |
77 | 74 | ||
78 | public void observer(@Observes AfterLoginSuccessful event) { | 75 | public void observer(@Observes AfterLoginSuccessful event) { |
@@ -81,15 +78,15 @@ public class DisabledAuthorizationTest { | @@ -81,15 +78,15 @@ public class DisabledAuthorizationTest { | ||
81 | 78 | ||
82 | @Test | 79 | @Test |
83 | public void hasPermissionProcess() { | 80 | public void hasPermissionProcess() { |
84 | - Assert.assertTrue(context.hasPermission("resource", "operation")); | ||
85 | - Assert.assertTrue(context.hasPermission("falseresource", "falseoperation")); | 81 | + assertTrue(context.hasPermission("resource", "operation")); |
82 | + assertTrue(context.hasPermission("falseresource", "falseoperation")); | ||
86 | assertNull(event); | 83 | assertNull(event); |
87 | } | 84 | } |
88 | 85 | ||
89 | @Test | 86 | @Test |
90 | - public void hasRoleProcess(){ | ||
91 | - Assert.assertTrue(context.hasRole("role")); | ||
92 | - Assert.assertTrue(context.hasRole("falserole")); | 87 | + public void hasRoleProcess() { |
88 | + assertTrue(context.hasRole("role")); | ||
89 | + assertTrue(context.hasRole("falserole")); | ||
93 | assertNull(event); | 90 | assertNull(event); |
94 | } | 91 | } |
95 | } | 92 | } |
impl/core/src/test/resources/configuration/field/enumeration/demoiselle.properties
0 → 100644
@@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
1 | +# Demoiselle Framework | ||
2 | +# Copyright (C) 2010 SERPRO | ||
3 | +# ---------------------------------------------------------------------------- | ||
4 | +# This file is part of Demoiselle Framework. | ||
5 | +# | ||
6 | +# Demoiselle Framework is free software; you can redistribute it and/or | ||
7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | ||
8 | +# as published by the Free Software Foundation. | ||
9 | +# | ||
10 | +# This program is distributed in the hope that it will be useful, | ||
11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | +# GNU General Public License for more details. | ||
14 | +# | ||
15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | ||
16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | +# ---------------------------------------------------------------------------- | ||
20 | +# Este arquivo é parte do Framework Demoiselle. | ||
21 | +# | ||
22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
24 | +# do Software Livre (FSF). | ||
25 | +# | ||
26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
29 | +# para maiores detalhes. | ||
30 | +# | ||
31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
35 | + | ||
36 | +prefix1.enumValue=VALUE_2 | ||
37 | +prefix1.emptyValue= | ||
38 | +prefix2.anotherValue=value_2 |
impl/core/src/test/resources/configuration/field/enumeration/demoiselle.xml
0 → 100644
@@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
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 | + | ||
38 | +<configuration> | ||
39 | + <prefix1> | ||
40 | + <enumValue>VALUE_2</enumValue> | ||
41 | + </prefix1> | ||
42 | + <prefix2> | ||
43 | + <anotherValue>value_2</anotherValue> | ||
44 | + </prefix2> | ||
45 | +</configuration> |
impl/core/src/test/resources/configuration/field/map/demoiselle.properties
@@ -33,9 +33,9 @@ | @@ -33,9 +33,9 @@ | ||
33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., | 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., |
34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
35 | 35 | ||
36 | -item1.stringWithDefinedKeyMap=demoiselle | ||
37 | -item2.stringWithDefinedKeyMap=framework | ||
38 | -item1.emptyValueMap= | ||
39 | -item2.emptyValueMap= | 36 | +configuration.test.stringWithDefinedKeyMap.item1=demoiselle |
37 | +configuration.test.stringWithDefinedKeyMap.item2=framework | ||
38 | +configuration.test.emptyValueMap.item1= | ||
39 | +configuration.test.emptyValueMap.item2= | ||
40 | 40 | ||
41 | -stringWithUndefinedKeyMap=undefined | 41 | +configuration.test.stringWithUndefinedKeyMap=undefined |
impl/core/src/test/resources/configuration/field/map/demoiselle.xml
@@ -36,17 +36,15 @@ | @@ -36,17 +36,15 @@ | ||
36 | --> | 36 | --> |
37 | 37 | ||
38 | <configuration> | 38 | <configuration> |
39 | - <item1> | ||
40 | - <stringWithDefinedKeyMap>demoiselle</stringWithDefinedKeyMap> | ||
41 | - </item1> | ||
42 | - <item2> | ||
43 | - <stringWithDefinedKeyMap>framework</stringWithDefinedKeyMap> | ||
44 | - </item2> | ||
45 | - <stringWithUndefinedKeyMap>undefined</stringWithUndefinedKeyMap> | ||
46 | - <item1> | ||
47 | - <emptyValueMap></emptyValueMap> | ||
48 | - </item1> | ||
49 | - <item2> | ||
50 | - <emptyValueMap></emptyValueMap> | ||
51 | - </item2> | 39 | + <stringWithDefinedKeyMap> |
40 | + <item1>demoiselle</item1> | ||
41 | + <item2>framework</item2> | ||
42 | + </stringWithDefinedKeyMap> | ||
43 | + | ||
44 | + <stringWithUndefinedKeyMap>undefined</stringWithUndefinedKeyMap> | ||
45 | + | ||
46 | + <emptyValueMap> | ||
47 | + <item1></item1> | ||
48 | + <item2></item2> | ||
49 | + </emptyValueMap> | ||
52 | </configuration> | 50 | </configuration> |
impl/extension/jdbc/pom.xml
@@ -74,6 +74,16 @@ | @@ -74,6 +74,16 @@ | ||
74 | 74 | ||
75 | <!-- for tests --> | 75 | <!-- for tests --> |
76 | <dependency> | 76 | <dependency> |
77 | + <groupId>org.jboss.arquillian.container</groupId> | ||
78 | + <artifactId>arquillian-glassfish-embedded-3.1</artifactId> | ||
79 | + <scope>test</scope> | ||
80 | + </dependency> | ||
81 | + <dependency> | ||
82 | + <groupId>org.glassfish.main.extras</groupId> | ||
83 | + <artifactId>glassfish-embedded-all</artifactId> | ||
84 | + <scope>test</scope> | ||
85 | + </dependency> | ||
86 | + <dependency> | ||
77 | <groupId>hsqldb</groupId> | 87 | <groupId>hsqldb</groupId> |
78 | <artifactId>hsqldb</artifactId> | 88 | <artifactId>hsqldb</artifactId> |
79 | <scope>test</scope> | 89 | <scope>test</scope> |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JDBCConfig.java
@@ -37,10 +37,10 @@ | @@ -37,10 +37,10 @@ | ||
37 | package br.gov.frameworkdemoiselle.internal.configuration; | 37 | package br.gov.frameworkdemoiselle.internal.configuration; |
38 | 38 | ||
39 | import java.io.Serializable; | 39 | import java.io.Serializable; |
40 | -import java.util.Map; | ||
41 | 40 | ||
42 | import br.gov.frameworkdemoiselle.annotation.Name; | 41 | import br.gov.frameworkdemoiselle.annotation.Name; |
43 | import br.gov.frameworkdemoiselle.configuration.Configuration; | 42 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
43 | + | ||
44 | /** | 44 | /** |
45 | * Provide used to access the configurations of the JDBC connection | 45 | * Provide used to access the configurations of the JDBC connection |
46 | * | 46 | * |
@@ -56,41 +56,41 @@ public class JDBCConfig implements Serializable { | @@ -56,41 +56,41 @@ public class JDBCConfig implements Serializable { | ||
56 | private String defaultDataSourceName; | 56 | private String defaultDataSourceName; |
57 | 57 | ||
58 | @Name("jndi.name") | 58 | @Name("jndi.name") |
59 | - private Map<String, String> jndiName; | 59 | + private JDBCConfigurationStore jndiName; |
60 | 60 | ||
61 | @Name("driver.class") | 61 | @Name("driver.class") |
62 | - private Map<String, String> driverClass; | 62 | + private JDBCConfigurationStore driverClass; |
63 | 63 | ||
64 | @Name("url") | 64 | @Name("url") |
65 | - private Map<String, String> url; | 65 | + private JDBCConfigurationStore url; |
66 | 66 | ||
67 | @Name("username") | 67 | @Name("username") |
68 | - private Map<String, String> username; | 68 | + private JDBCConfigurationStore username; |
69 | 69 | ||
70 | @Name("password") | 70 | @Name("password") |
71 | - private Map<String, String> password; | 71 | + private JDBCConfigurationStore password; |
72 | 72 | ||
73 | public String getDefaultDataSourceName() { | 73 | public String getDefaultDataSourceName() { |
74 | return defaultDataSourceName; | 74 | return defaultDataSourceName; |
75 | } | 75 | } |
76 | 76 | ||
77 | - public Map<String, String> getJndiName() { | 77 | + public JDBCConfigurationStore getJndiName() { |
78 | return jndiName; | 78 | return jndiName; |
79 | } | 79 | } |
80 | 80 | ||
81 | - public Map<String, String> getDriverClass() { | 81 | + public JDBCConfigurationStore getDriverClass() { |
82 | return driverClass; | 82 | return driverClass; |
83 | } | 83 | } |
84 | 84 | ||
85 | - public Map<String, String> getUrl() { | 85 | + public JDBCConfigurationStore getUrl() { |
86 | return url; | 86 | return url; |
87 | } | 87 | } |
88 | 88 | ||
89 | - public Map<String, String> getUsername() { | 89 | + public JDBCConfigurationStore getUsername() { |
90 | return username; | 90 | return username; |
91 | } | 91 | } |
92 | 92 | ||
93 | - public Map<String, String> getPassword() { | 93 | + public JDBCConfigurationStore getPassword() { |
94 | return password; | 94 | return password; |
95 | } | 95 | } |
96 | } | 96 | } |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JDBCConfigValueExtractor.java
0 → 100644
@@ -0,0 +1,90 @@ | @@ -0,0 +1,90 @@ | ||
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 br.gov.frameworkdemoiselle.annotation.Priority.L2_PRIORITY; | ||
40 | + | ||
41 | +import java.lang.reflect.Field; | ||
42 | +import java.util.Iterator; | ||
43 | +import java.util.regex.Matcher; | ||
44 | +import java.util.regex.Pattern; | ||
45 | + | ||
46 | +import org.apache.commons.configuration.Configuration; | ||
47 | + | ||
48 | +import br.gov.frameworkdemoiselle.annotation.Priority; | ||
49 | +import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | ||
50 | + | ||
51 | +/** | ||
52 | + * | ||
53 | + * TODO Adicionar verificação da existência de duas ou mais configurações JDBC com mesmo nome. Lançar INFO ou Exceção. | ||
54 | + * | ||
55 | + */ | ||
56 | +@Priority(L2_PRIORITY) | ||
57 | +public class JDBCConfigValueExtractor implements ConfigurationValueExtractor { | ||
58 | + | ||
59 | + @Override | ||
60 | + public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | ||
61 | + JDBCConfigurationStore value = null; | ||
62 | + | ||
63 | + String regexp = "^(" + prefix + ")((.+)\\.)?(" + key + ")$"; | ||
64 | + Pattern pattern = Pattern.compile(regexp); | ||
65 | + | ||
66 | + for (Iterator<String> iter = configuration.getKeys(); iter.hasNext();) { | ||
67 | + String iterKey = iter.next(); | ||
68 | + Matcher matcher = pattern.matcher(iterKey); | ||
69 | + | ||
70 | + if (matcher.matches()) { | ||
71 | + String confKey = matcher.group(1) + (matcher.group(2) == null ? "" : matcher.group(2)) | ||
72 | + + matcher.group(4); | ||
73 | + | ||
74 | + if (value == null) { | ||
75 | + value = new JDBCConfigurationStore(); | ||
76 | + } | ||
77 | + | ||
78 | + String mapKey = matcher.group(3) == null ? "default" : matcher.group(3); | ||
79 | + value.put(mapKey, configuration.getString(confKey)); | ||
80 | + } | ||
81 | + } | ||
82 | + | ||
83 | + return value; | ||
84 | + } | ||
85 | + | ||
86 | + @Override | ||
87 | + public boolean isSupported(Field field) { | ||
88 | + return field.getType() == JDBCConfigurationStore.class; | ||
89 | + } | ||
90 | +} |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JDBCConfigurationStore.java
0 → 100644
@@ -0,0 +1,80 @@ | @@ -0,0 +1,80 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.configuration; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.util.Collection; | ||
5 | +import java.util.HashMap; | ||
6 | +import java.util.Map; | ||
7 | +import java.util.Map.Entry; | ||
8 | +import java.util.Set; | ||
9 | + | ||
10 | + | ||
11 | +public class JDBCConfigurationStore implements Cloneable, Serializable { | ||
12 | + | ||
13 | + private static final long serialVersionUID = 1L; | ||
14 | + | ||
15 | + private HashMap<String, String> properties = new HashMap<String, String>(); | ||
16 | + | ||
17 | + public int size() { | ||
18 | + return properties.size(); | ||
19 | + } | ||
20 | + | ||
21 | + public boolean isEmpty() { | ||
22 | + return properties.isEmpty(); | ||
23 | + } | ||
24 | + | ||
25 | + public String get(Object key) { | ||
26 | + return properties.get(key); | ||
27 | + } | ||
28 | + | ||
29 | + public boolean equals(Object o) { | ||
30 | + return properties.equals(o); | ||
31 | + } | ||
32 | + | ||
33 | + public boolean containsKey(Object key) { | ||
34 | + return properties.containsKey(key); | ||
35 | + } | ||
36 | + | ||
37 | + public String put(String key, String value) { | ||
38 | + return properties.put(key, value); | ||
39 | + } | ||
40 | + | ||
41 | + public int hashCode() { | ||
42 | + return properties.hashCode(); | ||
43 | + } | ||
44 | + | ||
45 | + public String toString() { | ||
46 | + return properties.toString(); | ||
47 | + } | ||
48 | + | ||
49 | + public void putAll(Map<? extends String, ? extends String> m) { | ||
50 | + properties.putAll(m); | ||
51 | + } | ||
52 | + | ||
53 | + public String remove(Object key) { | ||
54 | + return properties.remove(key); | ||
55 | + } | ||
56 | + | ||
57 | + public void clear() { | ||
58 | + properties.clear(); | ||
59 | + } | ||
60 | + | ||
61 | + public boolean containsValue(Object value) { | ||
62 | + return properties.containsValue(value); | ||
63 | + } | ||
64 | + | ||
65 | + public Object clone() { | ||
66 | + return properties.clone(); | ||
67 | + } | ||
68 | + | ||
69 | + public Set<String> keySet() { | ||
70 | + return properties.keySet(); | ||
71 | + } | ||
72 | + | ||
73 | + public Collection<String> values() { | ||
74 | + return properties.values(); | ||
75 | + } | ||
76 | + | ||
77 | + public Set<Entry<String, String>> entrySet() { | ||
78 | + return properties.entrySet(); | ||
79 | + } | ||
80 | +} |
impl/extension/jdbc/src/test/resources/.arquillian-glassfish-embedded.profile
impl/extension/jmx/pom.xml
@@ -57,18 +57,8 @@ | @@ -57,18 +57,8 @@ | ||
57 | 57 | ||
58 | <!-- Test dependencies --> | 58 | <!-- Test dependencies --> |
59 | <dependency> | 59 | <dependency> |
60 | - <groupId>junit</groupId> | ||
61 | - <artifactId>junit</artifactId> | ||
62 | - <scope>test</scope> | ||
63 | - </dependency> | ||
64 | - <dependency> | ||
65 | - <groupId>org.jboss.arquillian.junit</groupId> | ||
66 | - <artifactId>arquillian-junit-container</artifactId> | ||
67 | - <scope>test</scope> | ||
68 | - </dependency> | ||
69 | - <dependency> | ||
70 | - <groupId>org.jboss.shrinkwrap.resolver</groupId> | ||
71 | - <artifactId>shrinkwrap-resolver-impl-maven</artifactId> | 60 | + <groupId>org.jboss.arquillian.container</groupId> |
61 | + <artifactId>arquillian-weld-se-embedded-1.1</artifactId> | ||
72 | <scope>test</scope> | 62 | <scope>test</scope> |
73 | </dependency> | 63 | </dependency> |
74 | <dependency> | 64 | <dependency> |
@@ -76,13 +66,6 @@ | @@ -76,13 +66,6 @@ | ||
76 | <artifactId>weld-se-core</artifactId> | 66 | <artifactId>weld-se-core</artifactId> |
77 | <scope>test</scope> | 67 | <scope>test</scope> |
78 | </dependency> | 68 | </dependency> |
79 | - <!-- | ||
80 | - <dependency> | ||
81 | - <groupId>org.jboss.arquillian.container</groupId> | ||
82 | - <artifactId>arquillian-weld-se-embedded-1.1</artifactId> | ||
83 | - <scope>test</scope> | ||
84 | - </dependency> | ||
85 | - --> | ||
86 | <dependency> | 69 | <dependency> |
87 | <groupId>org.hibernate</groupId> | 70 | <groupId>org.hibernate</groupId> |
88 | <artifactId>hibernate-validator</artifactId> | 71 | <artifactId>hibernate-validator</artifactId> |
impl/extension/jmx/src/test/resources/.arquillian-weld-se-embedded.profile
impl/extension/jpa/pom.xml
@@ -71,6 +71,18 @@ | @@ -71,6 +71,18 @@ | ||
71 | <groupId>org.eclipse.persistence</groupId> | 71 | <groupId>org.eclipse.persistence</groupId> |
72 | <artifactId>javax.persistence</artifactId> | 72 | <artifactId>javax.persistence</artifactId> |
73 | </dependency> | 73 | </dependency> |
74 | + | ||
75 | + <!-- for tests --> | ||
76 | + <dependency> | ||
77 | + <groupId>org.jboss.arquillian.container</groupId> | ||
78 | + <artifactId>arquillian-glassfish-embedded-3.1</artifactId> | ||
79 | + <scope>test</scope> | ||
80 | + </dependency> | ||
81 | + <dependency> | ||
82 | + <groupId>org.glassfish.main.extras</groupId> | ||
83 | + <artifactId>glassfish-embedded-all</artifactId> | ||
84 | + <scope>test</scope> | ||
85 | + </dependency> | ||
74 | </dependencies> | 86 | </dependencies> |
75 | 87 | ||
76 | <repositories> | 88 | <repositories> |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AbstractEntityManagerStore.java
@@ -41,13 +41,11 @@ import java.util.HashMap; | @@ -41,13 +41,11 @@ import java.util.HashMap; | ||
41 | import java.util.Map; | 41 | import java.util.Map; |
42 | 42 | ||
43 | import javax.enterprise.context.RequestScoped; | 43 | import javax.enterprise.context.RequestScoped; |
44 | -import javax.inject.Inject; | ||
45 | import javax.persistence.EntityManager; | 44 | import javax.persistence.EntityManager; |
46 | import javax.persistence.FlushModeType; | 45 | import javax.persistence.FlushModeType; |
47 | 46 | ||
48 | import org.slf4j.Logger; | 47 | import org.slf4j.Logger; |
49 | 48 | ||
50 | -import br.gov.frameworkdemoiselle.annotation.Name; | ||
51 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; | 49 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; |
52 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig.EntityManagerScope; | 50 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig.EntityManagerScope; |
53 | import br.gov.frameworkdemoiselle.util.Beans; | 51 | import br.gov.frameworkdemoiselle.util.Beans; |
@@ -74,19 +72,6 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | @@ -74,19 +72,6 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | ||
74 | 72 | ||
75 | private final Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); | 73 | private final Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); |
76 | 74 | ||
77 | - @Inject | ||
78 | - private EntityManagerFactoryProducer factory; | ||
79 | - | ||
80 | - @Inject | ||
81 | - private Logger logger; | ||
82 | - | ||
83 | - @Inject | ||
84 | - @Name("demoiselle-jpa-bundle") | ||
85 | - private ResourceBundle bundle; | ||
86 | - | ||
87 | - @Inject | ||
88 | - private EntityManagerConfig configuration; | ||
89 | - | ||
90 | public EntityManager getEntityManager(String persistenceUnit) { | 75 | public EntityManager getEntityManager(String persistenceUnit) { |
91 | EntityManager entityManager = null; | 76 | EntityManager entityManager = null; |
92 | 77 | ||
@@ -114,6 +99,7 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | @@ -114,6 +99,7 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | ||
114 | //Se o produtor não possui escopo, então o ciclo de vida | 99 | //Se o produtor não possui escopo, então o ciclo de vida |
115 | //de EntityManager produzidos é responsabilidade do desenvolvedor. Não | 100 | //de EntityManager produzidos é responsabilidade do desenvolvedor. Não |
116 | //fechamos os EntityManagers aqui. | 101 | //fechamos os EntityManagers aqui. |
102 | + EntityManagerConfig configuration = getConfiguration(); | ||
117 | if (configuration.getEntityManagerScope() != EntityManagerScope.NOSCOPE){ | 103 | if (configuration.getEntityManagerScope() != EntityManagerScope.NOSCOPE){ |
118 | for (EntityManager entityManager : cache.values()) { | 104 | for (EntityManager entityManager : cache.values()) { |
119 | entityManager.close(); | 105 | entityManager.close(); |
@@ -131,23 +117,18 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | @@ -131,23 +117,18 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | ||
131 | } | 117 | } |
132 | 118 | ||
133 | private EntityManagerFactoryProducer getFactory(){ | 119 | private EntityManagerFactoryProducer getFactory(){ |
134 | - if (factory==null){ | ||
135 | - factory = Beans.getReference(EntityManagerFactoryProducer.class); | ||
136 | - } | ||
137 | - return factory; | 120 | + return Beans.getReference(EntityManagerFactoryProducer.class); |
138 | } | 121 | } |
139 | 122 | ||
140 | private Logger getLogger(){ | 123 | private Logger getLogger(){ |
141 | - if (logger==null){ | ||
142 | - logger = Beans.getReference(Logger.class); | ||
143 | - } | ||
144 | - return logger; | 124 | + return Beans.getReference(Logger.class); |
145 | } | 125 | } |
146 | 126 | ||
147 | private ResourceBundle getBundle(){ | 127 | private ResourceBundle getBundle(){ |
148 | - if (bundle==null){ | ||
149 | - bundle = Beans.getReference(ResourceBundle.class , new NameQualifier("demoiselle-jpa-bundle")); | ||
150 | - } | ||
151 | - return bundle; | 128 | + return Beans.getReference(ResourceBundle.class , new NameQualifier("demoiselle-jpa-bundle")); |
129 | + } | ||
130 | + | ||
131 | + private EntityManagerConfig getConfiguration(){ | ||
132 | + return Beans.getReference(EntityManagerConfig.class); | ||
152 | } | 133 | } |
153 | } | 134 | } |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/EntityManagerProxy.java
@@ -117,8 +117,8 @@ public class EntityManagerProxy implements EntityManager, Serializable { | @@ -117,8 +117,8 @@ public class EntityManagerProxy implements EntityManager, Serializable { | ||
117 | @Override | 117 | @Override |
118 | public void persist(Object entity) { | 118 | public void persist(Object entity) { |
119 | joinTransactionIfNecessary(); | 119 | joinTransactionIfNecessary(); |
120 | - checkEntityManagerScopePassivable(entity); | ||
121 | getEntityManagerDelegate().persist(entity); | 120 | getEntityManagerDelegate().persist(entity); |
121 | + checkEntityManagerScopePassivable(entity); | ||
122 | } | 122 | } |
123 | 123 | ||
124 | /* | 124 | /* |
impl/extension/jpa/src/test/resources/.arquillian-glassfish-embedded.profile
impl/extension/jpa/src/test/resources/producer/demoiselle.properties
1 | frameworkdemoiselle.persistence.default.unit.name=pu | 1 | frameworkdemoiselle.persistence.default.unit.name=pu |
2 | -frameworkdemoiselle.persistence.entitymanager.scope=request | ||
3 | \ No newline at end of file | 2 | \ No newline at end of file |
3 | +frameworkdemoiselle.persistence.entitymanager.scope=REQUEST | ||
4 | \ No newline at end of file | 4 | \ No newline at end of file |
impl/extension/jpa/src/test/resources/producer/demoiselle_noscoped.properties
1 | frameworkdemoiselle.persistence.default.unit.name=pu | 1 | frameworkdemoiselle.persistence.default.unit.name=pu |
2 | -frameworkdemoiselle.persistence.entitymanager.scope=noscope | ||
3 | \ No newline at end of file | 2 | \ No newline at end of file |
3 | +frameworkdemoiselle.persistence.entitymanager.scope=NOSCOPE | ||
4 | \ No newline at end of file | 4 | \ No newline at end of file |
impl/extension/jpa/src/test/resources/producer/demoiselle_viewscoped.properties
1 | frameworkdemoiselle.persistence.default.unit.name=pu | 1 | frameworkdemoiselle.persistence.default.unit.name=pu |
2 | -frameworkdemoiselle.persistence.entitymanager.scope=view | ||
3 | \ No newline at end of file | 2 | \ No newline at end of file |
3 | +frameworkdemoiselle.persistence.entitymanager.scope=VIEW | ||
4 | \ No newline at end of file | 4 | \ No newline at end of file |
impl/extension/jsf/pom.xml
@@ -80,22 +80,27 @@ | @@ -80,22 +80,27 @@ | ||
80 | <artifactId>el-impl</artifactId> | 80 | <artifactId>el-impl</artifactId> |
81 | <scope>provided</scope> | 81 | <scope>provided</scope> |
82 | </dependency> | 82 | </dependency> |
83 | - <!-- For Tests --> | 83 | + |
84 | + <!-- for tests --> | ||
84 | <dependency> | 85 | <dependency> |
85 | <groupId>com.sun.faces</groupId> | 86 | <groupId>com.sun.faces</groupId> |
86 | <artifactId>jsf-impl</artifactId> | 87 | <artifactId>jsf-impl</artifactId> |
87 | <scope>test</scope> | 88 | <scope>test</scope> |
88 | </dependency> | 89 | </dependency> |
89 | <dependency> | 90 | <dependency> |
90 | - <groupId>commons-httpclient</groupId> | ||
91 | - <artifactId>commons-httpclient</artifactId> | ||
92 | - <version>3.1</version> | 91 | + <groupId>org.jboss.arquillian.container</groupId> |
92 | + <artifactId>arquillian-glassfish-embedded-3.1</artifactId> | ||
93 | <scope>test</scope> | 93 | <scope>test</scope> |
94 | </dependency> | 94 | </dependency> |
95 | <dependency> | 95 | <dependency> |
96 | - <groupId>com.ocpsoft</groupId> | ||
97 | - <artifactId>prettyfaces-jsf2</artifactId> | ||
98 | - <version>3.3.0</version> | 96 | + <groupId>org.glassfish.main.extras</groupId> |
97 | + <artifactId>glassfish-embedded-all</artifactId> | ||
98 | + <scope>test</scope> | ||
99 | + </dependency> | ||
100 | + <dependency> | ||
101 | + <groupId>commons-httpclient</groupId> | ||
102 | + <artifactId>commons-httpclient</artifactId> | ||
103 | + <version>3.1</version> | ||
99 | <scope>test</scope> | 104 | <scope>test</scope> |
100 | </dependency> | 105 | </dependency> |
101 | </dependencies> | 106 | </dependencies> |
@@ -124,4 +129,37 @@ | @@ -124,4 +129,37 @@ | ||
124 | </releases> | 129 | </releases> |
125 | </repository> | 130 | </repository> |
126 | </repositories> | 131 | </repositories> |
132 | + | ||
133 | + <profiles> | ||
134 | + <profile> | ||
135 | + <id>arquillian-test</id> | ||
136 | + <dependencies> | ||
137 | + <dependency> | ||
138 | + <groupId>com.sun.faces</groupId> | ||
139 | + <artifactId>jsf-api</artifactId> | ||
140 | + <scope>provided</scope> | ||
141 | + </dependency> | ||
142 | + <dependency> | ||
143 | + <groupId>br.gov.frameworkdemoiselle</groupId> | ||
144 | + <artifactId>demoiselle-servlet</artifactId> | ||
145 | + <exclusions> | ||
146 | + <exclusion> | ||
147 | + <groupId>javax.servlet</groupId> | ||
148 | + <artifactId>javax.servlet-api</artifactId> | ||
149 | + </exclusion> | ||
150 | + </exclusions> | ||
151 | + </dependency> | ||
152 | + <!-- | ||
153 | + --> | ||
154 | + <dependency> | ||
155 | + <groupId>com.ocpsoft</groupId> | ||
156 | + <artifactId>prettyfaces-jsf2</artifactId> | ||
157 | + <version>3.3.0</version> | ||
158 | + <scope>runtime</scope> | ||
159 | + </dependency> | ||
160 | + <!-- | ||
161 | + --> | ||
162 | + </dependencies> | ||
163 | + </profile> | ||
164 | + </profiles> | ||
127 | </project> | 165 | </project> |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ViewScopeConfig.java
0 → 100644
@@ -0,0 +1,59 @@ | @@ -0,0 +1,59 @@ | ||
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 java.io.Serializable; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
42 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
43 | + | ||
44 | +@Configuration(prefix = "frameworkdemoiselle.scope.view") | ||
45 | +public class ViewScopeConfig implements Serializable { | ||
46 | + | ||
47 | + private static final long serialVersionUID = 1L; | ||
48 | + | ||
49 | + @Name("timeout") | ||
50 | + private int viewScopeTimeout = 1800; | ||
51 | + | ||
52 | + public int getViewScopeTimeout() { | ||
53 | + return viewScopeTimeout; | ||
54 | + } | ||
55 | + | ||
56 | + public void setViewScopeTimeout(int viewScopeTimeout) { | ||
57 | + this.viewScopeTimeout = viewScopeTimeout; | ||
58 | + } | ||
59 | +} |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/context/FacesViewContextImpl.java
@@ -36,11 +36,14 @@ | @@ -36,11 +36,14 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.context; | 37 | package br.gov.frameworkdemoiselle.internal.context; |
38 | 38 | ||
39 | -import java.util.Map; | 39 | +import java.util.concurrent.ConcurrentHashMap; |
40 | +import java.util.concurrent.atomic.AtomicLong; | ||
40 | 41 | ||
41 | import javax.enterprise.inject.Alternative; | 42 | import javax.enterprise.inject.Alternative; |
42 | import javax.faces.component.UIViewRoot; | 43 | import javax.faces.component.UIViewRoot; |
43 | import javax.faces.context.FacesContext; | 44 | import javax.faces.context.FacesContext; |
45 | +import javax.servlet.http.HttpServletRequest; | ||
46 | +import javax.servlet.http.HttpSession; | ||
44 | 47 | ||
45 | import br.gov.frameworkdemoiselle.annotation.Priority; | 48 | import br.gov.frameworkdemoiselle.annotation.Priority; |
46 | import br.gov.frameworkdemoiselle.annotation.ViewScoped; | 49 | import br.gov.frameworkdemoiselle.annotation.ViewScoped; |
@@ -59,25 +62,80 @@ import br.gov.frameworkdemoiselle.util.Faces; | @@ -59,25 +62,80 @@ import br.gov.frameworkdemoiselle.util.Faces; | ||
59 | @Priority(Priority.L2_PRIORITY) | 62 | @Priority(Priority.L2_PRIORITY) |
60 | @Alternative | 63 | @Alternative |
61 | public class FacesViewContextImpl extends AbstractCustomContext implements ViewContext { | 64 | public class FacesViewContextImpl extends AbstractCustomContext implements ViewContext { |
62 | - | 65 | + |
66 | + private final AtomicLong atomicLong = new AtomicLong(); | ||
67 | + | ||
68 | + private ConcurrentHashMap<String, SessionBeanStore> sessionBeanStore = new ConcurrentHashMap<String, SessionBeanStore>(); | ||
69 | + | ||
70 | + private static final String FACES_KEY = FacesViewContextImpl.class.getCanonicalName(); | ||
71 | + | ||
63 | public FacesViewContextImpl() { | 72 | public FacesViewContextImpl() { |
64 | super(ViewScoped.class); | 73 | super(ViewScoped.class); |
65 | } | 74 | } |
66 | 75 | ||
67 | @Override | 76 | @Override |
68 | protected boolean isStoreInitialized() { | 77 | protected boolean isStoreInitialized() { |
69 | - return FacesContext.getCurrentInstance()!=null; | 78 | + return FacesContext.getCurrentInstance()!=null && getSessionId()!=null; |
70 | } | 79 | } |
71 | 80 | ||
72 | @Override | 81 | @Override |
73 | - protected Store getStore() { | ||
74 | - Map<String, Object> viewMap = Faces.getViewMap(); | ||
75 | - String key = Store.class.getName(); | ||
76 | - | ||
77 | - if (!viewMap.containsKey(key)) { | ||
78 | - viewMap.put(key, createStore()); | 82 | + protected BeanStore getStore() { |
83 | + clearInvalidatedSession(); | ||
84 | + | ||
85 | + final String sessionId = getSessionId(); | ||
86 | + | ||
87 | + if (sessionId==null){ | ||
88 | + return null; | ||
89 | + } | ||
90 | + | ||
91 | + Long viewId = (Long)Faces.getViewMap().get(FACES_KEY); | ||
92 | + if (viewId==null){ | ||
93 | + synchronized (this) { | ||
94 | + viewId = (Long)Faces.getViewMap().get(FACES_KEY); | ||
95 | + if (viewId==null){ | ||
96 | + viewId = atomicLong.incrementAndGet(); | ||
97 | + Faces.getViewMap().put(FACES_KEY, viewId); | ||
98 | + } | ||
99 | + } | ||
79 | } | 100 | } |
80 | 101 | ||
81 | - return (Store) viewMap.get(key); | 102 | + SessionBeanStore currentStore = sessionBeanStore.get(sessionId); |
103 | + if (currentStore==null){ | ||
104 | + synchronized (this) { | ||
105 | + currentStore = (SessionBeanStore) sessionBeanStore.get(sessionId); | ||
106 | + if (currentStore==null){ | ||
107 | + currentStore = new SessionBeanStore(); | ||
108 | + sessionBeanStore.put(sessionId, currentStore); | ||
109 | + } | ||
110 | + } | ||
111 | + } | ||
112 | + | ||
113 | + return currentStore.getStore(viewId, this); | ||
114 | + } | ||
115 | + | ||
116 | + private synchronized void clearInvalidatedSession(){ | ||
117 | + if (wasSessionInvalidated()){ | ||
118 | + final String requestedSessionId = getRequestedSessionId(); | ||
119 | + final SessionBeanStore store = sessionBeanStore.get(requestedSessionId); | ||
120 | + if (store!=null){ | ||
121 | + store.clear(this); | ||
122 | + sessionBeanStore.remove(requestedSessionId); | ||
123 | + } | ||
124 | + } | ||
125 | + } | ||
126 | + | ||
127 | + private String getSessionId(){ | ||
128 | + final HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true); | ||
129 | + return session!=null ? session.getId() : null; | ||
130 | + } | ||
131 | + | ||
132 | + private String getRequestedSessionId(){ | ||
133 | + final HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); | ||
134 | + return request!=null ? request.getRequestedSessionId() : null; | ||
135 | + } | ||
136 | + | ||
137 | + private boolean wasSessionInvalidated(){ | ||
138 | + final HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); | ||
139 | + return request!=null && request.getRequestedSessionId() != null && !request.isRequestedSessionIdValid(); | ||
82 | } | 140 | } |
83 | } | 141 | } |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/context/SessionBeanStore.java
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.context; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | + | ||
5 | +import javax.enterprise.context.SessionScoped; | ||
6 | +import javax.enterprise.context.spi.Contextual; | ||
7 | +import javax.enterprise.context.spi.CreationalContext; | ||
8 | + | ||
9 | +@SessionScoped | ||
10 | +public class SessionBeanStore implements Serializable { | ||
11 | + | ||
12 | + private static final long serialVersionUID = -8265458933971929432L; | ||
13 | + | ||
14 | + private Long lastViewId = null; | ||
15 | + | ||
16 | + private BeanStore store; | ||
17 | + | ||
18 | + synchronized BeanStore getStore(Long viewId, AbstractCustomContext context) { | ||
19 | + if (lastViewId == null || !lastViewId.equals(viewId)) { | ||
20 | + clear(context); | ||
21 | + lastViewId = viewId; | ||
22 | + store = AbstractCustomContext.createStore(); | ||
23 | + } | ||
24 | + | ||
25 | + return store; | ||
26 | + } | ||
27 | + | ||
28 | + @SuppressWarnings({ "rawtypes", "unchecked" }) | ||
29 | + public void clear(AbstractCustomContext context) { | ||
30 | + if (store != null) { | ||
31 | + for (String id : store) { | ||
32 | + Contextual contextual = context.getContextualStore().getContextual(id); | ||
33 | + Object instance = store.getInstance(id); | ||
34 | + CreationalContext creationalContext = store.getCreationalContext(id); | ||
35 | + | ||
36 | + if (contextual != null && instance != null) { | ||
37 | + contextual.destroy(instance, creationalContext); | ||
38 | + } | ||
39 | + } | ||
40 | + store.clear(); | ||
41 | + } | ||
42 | + } | ||
43 | +} |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ApplicationExceptionHandler.java
@@ -54,6 +54,7 @@ import br.gov.frameworkdemoiselle.util.Faces; | @@ -54,6 +54,7 @@ import br.gov.frameworkdemoiselle.util.Faces; | ||
54 | import br.gov.frameworkdemoiselle.util.PageNotFoundException; | 54 | import br.gov.frameworkdemoiselle.util.PageNotFoundException; |
55 | import br.gov.frameworkdemoiselle.util.Redirector; | 55 | import br.gov.frameworkdemoiselle.util.Redirector; |
56 | 56 | ||
57 | +@SuppressWarnings("deprecation") | ||
57 | public class ApplicationExceptionHandler extends AbstractExceptionHandler { | 58 | public class ApplicationExceptionHandler extends AbstractExceptionHandler { |
58 | 59 | ||
59 | public ApplicationExceptionHandler(final ExceptionHandler wrapped) { | 60 | public ApplicationExceptionHandler(final ExceptionHandler wrapped) { |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthenticationExceptionHandler.java
@@ -36,14 +36,20 @@ | @@ -36,14 +36,20 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
38 | 38 | ||
39 | +import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; | ||
40 | + | ||
39 | import javax.faces.context.ExceptionHandler; | 41 | import javax.faces.context.ExceptionHandler; |
40 | import javax.faces.context.FacesContext; | 42 | import javax.faces.context.FacesContext; |
43 | +import javax.servlet.http.HttpServletResponse; | ||
41 | 44 | ||
45 | +import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig; | ||
42 | import br.gov.frameworkdemoiselle.security.NotLoggedInException; | 46 | import br.gov.frameworkdemoiselle.security.NotLoggedInException; |
43 | import br.gov.frameworkdemoiselle.util.Beans; | 47 | import br.gov.frameworkdemoiselle.util.Beans; |
44 | 48 | ||
45 | public class AuthenticationExceptionHandler extends AbstractExceptionHandler { | 49 | public class AuthenticationExceptionHandler extends AbstractExceptionHandler { |
46 | 50 | ||
51 | + private transient JsfSecurityConfig config; | ||
52 | + | ||
47 | public AuthenticationExceptionHandler(final ExceptionHandler wrapped) { | 53 | public AuthenticationExceptionHandler(final ExceptionHandler wrapped) { |
48 | super(wrapped); | 54 | super(wrapped); |
49 | } | 55 | } |
@@ -53,10 +59,25 @@ public class AuthenticationExceptionHandler extends AbstractExceptionHandler { | @@ -53,10 +59,25 @@ public class AuthenticationExceptionHandler extends AbstractExceptionHandler { | ||
53 | 59 | ||
54 | if (cause instanceof NotLoggedInException) { | 60 | if (cause instanceof NotLoggedInException) { |
55 | handled = true; | 61 | handled = true; |
56 | - //TODO Inter [NQ]: remover referência a SecurityObserver criando uma classe comum que faz o redirecionamento e que é compartilhada entre elas. | ||
57 | - Beans.getReference(SecurityObserver.class).redirectToLoginPage(); | 62 | + // TODO Inter [NQ]: remover referência a SecurityObserver criando uma classe comum que faz o |
63 | + // redirecionamento e que é compartilhada entre elas. | ||
64 | + | ||
65 | + if (getConfig().isRedirectEnabled()) { | ||
66 | + Beans.getReference(SecurityObserver.class).redirectToLoginPage(); | ||
67 | + } else { | ||
68 | + HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); | ||
69 | + response.setStatus(SC_FORBIDDEN); | ||
70 | + } | ||
58 | } | 71 | } |
59 | 72 | ||
60 | return handled; | 73 | return handled; |
61 | } | 74 | } |
75 | + | ||
76 | + public JsfSecurityConfig getConfig() { | ||
77 | + if (this.config == null) { | ||
78 | + this.config = Beans.getReference(JsfSecurityConfig.class); | ||
79 | + } | ||
80 | + | ||
81 | + return this.config; | ||
82 | + } | ||
62 | } | 83 | } |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthorizationExceptionHandler.java
@@ -36,9 +36,12 @@ | @@ -36,9 +36,12 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
38 | 38 | ||
39 | +import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; | ||
40 | + | ||
39 | import javax.faces.context.ExceptionHandler; | 41 | import javax.faces.context.ExceptionHandler; |
40 | import javax.faces.context.FacesContext; | 42 | import javax.faces.context.FacesContext; |
41 | import javax.faces.event.PhaseId; | 43 | import javax.faces.event.PhaseId; |
44 | +import javax.servlet.http.HttpServletResponse; | ||
42 | 45 | ||
43 | import br.gov.frameworkdemoiselle.security.AuthorizationException; | 46 | import br.gov.frameworkdemoiselle.security.AuthorizationException; |
44 | import br.gov.frameworkdemoiselle.util.Faces; | 47 | import br.gov.frameworkdemoiselle.util.Faces; |
@@ -53,9 +56,15 @@ public class AuthorizationExceptionHandler extends AbstractExceptionHandler { | @@ -53,9 +56,15 @@ public class AuthorizationExceptionHandler extends AbstractExceptionHandler { | ||
53 | boolean handled = false; | 56 | boolean handled = false; |
54 | boolean rendering = PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId()); | 57 | boolean rendering = PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId()); |
55 | 58 | ||
56 | - if (!rendering && cause instanceof AuthorizationException) { | ||
57 | - Faces.addMessage(cause); | 59 | + if (cause instanceof AuthorizationException) { |
58 | handled = true; | 60 | handled = true; |
61 | + | ||
62 | + if (rendering) { | ||
63 | + HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); | ||
64 | + response.setStatus(SC_UNAUTHORIZED); | ||
65 | + } else { | ||
66 | + Faces.addMessage(cause); | ||
67 | + } | ||
59 | } | 68 | } |
60 | 69 | ||
61 | return handled; | 70 | return handled; |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/FacesMessageAppender.java
@@ -37,18 +37,26 @@ | @@ -37,18 +37,26 @@ | ||
37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
38 | 38 | ||
39 | import static br.gov.frameworkdemoiselle.annotation.Priority.L3_PRIORITY; | 39 | import static br.gov.frameworkdemoiselle.annotation.Priority.L3_PRIORITY; |
40 | + | ||
41 | +import javax.enterprise.context.ContextNotActiveException; | ||
42 | + | ||
40 | import br.gov.frameworkdemoiselle.annotation.Priority; | 43 | import br.gov.frameworkdemoiselle.annotation.Priority; |
41 | import br.gov.frameworkdemoiselle.message.Message; | 44 | import br.gov.frameworkdemoiselle.message.Message; |
42 | -import br.gov.frameworkdemoiselle.message.MessageAppender; | ||
43 | import br.gov.frameworkdemoiselle.util.Faces; | 45 | import br.gov.frameworkdemoiselle.util.Faces; |
44 | 46 | ||
45 | @Priority(L3_PRIORITY) | 47 | @Priority(L3_PRIORITY) |
46 | -public class FacesMessageAppender implements MessageAppender { | 48 | +public class FacesMessageAppender extends LoggerMessageAppender { |
47 | 49 | ||
48 | private static final long serialVersionUID = 1L; | 50 | private static final long serialVersionUID = 1L; |
49 | 51 | ||
50 | @Override | 52 | @Override |
51 | public void append(Message message) { | 53 | public void append(Message message) { |
52 | - Faces.addMessage(message); | 54 | + try { |
55 | + Faces.addMessage(message); | ||
56 | + } catch (ContextNotActiveException cause) { | ||
57 | + // TODO Logar warning... | ||
58 | + | ||
59 | + super.append(message); | ||
60 | + } | ||
53 | } | 61 | } |
54 | } | 62 | } |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityObserver.java
@@ -152,7 +152,8 @@ public class SecurityObserver implements Serializable { | @@ -152,7 +152,8 @@ public class SecurityObserver implements Serializable { | ||
152 | 152 | ||
153 | } finally { | 153 | } finally { |
154 | try { | 154 | try { |
155 | - Beans.getReference(HttpSession.class).invalidate(); | 155 | + HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false); |
156 | + session.invalidate(); | ||
156 | } catch (IllegalStateException e) { | 157 | } catch (IllegalStateException e) { |
157 | logger.debug("Esta sessão já foi invalidada."); | 158 | logger.debug("Esta sessão já foi invalidada."); |
158 | } | 159 | } |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/FacesContextProxy.java
@@ -5,7 +5,9 @@ import java.util.Iterator; | @@ -5,7 +5,9 @@ import java.util.Iterator; | ||
5 | import java.util.List; | 5 | import java.util.List; |
6 | import java.util.Map; | 6 | import java.util.Map; |
7 | 7 | ||
8 | +import javax.annotation.PostConstruct; | ||
8 | import javax.el.ELContext; | 9 | import javax.el.ELContext; |
10 | +import javax.enterprise.context.ContextNotActiveException; | ||
9 | import javax.enterprise.inject.Default; | 11 | import javax.enterprise.inject.Default; |
10 | import javax.faces.application.Application; | 12 | import javax.faces.application.Application; |
11 | import javax.faces.application.FacesMessage; | 13 | import javax.faces.application.FacesMessage; |
@@ -26,8 +28,16 @@ public class FacesContextProxy extends FacesContext implements Serializable { | @@ -26,8 +28,16 @@ public class FacesContextProxy extends FacesContext implements Serializable { | ||
26 | 28 | ||
27 | private static final long serialVersionUID = 1L; | 29 | private static final long serialVersionUID = 1L; |
28 | 30 | ||
29 | - private FacesContext getDelegate() { | ||
30 | - return FacesContext.getCurrentInstance(); | 31 | + @PostConstruct |
32 | + public FacesContext getDelegate() { | ||
33 | + FacesContext facesContext = FacesContext.getCurrentInstance(); | ||
34 | + | ||
35 | + if (facesContext == null) { | ||
36 | + // TODO Colocar a mensagem correta | ||
37 | + throw new ContextNotActiveException(); | ||
38 | + } | ||
39 | + | ||
40 | + return facesContext; | ||
31 | } | 41 | } |
32 | 42 | ||
33 | public int hashCode() { | 43 | public int hashCode() { |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBean.java
@@ -49,7 +49,7 @@ import br.gov.frameworkdemoiselle.util.Reflections; | @@ -49,7 +49,7 @@ import br.gov.frameworkdemoiselle.util.Reflections; | ||
49 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 49 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | - * Template Managed Bean class that implements the methods defined by the interface EditPageBean. | 52 | + * Template Managed AuthenticationBean class that implements the methods defined by the interface EditPageBean. |
53 | * | 53 | * |
54 | * @param <T> | 54 | * @param <T> |
55 | * bean object type | 55 | * bean object type |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractListPageBean.java
@@ -50,7 +50,7 @@ import br.gov.frameworkdemoiselle.pagination.Pagination; | @@ -50,7 +50,7 @@ import br.gov.frameworkdemoiselle.pagination.Pagination; | ||
50 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; | 50 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; |
51 | import br.gov.frameworkdemoiselle.util.Reflections; | 51 | import br.gov.frameworkdemoiselle.util.Reflections; |
52 | /** | 52 | /** |
53 | - * Template Managed Bean class that implements the methods defined by the interface ListPageBean. | 53 | + * Template Managed AuthenticationBean class that implements the methods defined by the interface ListPageBean. |
54 | * | 54 | * |
55 | * @param <T> | 55 | * @param <T> |
56 | * bean object type | 56 | * bean object type |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractPageBean.java
@@ -43,7 +43,7 @@ import br.gov.frameworkdemoiselle.annotation.NextView; | @@ -43,7 +43,7 @@ import br.gov.frameworkdemoiselle.annotation.NextView; | ||
43 | import br.gov.frameworkdemoiselle.annotation.PreviousView; | 43 | import br.gov.frameworkdemoiselle.annotation.PreviousView; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | - * Template Managed Bean class that implements the methods defined by the interface PageBean. | 46 | + * Template Managed AuthenticationBean class that implements the methods defined by the interface PageBean. |
47 | * | 47 | * |
48 | * @author SERPRO | 48 | * @author SERPRO |
49 | * @see PageBean | 49 | * @see PageBean |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Faces.java
@@ -59,7 +59,7 @@ import br.gov.frameworkdemoiselle.message.SeverityType; | @@ -59,7 +59,7 @@ import br.gov.frameworkdemoiselle.message.SeverityType; | ||
59 | * Utility class to insert messages in the FacesContext. | 59 | * Utility class to insert messages in the FacesContext. |
60 | * | 60 | * |
61 | * @author SERPRO | 61 | * @author SERPRO |
62 | - * */ | 62 | + */ |
63 | public class Faces { | 63 | public class Faces { |
64 | 64 | ||
65 | private Faces() { | 65 | private Faces() { |
@@ -171,4 +171,9 @@ public class Faces { | @@ -171,4 +171,9 @@ public class Faces { | ||
171 | UIViewRoot viewRoot = getFacesContext().getViewRoot(); | 171 | UIViewRoot viewRoot = getFacesContext().getViewRoot(); |
172 | return viewRoot.getViewMap(true); | 172 | return viewRoot.getViewMap(true); |
173 | } | 173 | } |
174 | + | ||
175 | + public static String getCurrentViewId(){ | ||
176 | + return getFacesContext().getViewRoot().getViewId(); | ||
177 | + } | ||
178 | + | ||
174 | } | 179 | } |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Redirector.java
@@ -48,11 +48,10 @@ import javax.faces.application.ViewHandler; | @@ -48,11 +48,10 @@ import javax.faces.application.ViewHandler; | ||
48 | import javax.faces.context.FacesContext; | 48 | import javax.faces.context.FacesContext; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | - * | ||
52 | * Utility class to redirect determined page to another one. | 51 | * Utility class to redirect determined page to another one. |
53 | * | 52 | * |
54 | * @author SERPRO | 53 | * @author SERPRO |
55 | - * */ | 54 | + */ |
56 | public class Redirector { | 55 | public class Redirector { |
57 | 56 | ||
58 | private Redirector() { | 57 | private Redirector() { |
@@ -74,6 +73,7 @@ public class Redirector { | @@ -74,6 +73,7 @@ public class Redirector { | ||
74 | } | 73 | } |
75 | 74 | ||
76 | } catch (NullPointerException cause) { | 75 | } catch (NullPointerException cause) { |
76 | + cause.printStackTrace(); | ||
77 | throw new PageNotFoundException(viewId); | 77 | throw new PageNotFoundException(viewId); |
78 | 78 | ||
79 | } catch (IOException cause) { | 79 | } catch (IOException cause) { |
impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationBean.java
@@ -46,9 +46,7 @@ public class AuthenticationBean implements Serializable { | @@ -46,9 +46,7 @@ public class AuthenticationBean implements Serializable { | ||
46 | 46 | ||
47 | private static final long serialVersionUID = 1L; | 47 | private static final long serialVersionUID = 1L; |
48 | 48 | ||
49 | - private String msg = "Authentication Exception"; | ||
50 | - | ||
51 | public String getMsg() { | 49 | public String getMsg() { |
52 | - throw new NotLoggedInException(msg); | 50 | + throw new NotLoggedInException(""); |
53 | } | 51 | } |
54 | } | 52 | } |
impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationExceptionTest.java
@@ -1,89 +0,0 @@ | @@ -1,89 +0,0 @@ | ||
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 exception.handler.authentication; | ||
38 | - | ||
39 | -import static org.junit.Assert.assertTrue; | ||
40 | - | ||
41 | -import java.io.IOException; | ||
42 | -import java.net.URL; | ||
43 | - | ||
44 | -import org.apache.commons.httpclient.HttpClient; | ||
45 | -import org.apache.commons.httpclient.HttpException; | ||
46 | -import org.apache.commons.httpclient.methods.GetMethod; | ||
47 | -import org.jboss.arquillian.container.test.api.Deployment; | ||
48 | -import org.jboss.arquillian.junit.Arquillian; | ||
49 | -import org.jboss.arquillian.test.api.ArquillianResource; | ||
50 | -import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
51 | -import org.junit.Test; | ||
52 | -import org.junit.runner.RunWith; | ||
53 | - | ||
54 | -import test.Tests; | ||
55 | - | ||
56 | -@RunWith(Arquillian.class) | ||
57 | -public class AuthenticationExceptionTest { | ||
58 | - | ||
59 | - @ArquillianResource | ||
60 | - private URL deploymentUrl; | ||
61 | - | ||
62 | - private static final String PATH = "src/test/resources/exception-handler-authentication"; | ||
63 | - | ||
64 | - @Deployment(testable = false) | ||
65 | - public static WebArchive createDeployment() { | ||
66 | - return Tests.createDeployment().addClass(AuthenticationExceptionTest.class).addClass(AuthenticationBean.class) | ||
67 | - .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | ||
68 | - .addAsWebResource(Tests.createFileAsset(PATH + "/login.xhtml"), "login.xhtml") | ||
69 | - .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | ||
70 | - } | ||
71 | - | ||
72 | - @Test | ||
73 | - public void authenticationException() { | ||
74 | - HttpClient client = new HttpClient(); | ||
75 | - GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | ||
76 | - | ||
77 | - try { | ||
78 | - client.executeMethod(method); | ||
79 | - String message = method.getResponseBodyAsString(); | ||
80 | - System.out.println("MESAGE: " + message); | ||
81 | - assertTrue(message.contains("Called the page /login")); | ||
82 | - | ||
83 | - } catch (HttpException e) { | ||
84 | - e.printStackTrace(); | ||
85 | - } catch (IOException e) { | ||
86 | - e.printStackTrace(); | ||
87 | - } | ||
88 | - } | ||
89 | -} |
impl/extension/jsf/src/test/java/exception/handler/authentication/HandledAuthenticationExceptionTest.java
0 → 100644
@@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
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 exception.handler.authentication; | ||
38 | + | ||
39 | +import static org.junit.Assert.assertTrue; | ||
40 | + | ||
41 | +import java.io.IOException; | ||
42 | +import java.net.URL; | ||
43 | + | ||
44 | +import org.apache.commons.httpclient.HttpClient; | ||
45 | +import org.apache.commons.httpclient.HttpException; | ||
46 | +import org.apache.commons.httpclient.methods.GetMethod; | ||
47 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
48 | +import org.jboss.arquillian.junit.Arquillian; | ||
49 | +import org.jboss.arquillian.test.api.ArquillianResource; | ||
50 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
51 | +import org.junit.Test; | ||
52 | +import org.junit.runner.RunWith; | ||
53 | + | ||
54 | +import test.Tests; | ||
55 | + | ||
56 | +@RunWith(Arquillian.class) | ||
57 | +public class HandledAuthenticationExceptionTest { | ||
58 | + | ||
59 | + @ArquillianResource | ||
60 | + private URL deploymentUrl; | ||
61 | + | ||
62 | + private static final String PATH = "src/test/resources/exception-handler-authentication"; | ||
63 | + | ||
64 | + @Deployment(testable = false) | ||
65 | + public static WebArchive createDeployment() { | ||
66 | + return Tests.createDeployment().addClasses(AuthenticationBean.class) | ||
67 | + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | ||
68 | + .addAsWebResource(Tests.createFileAsset(PATH + "/login.xhtml"), "login.xhtml") | ||
69 | + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | ||
70 | + } | ||
71 | + | ||
72 | + @Test | ||
73 | + public void authenticationException() throws HttpException, IOException { | ||
74 | + HttpClient client = new HttpClient(); | ||
75 | + GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | ||
76 | + | ||
77 | + client.executeMethod(method); | ||
78 | + String message = method.getResponseBodyAsString(); | ||
79 | + assertTrue(message.contains("Called the page /login")); | ||
80 | + } | ||
81 | +} |
impl/extension/jsf/src/test/java/exception/handler/authentication/UnhandledAuthenticationExceptionTest.java
0 → 100644
@@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
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 exception.handler.authentication; | ||
38 | + | ||
39 | +import static org.apache.http.HttpStatus.SC_FORBIDDEN; | ||
40 | +import static org.junit.Assert.assertEquals; | ||
41 | + | ||
42 | +import java.io.IOException; | ||
43 | +import java.net.URL; | ||
44 | + | ||
45 | +import org.apache.commons.httpclient.HttpClient; | ||
46 | +import org.apache.commons.httpclient.HttpException; | ||
47 | +import org.apache.commons.httpclient.methods.GetMethod; | ||
48 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
49 | +import org.jboss.arquillian.junit.Arquillian; | ||
50 | +import org.jboss.arquillian.test.api.ArquillianResource; | ||
51 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
52 | +import org.junit.Test; | ||
53 | +import org.junit.runner.RunWith; | ||
54 | + | ||
55 | +import test.Tests; | ||
56 | + | ||
57 | +@RunWith(Arquillian.class) | ||
58 | +public class UnhandledAuthenticationExceptionTest { | ||
59 | + | ||
60 | + @ArquillianResource | ||
61 | + private URL deploymentUrl; | ||
62 | + | ||
63 | + private static final String PATH = "src/test/resources/exception-handler-authentication"; | ||
64 | + | ||
65 | + @Deployment(testable = false) | ||
66 | + public static WebArchive createDeployment() { | ||
67 | + return Tests.createDeployment().addClasses(AuthenticationBean.class) | ||
68 | + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | ||
69 | + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") | ||
70 | + .addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
71 | + } | ||
72 | + | ||
73 | + @Test | ||
74 | + public void authenticationException() throws HttpException, IOException { | ||
75 | + HttpClient client = new HttpClient(); | ||
76 | + GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | ||
77 | + | ||
78 | + int status = client.executeMethod(method); | ||
79 | + assertEquals(SC_FORBIDDEN, status); | ||
80 | + } | ||
81 | +} |
impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationBean.java
@@ -46,20 +46,7 @@ public class AuthorizationBean implements Serializable { | @@ -46,20 +46,7 @@ public class AuthorizationBean implements Serializable { | ||
46 | 46 | ||
47 | private static final long serialVersionUID = 1L; | 47 | private static final long serialVersionUID = 1L; |
48 | 48 | ||
49 | - private String correctMessage = "Authorization Message."; | ||
50 | - | ||
51 | - private String exceptionMessage = "Authorization Exception!"; | ||
52 | - | ||
53 | - public String getCorrectMessage() { | ||
54 | - return correctMessage; | ||
55 | - } | ||
56 | - | ||
57 | - public String getExceptionMessage() { | ||
58 | - throw new AuthorizationException(exceptionMessage); | 49 | + public String getThrowExceptionMessage() { |
50 | + throw new AuthorizationException("Authorization Exception!"); | ||
59 | } | 51 | } |
60 | - | ||
61 | - public void loadExceptionMessage() { | ||
62 | - throw new AuthorizationException(exceptionMessage); | ||
63 | - } | ||
64 | - | ||
65 | } | 52 | } |
impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationHandledExceptionTest.java
@@ -1,94 +0,0 @@ | @@ -1,94 +0,0 @@ | ||
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 exception.handler.authorization; | ||
38 | - | ||
39 | -import static org.junit.Assert.assertNotSame; | ||
40 | -import static org.junit.Assert.assertTrue; | ||
41 | - | ||
42 | -import java.io.IOException; | ||
43 | -import java.net.URL; | ||
44 | - | ||
45 | -import org.apache.commons.httpclient.HttpClient; | ||
46 | -import org.apache.commons.httpclient.HttpException; | ||
47 | -import org.apache.commons.httpclient.HttpStatus; | ||
48 | -import org.apache.commons.httpclient.methods.GetMethod; | ||
49 | -import org.jboss.arquillian.container.test.api.Deployment; | ||
50 | -import org.jboss.arquillian.junit.Arquillian; | ||
51 | -import org.jboss.arquillian.test.api.ArquillianResource; | ||
52 | -import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
53 | -import org.junit.Test; | ||
54 | -import org.junit.runner.RunWith; | ||
55 | - | ||
56 | -import test.Tests; | ||
57 | - | ||
58 | -@RunWith(Arquillian.class) | ||
59 | -public class AuthorizationHandledExceptionTest { | ||
60 | - | ||
61 | - @ArquillianResource | ||
62 | - private URL deploymentUrl; | ||
63 | - | ||
64 | - private static final String PATH = "src/test/resources/exception-handler-authorization"; | ||
65 | - | ||
66 | - @Deployment(testable = false) | ||
67 | - public static WebArchive createDeployment() { | ||
68 | - return Tests.createDeployment().addClass(AuthorizationHandledExceptionTest.class).addClass(AuthorizationBean.class) | ||
69 | - .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | ||
70 | - .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") | ||
71 | - .addAsWebInfResource(Tests.createFileAsset(PATH + "/pretty-config.xml"), "pretty-config.xml"); | ||
72 | - | ||
73 | - } | ||
74 | - | ||
75 | - @Test | ||
76 | - public void authorizationHandledException() { | ||
77 | - HttpClient client = new HttpClient(); | ||
78 | - GetMethod method = new GetMethod(deploymentUrl + "/index"); | ||
79 | - | ||
80 | - try { | ||
81 | - int status = client.executeMethod(method); | ||
82 | - String message = method.getResponseBodyAsString(); | ||
83 | - | ||
84 | - assertNotSame(HttpStatus.SC_INTERNAL_SERVER_ERROR, status); | ||
85 | - assertTrue(message.contains("Authorization Message.")); | ||
86 | - assertTrue(message.contains("Authorization Exception!")); | ||
87 | - | ||
88 | - } catch (HttpException e) { | ||
89 | - e.printStackTrace(); | ||
90 | - } catch (IOException e) { | ||
91 | - e.printStackTrace(); | ||
92 | - } | ||
93 | - } | ||
94 | -} |
impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationNotHandledExceptionTest.java
@@ -1,93 +0,0 @@ | @@ -1,93 +0,0 @@ | ||
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 exception.handler.authorization; | ||
38 | - | ||
39 | -import static org.junit.Assert.assertEquals; | ||
40 | -import static org.junit.Assert.assertFalse; | ||
41 | -import static org.junit.Assert.assertTrue; | ||
42 | - | ||
43 | -import java.io.IOException; | ||
44 | -import java.net.URL; | ||
45 | - | ||
46 | -import org.apache.commons.httpclient.HttpClient; | ||
47 | -import org.apache.commons.httpclient.HttpException; | ||
48 | -import org.apache.commons.httpclient.HttpStatus; | ||
49 | -import org.apache.commons.httpclient.methods.GetMethod; | ||
50 | -import org.jboss.arquillian.container.test.api.Deployment; | ||
51 | -import org.jboss.arquillian.junit.Arquillian; | ||
52 | -import org.jboss.arquillian.test.api.ArquillianResource; | ||
53 | -import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
54 | -import org.junit.Test; | ||
55 | -import org.junit.runner.RunWith; | ||
56 | - | ||
57 | -import test.Tests; | ||
58 | - | ||
59 | -@RunWith(Arquillian.class) | ||
60 | -public class AuthorizationNotHandledExceptionTest { | ||
61 | - | ||
62 | - @ArquillianResource | ||
63 | - private URL deploymentUrl; | ||
64 | - | ||
65 | - private static final String PATH = "src/test/resources/exception-handler-authorization"; | ||
66 | - | ||
67 | - @Deployment(testable = false) | ||
68 | - public static WebArchive createDeployment() { | ||
69 | - return Tests.createDeployment().addClass(AuthorizationNotHandledExceptionTest.class).addClass(AuthorizationBean.class) | ||
70 | - .addAsWebResource(Tests.createFileAsset(PATH + "/page.xhtml"), "page.xhtml") | ||
71 | - .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | ||
72 | - } | ||
73 | - | ||
74 | - @Test | ||
75 | - public void authorizationNotHandledException() { | ||
76 | - HttpClient client = new HttpClient(); | ||
77 | - GetMethod method = new GetMethod(deploymentUrl + "/page.jsf"); | ||
78 | - | ||
79 | - try { | ||
80 | - int status = client.executeMethod(method); | ||
81 | - String message = method.getResponseBodyAsString(); | ||
82 | - | ||
83 | - assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, status); | ||
84 | - assertTrue(message.contains("Authorization Exception!")); | ||
85 | - assertFalse(message.contains("Authorization Message.")); | ||
86 | - | ||
87 | - } catch (HttpException e) { | ||
88 | - e.printStackTrace(); | ||
89 | - } catch (IOException e) { | ||
90 | - e.printStackTrace(); | ||
91 | - } | ||
92 | - } | ||
93 | -} |
impl/extension/jsf/src/test/java/exception/handler/authorization/HandledAuthorizationExceptionTest.java
0 → 100644
@@ -0,0 +1,86 @@ | @@ -0,0 +1,86 @@ | ||
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 exception.handler.authorization; | ||
38 | + | ||
39 | +import static org.apache.commons.httpclient.HttpStatus.SC_OK; | ||
40 | +import static org.junit.Assert.assertEquals; | ||
41 | +import static org.junit.Assert.assertTrue; | ||
42 | + | ||
43 | +import java.io.IOException; | ||
44 | +import java.net.URL; | ||
45 | + | ||
46 | +import org.apache.commons.httpclient.HttpClient; | ||
47 | +import org.apache.commons.httpclient.HttpException; | ||
48 | +import org.apache.commons.httpclient.methods.GetMethod; | ||
49 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
50 | +import org.jboss.arquillian.junit.Arquillian; | ||
51 | +import org.jboss.arquillian.test.api.ArquillianResource; | ||
52 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
53 | +import org.junit.Test; | ||
54 | +import org.junit.runner.RunWith; | ||
55 | + | ||
56 | +import test.Tests; | ||
57 | + | ||
58 | +@RunWith(Arquillian.class) | ||
59 | +public class HandledAuthorizationExceptionTest { | ||
60 | + | ||
61 | + @ArquillianResource | ||
62 | + private URL deploymentUrl; | ||
63 | + | ||
64 | + private static final String PATH = "src/test/resources/exception-handler-authorization"; | ||
65 | + | ||
66 | + @Deployment(testable = false) | ||
67 | + public static WebArchive createDeployment() { | ||
68 | + return Tests.createDeployment().addClasses(AuthorizationBean.class) | ||
69 | + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | ||
70 | + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") | ||
71 | + .addAsWebInfResource(Tests.createFileAsset(PATH + "/pretty-config.xml"), "pretty-config.xml"); | ||
72 | + | ||
73 | + } | ||
74 | + | ||
75 | + @Test | ||
76 | + public void authorizationException() throws HttpException, IOException { | ||
77 | + HttpClient client = new HttpClient(); | ||
78 | + GetMethod method = new GetMethod(deploymentUrl + "/index"); | ||
79 | + | ||
80 | + int status = client.executeMethod(method); | ||
81 | + String message = method.getResponseBodyAsString(); | ||
82 | + | ||
83 | + assertEquals(SC_OK, status); | ||
84 | + assertTrue(message.contains("Authorization Exception!")); | ||
85 | + } | ||
86 | +} |
impl/extension/jsf/src/test/java/exception/handler/authorization/UnhandledAuthorizationExceptionTest.java
0 → 100644
@@ -0,0 +1,80 @@ | @@ -0,0 +1,80 @@ | ||
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 exception.handler.authorization; | ||
38 | + | ||
39 | +import static org.apache.commons.httpclient.HttpStatus.SC_UNAUTHORIZED; | ||
40 | +import static org.junit.Assert.assertEquals; | ||
41 | + | ||
42 | +import java.io.IOException; | ||
43 | +import java.net.URL; | ||
44 | + | ||
45 | +import org.apache.commons.httpclient.HttpClient; | ||
46 | +import org.apache.commons.httpclient.HttpException; | ||
47 | +import org.apache.commons.httpclient.methods.GetMethod; | ||
48 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
49 | +import org.jboss.arquillian.junit.Arquillian; | ||
50 | +import org.jboss.arquillian.test.api.ArquillianResource; | ||
51 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
52 | +import org.junit.Test; | ||
53 | +import org.junit.runner.RunWith; | ||
54 | + | ||
55 | +import test.Tests; | ||
56 | + | ||
57 | +@RunWith(Arquillian.class) | ||
58 | +public class UnhandledAuthorizationExceptionTest { | ||
59 | + | ||
60 | + @ArquillianResource | ||
61 | + private URL deploymentUrl; | ||
62 | + | ||
63 | + private static final String PATH = "src/test/resources/exception-handler-authorization"; | ||
64 | + | ||
65 | + @Deployment(testable = false) | ||
66 | + public static WebArchive createDeployment() { | ||
67 | + return Tests.createDeployment().addClasses(AuthorizationBean.class) | ||
68 | + .addAsWebResource(Tests.createFileAsset(PATH + "/error.xhtml"), "error.xhtml") | ||
69 | + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | ||
70 | + } | ||
71 | + | ||
72 | + @Test | ||
73 | + public void authorizationException() throws HttpException, IOException { | ||
74 | + HttpClient client = new HttpClient(); | ||
75 | + GetMethod method = new GetMethod(deploymentUrl + "/error.jsf"); | ||
76 | + | ||
77 | + int status = client.executeMethod(method); | ||
78 | + assertEquals(SC_UNAUTHORIZED, status); | ||
79 | + } | ||
80 | +} |
impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerDefaultConfigTest.java
@@ -51,48 +51,33 @@ import org.jboss.shrinkwrap.api.spec.WebArchive; | @@ -51,48 +51,33 @@ import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
51 | import org.junit.Test; | 51 | import org.junit.Test; |
52 | import org.junit.runner.RunWith; | 52 | import org.junit.runner.RunWith; |
53 | 53 | ||
54 | +import test.Tests; | ||
54 | import exception.handler.common.DummyException; | 55 | import exception.handler.common.DummyException; |
55 | import exception.handler.common.ExceptionHandlerConfigBean; | 56 | import exception.handler.common.ExceptionHandlerConfigBean; |
56 | -import test.Tests; | ||
57 | 57 | ||
58 | @RunWith(Arquillian.class) | 58 | @RunWith(Arquillian.class) |
59 | -public class ExceptionHandlerDefaultConfigTest{ | 59 | +public class ExceptionHandlerDefaultConfigTest { |
60 | 60 | ||
61 | @ArquillianResource | 61 | @ArquillianResource |
62 | private URL deploymentUrl; | 62 | private URL deploymentUrl; |
63 | - | 63 | + |
64 | private static final String PATH = "src/test/resources/exception-handler-config"; | 64 | private static final String PATH = "src/test/resources/exception-handler-config"; |
65 | 65 | ||
66 | @Deployment(testable = false) | 66 | @Deployment(testable = false) |
67 | public static WebArchive createDeployment() { | 67 | public static WebArchive createDeployment() { |
68 | - return Tests.createDeployment().addClass(ExceptionHandlerDefaultConfigTest.class) | ||
69 | - .addClass(DummyException.class) | ||
70 | - .addClass(ExceptionHandlerConfigBean.class) | 68 | + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) |
71 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | 69 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") |
72 | .addAsWebResource(Tests.createFileAsset(PATH + "/application_error.xhtml"), "application_error.xhtml") | 70 | .addAsWebResource(Tests.createFileAsset(PATH + "/application_error.xhtml"), "application_error.xhtml") |
73 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | 71 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); |
74 | } | 72 | } |
75 | - | 73 | + |
76 | @Test | 74 | @Test |
77 | - public void defaultConfiguration() { | 75 | + public void defaultConfiguration() throws HttpException, IOException { |
78 | HttpClient client = new HttpClient(); | 76 | HttpClient client = new HttpClient(); |
79 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | 77 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); |
80 | - | ||
81 | - try { | ||
82 | - client.executeMethod(method); | ||
83 | - String message = method.getResponseBodyAsString(); | ||
84 | - assertTrue(message.contains("Called the page /application_error")); | ||
85 | - | ||
86 | - } catch (HttpException e) { | ||
87 | - e.printStackTrace(); | ||
88 | - } catch (IOException e) { | ||
89 | - e.printStackTrace(); | ||
90 | - } | 78 | + |
79 | + client.executeMethod(method); | ||
80 | + String message = method.getResponseBodyAsString(); | ||
81 | + assertTrue(message.contains("Called the page /application_error")); | ||
91 | } | 82 | } |
92 | } | 83 | } |
93 | - | ||
94 | - | ||
95 | - | ||
96 | - | ||
97 | - | ||
98 | - |
impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerRedirectConfigTest.java
@@ -65,8 +65,7 @@ public class ExceptionHandlerRedirectConfigTest { | @@ -65,8 +65,7 @@ public class ExceptionHandlerRedirectConfigTest { | ||
65 | 65 | ||
66 | @Deployment(testable = false) | 66 | @Deployment(testable = false) |
67 | public static WebArchive createDeployment() { | 67 | public static WebArchive createDeployment() { |
68 | - return Tests.createDeployment().addClass(ExceptionHandlerRedirectConfigTest.class) | ||
69 | - .addClass(DummyException.class).addClass(ExceptionHandlerConfigBean.class) | 68 | + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) |
70 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | 69 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") |
71 | .addAsWebResource(Tests.createFileAsset(PATH + "/error_page.xhtml"), "error_page.xhtml") | 70 | .addAsWebResource(Tests.createFileAsset(PATH + "/error_page.xhtml"), "error_page.xhtml") |
72 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") | 71 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") |
impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionNotHandlerConfigTest.java
@@ -66,8 +66,7 @@ public class ExceptionNotHandlerConfigTest { | @@ -66,8 +66,7 @@ public class ExceptionNotHandlerConfigTest { | ||
66 | 66 | ||
67 | @Deployment(testable = false) | 67 | @Deployment(testable = false) |
68 | public static WebArchive createDeployment() { | 68 | public static WebArchive createDeployment() { |
69 | - return Tests.createDeployment().addClass(ExceptionNotHandlerConfigTest.class).addClass(DummyException.class) | ||
70 | - .addClass(ExceptionHandlerConfigBean.class) | 69 | + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) |
71 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | 70 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") |
72 | .addAsWebResource(Tests.createFileAsset(PATH + "/application_error.xhtml"), "application_error.xhtml") | 71 | .addAsWebResource(Tests.createFileAsset(PATH + "/application_error.xhtml"), "application_error.xhtml") |
73 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") | 72 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") |
@@ -75,17 +74,10 @@ public class ExceptionNotHandlerConfigTest { | @@ -75,17 +74,10 @@ public class ExceptionNotHandlerConfigTest { | ||
75 | } | 74 | } |
76 | 75 | ||
77 | @Test | 76 | @Test |
78 | - public void notHandlerConfiguration() { | 77 | + public void notHandlerConfiguration() throws HttpException, IOException { |
79 | HttpClient client = new HttpClient(); | 78 | HttpClient client = new HttpClient(); |
80 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | 79 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); |
81 | 80 | ||
82 | - try { | ||
83 | - assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, client.executeMethod(method)); | ||
84 | - | ||
85 | - } catch (HttpException e) { | ||
86 | - e.printStackTrace(); | ||
87 | - } catch (IOException e) { | ||
88 | - e.printStackTrace(); | ||
89 | - } | 81 | + assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, client.executeMethod(method)); |
90 | } | 82 | } |
91 | } | 83 | } |
impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionHandlerRedirectConfigTest.java
@@ -65,8 +65,7 @@ public class ExceptionHandlerRedirectConfigTest { | @@ -65,8 +65,7 @@ public class ExceptionHandlerRedirectConfigTest { | ||
65 | 65 | ||
66 | @Deployment(testable = false) | 66 | @Deployment(testable = false) |
67 | public static WebArchive createDeployment() { | 67 | public static WebArchive createDeployment() { |
68 | - return Tests.createDeployment().addClass(ExceptionHandlerRedirectConfigTest.class) | ||
69 | - .addClass(DummyException.class).addClass(ExceptionHandlerConfigBean.class) | 68 | + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) |
70 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | 69 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") |
71 | .addAsWebResource(Tests.createFileAsset(PATH + "/error_page.xhtml"), "error_page.xhtml") | 70 | .addAsWebResource(Tests.createFileAsset(PATH + "/error_page.xhtml"), "error_page.xhtml") |
72 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") | 71 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") |
@@ -74,19 +73,12 @@ public class ExceptionHandlerRedirectConfigTest { | @@ -74,19 +73,12 @@ public class ExceptionHandlerRedirectConfigTest { | ||
74 | } | 73 | } |
75 | 74 | ||
76 | @Test | 75 | @Test |
77 | - public void notHandlerConfiguration() { | 76 | + public void notHandlerConfiguration() throws HttpException, IOException { |
78 | HttpClient client = new HttpClient(); | 77 | HttpClient client = new HttpClient(); |
79 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | 78 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); |
80 | 79 | ||
81 | - try { | ||
82 | - client.executeMethod(method); | ||
83 | - String message = method.getResponseBodyAsString(); | ||
84 | - assertTrue(message.contains("Called the page /error_page")); | ||
85 | - | ||
86 | - } catch (HttpException e) { | ||
87 | - e.printStackTrace(); | ||
88 | - } catch (IOException e) { | ||
89 | - e.printStackTrace(); | ||
90 | - } | 80 | + client.executeMethod(method); |
81 | + String message = method.getResponseBodyAsString(); | ||
82 | + assertTrue(message.contains("Called the page /error_page")); | ||
91 | } | 83 | } |
92 | } | 84 | } |
impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionNotHandlerConfigTest.java
@@ -66,8 +66,7 @@ public class ExceptionNotHandlerConfigTest { | @@ -66,8 +66,7 @@ public class ExceptionNotHandlerConfigTest { | ||
66 | 66 | ||
67 | @Deployment(testable = false) | 67 | @Deployment(testable = false) |
68 | public static WebArchive createDeployment() { | 68 | public static WebArchive createDeployment() { |
69 | - return Tests.createDeployment().addClass(ExceptionNotHandlerConfigTest.class).addClass(DummyException.class) | ||
70 | - .addClass(ExceptionHandlerConfigBean.class) | 69 | + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) |
71 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | 70 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") |
72 | .addAsWebResource(Tests.createFileAsset(PATH + "/application_error.xhtml"), "application_error.xhtml") | 71 | .addAsWebResource(Tests.createFileAsset(PATH + "/application_error.xhtml"), "application_error.xhtml") |
73 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") | 72 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") |
@@ -75,18 +74,11 @@ public class ExceptionNotHandlerConfigTest { | @@ -75,18 +74,11 @@ public class ExceptionNotHandlerConfigTest { | ||
75 | } | 74 | } |
76 | 75 | ||
77 | @Test | 76 | @Test |
78 | - public void notHandlerConfiguration() { | 77 | + public void notHandlerConfiguration() throws HttpException, IOException { |
79 | HttpClient client = new HttpClient(); | 78 | HttpClient client = new HttpClient(); |
80 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | 79 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); |
81 | 80 | ||
82 | - try { | ||
83 | - int status = client.executeMethod(method); | ||
84 | - assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, status); | ||
85 | - | ||
86 | - } catch (HttpException e) { | ||
87 | - e.printStackTrace(); | ||
88 | - } catch (IOException e) { | ||
89 | - e.printStackTrace(); | ||
90 | - } | 81 | + int status = client.executeMethod(method); |
82 | + assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, status); | ||
91 | } | 83 | } |
92 | } | 84 | } |
impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java
@@ -25,20 +25,18 @@ public class RedirectExceptionTest { | @@ -25,20 +25,18 @@ public class RedirectExceptionTest { | ||
25 | 25 | ||
26 | @ArquillianResource | 26 | @ArquillianResource |
27 | private URL deploymentUrl; | 27 | private URL deploymentUrl; |
28 | - | 28 | + |
29 | private static final String PATH = "src/test/resources/exception-handler-redirect"; | 29 | private static final String PATH = "src/test/resources/exception-handler-redirect"; |
30 | 30 | ||
31 | @Deployment(testable = false) | 31 | @Deployment(testable = false) |
32 | public static WebArchive createDeployment() { | 32 | public static WebArchive createDeployment() { |
33 | - return Tests.createDeployment().addClass(RedirectExceptionTest.class) | ||
34 | - .addClass(RedirectBean.class) | ||
35 | - .addClass(ExceptionWithCorrectRedirect.class) | 33 | + return Tests.createDeployment().addClasses(RedirectBean.class, ExceptionWithCorrectRedirect.class) |
36 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | 34 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") |
37 | .addAsWebResource(Tests.createFileAsset(PATH + "/page.xhtml"), "page.xhtml") | 35 | .addAsWebResource(Tests.createFileAsset(PATH + "/page.xhtml"), "page.xhtml") |
38 | .addAsWebResource(Tests.createFileAsset(PATH + "/redirect.xhtml"), "redirect.xhtml") | 36 | .addAsWebResource(Tests.createFileAsset(PATH + "/redirect.xhtml"), "redirect.xhtml") |
39 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | 37 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); |
40 | } | 38 | } |
41 | - | 39 | + |
42 | @Test | 40 | @Test |
43 | public void handleExceptionWithCorrectRedirect() { | 41 | public void handleExceptionWithCorrectRedirect() { |
44 | HttpClient client = new HttpClient(); | 42 | HttpClient client = new HttpClient(); |
@@ -47,7 +45,7 @@ public class RedirectExceptionTest { | @@ -47,7 +45,7 @@ public class RedirectExceptionTest { | ||
47 | try { | 45 | try { |
48 | int status = client.executeMethod(method); | 46 | int status = client.executeMethod(method); |
49 | String message = method.getResponseBodyAsString(); | 47 | String message = method.getResponseBodyAsString(); |
50 | - | 48 | + |
51 | assertEquals(HttpStatus.SC_OK, status); | 49 | assertEquals(HttpStatus.SC_OK, status); |
52 | assertFalse(message.contains("Correct Redirect Exception!")); | 50 | assertFalse(message.contains("Correct Redirect Exception!")); |
53 | assertTrue(message.contains("Page redirected!")); | 51 | assertTrue(message.contains("Page redirected!")); |
@@ -58,7 +56,7 @@ public class RedirectExceptionTest { | @@ -58,7 +56,7 @@ public class RedirectExceptionTest { | ||
58 | e.printStackTrace(); | 56 | e.printStackTrace(); |
59 | } | 57 | } |
60 | } | 58 | } |
61 | - | 59 | + |
62 | @Test | 60 | @Test |
63 | public void handleExceptionWithWrongRedirect() { | 61 | public void handleExceptionWithWrongRedirect() { |
64 | HttpClient client = new HttpClient(); | 62 | HttpClient client = new HttpClient(); |
@@ -75,4 +73,3 @@ public class RedirectExceptionTest { | @@ -75,4 +73,3 @@ public class RedirectExceptionTest { | ||
75 | } | 73 | } |
76 | } | 74 | } |
77 | } | 75 | } |
78 | - |
impl/extension/jsf/src/test/java/message/MessageTest.java
@@ -63,26 +63,18 @@ public class MessageTest { | @@ -63,26 +63,18 @@ public class MessageTest { | ||
63 | 63 | ||
64 | @Deployment(testable = false) | 64 | @Deployment(testable = false) |
65 | public static WebArchive createDeployment() { | 65 | public static WebArchive createDeployment() { |
66 | - return Tests.createDeployment().addClass(MessageTest.class) | ||
67 | - .addClass(MessageBean.class) | 66 | + return Tests.createDeployment().addClasses(MessageBean.class) |
68 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | 67 | .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") |
69 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | 68 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); |
70 | } | 69 | } |
71 | 70 | ||
72 | @Test | 71 | @Test |
73 | - public void showMessage() { | 72 | + public void showMessage() throws HttpException, IOException { |
74 | HttpClient client = new HttpClient(); | 73 | HttpClient client = new HttpClient(); |
75 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | 74 | GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); |
76 | 75 | ||
77 | - try { | ||
78 | - client.executeMethod(method); | ||
79 | - String message = method.getResponseBodyAsString(); | ||
80 | - assertTrue(message.contains("Message shown.")); | ||
81 | - | ||
82 | - } catch (HttpException e) { | ||
83 | - e.printStackTrace(); | ||
84 | - } catch (IOException e) { | ||
85 | - e.printStackTrace(); | ||
86 | - } | 76 | + client.executeMethod(method); |
77 | + String message = method.getResponseBodyAsString(); | ||
78 | + assertTrue(message.contains("Message shown.")); | ||
87 | } | 79 | } |
88 | } | 80 | } |
impl/extension/jsf/src/test/java/proxy/FacesContextProxyBean.java
0 → 100644
@@ -0,0 +1,61 @@ | @@ -0,0 +1,61 @@ | ||
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 proxy; | ||
38 | + | ||
39 | +import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED; | ||
40 | + | ||
41 | +import javax.faces.context.FacesContext; | ||
42 | +import javax.inject.Inject; | ||
43 | +import javax.inject.Named; | ||
44 | +import javax.servlet.http.HttpServletResponse; | ||
45 | + | ||
46 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
47 | + | ||
48 | +@Named | ||
49 | +public class FacesContextProxyBean { | ||
50 | + | ||
51 | + @Inject | ||
52 | + private HttpServletResponse response; | ||
53 | + | ||
54 | + public String getOk() { | ||
55 | + FacesContext facesContext = Beans.getReference(FacesContext.class); | ||
56 | + facesContext.responseComplete(); | ||
57 | + | ||
58 | + response.setStatus(SC_ACCEPTED); | ||
59 | + return null; | ||
60 | + } | ||
61 | +} |
impl/extension/jsf/src/test/java/proxy/FacesContextProxyServlet.java
@@ -36,8 +36,12 @@ | @@ -36,8 +36,12 @@ | ||
36 | */ | 36 | */ |
37 | package proxy; | 37 | package proxy; |
38 | 38 | ||
39 | +import static javax.servlet.http.HttpServletResponse.SC_EXPECTATION_FAILED; | ||
40 | +import static javax.servlet.http.HttpServletResponse.SC_OK; | ||
41 | + | ||
39 | import java.io.IOException; | 42 | import java.io.IOException; |
40 | 43 | ||
44 | +import javax.enterprise.context.ContextNotActiveException; | ||
41 | import javax.faces.context.FacesContext; | 45 | import javax.faces.context.FacesContext; |
42 | import javax.servlet.ServletException; | 46 | import javax.servlet.ServletException; |
43 | import javax.servlet.annotation.WebServlet; | 47 | import javax.servlet.annotation.WebServlet; |
@@ -45,9 +49,6 @@ import javax.servlet.http.HttpServlet; | @@ -45,9 +49,6 @@ import javax.servlet.http.HttpServlet; | ||
45 | import javax.servlet.http.HttpServletRequest; | 49 | import javax.servlet.http.HttpServletRequest; |
46 | import javax.servlet.http.HttpServletResponse; | 50 | import javax.servlet.http.HttpServletResponse; |
47 | 51 | ||
48 | -import org.apache.commons.httpclient.HttpStatus; | ||
49 | - | ||
50 | -import br.gov.frameworkdemoiselle.internal.proxy.FacesContextProxy; | ||
51 | import br.gov.frameworkdemoiselle.util.Beans; | 52 | import br.gov.frameworkdemoiselle.util.Beans; |
52 | 53 | ||
53 | @WebServlet("/index") | 54 | @WebServlet("/index") |
@@ -55,15 +56,14 @@ public class FacesContextProxyServlet extends HttpServlet { | @@ -55,15 +56,14 @@ public class FacesContextProxyServlet extends HttpServlet { | ||
55 | 56 | ||
56 | private static final long serialVersionUID = 1L; | 57 | private static final long serialVersionUID = 1L; |
57 | 58 | ||
58 | - private FacesContext facesContext; | ||
59 | - | ||
60 | @Override | 59 | @Override |
61 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | 60 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
62 | - facesContext = Beans.getReference(FacesContext.class); | ||
63 | - if (facesContext.getClass() == FacesContextProxy.class) { | ||
64 | - response.setStatus(HttpStatus.SC_OK); | ||
65 | - } else { | ||
66 | - response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); | 61 | + try { |
62 | + Beans.getReference(FacesContext.class); | ||
63 | + response.setStatus(SC_OK); | ||
64 | + | ||
65 | + } catch (ContextNotActiveException cause) { | ||
66 | + response.setStatus(SC_EXPECTATION_FAILED); | ||
67 | } | 67 | } |
68 | } | 68 | } |
69 | } | 69 | } |
impl/extension/jsf/src/test/java/proxy/FacesContextProxyTest.java
@@ -36,6 +36,8 @@ | @@ -36,6 +36,8 @@ | ||
36 | */ | 36 | */ |
37 | package proxy; | 37 | package proxy; |
38 | 38 | ||
39 | +import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED; | ||
40 | +import static javax.servlet.http.HttpServletResponse.SC_EXPECTATION_FAILED; | ||
39 | import static org.junit.Assert.assertEquals; | 41 | import static org.junit.Assert.assertEquals; |
40 | 42 | ||
41 | import java.io.IOException; | 43 | import java.io.IOException; |
@@ -43,7 +45,6 @@ import java.net.URL; | @@ -43,7 +45,6 @@ import java.net.URL; | ||
43 | 45 | ||
44 | import org.apache.commons.httpclient.HttpClient; | 46 | import org.apache.commons.httpclient.HttpClient; |
45 | import org.apache.commons.httpclient.HttpException; | 47 | import org.apache.commons.httpclient.HttpException; |
46 | -import org.apache.commons.httpclient.HttpStatus; | ||
47 | import org.apache.commons.httpclient.methods.GetMethod; | 48 | import org.apache.commons.httpclient.methods.GetMethod; |
48 | import org.jboss.arquillian.container.test.api.Deployment; | 49 | import org.jboss.arquillian.container.test.api.Deployment; |
49 | import org.jboss.arquillian.junit.Arquillian; | 50 | import org.jboss.arquillian.junit.Arquillian; |
@@ -64,22 +65,26 @@ public class FacesContextProxyTest { | @@ -64,22 +65,26 @@ public class FacesContextProxyTest { | ||
64 | 65 | ||
65 | @Deployment(testable = false) | 66 | @Deployment(testable = false) |
66 | public static WebArchive createDeployment() { | 67 | public static WebArchive createDeployment() { |
67 | - return Tests.createDeployment().addClass(FacesContextProxyServlet.class) | 68 | + return Tests.createDeployment().addClasses(FacesContextProxyServlet.class, FacesContextProxyBean.class) |
69 | + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | ||
68 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | 70 | .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); |
69 | } | 71 | } |
70 | 72 | ||
71 | @Test | 73 | @Test |
72 | - public void facesContextProxy() { | 74 | + public void validProxyCreated() throws HttpException, IOException { |
75 | + HttpClient client = new HttpClient(); | ||
76 | + GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | ||
77 | + | ||
78 | + int status = client.executeMethod(method); | ||
79 | + assertEquals(SC_ACCEPTED, status); | ||
80 | + } | ||
81 | + | ||
82 | + @Test | ||
83 | + public void inValidProxyCreatedCausedByContextNotActiveException() throws HttpException, IOException { | ||
73 | HttpClient client = new HttpClient(); | 84 | HttpClient client = new HttpClient(); |
74 | GetMethod method = new GetMethod(deploymentUrl + "/index"); | 85 | GetMethod method = new GetMethod(deploymentUrl + "/index"); |
75 | 86 | ||
76 | - try { | ||
77 | - int status = client.executeMethod(method); | ||
78 | - assertEquals( HttpStatus.SC_OK, status); | ||
79 | - } catch (HttpException e) { | ||
80 | - e.printStackTrace(); | ||
81 | - } catch (IOException e) { | ||
82 | - e.printStackTrace(); | ||
83 | - } | 87 | + int status = client.executeMethod(method); |
88 | + assertEquals(SC_EXPECTATION_FAILED, status); | ||
84 | } | 89 | } |
85 | } | 90 | } |
impl/extension/jsf/src/test/java/test/Tests.java
@@ -81,15 +81,12 @@ import br.gov.frameworkdemoiselle.util.Parameter; | @@ -81,15 +81,12 @@ import br.gov.frameworkdemoiselle.util.Parameter; | ||
81 | import br.gov.frameworkdemoiselle.util.Redirector; | 81 | import br.gov.frameworkdemoiselle.util.Redirector; |
82 | 82 | ||
83 | @Ignore | 83 | @Ignore |
84 | +@SuppressWarnings("deprecation") | ||
84 | public final class Tests { | 85 | public final class Tests { |
85 | 86 | ||
86 | private Tests() { | 87 | private Tests() { |
87 | } | 88 | } |
88 | 89 | ||
89 | - public static WebArchive createDeployment(final Class<?> baseClass) { | ||
90 | - return createDeployment().addPackages(true, baseClass.getPackage()).addClass(Tests.class); | ||
91 | - } | ||
92 | - | ||
93 | public static WebArchive createDeployment() { | 90 | public static WebArchive createDeployment() { |
94 | File[] libs = Maven.resolver().offline().loadPomFromFile("pom.xml", "arquillian-test") | 91 | File[] libs = Maven.resolver().offline().loadPomFromFile("pom.xml", "arquillian-test") |
95 | .importCompileAndRuntimeDependencies().resolve().withTransitivity().asFile(); | 92 | .importCompileAndRuntimeDependencies().resolve().withTransitivity().asFile(); |
impl/extension/jsf/src/test/resources/.arquillian-glassfish-embedded.profile
impl/extension/jsf/src/test/resources/exception-handler-authentication/demoiselle.properties
0 → 100644
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +# Demoiselle Framework | ||
2 | +# Copyright (C) 2010 SERPRO | ||
3 | +# ---------------------------------------------------------------------------- | ||
4 | +# This file is part of Demoiselle Framework. | ||
5 | +# | ||
6 | +# Demoiselle Framework is free software; you can redistribute it and/or | ||
7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | ||
8 | +# as published by the Free Software Foundation. | ||
9 | +# | ||
10 | +# This program is distributed in the hope that it will be useful, | ||
11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | +# GNU General Public License for more details. | ||
14 | +# | ||
15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | ||
16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | +# ---------------------------------------------------------------------------- | ||
20 | +# Este arquivo é parte do Framework Demoiselle. | ||
21 | +# | ||
22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
24 | +# do Software Livre (FSF). | ||
25 | +# | ||
26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
29 | +# para maiores detalhes. | ||
30 | +# | ||
31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
35 | + | ||
36 | +frameworkdemoiselle.security.redirect.enabled=false | ||
0 | \ No newline at end of file | 37 | \ No newline at end of file |
impl/extension/jsf/src/test/resources/exception-handler-authorization/error.xhtml
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
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 | +<html xmlns:h="http://java.sun.com/jsf/html"> | ||
38 | + | ||
39 | + <h:body> | ||
40 | + #{authorizationBean.throwExceptionMessage} | ||
41 | + </h:body> | ||
42 | + | ||
43 | +</html> |
impl/extension/jsf/src/test/resources/exception-handler-authorization/index.xhtml
1 | -<html xmlns:h="http://java.sun.com/jsf/html" | ||
2 | - xmlns:ui="http://java.sun.com/jsf/facelets"> | 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 | +<html xmlns:h="http://java.sun.com/jsf/html"> | ||
3 | 38 | ||
4 | <h:body> | 39 | <h:body> |
5 | - #{authorizationBean.correctMessage} | ||
6 | - <h:messages /> | 40 | + <h:messages /> |
7 | </h:body> | 41 | </h:body> |
8 | 42 | ||
9 | </html> | 43 | </html> |
impl/extension/jsf/src/test/resources/exception-handler-authorization/page.xhtml
@@ -1,10 +0,0 @@ | @@ -1,10 +0,0 @@ | ||
1 | -<html xmlns:h="http://java.sun.com/jsf/html" | ||
2 | - xmlns:ui="http://java.sun.com/jsf/facelets"> | ||
3 | - | ||
4 | - <h:body> | ||
5 | - #{authorizationBean.correctMessage} | ||
6 | - #{authorizationBean.exceptionMessage} | ||
7 | - <h:messages /> | ||
8 | - </h:body> | ||
9 | - | ||
10 | -</html> | ||
11 | \ No newline at end of file | 0 | \ No newline at end of file |
impl/extension/jsf/src/test/resources/exception-handler-authorization/pretty-config.xml
@@ -43,7 +43,7 @@ | @@ -43,7 +43,7 @@ | ||
43 | <url-mapping id="index"> | 43 | <url-mapping id="index"> |
44 | <pattern value="/index" /> | 44 | <pattern value="/index" /> |
45 | <view-id value="/index.jsf" /> | 45 | <view-id value="/index.jsf" /> |
46 | - <action>#{authorizationBean.loadExceptionMessage}</action> | 46 | + <action>#{authorizationBean.getThrowExceptionMessage}</action> |
47 | </url-mapping> | 47 | </url-mapping> |
48 | 48 | ||
49 | </pretty-config> | 49 | </pretty-config> |
50 | \ No newline at end of file | 50 | \ No newline at end of file |
impl/extension/jsf/src/test/resources/exception-handler-authorization/web.xml
@@ -71,4 +71,9 @@ | @@ -71,4 +71,9 @@ | ||
71 | <servlet-name>Faces Servlet</servlet-name> | 71 | <servlet-name>Faces Servlet</servlet-name> |
72 | <url-pattern>*.jsf</url-pattern> | 72 | <url-pattern>*.jsf</url-pattern> |
73 | </servlet-mapping> | 73 | </servlet-mapping> |
74 | + | ||
75 | + <context-param> | ||
76 | + <param-name>facelets.SKIP_COMMENTS</param-name> | ||
77 | + <param-value>true</param-value> | ||
78 | + </context-param> | ||
74 | </web-app> | 79 | </web-app> |
75 | \ No newline at end of file | 80 | \ No newline at end of file |
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
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 | +<html xmlns:h="http://java.sun.com/jsf/html"> | ||
38 | + | ||
39 | + <h:body> | ||
40 | + #{facesContextProxyBean.ok} | ||
41 | + </h:body> | ||
42 | + | ||
43 | +</html> |
impl/extension/jsf/src/test/resources/proxy/web.xml
@@ -48,7 +48,17 @@ | @@ -48,7 +48,17 @@ | ||
48 | <filter-name>Demoiselle Servlet Filter</filter-name> | 48 | <filter-name>Demoiselle Servlet Filter</filter-name> |
49 | <url-pattern>/*</url-pattern> | 49 | <url-pattern>/*</url-pattern> |
50 | </filter-mapping> | 50 | </filter-mapping> |
51 | - | 51 | + |
52 | + <servlet> | ||
53 | + <servlet-name>Faces Servlet</servlet-name> | ||
54 | + <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> | ||
55 | + <load-on-startup>1</load-on-startup> | ||
56 | + </servlet> | ||
57 | + <servlet-mapping> | ||
58 | + <servlet-name>Faces Servlet</servlet-name> | ||
59 | + <url-pattern>*.jsf</url-pattern> | ||
60 | + </servlet-mapping> | ||
61 | + | ||
52 | <servlet> | 62 | <servlet> |
53 | <servlet-name>Servlet Class</servlet-name> | 63 | <servlet-name>Servlet Class</servlet-name> |
54 | <servlet-class>proxy.FacesContextProxyServlet</servlet-class> | 64 | <servlet-class>proxy.FacesContextProxyServlet</servlet-class> |
@@ -56,6 +66,6 @@ | @@ -56,6 +66,6 @@ | ||
56 | <servlet-mapping> | 66 | <servlet-mapping> |
57 | <servlet-name>Servlet Class</servlet-name> | 67 | <servlet-name>Servlet Class</servlet-name> |
58 | <url-pattern>/index</url-pattern> | 68 | <url-pattern>/index</url-pattern> |
59 | - </servlet-mapping> | 69 | + </servlet-mapping> |
60 | 70 | ||
61 | </web-app> | 71 | </web-app> |
62 | \ No newline at end of file | 72 | \ No newline at end of file |
impl/extension/jsf/src/test/resources/xxx/web.xml
@@ -1,52 +0,0 @@ | @@ -1,52 +0,0 @@ | ||
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 | -<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
38 | - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> | ||
39 | - | ||
40 | - <listener> | ||
41 | - <listener-class>br.gov.frameworkdemoiselle.util.ServletListener</listener-class> | ||
42 | - </listener> | ||
43 | - <filter> | ||
44 | - <filter-name>Demoiselle Servlet Filter</filter-name> | ||
45 | - <filter-class>br.gov.frameworkdemoiselle.util.ServletFilter</filter-class> | ||
46 | - </filter> | ||
47 | - <filter-mapping> | ||
48 | - <filter-name>Demoiselle Servlet Filter</filter-name> | ||
49 | - <url-pattern>/*</url-pattern> | ||
50 | - </filter-mapping> | ||
51 | - | ||
52 | -</web-app> | ||
53 | \ No newline at end of file | 0 | \ No newline at end of file |
impl/extension/jta/pom.xml
@@ -72,6 +72,17 @@ | @@ -72,6 +72,17 @@ | ||
72 | <artifactId>jta</artifactId> | 72 | <artifactId>jta</artifactId> |
73 | </dependency> | 73 | </dependency> |
74 | 74 | ||
75 | + <!-- for tests --> | ||
76 | + <dependency> | ||
77 | + <groupId>org.jboss.arquillian.container</groupId> | ||
78 | + <artifactId>arquillian-glassfish-embedded-3.1</artifactId> | ||
79 | + <scope>test</scope> | ||
80 | + </dependency> | ||
81 | + <dependency> | ||
82 | + <groupId>org.glassfish.main.extras</groupId> | ||
83 | + <artifactId>glassfish-embedded-all</artifactId> | ||
84 | + <scope>test</scope> | ||
85 | + </dependency> | ||
75 | <dependency> | 86 | <dependency> |
76 | <groupId>org.hibernate</groupId> | 87 | <groupId>org.hibernate</groupId> |
77 | <artifactId>hibernate-entitymanager</artifactId> | 88 | <artifactId>hibernate-entitymanager</artifactId> |
impl/extension/jta/src/test/resources/.arquillian-glassfish-embedded.profile
impl/extension/se/pom.xml
@@ -53,7 +53,21 @@ | @@ -53,7 +53,21 @@ | ||
53 | Extensão para aplicações SE | 53 | Extensão para aplicações SE |
54 | </description> | 54 | </description> |
55 | <url>http://www.frameworkdemoiselle.gov.br</url> | 55 | <url>http://www.frameworkdemoiselle.gov.br</url> |
56 | - | 56 | + |
57 | + <dependencies> | ||
58 | + <!-- for tests --> | ||
59 | + <dependency> | ||
60 | + <groupId>org.jboss.arquillian.container</groupId> | ||
61 | + <artifactId>arquillian-weld-se-embedded-1.1</artifactId> | ||
62 | + <scope>test</scope> | ||
63 | + </dependency> | ||
64 | + <dependency> | ||
65 | + <groupId>org.jboss.weld.se</groupId> | ||
66 | + <artifactId>weld-se-core</artifactId> | ||
67 | + <scope>test</scope> | ||
68 | + </dependency> | ||
69 | + </dependencies> | ||
70 | + | ||
57 | <licenses> | 71 | <licenses> |
58 | <license> | 72 | <license> |
59 | <name>GNU Lesser General Public License, Version 3</name> | 73 | <name>GNU Lesser General Public License, Version 3</name> |