Commit 1267e2a212ae74a55782391c860334464ff5b994
1 parent
be4b3954
Exists in
master
Implementados alguns testes do contexto customizado StaticContext
Showing
3 changed files
with
139 additions
and
0 deletions
Show diff stats
impl/core/src/test/java/context/staticcontext/ConversationBean.java
0 → 100644
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 1 | +package context.staticcontext; | ||
| 2 | + | ||
| 3 | +import javax.enterprise.context.ConversationScoped; | ||
| 4 | +import java.io.Serializable; | ||
| 5 | + | ||
| 6 | +@ConversationScoped | ||
| 7 | +public class ConversationBean implements Serializable { | ||
| 8 | + | ||
| 9 | + private static final long serialVersionUID = 1L; | ||
| 10 | + | ||
| 11 | + private String data = "test"; | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + public String getData() { | ||
| 15 | + return data; | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + public void setData(String data) { | ||
| 20 | + this.data = data; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +} |
impl/core/src/test/java/context/staticcontext/SessionBean.java
0 → 100644
| @@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
| 1 | +package context.staticcontext; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 5 | +import javax.enterprise.context.SessionScoped; | ||
| 6 | + | ||
| 7 | +@SessionScoped | ||
| 8 | +public class SessionBean implements Serializable{ | ||
| 9 | + | ||
| 10 | + private static final long serialVersionUID = 1L; | ||
| 11 | + | ||
| 12 | + private String data = "test"; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + public String getData() { | ||
| 16 | + return data; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + public void setData(String data) { | ||
| 21 | + this.data = data; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +} |
impl/core/src/test/java/context/staticcontext/StaticContextTest.java
0 → 100644
| @@ -0,0 +1,88 @@ | @@ -0,0 +1,88 @@ | ||
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 37 | +package context.staticcontext; | ||
| 38 | + | ||
| 39 | +import javax.enterprise.inject.spi.Bean; | ||
| 40 | + | ||
| 41 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 42 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 43 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 44 | +import org.junit.Assert; | ||
| 45 | +import org.junit.Test; | ||
| 46 | +import org.junit.runner.RunWith; | ||
| 47 | + | ||
| 48 | +import br.gov.frameworkdemoiselle.context.ConversationContext; | ||
| 49 | +import br.gov.frameworkdemoiselle.context.SessionContext; | ||
| 50 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
| 51 | +import test.Tests; | ||
| 52 | + | ||
| 53 | +@RunWith(Arquillian.class) | ||
| 54 | +public class StaticContextTest { | ||
| 55 | + | ||
| 56 | + @Deployment | ||
| 57 | + public static JavaArchive createDeployment() { | ||
| 58 | + JavaArchive deployment = Tests.createDeployment(StaticContextTest.class); | ||
| 59 | + return deployment; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Test | ||
| 63 | + public void checkSeparatedStores(){ | ||
| 64 | + | ||
| 65 | + ConversationContext conversationContext = Beans.getReference(ConversationContext.class); | ||
| 66 | + SessionContext sessionContext = Beans.getReference(SessionContext.class); | ||
| 67 | + | ||
| 68 | + conversationContext.activate(); | ||
| 69 | + sessionContext.activate(); | ||
| 70 | + | ||
| 71 | + ConversationBean conversationBean = Beans.getReference(ConversationBean.class); | ||
| 72 | + conversationBean.getData(); | ||
| 73 | + | ||
| 74 | + SessionBean sessionBean = Beans.getReference(SessionBean.class); | ||
| 75 | + sessionBean.getData(); | ||
| 76 | + | ||
| 77 | + Bean<?> conversationContextual = Beans.getBeanManager().getBeans(ConversationBean.class).iterator().next(); | ||
| 78 | + Bean<?> sessionContextual = Beans.getBeanManager().getBeans(SessionBean.class).iterator().next(); | ||
| 79 | + | ||
| 80 | + Assert.assertNotNull( conversationContext.get(conversationContextual) ); | ||
| 81 | + Assert.assertNull( conversationContext.get(sessionContextual) ); | ||
| 82 | + | ||
| 83 | + Assert.assertNotNull( sessionContext.get(sessionContextual) ); | ||
| 84 | + Assert.assertNull( sessionContext.get(conversationContextual) ); | ||
| 85 | + | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | +} |