Commit bd05cf212e73c9acbe7d2b07b9c1283a48e56c7f
Exists in
master
Merge branch 'master' of git@github.com:demoiselle/framework.git
Showing
19 changed files
with
1244 additions
and
600 deletions
Show diff stats
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/SecurityConfigTest.java
| ... | ... | @@ -5,7 +5,11 @@ import static org.junit.Assert.assertEquals; |
| 5 | 5 | import org.junit.Before; |
| 6 | 6 | import org.junit.Test; |
| 7 | 7 | |
| 8 | - | |
| 8 | +import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthenticator; | |
| 9 | +import br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthorizer; | |
| 10 | +import br.gov.frameworkdemoiselle.security.Authenticator; | |
| 11 | +import br.gov.frameworkdemoiselle.security.Authorizer; | |
| 12 | +import br.gov.frameworkdemoiselle.security.User; | |
| 9 | 13 | |
| 10 | 14 | public class SecurityConfigTest { |
| 11 | 15 | |
| ... | ... | @@ -21,4 +25,26 @@ public class SecurityConfigTest { |
| 21 | 25 | assertEquals(true, config.isEnabled()); |
| 22 | 26 | } |
| 23 | 27 | |
| 28 | + @Test | |
| 29 | + public void testSetEnabled() { | |
| 30 | + config.setEnabled(false); | |
| 31 | + assertEquals(false, config.isEnabled()); | |
| 32 | + } | |
| 33 | + | |
| 34 | + @Test | |
| 35 | + public void testSetAuthenticatorClass() { | |
| 36 | + Authenticator authenticator = new DefaultAuthenticator(); | |
| 37 | + config.setAuthenticatorClass(authenticator.getClass()); | |
| 38 | + assertEquals("br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthenticator", config | |
| 39 | + .getAuthenticatorClass().getName()); | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Test | |
| 43 | + public void testSetAuthorizerClass() { | |
| 44 | + Authorizer authorizer = new DefaultAuthorizer(); | |
| 45 | + config.setAuthorizerClass(authorizer.getClass()); | |
| 46 | + assertEquals("br.gov.frameworkdemoiselle.internal.implementation.DefaultAuthorizer", config | |
| 47 | + .getAuthorizerClass().getName()); | |
| 48 | + } | |
| 49 | + | |
| 24 | 50 | } | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/TransactionConfigTest.java
0 → 100644
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +package br.gov.frameworkdemoiselle.internal.configuration; | |
| 2 | + | |
| 3 | +import junit.framework.Assert; | |
| 4 | + | |
| 5 | +import org.junit.Before; | |
| 6 | +import org.junit.Test; | |
| 7 | + | |
| 8 | + | |
| 9 | +public class TransactionConfigTest { | |
| 10 | + | |
| 11 | + TransactionConfig transactionConfig; | |
| 12 | + | |
| 13 | + @Before | |
| 14 | + public void setUp() { | |
| 15 | + transactionConfig = new TransactionConfig(); | |
| 16 | + } | |
| 17 | + | |
| 18 | + @Test | |
| 19 | + public void testGetTransactionClass() { | |
| 20 | + Assert.assertNull(transactionConfig.getTransactionClass()); | |
| 21 | + } | |
| 22 | + | |
| 23 | +} | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImplTest.java
0 → 100644
| ... | ... | @@ -0,0 +1,122 @@ |
| 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 org.easymock.EasyMock.expect; | |
| 40 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | |
| 41 | +import static org.powermock.api.easymock.PowerMock.replayAll; | |
| 42 | + | |
| 43 | +import java.util.ArrayList; | |
| 44 | +import java.util.List; | |
| 45 | + | |
| 46 | +import junit.framework.Assert; | |
| 47 | + | |
| 48 | +import org.junit.Test; | |
| 49 | +import org.junit.runner.RunWith; | |
| 50 | +import org.powermock.api.easymock.PowerMock; | |
| 51 | +import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 52 | +import org.powermock.modules.junit4.PowerMockRunner; | |
| 53 | + | |
| 54 | +import br.gov.frameworkdemoiselle.internal.bootstrap.TransactionBootstrap; | |
| 55 | +import br.gov.frameworkdemoiselle.internal.configuration.TransactionConfig; | |
| 56 | +import br.gov.frameworkdemoiselle.transaction.Transaction; | |
| 57 | +import br.gov.frameworkdemoiselle.transaction.TransactionContext; | |
| 58 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 59 | + | |
| 60 | +@RunWith(PowerMockRunner.class) | |
| 61 | +@PrepareForTest({Beans.class,StrategySelector.class}) | |
| 62 | +public class TransactionContextImplTest { | |
| 63 | + | |
| 64 | + private TransactionContext context; | |
| 65 | + private Transaction transaction; | |
| 66 | + | |
| 67 | + class TransactionImpl implements Transaction{ | |
| 68 | + | |
| 69 | + private static final long serialVersionUID = 1L; | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public boolean isActive() { | |
| 73 | + return false; | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public boolean isMarkedRollback() { | |
| 78 | + return false; | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + public void begin() { | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Override | |
| 86 | + public void commit() { | |
| 87 | + } | |
| 88 | + | |
| 89 | + @Override | |
| 90 | + public void rollback() { | |
| 91 | + } | |
| 92 | + | |
| 93 | + @Override | |
| 94 | + public void setRollbackOnly() { | |
| 95 | + } | |
| 96 | + } | |
| 97 | + | |
| 98 | + @Test | |
| 99 | + public void testGetTransactionNull() { | |
| 100 | + context = new TransactionContextImpl(); | |
| 101 | + | |
| 102 | + Class<? extends Transaction> cache = TransactionImpl.class; | |
| 103 | + | |
| 104 | + List<Class<? extends Transaction>> cacheList = new ArrayList<Class<? extends Transaction>>(); | |
| 105 | + cacheList.add(cache); | |
| 106 | + | |
| 107 | + TransactionBootstrap bootstrap = PowerMock.createMock(TransactionBootstrap.class); | |
| 108 | + TransactionConfig config = PowerMock.createMock(TransactionConfig.class); | |
| 109 | + | |
| 110 | + mockStatic(Beans.class); | |
| 111 | + expect(Beans.getReference(TransactionBootstrap.class)).andReturn(bootstrap).anyTimes(); | |
| 112 | + expect(Beans.getReference(TransactionConfig.class)).andReturn(config); | |
| 113 | + expect(config.getTransactionClass()).andReturn(null).anyTimes(); | |
| 114 | + expect(bootstrap.getCache()).andReturn(cacheList); | |
| 115 | + expect(Beans.getReference(TransactionImpl.class)).andReturn(new TransactionImpl()); | |
| 116 | + | |
| 117 | + replayAll(Beans.class); | |
| 118 | + | |
| 119 | + transaction = context.getCurrentTransaction(); | |
| 120 | + Assert.assertNotNull(transaction); | |
| 121 | + } | |
| 122 | +} | ... | ... |
impl/extension/jsf/pom.xml
| ... | ... | @@ -80,6 +80,11 @@ |
| 80 | 80 | <artifactId>jsf-impl</artifactId> |
| 81 | 81 | <scope>test</scope> |
| 82 | 82 | </dependency> |
| 83 | + <dependency> | |
| 84 | + <groupId>org.glassfish.web</groupId> | |
| 85 | + <artifactId>el-impl</artifactId> | |
| 86 | + <scope>test</scope> | |
| 87 | + </dependency> | |
| 83 | 88 | </dependencies> |
| 84 | 89 | |
| 85 | 90 | <repositories> | ... | ... |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityObserver.java
| ... | ... | @@ -74,12 +74,12 @@ public class SecurityObserver implements Serializable { |
| 74 | 74 | public SecurityObserver() { |
| 75 | 75 | clear(); |
| 76 | 76 | } |
| 77 | - | |
| 78 | - private Map<String, Object> getSavedParams(){ | |
| 79 | - if(this.savedParams == null) { | |
| 77 | + | |
| 78 | + private Map<String, Object> getSavedParams() { | |
| 79 | + if (this.savedParams == null) { | |
| 80 | 80 | this.savedParams = new HashMap<String, Object>(); |
| 81 | 81 | } |
| 82 | - | |
| 82 | + | |
| 83 | 83 | return this.savedParams; |
| 84 | 84 | } |
| 85 | 85 | ... | ... |
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,8 +35,11 @@ |
| 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 | +import java.io.ByteArrayInputStream; | |
| 40 | +import java.io.File; | |
| 39 | 41 | import java.io.IOException; |
| 42 | +import java.io.InputStream; | |
| 40 | 43 | |
| 41 | 44 | import javax.faces.context.FacesContext; |
| 42 | 45 | import javax.servlet.ServletOutputStream; |
| ... | ... | @@ -57,7 +60,7 @@ import org.slf4j.Logger; |
| 57 | 60 | import br.gov.frameworkdemoiselle.util.Faces; |
| 58 | 61 | import br.gov.frameworkdemoiselle.util.FileRenderer; |
| 59 | 62 | import br.gov.frameworkdemoiselle.util.FileRenderer.ContentType; |
| 60 | -@Ignore | |
| 63 | + | |
| 61 | 64 | @RunWith(PowerMockRunner.class) |
| 62 | 65 | @PrepareForTest({ Faces.class }) |
| 63 | 66 | public class FileRendererImplTest { |
| ... | ... | @@ -123,7 +126,7 @@ public class FileRendererImplTest { |
| 123 | 126 | } |
| 124 | 127 | |
| 125 | 128 | @Test |
| 126 | - public void testRenderBytesSuccess() { | |
| 129 | + public void testRenderBytesSuccess() throws IOException { | |
| 127 | 130 | byte[] bytes = "Test".getBytes(); |
| 128 | 131 | String fileName = "fileName.pdf"; |
| 129 | 132 | |
| ... | ... | @@ -143,24 +146,183 @@ public class FileRendererImplTest { |
| 143 | 146 | EasyMock.expectLastCall().times(1); |
| 144 | 147 | |
| 145 | 148 | ServletOutputStream stream = PowerMock.createMock(ServletOutputStream.class); |
| 149 | + stream.write(bytes, 0, bytes.length); | |
| 150 | + EasyMock.expectLastCall().times(1); | |
| 151 | + | |
| 152 | + stream.flush(); | |
| 153 | + EasyMock.expectLastCall().times(1); | |
| 154 | + | |
| 155 | + stream.close(); | |
| 156 | + EasyMock.expectLastCall().times(1); | |
| 157 | + | |
| 158 | + EasyMock.expect(response.getOutputStream()).andReturn(stream).times(3); | |
| 159 | + | |
| 160 | + PowerMock.replayAll(); | |
| 161 | + renderer.render(bytes, ContentType.PDF, fileName); | |
| 162 | + PowerMock.verifyAll(); | |
| 163 | + } | |
| 164 | + | |
| 165 | + @Test | |
| 166 | + public void testRenderStreamFail() { | |
| 167 | + byte[] bytes = "Test".getBytes(); | |
| 168 | + InputStream stream = new ByteArrayInputStream(bytes); | |
| 169 | + String fileName = "fileName.pdf"; | |
| 170 | + | |
| 171 | + logger.debug(EasyMock.anyObject(String.class)); | |
| 172 | + EasyMock.expectLastCall().anyTimes(); | |
| 173 | + | |
| 174 | + IOException exception = new IOException(); | |
| 175 | + logger.info("Erro na geração do relatório. Incluíndo a exceção de erro em um FacesMessage", exception); | |
| 176 | + EasyMock.expectLastCall().anyTimes(); | |
| 177 | + | |
| 178 | + response.setContentType(ContentType.PDF.getContentType()); | |
| 179 | + EasyMock.expectLastCall().times(1); | |
| 180 | + | |
| 181 | + response.setContentLength(bytes.length); | |
| 182 | + EasyMock.expectLastCall().times(1); | |
| 183 | + | |
| 184 | + response.setHeader("Content-Disposition", "filename=\"" + fileName + "\""); | |
| 185 | + EasyMock.expectLastCall().times(1); | |
| 186 | + | |
| 187 | + facesContext.responseComplete(); | |
| 188 | + EasyMock.expectLastCall().times(1); | |
| 189 | + | |
| 146 | 190 | try { |
| 147 | - stream.write(bytes, 0, bytes.length); | |
| 148 | - EasyMock.expectLastCall().times(1); | |
| 191 | + EasyMock.expect(response.getOutputStream()).andThrow(exception); | |
| 192 | + } catch (IOException e) { | |
| 193 | + Assert.fail(); | |
| 194 | + } | |
| 195 | + | |
| 196 | + PowerMock.mockStatic(Faces.class); | |
| 197 | + Faces.addMessage(exception); | |
| 149 | 198 | |
| 150 | - stream.flush(); | |
| 151 | - EasyMock.expectLastCall().times(1); | |
| 199 | + PowerMock.replayAll(); | |
| 200 | + renderer.render(stream, ContentType.PDF, fileName, false); | |
| 201 | + PowerMock.verifyAll(); | |
| 202 | + } | |
| 152 | 203 | |
| 153 | - stream.close(); | |
| 154 | - EasyMock.expectLastCall().times(1); | |
| 204 | + @Test | |
| 205 | + public void testRenderStreamSuccess() throws IOException { | |
| 206 | + byte[] bytes = "Test".getBytes(); | |
| 207 | + InputStream inputStream = new ByteArrayInputStream(bytes); | |
| 155 | 208 | |
| 156 | - EasyMock.expect(response.getOutputStream()).andReturn(stream).times(3); | |
| 209 | + String fileName = "fileName.pdf"; | |
| 210 | + | |
| 211 | + logger.debug(EasyMock.anyObject(String.class)); | |
| 212 | + EasyMock.expectLastCall().anyTimes(); | |
| 213 | + | |
| 214 | + facesContext.responseComplete(); | |
| 215 | + EasyMock.expectLastCall().times(1); | |
| 216 | + | |
| 217 | + response.setContentType(ContentType.PDF.getContentType()); | |
| 218 | + EasyMock.expectLastCall().times(1); | |
| 219 | + | |
| 220 | + response.setContentLength(bytes.length); | |
| 221 | + EasyMock.expectLastCall().times(1); | |
| 222 | + | |
| 223 | + response.setHeader("Content-Disposition", "filename=\"" + fileName + "\""); | |
| 224 | + EasyMock.expectLastCall().times(1); | |
| 225 | + | |
| 226 | + ServletOutputStream stream = new ServletOutputStream() { | |
| 227 | + | |
| 228 | + @Override | |
| 229 | + public void write(int b) throws IOException { | |
| 230 | + Assert.assertTrue(true); | |
| 231 | + } | |
| 232 | + }; | |
| 233 | + | |
| 234 | + EasyMock.expect(response.getOutputStream()).andReturn(stream).times(3); | |
| 235 | + | |
| 236 | + PowerMock.replayAll(); | |
| 237 | + renderer.render(inputStream, ContentType.PDF, fileName); | |
| 238 | + PowerMock.verifyAll(); | |
| 239 | + } | |
| 240 | + | |
| 241 | + @Test | |
| 242 | + public void testRenderFileFail() throws IOException { | |
| 243 | + | |
| 244 | + File file = new File("fileName"); | |
| 245 | + file.createNewFile(); | |
| 246 | + | |
| 247 | + String fileName = "fileName.pdf"; | |
| 248 | + | |
| 249 | + logger.debug(EasyMock.anyObject(String.class)); | |
| 250 | + EasyMock.expectLastCall().anyTimes(); | |
| 251 | + | |
| 252 | + IOException exception = new IOException(); | |
| 253 | + logger.info("Erro na geração do relatório. Incluíndo a exceção de erro em um FacesMessage", exception); | |
| 254 | + EasyMock.expectLastCall().anyTimes(); | |
| 255 | + | |
| 256 | + response.setContentType(ContentType.PDF.getContentType()); | |
| 257 | + EasyMock.expectLastCall().times(1); | |
| 258 | + | |
| 259 | + response.setContentLength((int) file.length()); | |
| 260 | + EasyMock.expectLastCall().times(1); | |
| 261 | + | |
| 262 | + response.setHeader("Content-Disposition", "filename=\"" + fileName + "\""); | |
| 263 | + EasyMock.expectLastCall().times(1); | |
| 264 | + | |
| 265 | + facesContext.responseComplete(); | |
| 266 | + EasyMock.expectLastCall().times(1); | |
| 267 | + | |
| 268 | + try { | |
| 269 | + EasyMock.expect(response.getOutputStream()).andThrow(exception); | |
| 157 | 270 | } catch (IOException e) { |
| 158 | 271 | Assert.fail(); |
| 159 | 272 | } |
| 160 | 273 | |
| 274 | + PowerMock.mockStatic(Faces.class); | |
| 275 | + Faces.addMessage(exception); | |
| 276 | + | |
| 161 | 277 | PowerMock.replayAll(); |
| 162 | - renderer.render(bytes, ContentType.PDF, fileName); | |
| 278 | + renderer.render(file, ContentType.PDF, fileName); | |
| 163 | 279 | PowerMock.verifyAll(); |
| 280 | + | |
| 281 | + file.delete(); | |
| 164 | 282 | } |
| 165 | 283 | |
| 284 | + @Test | |
| 285 | + public void testRenderFileNotFoundException() throws IOException { | |
| 286 | + | |
| 287 | + File file = new File("fileName"); | |
| 288 | + file.createNewFile(); | |
| 289 | + | |
| 290 | + String fileName = "fileName.pdf"; | |
| 291 | + | |
| 292 | + logger.debug(EasyMock.anyObject(String.class)); | |
| 293 | + EasyMock.expectLastCall().anyTimes(); | |
| 294 | + | |
| 295 | + IOException exception = new IOException(); | |
| 296 | + logger.info("Erro na geração do relatório. Incluíndo a exceção de erro em um FacesMessage", exception); | |
| 297 | + EasyMock.expectLastCall().anyTimes(); | |
| 298 | + | |
| 299 | + response.setContentType(ContentType.PDF.getContentType()); | |
| 300 | + EasyMock.expectLastCall().times(1); | |
| 301 | + | |
| 302 | + response.setContentLength((int) file.length()); | |
| 303 | + EasyMock.expectLastCall().times(1); | |
| 304 | + | |
| 305 | + response.setHeader("Content-Disposition", "filename=\"" + fileName + "\""); | |
| 306 | + EasyMock.expectLastCall().times(1); | |
| 307 | + | |
| 308 | + facesContext.responseComplete(); | |
| 309 | + EasyMock.expectLastCall().times(1); | |
| 310 | + | |
| 311 | + try { | |
| 312 | + EasyMock.expect(response.getOutputStream()).andThrow(exception); | |
| 313 | + } catch (IOException e) { | |
| 314 | + Assert.fail(); | |
| 315 | + } | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + PowerMock.mockStatic(Faces.class); | |
| 320 | + Faces.addMessage(exception); | |
| 321 | + | |
| 322 | + PowerMock.replayAll(); | |
| 323 | + renderer.render(file, ContentType.PDF, fileName); | |
| 324 | + PowerMock.verifyAll(); | |
| 325 | + | |
| 326 | + file.delete(); | |
| 327 | + } | |
| 166 | 328 | } | ... | ... |
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImplTest.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 org.easymock.EasyMock.expect; | |
| 40 | -//import static org.junit.Assert.assertEquals; | |
| 41 | -//import static org.powermock.api.easymock.PowerMock.createMock; | |
| 42 | -//import static org.powermock.api.easymock.PowerMock.mockStatic; | |
| 43 | -//import static org.powermock.api.easymock.PowerMock.replayAll; | |
| 44 | -//import static org.powermock.api.easymock.PowerMock.verifyAll; | |
| 45 | -// | |
| 46 | -//import java.lang.reflect.Member; | |
| 47 | -//import java.util.HashMap; | |
| 48 | -//import java.util.Map; | |
| 49 | -// | |
| 50 | -//import javax.enterprise.context.RequestScoped; | |
| 51 | -//import javax.enterprise.context.SessionScoped; | |
| 52 | -//import javax.enterprise.inject.spi.Annotated; | |
| 53 | -//import javax.enterprise.inject.spi.InjectionPoint; | |
| 54 | -//import javax.faces.convert.Converter; | |
| 55 | -//import javax.servlet.http.HttpServletRequest; | |
| 56 | -//import javax.servlet.http.HttpSession; | |
| 57 | -// | |
| 58 | -//import org.easymock.EasyMock; | |
| 59 | -//import org.junit.Before; | |
| 60 | -//import org.junit.Test; | |
| 61 | -//import org.junit.runner.RunWith; | |
| 62 | -//import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 63 | -//import org.powermock.modules.junit4.PowerMockRunner; | |
| 64 | -//import org.powermock.reflect.Whitebox; | |
| 65 | -// | |
| 66 | -//import br.gov.frameworkdemoiselle.annotation.Name; | |
| 67 | -//import br.gov.frameworkdemoiselle.annotation.ViewScoped; | |
| 68 | -//import br.gov.frameworkdemoiselle.util.Faces; | |
| 69 | -//import br.gov.frameworkdemoiselle.util.Reflections; | |
| 70 | -// | |
| 71 | -//@RunWith(PowerMockRunner.class) | |
| 72 | -//@PrepareForTest({ Reflections.class, Faces.class }) | |
| 73 | -//public class ParameterImplTest { | |
| 74 | -// | |
| 75 | -// private ParameterImpl<Long> param; | |
| 76 | -// | |
| 77 | -// private HttpServletRequest request; | |
| 78 | -// | |
| 79 | -// private InjectionPoint ip; | |
| 80 | -// | |
| 81 | -// private Converter converter; | |
| 82 | -// | |
| 83 | -// private Annotated annotated; | |
| 84 | -// | |
| 85 | -// private Name name; | |
| 86 | -// | |
| 87 | -// private HttpSession session; | |
| 88 | -// | |
| 89 | -// private Member member; | |
| 90 | -// | |
| 91 | -// @Before | |
| 92 | -// public void before() { | |
| 93 | -// ip = createMock(InjectionPoint.class); | |
| 94 | -// request = createMock(HttpServletRequest.class); | |
| 95 | -// session = createMock(HttpSession.class); | |
| 96 | -// annotated = createMock(Annotated.class); | |
| 97 | -// name = createMock(Name.class); | |
| 98 | -// converter = createMock(Converter.class); | |
| 99 | -// member = createMock(Member.class); | |
| 100 | -// | |
| 101 | -// mockStatic(Reflections.class); | |
| 102 | -// mockStatic(Faces.class); | |
| 103 | -// } | |
| 104 | -// | |
| 105 | -// private void prepareForTestWithKeyFromNameAnnotation() { | |
| 106 | -// expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | |
| 107 | -// expect(ip.getMember()).andReturn(null); | |
| 108 | -// expect(annotated.isAnnotationPresent(Name.class)).andReturn(true); | |
| 109 | -// expect(annotated.getAnnotation(Name.class)).andReturn(name); | |
| 110 | -// expect(name.value()).andReturn("name"); | |
| 111 | -// expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Member.class), EasyMock.anyInt())).andReturn( | |
| 112 | -// Object.class); | |
| 113 | -// expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); | |
| 114 | -// } | |
| 115 | -// | |
| 116 | -// @Test | |
| 117 | -// public void testConstructorCase1() { | |
| 118 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 119 | -// | |
| 120 | -// replayAll(); | |
| 121 | -// param = new ParameterImpl<Long>(ip, request); | |
| 122 | -// assertEquals("name", param.getKey()); | |
| 123 | -// assertEquals(Object.class, Whitebox.getInternalState(param, "type")); | |
| 124 | -// assertEquals(converter, param.getConverter()); | |
| 125 | -// verifyAll(); | |
| 126 | -// } | |
| 127 | -// | |
| 128 | -// @Test | |
| 129 | -// public void testConstructorCase2() { | |
| 130 | -// expect(member.getName()).andReturn("memberName"); | |
| 131 | -// expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | |
| 132 | -// expect(ip.getMember()).andReturn(member).anyTimes(); | |
| 133 | -// expect(annotated.isAnnotationPresent(Name.class)).andReturn(false); | |
| 134 | -// expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Member.class), EasyMock.anyInt())).andReturn( | |
| 135 | -// Object.class); | |
| 136 | -// expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); | |
| 137 | -// | |
| 138 | -// replayAll(); | |
| 139 | -// param = new ParameterImpl<Long>(ip, request); | |
| 140 | -// assertEquals("memberName", param.getKey()); | |
| 141 | -// assertEquals(Object.class, Whitebox.getInternalState(param, "type")); | |
| 142 | -// assertEquals(converter, param.getConverter()); | |
| 143 | -// verifyAll(); | |
| 144 | -// } | |
| 145 | -// | |
| 146 | -// @Test | |
| 147 | -// public void testGetValueWhenSessionScopedAndParameterValueNotNull() { | |
| 148 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 149 | -// | |
| 150 | -// expect(Faces.convert("1", converter)).andReturn("return"); | |
| 151 | -// expect(request.getSession()).andReturn(session).anyTimes(); | |
| 152 | -// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 153 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); | |
| 154 | -// expect(session.getAttribute("name")).andReturn("return"); | |
| 155 | -// | |
| 156 | -// session.setAttribute("name", "return"); | |
| 157 | -// | |
| 158 | -// replayAll(); | |
| 159 | -// param = new ParameterImpl<Long>(ip, request); | |
| 160 | -// assertEquals("return", param.getValue()); | |
| 161 | -// verifyAll(); | |
| 162 | -// } | |
| 163 | -// | |
| 164 | -// @Test | |
| 165 | -// public void testGetValueWhenSessionScopedAndParameterValueNull() { | |
| 166 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 167 | -// | |
| 168 | -// expect(request.getSession()).andReturn(session).anyTimes(); | |
| 169 | -// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn(null); | |
| 170 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); | |
| 171 | -// expect(session.getAttribute("name")).andReturn("return"); | |
| 172 | -// | |
| 173 | -// replayAll(); | |
| 174 | -// param = new ParameterImpl<Long>(ip, request); | |
| 175 | -// assertEquals("return", param.getValue()); | |
| 176 | -// verifyAll(); | |
| 177 | -// } | |
| 178 | -// | |
| 179 | -// @Test | |
| 180 | -// public void testGetValueWhenRequestScoped() { | |
| 181 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 182 | -// | |
| 183 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 184 | -// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); | |
| 185 | -// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 186 | -// expect(Faces.convert("1", converter)).andReturn("return"); | |
| 187 | -// | |
| 188 | -// replayAll(); | |
| 189 | -// param = new ParameterImpl<Long>(ip, request); | |
| 190 | -// assertEquals("return", param.getValue()); | |
| 191 | -// verifyAll(); | |
| 192 | -// } | |
| 193 | -// | |
| 194 | -// @Test | |
| 195 | -// public void testGetValueWhenViewScopedWithParamValueNotNull() { | |
| 196 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 197 | -// Map<String, Object> map = new HashMap<String,Object>(); | |
| 198 | -// | |
| 199 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 200 | -// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 201 | -// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); | |
| 202 | -// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 203 | -// expect(Faces.getViewMap()).andReturn(map); | |
| 204 | -// expect(Faces.convert("1", converter)).andReturn("return"); | |
| 205 | -// | |
| 206 | -// replayAll(); | |
| 207 | -// param = new ParameterImpl<Long>(ip, request); | |
| 208 | -// assertEquals("return", param.getValue()); | |
| 209 | -// assertEquals("return", map.get("name")); | |
| 210 | -// verifyAll(); | |
| 211 | -// } | |
| 212 | -// | |
| 213 | -// @Test | |
| 214 | -// public void testGetValueWhenViewScopedWithParamValueNull() { | |
| 215 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 216 | -// Map<String, Object> map = new HashMap<String,Object>(); | |
| 217 | -// map.put("name", "ops"); | |
| 218 | -// | |
| 219 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 220 | -// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 221 | -// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); | |
| 222 | -// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn(null); | |
| 223 | -// expect(Faces.getViewMap()).andReturn(map); | |
| 224 | -// | |
| 225 | -// replayAll(); | |
| 226 | -// param = new ParameterImpl<Long>(ip, request); | |
| 227 | -// assertEquals("ops", param.getValue()); | |
| 228 | -// assertEquals("ops", map.get("name")); | |
| 229 | -// verifyAll(); | |
| 230 | -// } | |
| 231 | -// | |
| 232 | -// @Test | |
| 233 | -// public void testGetValueElseWithValueNull() { | |
| 234 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 235 | -// | |
| 236 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 237 | -// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 238 | -// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 239 | -// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 240 | -// expect(Faces.convert("1", converter)).andReturn("return"); | |
| 241 | -// | |
| 242 | -// replayAll(); | |
| 243 | -// param = new ParameterImpl<Long>(ip, request); | |
| 244 | -// assertEquals("return", param.getValue()); | |
| 245 | -// verifyAll(); | |
| 246 | -// } | |
| 247 | -// | |
| 248 | -// @Test | |
| 249 | -// public void testGetValueElseWithValueNotNull() { | |
| 250 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 251 | -// | |
| 252 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 253 | -// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 254 | -// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 255 | -// expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 256 | -// | |
| 257 | -// replayAll(); | |
| 258 | -// param = new ParameterImpl<Long>(ip, request); | |
| 259 | -// Whitebox.setInternalState(param, "value", "myvalue"); | |
| 260 | -// assertEquals("myvalue", param.getValue()); | |
| 261 | -// verifyAll(); | |
| 262 | -// } | |
| 263 | -// | |
| 264 | -// @Test | |
| 265 | -// public void testSetValueIsSessionScoped() { | |
| 266 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 267 | -// | |
| 268 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); | |
| 269 | -// expect(request.getSession()).andReturn(session); | |
| 270 | -// | |
| 271 | -// session.setAttribute("name", 1L); | |
| 272 | -// | |
| 273 | -// replayAll(); | |
| 274 | -// param = new ParameterImpl<Long>(ip, request); | |
| 275 | -// param.setValue(1L); | |
| 276 | -// verifyAll(); | |
| 277 | -// } | |
| 278 | -// | |
| 279 | -// @Test | |
| 280 | -// public void testSetValueIsViewScoped() { | |
| 281 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 282 | -// | |
| 283 | -// Map<String, Object> map = new HashMap<String, Object>(); | |
| 284 | -// | |
| 285 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 286 | -// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 287 | -// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); | |
| 288 | -// expect(Faces.getViewMap()).andReturn(map); | |
| 289 | -// | |
| 290 | -// replayAll(); | |
| 291 | -// param = new ParameterImpl<Long>(ip, request); | |
| 292 | -// param.setValue(1L); | |
| 293 | -// assertEquals(1L, map.get("name")); | |
| 294 | -// verifyAll(); | |
| 295 | -// } | |
| 296 | -// | |
| 297 | -// @Test | |
| 298 | -// public void testSetValueElse() { | |
| 299 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 300 | -// | |
| 301 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 302 | -// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 303 | -// expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 304 | -// | |
| 305 | -// replayAll(); | |
| 306 | -// param = new ParameterImpl<Long>(ip, request); | |
| 307 | -// param.setValue(1L); | |
| 308 | -// assertEquals(1L, Whitebox.getInternalState(param, "value")); | |
| 309 | -// verifyAll(); | |
| 310 | -// } | |
| 311 | -// | |
| 312 | -// @Test | |
| 313 | -// public void testOthers() { | |
| 314 | -// this.prepareForTestWithKeyFromNameAnnotation(); | |
| 315 | -// | |
| 316 | -// expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 317 | -// expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); | |
| 318 | -// | |
| 319 | -// replayAll(); | |
| 320 | -// param = new ParameterImpl<Long>(ip, request); | |
| 321 | -// param.setValue(1L); | |
| 322 | -// verifyAll(); | |
| 323 | -// } | |
| 324 | -// | |
| 325 | -//} | |
| 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 PURPaOSE. 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 org.easymock.EasyMock.expect; | |
| 40 | +import static org.junit.Assert.assertEquals; | |
| 41 | +import static org.powermock.api.easymock.PowerMock.createMock; | |
| 42 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | |
| 43 | +import static org.powermock.api.easymock.PowerMock.replayAll; | |
| 44 | +import static org.powermock.api.easymock.PowerMock.verifyAll; | |
| 45 | + | |
| 46 | +import java.lang.reflect.Member; | |
| 47 | +import java.util.HashMap; | |
| 48 | +import java.util.Map; | |
| 49 | + | |
| 50 | +import javax.enterprise.context.RequestScoped; | |
| 51 | +import javax.enterprise.context.SessionScoped; | |
| 52 | +import javax.enterprise.inject.spi.Annotated; | |
| 53 | +import javax.enterprise.inject.spi.InjectionPoint; | |
| 54 | +import javax.faces.convert.Converter; | |
| 55 | +import javax.servlet.http.HttpServletRequest; | |
| 56 | +import javax.servlet.http.HttpSession; | |
| 57 | +import javax.swing.text.View; | |
| 58 | + | |
| 59 | +import org.easymock.EasyMock; | |
| 60 | +import org.junit.Before; | |
| 61 | +import org.junit.Test; | |
| 62 | +import org.junit.runner.RunWith; | |
| 63 | +import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 64 | +import org.powermock.modules.junit4.PowerMockRunner; | |
| 65 | +import org.powermock.reflect.Whitebox; | |
| 66 | + | |
| 67 | +import br.gov.frameworkdemoiselle.annotation.Name; | |
| 68 | +import br.gov.frameworkdemoiselle.annotation.ViewScoped; | |
| 69 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 70 | +import br.gov.frameworkdemoiselle.util.Faces; | |
| 71 | +import br.gov.frameworkdemoiselle.util.Reflections; | |
| 72 | + | |
| 73 | +@RunWith(PowerMockRunner.class) | |
| 74 | +@PrepareForTest({ Reflections.class, Faces.class, Beans.class }) | |
| 75 | +public class ParameterImplTest { | |
| 76 | + | |
| 77 | + private ParameterImpl<Long> param; | |
| 78 | + | |
| 79 | + private HttpServletRequest request; | |
| 80 | + | |
| 81 | + private InjectionPoint ip; | |
| 82 | + | |
| 83 | + private Converter converter; | |
| 84 | + | |
| 85 | + private Annotated annotated; | |
| 86 | + | |
| 87 | + private Name name; | |
| 88 | + | |
| 89 | + private HttpSession session; | |
| 90 | + | |
| 91 | + private Member member; | |
| 92 | + | |
| 93 | + @Before | |
| 94 | + public void before() { | |
| 95 | + ip = createMock(InjectionPoint.class); | |
| 96 | + request = createMock(HttpServletRequest.class); | |
| 97 | + session = createMock(HttpSession.class); | |
| 98 | + annotated = createMock(Annotated.class); | |
| 99 | + name = createMock(Name.class); | |
| 100 | + converter = createMock(Converter.class); | |
| 101 | + member = createMock(Member.class); | |
| 102 | + | |
| 103 | + mockStatic(Reflections.class); | |
| 104 | + mockStatic(Faces.class); | |
| 105 | + } | |
| 106 | + | |
| 107 | + private void prepareForTestWithKeyFromNameAnnotation() { | |
| 108 | + expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | |
| 109 | + expect(ip.getMember()).andReturn(null); | |
| 110 | + expect(annotated.isAnnotationPresent(Name.class)).andReturn(true); | |
| 111 | + expect(annotated.getAnnotation(Name.class)).andReturn(name); | |
| 112 | + expect(name.value()).andReturn("name"); | |
| 113 | + expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Member.class), EasyMock.anyInt())).andReturn( | |
| 114 | + Object.class); | |
| 115 | + } | |
| 116 | + | |
| 117 | + @Test | |
| 118 | + public void testConstructorCase1() { | |
| 119 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 120 | + expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); | |
| 121 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); | |
| 122 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); | |
| 123 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); | |
| 124 | + | |
| 125 | + replayAll(); | |
| 126 | + param = new ParameterImpl<Long>(ip); | |
| 127 | + assertEquals("name", param.getKey()); | |
| 128 | + assertEquals(Object.class, Whitebox.getInternalState(param, "type")); | |
| 129 | + assertEquals(converter, param.getConverter()); | |
| 130 | + verifyAll(); | |
| 131 | + } | |
| 132 | + | |
| 133 | + @Test | |
| 134 | + public void testConstructorCase2() { | |
| 135 | + expect(member.getName()).andReturn("memberName"); | |
| 136 | + expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | |
| 137 | + expect(ip.getMember()).andReturn(member).anyTimes(); | |
| 138 | + expect(annotated.isAnnotationPresent(Name.class)).andReturn(false); | |
| 139 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); | |
| 140 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); | |
| 141 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); | |
| 142 | + expect(Reflections.getGenericTypeArgument(EasyMock.anyObject(Member.class), EasyMock.anyInt())).andReturn( | |
| 143 | + Object.class); | |
| 144 | + expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); | |
| 145 | + | |
| 146 | + replayAll(); | |
| 147 | + param = new ParameterImpl<Long>(ip); | |
| 148 | + assertEquals("memberName", param.getKey()); | |
| 149 | + assertEquals(Object.class, Whitebox.getInternalState(param, "type")); | |
| 150 | + assertEquals(converter, param.getConverter()); | |
| 151 | + verifyAll(); | |
| 152 | + } | |
| 153 | + | |
| 154 | + @Test | |
| 155 | + public void testGetValueWhenSessionScopedAndParameterValueNotNull() { | |
| 156 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 157 | + expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); | |
| 158 | + | |
| 159 | + mockStatic(Beans.class); | |
| 160 | + expect(Beans.getReference(HttpServletRequest.class)).andReturn(request).anyTimes(); | |
| 161 | + | |
| 162 | + expect(Faces.convert("1", converter)).andReturn("return"); | |
| 163 | + expect(request.getSession()).andReturn(session).anyTimes(); | |
| 164 | + expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 165 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); | |
| 166 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 167 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 168 | + | |
| 169 | + expect(session.getAttribute("name")).andReturn("return"); | |
| 170 | + | |
| 171 | + session.setAttribute("name", "return"); | |
| 172 | + | |
| 173 | + replayAll(); | |
| 174 | + param = new ParameterImpl<Long>(ip); | |
| 175 | + assertEquals("return", param.getValue()); | |
| 176 | + verifyAll(); | |
| 177 | + } | |
| 178 | + | |
| 179 | + @Test | |
| 180 | + public void testGetValueWhenSessionScopedAndParameterValueNull() { | |
| 181 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 182 | + | |
| 183 | + mockStatic(Beans.class); | |
| 184 | + expect(Beans.getReference(HttpServletRequest.class)).andReturn(request).anyTimes(); | |
| 185 | + | |
| 186 | + expect(request.getSession()).andReturn(session).anyTimes(); | |
| 187 | + expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn(null); | |
| 188 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); | |
| 189 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 190 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 191 | + expect(session.getAttribute("name")).andReturn("return"); | |
| 192 | + | |
| 193 | + replayAll(); | |
| 194 | + param = new ParameterImpl<Long>(ip); | |
| 195 | + assertEquals("return", param.getValue()); | |
| 196 | + verifyAll(); | |
| 197 | + } | |
| 198 | + | |
| 199 | + @Test | |
| 200 | + public void testGetValueWhenRequestScoped() { | |
| 201 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 202 | + expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); | |
| 203 | + | |
| 204 | + mockStatic(Beans.class); | |
| 205 | + expect(Beans.getReference(HttpServletRequest.class)).andReturn(request).anyTimes(); | |
| 206 | + | |
| 207 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 208 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); | |
| 209 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 210 | + expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 211 | + expect(request.getSession()).andReturn(session).anyTimes(); | |
| 212 | + expect(Faces.convert("1", converter)).andReturn("return"); | |
| 213 | + | |
| 214 | + replayAll(); | |
| 215 | + param = new ParameterImpl<Long>(ip); | |
| 216 | + assertEquals("return", param.getValue()); | |
| 217 | + verifyAll(); | |
| 218 | + } | |
| 219 | + | |
| 220 | + @Test | |
| 221 | + public void testGetValueWhenViewScopedWithParamValueNotNull() { | |
| 222 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 223 | + expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); | |
| 224 | + Map<String, Object> map = new HashMap<String,Object>(); | |
| 225 | + | |
| 226 | + mockStatic(Beans.class); | |
| 227 | + expect(Beans.getReference(HttpServletRequest.class)).andReturn(request).anyTimes(); | |
| 228 | + | |
| 229 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 230 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 231 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); | |
| 232 | + expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 233 | + expect(Faces.getViewMap()).andReturn(map); | |
| 234 | + expect(Faces.convert("1", converter)).andReturn("return"); | |
| 235 | + | |
| 236 | + replayAll(); | |
| 237 | + param = new ParameterImpl<Long>(ip); | |
| 238 | + assertEquals("return", param.getValue()); | |
| 239 | + assertEquals("return", map.get("name")); | |
| 240 | + verifyAll(); | |
| 241 | + } | |
| 242 | + | |
| 243 | + @Test | |
| 244 | + public void testGetValueWhenViewScopedWithParamValueNull() { | |
| 245 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 246 | + Map<String, Object> map = new HashMap<String,Object>(); | |
| 247 | + map.put("name", "ops"); | |
| 248 | + | |
| 249 | + mockStatic(Beans.class); | |
| 250 | + expect(Beans.getReference(HttpServletRequest.class)).andReturn(request).anyTimes(); | |
| 251 | + | |
| 252 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 253 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 254 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); | |
| 255 | + expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn(null); | |
| 256 | + expect(Faces.getViewMap()).andReturn(map); | |
| 257 | + | |
| 258 | + replayAll(); | |
| 259 | + param = new ParameterImpl<Long>(ip); | |
| 260 | + assertEquals("ops", param.getValue()); | |
| 261 | + assertEquals("ops", map.get("name")); | |
| 262 | + verifyAll(); | |
| 263 | + } | |
| 264 | + | |
| 265 | + @Test | |
| 266 | + public void testGetValueElseWithValueNull() { | |
| 267 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 268 | + expect(Faces.getConverter(EasyMock.anyObject(Class.class))).andReturn(converter); | |
| 269 | + | |
| 270 | + mockStatic(Beans.class); | |
| 271 | + expect(Beans.getReference(HttpServletRequest.class)).andReturn(request).anyTimes(); | |
| 272 | + | |
| 273 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 274 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 275 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 276 | + expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 277 | + expect(Faces.convert("1", converter)).andReturn("return"); | |
| 278 | + | |
| 279 | + replayAll(); | |
| 280 | + param = new ParameterImpl<Long>(ip); | |
| 281 | + assertEquals("return", param.getValue()); | |
| 282 | + verifyAll(); | |
| 283 | + } | |
| 284 | + | |
| 285 | + @Test | |
| 286 | + public void testGetValueElseWithValueNotNull() { | |
| 287 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 288 | + | |
| 289 | + mockStatic(Beans.class); | |
| 290 | + expect(Beans.getReference(HttpServletRequest.class)).andReturn(request).anyTimes(); | |
| 291 | + | |
| 292 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 293 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 294 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 295 | + expect(request.getParameter(EasyMock.anyObject(String.class))).andReturn("1"); | |
| 296 | + | |
| 297 | + replayAll(); | |
| 298 | + param = new ParameterImpl<Long>(ip); | |
| 299 | + Whitebox.setInternalState(param, "value", "myvalue"); | |
| 300 | + assertEquals("myvalue", param.getValue()); | |
| 301 | + verifyAll(); | |
| 302 | + } | |
| 303 | + | |
| 304 | + @Test | |
| 305 | + public void testSetValueIsSessionScoped() { | |
| 306 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 307 | + | |
| 308 | + mockStatic(Beans.class); | |
| 309 | + expect(Beans.getReference(HttpServletRequest.class)).andReturn(request).anyTimes(); | |
| 310 | + | |
| 311 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(true); | |
| 312 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 313 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 314 | + expect(request.getSession()).andReturn(session); | |
| 315 | + | |
| 316 | + session.setAttribute("name", 1L); | |
| 317 | + | |
| 318 | + replayAll(); | |
| 319 | + param = new ParameterImpl<Long>(ip); | |
| 320 | + param.setValue(1L); | |
| 321 | + verifyAll(); | |
| 322 | + } | |
| 323 | + | |
| 324 | + @Test | |
| 325 | + public void testSetValueIsViewScoped() { | |
| 326 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 327 | + | |
| 328 | + Map<String, Object> map = new HashMap<String, Object>(); | |
| 329 | + | |
| 330 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 331 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 332 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(true); | |
| 333 | + expect(Faces.getViewMap()).andReturn(map); | |
| 334 | + | |
| 335 | + replayAll(); | |
| 336 | + param = new ParameterImpl<Long>(ip); | |
| 337 | + param.setValue(1L); | |
| 338 | + assertEquals(1L, map.get("name")); | |
| 339 | + verifyAll(); | |
| 340 | + } | |
| 341 | + | |
| 342 | + @Test | |
| 343 | + public void testSetValueElse() { | |
| 344 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 345 | + | |
| 346 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 347 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(false); | |
| 348 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 349 | + | |
| 350 | + replayAll(); | |
| 351 | + param = new ParameterImpl<Long>(ip); | |
| 352 | + param.setValue(1L); | |
| 353 | + assertEquals(1L, Whitebox.getInternalState(param, "value")); | |
| 354 | + verifyAll(); | |
| 355 | + } | |
| 356 | + | |
| 357 | + @Test | |
| 358 | + public void testOthers() { | |
| 359 | + this.prepareForTestWithKeyFromNameAnnotation(); | |
| 360 | + | |
| 361 | + expect(annotated.isAnnotationPresent(SessionScoped.class)).andReturn(false); | |
| 362 | + expect(annotated.isAnnotationPresent(RequestScoped.class)).andReturn(true); | |
| 363 | + expect(annotated.isAnnotationPresent(ViewScoped.class)).andReturn(false); | |
| 364 | + | |
| 365 | + replayAll(); | |
| 366 | + param = new ParameterImpl<Long>(ip); | |
| 367 | + param.setValue(1L); | |
| 368 | + verifyAll(); | |
| 369 | + } | |
| 370 | + | |
| 371 | +} | ... | ... |
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/internal/proxy/HttpSessionProxyTest.java
0 → 100644
| ... | ... | @@ -0,0 +1,125 @@ |
| 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 | +package br.gov.frameworkdemoiselle.internal.proxy; | |
| 39 | + | |
| 40 | +import static org.easymock.EasyMock.expect; | |
| 41 | +import static org.easymock.EasyMock.replay; | |
| 42 | +import static org.easymock.EasyMock.verify; | |
| 43 | +import static org.junit.Assert.assertEquals; | |
| 44 | + | |
| 45 | +import java.util.Enumeration; | |
| 46 | + | |
| 47 | +import javax.servlet.ServletContext; | |
| 48 | +import javax.servlet.http.HttpSession; | |
| 49 | +import javax.servlet.http.HttpSessionContext; | |
| 50 | + | |
| 51 | +import org.junit.Before; | |
| 52 | +import org.junit.Test; | |
| 53 | +import org.junit.runner.RunWith; | |
| 54 | +import org.powermock.api.easymock.PowerMock; | |
| 55 | +import org.powermock.modules.junit4.PowerMockRunner; | |
| 56 | + | |
| 57 | +@SuppressWarnings("deprecation") | |
| 58 | +@RunWith(PowerMockRunner.class) | |
| 59 | +public class HttpSessionProxyTest { | |
| 60 | + | |
| 61 | + private HttpSessionProxy proxy; | |
| 62 | + | |
| 63 | + private ServletContext servletContext; | |
| 64 | + | |
| 65 | + private Enumeration<?> enumeration; | |
| 66 | + | |
| 67 | + private HttpSession session; | |
| 68 | + | |
| 69 | + private HttpSessionContext sessionContext; | |
| 70 | + | |
| 71 | + @Before | |
| 72 | + public void before() { | |
| 73 | + session = PowerMock.createMock(HttpSession.class); | |
| 74 | + servletContext = PowerMock.createMock(ServletContext.class); | |
| 75 | + enumeration = PowerMock.createMock(Enumeration.class); | |
| 76 | + sessionContext = PowerMock.createMock(HttpSessionContext.class); | |
| 77 | + | |
| 78 | + expect(session.getValueNames()).andReturn(new String[] { "abcdef" }); | |
| 79 | + expect(session.getValue("value")).andReturn("value"); | |
| 80 | + expect(session.getSessionContext()).andReturn(sessionContext); | |
| 81 | + expect(session.getCreationTime()).andReturn(10L); | |
| 82 | + expect(session.getId()).andReturn("ID"); | |
| 83 | + expect(session.getLastAccessedTime()).andReturn(1L); | |
| 84 | + expect(session.getServletContext()).andReturn(servletContext); | |
| 85 | + expect(session.getMaxInactiveInterval()).andReturn(2); | |
| 86 | + expect(session.getAttribute("attribute")).andReturn("attribute-1"); | |
| 87 | + expect(session.getAttributeNames()).andReturn(enumeration); | |
| 88 | + expect(session.isNew()).andReturn(true); | |
| 89 | + | |
| 90 | + session.removeValue("removeValue"); | |
| 91 | + session.putValue("put", "it"); | |
| 92 | + session.invalidate(); | |
| 93 | + session.removeAttribute("remove"); | |
| 94 | + session.setAttribute("name", "object"); | |
| 95 | + session.setMaxInactiveInterval(1); | |
| 96 | + | |
| 97 | + replay(session); | |
| 98 | + | |
| 99 | + proxy = new HttpSessionProxy(session); | |
| 100 | + } | |
| 101 | + | |
| 102 | + @Test | |
| 103 | + public void testDelegation() { | |
| 104 | + assertEquals(sessionContext, proxy.getSessionContext()); | |
| 105 | + assertEquals("value", proxy.getValue("value")); | |
| 106 | + assertEquals("abcdef", proxy.getValueNames()[0]); | |
| 107 | + assertEquals(10L, proxy.getCreationTime()); | |
| 108 | + assertEquals("ID", proxy.getId()); | |
| 109 | + assertEquals(1L, proxy.getLastAccessedTime()); | |
| 110 | + assertEquals(servletContext, proxy.getServletContext()); | |
| 111 | + assertEquals(2, proxy.getMaxInactiveInterval()); | |
| 112 | + assertEquals("attribute-1", proxy.getAttribute("attribute")); | |
| 113 | + assertEquals(enumeration, proxy.getAttributeNames()); | |
| 114 | + assertEquals(true, proxy.isNew()); | |
| 115 | + | |
| 116 | + proxy.removeValue("removeValue"); | |
| 117 | + proxy.putValue("put", "it"); | |
| 118 | + proxy.invalidate(); | |
| 119 | + proxy.removeAttribute("remove"); | |
| 120 | + proxy.setAttribute("name", "object"); | |
| 121 | + proxy.setMaxInactiveInterval(1); | |
| 122 | + | |
| 123 | + verify(session); | |
| 124 | + } | |
| 125 | +} | ... | ... |
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(); | ... | ... |