Commit d76ee5a98c18941e894f1db2de6a425b8188a071

Authored by Ednara Oliveira
1 parent c302acc6
Exists in master

Refatoração de testes unitários da extensão demoiselle-jsf

impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityObserver.java
... ... @@ -87,7 +87,8 @@ public class SecurityObserver implements Serializable {
87 87 clear();
88 88 FacesContext facesContext = Beans.getReference(FacesContext.class);
89 89  
90   - if (!config.getLoginPage().equals(facesContext.getViewRoot().getViewId())) {
  90 + if (!config.getLoginPage()
  91 + .equals(facesContext.getViewRoot().getViewId())) {
91 92 getSavedParams().putAll(facesContext.getExternalContext().getRequestParameterMap());
92 93 savedViewId = facesContext.getViewRoot().getViewId();
93 94 }
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/FacesBootstrapTest.java
... ... @@ -1,72 +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.bootstrap;
38   -//import org.junit.Ignore;
39   -//import static org.powermock.api.easymock.PowerMock.createMock;
40   -//import static org.powermock.api.easymock.PowerMock.replay;
41   -//import static org.powermock.api.easymock.PowerMock.verifyAll;
42   -//
43   -//import javax.enterprise.inject.spi.AfterBeanDiscovery;
44   -//
45   -//import org.easymock.EasyMock;
46   -//import org.junit.Before;
47   -//import org.junit.Test;
48   -//import org.junit.runner.RunWith;
49   -//import org.powermock.modules.junit4.PowerMockRunner;
50   -//
51   -//import br.gov.frameworkdemoiselle.internal.context.ViewContext;
52   -//@Ignore
53   -//@RunWith(PowerMockRunner.class)
54   -//public class FacesBootstrapTest {
55   -//
56   -// private JsfBootstrap bootstrap;
57   -//
58   -// @Before
59   -// public void before() {
60   -// bootstrap = new JsfBootstrap();
61   -// }
62   -//
63   -// @Test
64   -// public void testLoadContexts() {
65   -// AfterBeanDiscovery event = createMock(AfterBeanDiscovery.class);
66   -// event.addContext(EasyMock.anyObject(ViewContext.class));
67   -// replay(event);
68   -// bootstrap.loadContexts(event);
69   -// verifyAll();
70   -// }
71   -//
72   -//}
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/JsfBootstrapTest.java 0 → 100644
... ... @@ -0,0 +1,131 @@
  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.bootstrap;
  38 +
  39 +import static org.easymock.EasyMock.expect;
  40 +import static org.powermock.api.easymock.PowerMock.createMock;
  41 +import static org.powermock.api.easymock.PowerMock.mockStatic;
  42 +import static org.powermock.api.easymock.PowerMock.replayAll;
  43 +import static org.powermock.api.easymock.PowerMock.replay;
  44 +import static org.powermock.api.easymock.PowerMock.verifyAll;
  45 +import static org.powermock.api.easymock.PowerMock.verify;
  46 +
  47 +import java.lang.annotation.Annotation;
  48 +import java.util.ArrayList;
  49 +import java.util.List;
  50 +import java.util.Locale;
  51 +
  52 +import javax.enterprise.context.spi.Contextual;
  53 +import javax.enterprise.context.spi.CreationalContext;
  54 +import javax.enterprise.inject.spi.AfterBeanDiscovery;
  55 +import javax.enterprise.inject.spi.AfterDeploymentValidation;
  56 +
  57 +import junit.framework.Assert;
  58 +
  59 +import org.easymock.EasyMock;
  60 +import org.junit.Before;
  61 +import org.junit.Test;
  62 +import org.junit.rules.TemporaryFolder;
  63 +import org.junit.runner.RunWith;
  64 +import org.powermock.core.classloader.annotations.PrepareForTest;
  65 +import org.powermock.modules.junit4.PowerMockRunner;
  66 +import org.powermock.reflect.Whitebox;
  67 +
  68 +import br.gov.frameworkdemoiselle.internal.context.Contexts;
  69 +import br.gov.frameworkdemoiselle.internal.context.CustomContext;
  70 +import br.gov.frameworkdemoiselle.internal.context.ViewContext;
  71 +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
  72 +import br.gov.frameworkdemoiselle.util.Beans;
  73 +
  74 +@RunWith(PowerMockRunner.class)
  75 +@PrepareForTest({ Beans.class, Contexts.class })
  76 +public class JsfBootstrapTest {
  77 +
  78 + private JsfBootstrap bootstrap;
  79 +
  80 + private AfterBeanDiscovery event;
  81 +
  82 + @Before
  83 + public void before() {
  84 + event = createMock(AfterBeanDiscovery.class);
  85 + mockStatic(Beans.class);
  86 + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()).anyTimes();
  87 + replay(Beans.class);
  88 + bootstrap = new JsfBootstrap();
  89 + }
  90 +
  91 + @Test
  92 + public void testStoreContexts() {
  93 + bootstrap.storeContexts(event);
  94 + replay(event);
  95 +
  96 + Assert.assertEquals(event, Whitebox.getInternalState(bootstrap, "afterBeanDiscoveryEvent"));
  97 + List<CustomContext> context = Whitebox.getInternalState(bootstrap, "tempContexts");
  98 + Assert.assertEquals(1, context.size());
  99 + verifyAll();
  100 + }
  101 +
  102 + @Test
  103 + public void testAddContexts() {
  104 + List<CustomContext> tempContexts = new ArrayList<CustomContext>();
  105 + CustomContext tempContext = new ViewContext();
  106 + tempContexts.add(tempContext);
  107 + Whitebox.setInternalState(bootstrap, "tempContexts", tempContexts);
  108 + Whitebox.setInternalState(bootstrap, "afterBeanDiscoveryEvent", event);
  109 +
  110 + AfterDeploymentValidation afterDeploymentValidation = createMock(AfterDeploymentValidation.class);
  111 +
  112 + event.addContext(tempContext);
  113 +
  114 + replay(event, afterDeploymentValidation);
  115 +
  116 + bootstrap.addContexts(afterDeploymentValidation);
  117 + verifyAll();
  118 + }
  119 +
  120 + @Test
  121 + public void testRemoveContexts() {
  122 + bootstrap.storeContexts(event);
  123 +
  124 + AfterShutdownProccess afterShutdownProccess = createMock(AfterShutdownProccess.class);
  125 + replay(event, afterShutdownProccess);
  126 + bootstrap.removeContexts(afterShutdownProccess);
  127 +
  128 + verifyAll();
  129 + }
  130 +
  131 +}
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ExceptionHandlerConfigTest.java 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +package br.gov.frameworkdemoiselle.internal.configuration;
  2 +
  3 +import static org.junit.Assert.assertEquals;
  4 +
  5 +import org.junit.Before;
  6 +import org.junit.Test;
  7 +
  8 +public class ExceptionHandlerConfigTest {
  9 +
  10 + private ExceptionHandlerConfig config;
  11 +
  12 + @Before
  13 + public void setUP() throws Exception {
  14 + this.config = new ExceptionHandlerConfig();
  15 + }
  16 +
  17 + @Test
  18 + public void testGetExceptionPage() {
  19 + assertEquals("/application_error", config.getExceptionPage());
  20 + }
  21 +
  22 + @Test
  23 + public void testIsHandleApplicationException() {
  24 + assertEquals(true, config.isHandleApplicationException());
  25 + }
  26 +
  27 +}
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/JsfSecurityConfigTest.java 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +package br.gov.frameworkdemoiselle.internal.configuration;
  2 +
  3 +import static org.junit.Assert.assertEquals;
  4 +
  5 +import org.junit.Before;
  6 +import org.junit.Test;
  7 +
  8 +
  9 +public class JsfSecurityConfigTest {
  10 +
  11 + private JsfSecurityConfig config;
  12 +
  13 + @Before
  14 + public void setUp() throws Exception {
  15 + this.config = new JsfSecurityConfig();
  16 + }
  17 +
  18 + @Test
  19 + public void testGetLoginPage() {
  20 + assertEquals("/login", config.getLoginPage());
  21 + }
  22 +
  23 + @Test
  24 + public void testGetRedirectAfterLogin() {
  25 + assertEquals("/index", config.getRedirectAfterLogin());
  26 + }
  27 +
  28 + @Test
  29 + public void testGetRedirectAfterLogout() {
  30 + assertEquals("/login", config.getRedirectAfterLogout());
  31 + }
  32 +
  33 + @Test
  34 + public void testIsRedirectEnabled() {
  35 + assertEquals(true, config.isRedirectEnabled());
  36 + }
  37 +
  38 +}
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/ApplicationExceptionHandlerTest.java
... ... @@ -35,7 +35,7 @@
35 35 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
36 36 */
37 37 package br.gov.frameworkdemoiselle.internal.implementation;
38   -import org.junit.Ignore;
  38 +
39 39 import static junit.framework.Assert.assertFalse;
40 40 import static junit.framework.Assert.assertTrue;
41 41 import static org.easymock.EasyMock.expect;
... ... @@ -66,7 +66,6 @@ import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig;
66 66 import br.gov.frameworkdemoiselle.util.Beans;
67 67 import br.gov.frameworkdemoiselle.util.Faces;
68 68  
69   -@Ignore
70 69 @RunWith(PowerMockRunner.class)
71 70 @PrepareForTest({ Beans.class, FacesContext.class, Faces.class })
72 71 public class ApplicationExceptionHandlerTest {
... ... @@ -142,10 +141,10 @@ public class ApplicationExceptionHandlerTest {
142 141 public void testHandleAnApplicationExceptionOnRenderResponse() {
143 142  
144 143 AnnotatedAppException exception = new AnnotatedAppException();
145   -// PhaseId phaseId = PhaseId.RENDER_RESPONSE;
  144 + // PhaseId phaseId = PhaseId.RENDER_RESPONSE;
146 145  
147 146 expect(eventContext.getException()).andReturn(exception);
148   -// expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
  147 + // expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
149 148 expect(config.isHandleApplicationException()).andReturn(false);
150 149  
151 150 handler.getWrapped().handle();
... ... @@ -165,10 +164,10 @@ public class ApplicationExceptionHandlerTest {
165 164 public void testHandleAnyException() {
166 165  
167 166 SomeException exception = new SomeException();
168   -// PhaseId phaseId = PowerMock.createMock(PhaseId.class);
  167 + // PhaseId phaseId = PowerMock.createMock(PhaseId.class);
169 168  
170 169 expect(eventContext.getException()).andReturn(exception);
171   -// expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
  170 + // expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
172 171 expect(config.isHandleApplicationException()).andReturn(true);
173 172  
174 173 handler.getWrapped().handle();
... ... @@ -204,5 +203,4 @@ public class ApplicationExceptionHandlerTest {
204 203 verifyAll();
205 204  
206 205 }
207   -
208 206 }
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/AuthorizationExceptionHandlerTest.java
1   -///*
2   -// * Demoiselle Framework
3   -// * Copyright (C) 2010 SERPRO
4   -// * ----------------------------------------------------------------------------
5   -// * This file is part of Demoiselle Framework.
6   -// *
7   -// * Demoiselle Framework is free software; you can redistribute it and/or
8   -// * modify it under the terms of the GNU Lesser General Public License version 3
9   -// * as published by the Free Software Foundation.
10   -// *
11   -// * This program is distributed in the hope that it will be useful,
12   -// * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   -// * GNU General Public License for more details.
15   -// *
16   -// * You should have received a copy of the GNU Lesser General Public License version 3
17   -// * along with this program; if not, see <http://www.gnu.org/licenses/>
18   -// * or write to the Free Software Foundation, Inc., 51 Franklin Street,
19   -// * Fifth Floor, Boston, MA 02110-1301, USA.
20   -// * ----------------------------------------------------------------------------
21   -// * Este arquivo é parte do Framework Demoiselle.
22   -// *
23   -// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
24   -// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
25   -// * do Software Livre (FSF).
26   -// *
27   -// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
28   -// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
29   -// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
30   -// * para maiores detalhes.
31   -// *
32   -// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
33   -// * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
34   -// * ou escreva para a Fundação do Software Livre (FSF) Inc.,
35   -// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
36   -// */
37   -//package br.gov.frameworkdemoiselle.internal.implementation;
38   -//
39   -//import static junit.framework.Assert.assertFalse;
40   -//import static junit.framework.Assert.assertTrue;
41   -//import static org.easymock.EasyMock.expect;
42   -//import static org.powermock.api.easymock.PowerMock.createMock;
43   -//import static org.powermock.api.easymock.PowerMock.expectLastCall;
44   -//import static org.powermock.api.easymock.PowerMock.mockStatic;
45   -//import static org.powermock.api.easymock.PowerMock.replayAll;
46   -//import static org.powermock.api.easymock.PowerMock.verifyAll;
47   -//
48   -//import java.util.ArrayList;
49   -//import java.util.Collection;
50   -//
51   -//import javax.faces.context.ExceptionHandler;
52   -//import javax.faces.context.FacesContext;
53   -//import javax.faces.event.ExceptionQueuedEvent;
54   -//import javax.faces.event.ExceptionQueuedEventContext;
55   -//import javax.faces.event.PhaseId;
56   -//
57   -//import org.junit.Before;
58   -//import org.junit.Test;
59   -//import org.junit.runner.RunWith;
60   -//import org.powermock.api.easymock.PowerMock;
61   -//import org.powermock.core.classloader.annotations.PrepareForTest;
62   -//import org.powermock.modules.junit4.PowerMockRunner;
63   -//
64   -//import br.gov.frameworkdemoiselle.security.AuthorizationException;
65   -//import br.gov.frameworkdemoiselle.util.Faces;
66   -//
67   -//@RunWith(PowerMockRunner.class)
68   -//@PrepareForTest({ FacesContext.class, CoreBundle.class, Faces.class })
69   -//public class AuthorizationExceptionHandlerTest {
70   -//
71   -// private AuthorizationExceptionHandler handler;
72   -//
73   -// private ExceptionQueuedEventContext eventContext;
74   -//
75   -// private Collection<ExceptionQueuedEvent> events;
76   -//
77   -// private FacesContext facesContext;
78   -//
79   -// @Before
80   -// public void setUp() {
81   -//
82   -// mockStatic(FacesContext.class);
83   -//
84   -// events = new ArrayList<ExceptionQueuedEvent>();
85   -// ExceptionHandler jsfExceptionHandler = createMock(ExceptionHandler.class);
86   -// handler = new AuthorizationExceptionHandler(jsfExceptionHandler);
87   -// eventContext = createMock(ExceptionQueuedEventContext.class);
88   -// ExceptionQueuedEvent event = createMock(ExceptionQueuedEvent.class);
89   -// facesContext = PowerMock.createMock(FacesContext.class);
90   -//
91   -// expect(event.getSource()).andReturn(eventContext);
92   -// events.add(event);
93   -// expect(handler.getUnhandledExceptionQueuedEvents()).andReturn(events).times(2);
94   -// expect(FacesContext.getCurrentInstance()).andReturn(facesContext).anyTimes();
95   -//
96   -//
97   -// }
98   -//
99   -// @Test
100   -// public void testHandleAnAuthorizationExceptionNotOnRenderResponse() {
101   -//
102   -// mockStatic(Faces.class);
103   -//
104   -//// ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle"));
105   -//
106   -// AuthorizationException exception = new AuthorizationException("");
107   -// PhaseId phaseId = PowerMock.createMock(PhaseId.class);
108   -//
109   -// expect(eventContext.getException()).andReturn(exception);
110   -// expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
111   -//
112   -// Faces.addMessage(exception);
113   -// expectLastCall();
114   -//
115   -// replayAll();
116   -//
117   -// handler.handle();
118   -//
119   -// assertTrue(events.isEmpty());
120   -//
121   -// verifyAll();
122   -//
123   -// }
124   -//
125   -// @Test
126   -// public void testHandleAnAuthorizationExceptionOnRenderResponse() {
127   -//
128   -//// ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle"));
129   -//
130   -// AuthorizationException exception = new AuthorizationException("");
131   -// PhaseId phaseId = PhaseId.RENDER_RESPONSE;
132   -//
133   -// expect(eventContext.getException()).andReturn(exception);
134   -// expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
135   -//
136   -// handler.getWrapped().handle();
137   -// expectLastCall();
138   -//
139   -// replayAll();
140   -//
141   -// handler.handle();
142   -//
143   -// assertFalse(events.isEmpty());
144   -//
145   -// verifyAll();
146   -//
147   -// }
148   -//
149   -// @Test
150   -// public void testHandleAnyException() {
151   -//
152   -// Exception exception = new Exception();
153   -// PhaseId phaseId = PowerMock.createMock(PhaseId.class);
154   -//
155   -// expect(eventContext.getException()).andReturn(exception);
156   -// expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
157   -//
158   -// handler.getWrapped().handle();
159   -// expectLastCall();
160   -//
161   -// replayAll();
162   -//
163   -// handler.handle();
164   -//
165   -// assertFalse(events.isEmpty());
166   -//
167   -// verifyAll();
168   -//
169   -// }
170   -//
171   -//}
  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.implementation;
  38 +
  39 +import static junit.framework.Assert.assertFalse;
  40 +import static junit.framework.Assert.assertTrue;
  41 +import static org.easymock.EasyMock.expect;
  42 +import static org.powermock.api.easymock.PowerMock.createMock;
  43 +import static org.powermock.api.easymock.PowerMock.expectLastCall;
  44 +import static org.powermock.api.easymock.PowerMock.mockStatic;
  45 +import static org.powermock.api.easymock.PowerMock.replayAll;
  46 +import static org.powermock.api.easymock.PowerMock.verifyAll;
  47 +
  48 +import java.util.ArrayList;
  49 +import java.util.Collection;
  50 +
  51 +import javax.faces.context.ExceptionHandler;
  52 +import javax.faces.context.FacesContext;
  53 +import javax.faces.event.ExceptionQueuedEvent;
  54 +import javax.faces.event.ExceptionQueuedEventContext;
  55 +import javax.faces.event.PhaseId;
  56 +
  57 +import org.junit.Before;
  58 +import org.junit.Test;
  59 +import org.junit.runner.RunWith;
  60 +import org.powermock.api.easymock.PowerMock;
  61 +import org.powermock.core.classloader.annotations.PrepareForTest;
  62 +import org.powermock.modules.junit4.PowerMockRunner;
  63 +
  64 +import br.gov.frameworkdemoiselle.security.AuthorizationException;
  65 +import br.gov.frameworkdemoiselle.util.Faces;
  66 +
  67 +@RunWith(PowerMockRunner.class)
  68 +@PrepareForTest({ FacesContext.class, Faces.class })
  69 +public class AuthorizationExceptionHandlerTest {
  70 +
  71 + private AuthorizationExceptionHandler handler;
  72 +
  73 + private ExceptionQueuedEventContext eventContext;
  74 +
  75 + private Collection<ExceptionQueuedEvent> events;
  76 +
  77 + private FacesContext facesContext;
  78 +
  79 + @Before
  80 + public void setUp() {
  81 +
  82 + mockStatic(FacesContext.class);
  83 +
  84 + events = new ArrayList<ExceptionQueuedEvent>();
  85 + ExceptionHandler jsfExceptionHandler = createMock(ExceptionHandler.class);
  86 + handler = new AuthorizationExceptionHandler(jsfExceptionHandler);
  87 + eventContext = createMock(ExceptionQueuedEventContext.class);
  88 + ExceptionQueuedEvent event = createMock(ExceptionQueuedEvent.class);
  89 + facesContext = PowerMock.createMock(FacesContext.class);
  90 +
  91 + expect(event.getSource()).andReturn(eventContext);
  92 + events.add(event);
  93 + expect(handler.getUnhandledExceptionQueuedEvents()).andReturn(events).times(2);
  94 + expect(FacesContext.getCurrentInstance()).andReturn(facesContext).anyTimes();
  95 +
  96 +
  97 + }
  98 +
  99 + @Test
  100 + public void testHandleAnAuthorizationExceptionNotOnRenderResponse() {
  101 +
  102 + mockStatic(Faces.class);
  103 +
  104 +// ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle"));
  105 +
  106 + AuthorizationException exception = new AuthorizationException("");
  107 + PhaseId phaseId = PowerMock.createMock(PhaseId.class);
  108 +
  109 + expect(eventContext.getException()).andReturn(exception);
  110 + expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
  111 +
  112 + Faces.addMessage(exception);
  113 + expectLastCall();
  114 +
  115 + replayAll();
  116 +
  117 + handler.handle();
  118 +
  119 + assertTrue(events.isEmpty());
  120 +
  121 + verifyAll();
  122 +
  123 + }
  124 +
  125 + @Test
  126 + public void testHandleAnAuthorizationExceptionOnRenderResponse() {
  127 +
  128 +// ResourceBundle bundle = new ResourceBundle(ResourceBundle.getBundle("demoiselle-core-bundle"));
  129 +
  130 + AuthorizationException exception = new AuthorizationException("");
  131 + PhaseId phaseId = PhaseId.RENDER_RESPONSE;
  132 +
  133 + expect(eventContext.getException()).andReturn(exception);
  134 + expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
  135 +
  136 + handler.getWrapped().handle();
  137 + expectLastCall();
  138 +
  139 + replayAll();
  140 +
  141 + handler.handle();
  142 +
  143 + assertFalse(events.isEmpty());
  144 +
  145 + verifyAll();
  146 +
  147 + }
  148 +
  149 + @Test
  150 + public void testHandleAnyException() {
  151 +
  152 + Exception exception = new Exception();
  153 + PhaseId phaseId = PowerMock.createMock(PhaseId.class);
  154 +
  155 + expect(eventContext.getException()).andReturn(exception);
  156 + expect(facesContext.getCurrentPhaseId()).andReturn(phaseId);
  157 +
  158 + handler.getWrapped().handle();
  159 + expectLastCall();
  160 +
  161 + replayAll();
  162 +
  163 + handler.handle();
  164 +
  165 + assertFalse(events.isEmpty());
  166 +
  167 + verifyAll();
  168 +
  169 + }
  170 +
  171 +}
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/FileRendererImplTest.java
... ... @@ -35,7 +35,7 @@
35 35 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
36 36 */
37 37 package br.gov.frameworkdemoiselle.internal.implementation;
38   -import org.junit.Ignore;
  38 +
39 39 import java.io.IOException;
40 40  
41 41 import javax.faces.context.FacesContext;
... ... @@ -57,7 +57,7 @@ import org.slf4j.Logger;
57 57 import br.gov.frameworkdemoiselle.util.Faces;
58 58 import br.gov.frameworkdemoiselle.util.FileRenderer;
59 59 import br.gov.frameworkdemoiselle.util.FileRenderer.ContentType;
60   -@Ignore
  60 +
61 61 @RunWith(PowerMockRunner.class)
62 62 @PrepareForTest({ Faces.class })
63 63 public class FileRendererImplTest {
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/producer/FacesContextProducerTest.java
... ... @@ -35,7 +35,6 @@
35 35 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
36 36 */
37 37 package br.gov.frameworkdemoiselle.internal.producer;
38   -import org.junit.Ignore;
39 38 import static org.easymock.EasyMock.expect;
40 39 import static org.junit.Assert.assertEquals;
41 40 import static org.junit.Assert.fail;
... ... @@ -53,7 +52,6 @@ import org.powermock.api.easymock.PowerMock;
53 52 import org.powermock.core.classloader.annotations.PrepareForTest;
54 53 import org.powermock.modules.junit4.PowerMockRunner;
55 54  
56   -@Ignore
57 55 @RunWith(PowerMockRunner.class)
58 56 @PrepareForTest({ FacesContext.class })
59 57 public class FacesContextProducerTest {
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBeanTest.java
... ... @@ -35,7 +35,7 @@
35 35 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
36 36 */
37 37 package br.gov.frameworkdemoiselle.template;
38   -import org.junit.Ignore;
  38 +
39 39 import static org.easymock.EasyMock.expect;
40 40 import static org.junit.Assert.assertEquals;
41 41 import static org.junit.Assert.assertFalse;
... ... @@ -70,7 +70,7 @@ import br.gov.frameworkdemoiselle.util.Reflections;
70 70 import br.gov.frameworkdemoiselle.util.ResourceBundle;
71 71  
72 72 import com.sun.faces.util.Util;
73   -@Ignore
  73 +
74 74 @RunWith(PowerMockRunner.class)
75 75 @PrepareForTest({ Parameter.class, Beans.class, Reflections.class, Converter.class, FacesContext.class, Util.class,
76 76 Faces.class })
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractListPageBeanTest.java
... ... @@ -162,6 +162,21 @@ public class AbstractListPageBeanTest {
162 162 verifyAll();
163 163 }
164 164  
  165 + @Test
  166 + public void testClearSelection() {
  167 + pageBean.clearSelection();
  168 + assertEquals(true, pageBean.getSelectedList().isEmpty());
  169 + }
  170 +
  171 + @Test
  172 + public void testGetSelectedList() {
  173 + Map<Long, Boolean> map = new HashMap<Long, Boolean>();
  174 + map.put(1L, true);
  175 + map.put(2L, true);
  176 + pageBean.setSelection(map);
  177 + assertEquals(2, pageBean.getSelectedList().size());
  178 + }
  179 +
165 180 }
166 181  
167 182 @SuppressWarnings("serial")
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractPageTest.java
... ... @@ -35,7 +35,7 @@
35 35 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
36 36 */
37 37 package br.gov.frameworkdemoiselle.template;
38   -import org.junit.Ignore;
  38 +
39 39 import static org.easymock.EasyMock.expect;
40 40 import static org.junit.Assert.assertEquals;
41 41 import static org.powermock.api.easymock.PowerMock.replayAll;
... ... @@ -55,7 +55,7 @@ import org.powermock.reflect.Whitebox;
55 55 import br.gov.frameworkdemoiselle.annotation.NextView;
56 56 import br.gov.frameworkdemoiselle.annotation.PreviousView;
57 57 import br.gov.frameworkdemoiselle.message.MessageContext;
58   -@Ignore
  58 +
59 59 @RunWith(PowerMockRunner.class)
60 60 @PrepareForTest({ MessageContext.class })
61 61 public class AbstractPageTest {
... ...
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/util/FacesTest.java
... ... @@ -35,7 +35,7 @@
35 35 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
36 36 */
37 37 package br.gov.frameworkdemoiselle.util;
38   -import org.junit.Ignore;
  38 +
39 39 import static junit.framework.Assert.assertEquals;
40 40 import static org.easymock.EasyMock.expect;
41 41 import static org.powermock.api.easymock.PowerMock.replayAll;
... ... @@ -66,7 +66,7 @@ import br.gov.frameworkdemoiselle.message.Message;
66 66 import br.gov.frameworkdemoiselle.message.SeverityType;
67 67  
68 68 import com.sun.faces.util.Util;
69   -@Ignore
  69 +
70 70 @RunWith(PowerMockRunner.class)
71 71 @PrepareForTest({ Beans.class, Strings.class, Converter.class, Util.class, ResourceBundle.class })
72 72 public class FacesTest {
... ... @@ -184,7 +184,7 @@ public class FacesTest {
184 184 expect(Beans.getReference(FacesContext.class)).andReturn(facesContext);
185 185 expect(facesContext.getApplication()).andReturn(application);
186 186 expect(application.createConverter(getClass())).andReturn(converter);
187   -
  187 +
188 188 replayAll();
189 189 assertEquals(converter, faces.getConverter(getClass()));
190 190 verifyAll();
... ...