Commit 92f95eb8df046c44ba54d0234eb86bdad8476d96
1 parent
e55c4eda
Exists in
master
FacesContext deixou de ter @RequestEscoped, adicionado FacesContextProxy
e retirado o FacesContextProducer.
Showing
4 changed files
with
185 additions
and
149 deletions
Show diff stats
impl/extension/jsf/pom.xml
@@ -83,7 +83,7 @@ | @@ -83,7 +83,7 @@ | ||
83 | <dependency> | 83 | <dependency> |
84 | <groupId>org.glassfish.web</groupId> | 84 | <groupId>org.glassfish.web</groupId> |
85 | <artifactId>el-impl</artifactId> | 85 | <artifactId>el-impl</artifactId> |
86 | - <scope>test</scope> | 86 | + <scope>provided</scope> |
87 | </dependency> | 87 | </dependency> |
88 | </dependencies> | 88 | </dependencies> |
89 | 89 |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/producer/FacesContextProducer.java
@@ -1,61 +0,0 @@ | @@ -1,61 +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 br.gov.frameworkdemoiselle.internal.producer; | ||
38 | - | ||
39 | -import javax.enterprise.context.ContextNotActiveException; | ||
40 | -import javax.enterprise.context.RequestScoped; | ||
41 | -import javax.enterprise.inject.Default; | ||
42 | -import javax.enterprise.inject.Produces; | ||
43 | -import javax.faces.context.FacesContext; | ||
44 | - | ||
45 | -public class FacesContextProducer { | ||
46 | - | ||
47 | - @Produces | ||
48 | - @RequestScoped | ||
49 | - @Default | ||
50 | - public FacesContext create() { | ||
51 | - FacesContext ctx = FacesContext.getCurrentInstance(); | ||
52 | - | ||
53 | - if (ctx == null) { | ||
54 | - // TODO Usar o bundle para a mensagem | ||
55 | - throw new ContextNotActiveException("FacesContext isn't active"); | ||
56 | - } | ||
57 | - | ||
58 | - return ctx; | ||
59 | - } | ||
60 | - | ||
61 | -} |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/FacesContextProxy.java
0 → 100644
@@ -0,0 +1,184 @@ | @@ -0,0 +1,184 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.proxy; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.util.Iterator; | ||
5 | +import java.util.List; | ||
6 | +import java.util.Map; | ||
7 | + | ||
8 | +import javax.el.ELContext; | ||
9 | +import javax.enterprise.inject.Default; | ||
10 | +import javax.faces.application.Application; | ||
11 | +import javax.faces.application.FacesMessage; | ||
12 | +import javax.faces.application.FacesMessage.Severity; | ||
13 | +import javax.faces.application.ProjectStage; | ||
14 | +import javax.faces.component.UIViewRoot; | ||
15 | +import javax.faces.context.ExceptionHandler; | ||
16 | +import javax.faces.context.ExternalContext; | ||
17 | +import javax.faces.context.FacesContext; | ||
18 | +import javax.faces.context.PartialViewContext; | ||
19 | +import javax.faces.context.ResponseStream; | ||
20 | +import javax.faces.context.ResponseWriter; | ||
21 | +import javax.faces.event.PhaseId; | ||
22 | +import javax.faces.render.RenderKit; | ||
23 | + | ||
24 | +@Default | ||
25 | +public class FacesContextProxy extends FacesContext implements Serializable { | ||
26 | + | ||
27 | + private static final long serialVersionUID = 1L; | ||
28 | + | ||
29 | + private FacesContext getDelegate() { | ||
30 | + return FacesContext.getCurrentInstance(); | ||
31 | + } | ||
32 | + | ||
33 | + public int hashCode() { | ||
34 | + return getDelegate().hashCode(); | ||
35 | + } | ||
36 | + | ||
37 | + public boolean equals(Object obj) { | ||
38 | + return getDelegate().equals(obj); | ||
39 | + } | ||
40 | + | ||
41 | + public Application getApplication() { | ||
42 | + return getDelegate().getApplication(); | ||
43 | + } | ||
44 | + | ||
45 | + public Map<Object, Object> getAttributes() { | ||
46 | + return getDelegate().getAttributes(); | ||
47 | + } | ||
48 | + | ||
49 | + public PartialViewContext getPartialViewContext() { | ||
50 | + return getDelegate().getPartialViewContext(); | ||
51 | + } | ||
52 | + | ||
53 | + public Iterator<String> getClientIdsWithMessages() { | ||
54 | + return getDelegate().getClientIdsWithMessages(); | ||
55 | + } | ||
56 | + | ||
57 | + public String toString() { | ||
58 | + return getDelegate().toString(); | ||
59 | + } | ||
60 | + | ||
61 | + public ELContext getELContext() { | ||
62 | + return getDelegate().getELContext(); | ||
63 | + } | ||
64 | + | ||
65 | + public ExceptionHandler getExceptionHandler() { | ||
66 | + return getDelegate().getExceptionHandler(); | ||
67 | + } | ||
68 | + | ||
69 | + public void setExceptionHandler(ExceptionHandler exceptionHandler) { | ||
70 | + getDelegate().setExceptionHandler(exceptionHandler); | ||
71 | + } | ||
72 | + | ||
73 | + public ExternalContext getExternalContext() { | ||
74 | + return getDelegate().getExternalContext(); | ||
75 | + } | ||
76 | + | ||
77 | + public Severity getMaximumSeverity() { | ||
78 | + return getDelegate().getMaximumSeverity(); | ||
79 | + } | ||
80 | + | ||
81 | + public Iterator<FacesMessage> getMessages() { | ||
82 | + return getDelegate().getMessages(); | ||
83 | + } | ||
84 | + | ||
85 | + public List<FacesMessage> getMessageList() { | ||
86 | + return getDelegate().getMessageList(); | ||
87 | + } | ||
88 | + | ||
89 | + public List<FacesMessage> getMessageList(String clientId) { | ||
90 | + return getDelegate().getMessageList(clientId); | ||
91 | + } | ||
92 | + | ||
93 | + public Iterator<FacesMessage> getMessages(String clientId) { | ||
94 | + return getDelegate().getMessages(clientId); | ||
95 | + } | ||
96 | + | ||
97 | + public RenderKit getRenderKit() { | ||
98 | + return getDelegate().getRenderKit(); | ||
99 | + } | ||
100 | + | ||
101 | + public boolean getRenderResponse() { | ||
102 | + return getDelegate().getRenderResponse(); | ||
103 | + } | ||
104 | + | ||
105 | + public boolean getResponseComplete() { | ||
106 | + return getDelegate().getResponseComplete(); | ||
107 | + } | ||
108 | + | ||
109 | + public boolean isValidationFailed() { | ||
110 | + return getDelegate().isValidationFailed(); | ||
111 | + } | ||
112 | + | ||
113 | + public ResponseStream getResponseStream() { | ||
114 | + return getDelegate().getResponseStream(); | ||
115 | + } | ||
116 | + | ||
117 | + public void setResponseStream(ResponseStream responseStream) { | ||
118 | + getDelegate().setResponseStream(responseStream); | ||
119 | + } | ||
120 | + | ||
121 | + public ResponseWriter getResponseWriter() { | ||
122 | + return getDelegate().getResponseWriter(); | ||
123 | + } | ||
124 | + | ||
125 | + public void setResponseWriter(ResponseWriter responseWriter) { | ||
126 | + getDelegate().setResponseWriter(responseWriter); | ||
127 | + } | ||
128 | + | ||
129 | + public UIViewRoot getViewRoot() { | ||
130 | + return getDelegate().getViewRoot(); | ||
131 | + } | ||
132 | + | ||
133 | + public void setViewRoot(UIViewRoot root) { | ||
134 | + getDelegate().setViewRoot(root); | ||
135 | + } | ||
136 | + | ||
137 | + public void addMessage(String clientId, FacesMessage message) { | ||
138 | + getDelegate().addMessage(clientId, message); | ||
139 | + } | ||
140 | + | ||
141 | + public boolean isReleased() { | ||
142 | + return getDelegate().isReleased(); | ||
143 | + } | ||
144 | + | ||
145 | + public void release() { | ||
146 | + getDelegate().release(); | ||
147 | + } | ||
148 | + | ||
149 | + public void renderResponse() { | ||
150 | + getDelegate().renderResponse(); | ||
151 | + } | ||
152 | + | ||
153 | + public boolean isPostback() { | ||
154 | + return getDelegate().isPostback(); | ||
155 | + } | ||
156 | + | ||
157 | + public void responseComplete() { | ||
158 | + getDelegate().responseComplete(); | ||
159 | + } | ||
160 | + | ||
161 | + public void validationFailed() { | ||
162 | + getDelegate().validationFailed(); | ||
163 | + } | ||
164 | + | ||
165 | + public PhaseId getCurrentPhaseId() { | ||
166 | + return getDelegate().getCurrentPhaseId(); | ||
167 | + } | ||
168 | + | ||
169 | + public void setCurrentPhaseId(PhaseId currentPhaseId) { | ||
170 | + getDelegate().setCurrentPhaseId(currentPhaseId); | ||
171 | + } | ||
172 | + | ||
173 | + public void setProcessingEvents(boolean processingEvents) { | ||
174 | + getDelegate().setProcessingEvents(processingEvents); | ||
175 | + } | ||
176 | + | ||
177 | + public boolean isProcessingEvents() { | ||
178 | + return getDelegate().isProcessingEvents(); | ||
179 | + } | ||
180 | + | ||
181 | + public boolean isProjectStage(ProjectStage stage) { | ||
182 | + return getDelegate().isProjectStage(stage); | ||
183 | + } | ||
184 | +} |
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/producer/FacesContextProducerTest.java
@@ -1,87 +0,0 @@ | @@ -1,87 +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 br.gov.frameworkdemoiselle.internal.producer; | ||
38 | -import static org.easymock.EasyMock.expect; | ||
39 | -import static org.junit.Assert.assertEquals; | ||
40 | -import static org.junit.Assert.fail; | ||
41 | -import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
42 | -import static org.powermock.api.easymock.PowerMock.replay; | ||
43 | -import static org.powermock.api.easymock.PowerMock.verifyAll; | ||
44 | - | ||
45 | -import javax.enterprise.context.ContextNotActiveException; | ||
46 | -import javax.faces.context.FacesContext; | ||
47 | - | ||
48 | -import org.junit.Before; | ||
49 | -import org.junit.Test; | ||
50 | -import org.junit.runner.RunWith; | ||
51 | -import org.powermock.api.easymock.PowerMock; | ||
52 | -import org.powermock.core.classloader.annotations.PrepareForTest; | ||
53 | -import org.powermock.modules.junit4.PowerMockRunner; | ||
54 | - | ||
55 | -@RunWith(PowerMockRunner.class) | ||
56 | -@PrepareForTest({ FacesContext.class }) | ||
57 | -public class FacesContextProducerTest { | ||
58 | - | ||
59 | - private FacesContextProducer producer; | ||
60 | - | ||
61 | - @Before | ||
62 | - public void before() { | ||
63 | - this.producer = new FacesContextProducer(); | ||
64 | - } | ||
65 | - | ||
66 | - @Test | ||
67 | - public void createOK() { | ||
68 | - mockStatic(FacesContext.class); | ||
69 | - FacesContext facesContext = PowerMock.createMock(FacesContext.class); | ||
70 | - expect(FacesContext.getCurrentInstance()).andReturn(facesContext); | ||
71 | - replay(facesContext, FacesContext.class); | ||
72 | - assertEquals(facesContext, producer.create()); | ||
73 | - verifyAll(); | ||
74 | - } | ||
75 | - | ||
76 | - @Test | ||
77 | - public void createNOK() { | ||
78 | - mockStatic(FacesContext.class); | ||
79 | - expect(FacesContext.getCurrentInstance()).andReturn(null); | ||
80 | - replay(FacesContext.class); | ||
81 | - try { | ||
82 | - this.producer.create(); | ||
83 | - fail(); | ||
84 | - } catch(ContextNotActiveException exception) {} | ||
85 | - verifyAll(); | ||
86 | - } | ||
87 | -} |