Commit f6ddae7800887b898b9ce9ad468c1e23a853ef22
Exists in
master
Merge branch 'master' of git@github.com:demoiselle/framework.git
Showing
1 changed file
with
122 additions
and
0 deletions
Show diff stats
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImplTest.java
0 → 100644
@@ -0,0 +1,122 @@ | @@ -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 | +} |