Commit 5bbd062565bd44237851cc9cbd98783791cbe709
1 parent
e3193825
Exists in
master
Adição de testes para paginação dentro do core.
Showing
5 changed files
with
538 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,40 @@ |
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 pagination; | |
38 | + | |
39 | +public class DummyEntity { | |
40 | +} | ... | ... |
impl/core/src/test/java/pagination/PaginationBasicTest.java
0 → 100644
... | ... | @@ -0,0 +1,74 @@ |
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 pagination; | |
38 | + | |
39 | +import static junit.framework.Assert.assertEquals; | |
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.Test; | |
45 | +import org.junit.runner.RunWith; | |
46 | + | |
47 | +import test.Tests; | |
48 | +import transaction.defaultstrategy.TransactionDefaultTest; | |
49 | +import br.gov.frameworkdemoiselle.internal.implementation.PaginationImpl; | |
50 | +import br.gov.frameworkdemoiselle.pagination.Pagination; | |
51 | + | |
52 | +@RunWith(Arquillian.class) | |
53 | +public class PaginationBasicTest { | |
54 | + | |
55 | + private Pagination pagination; | |
56 | + | |
57 | + @Deployment | |
58 | + public static JavaArchive createDeployment() { | |
59 | + JavaArchive deployment = Tests.createDeployment(TransactionDefaultTest.class); | |
60 | + return deployment; | |
61 | + } | |
62 | + | |
63 | + @Test | |
64 | + public void createDefaultPagination(){ | |
65 | + pagination = new PaginationImpl(); | |
66 | + | |
67 | + assertEquals(pagination.getPageSize(), 0); | |
68 | + assertEquals(pagination.getCurrentPage(), 0); | |
69 | + assertEquals(pagination.getTotalResults(), 0); | |
70 | + assertEquals(pagination.getTotalPages(), 0); | |
71 | + assertEquals(pagination.getFirstResult(), 0); | |
72 | + } | |
73 | + | |
74 | +} | ... | ... |
impl/core/src/test/java/pagination/PaginationContextBasicTest.java
0 → 100644
... | ... | @@ -0,0 +1,224 @@ |
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 pagination; | |
38 | + | |
39 | +import static junit.framework.Assert.assertEquals; | |
40 | + | |
41 | +import javax.enterprise.context.SessionScoped; | |
42 | +import javax.inject.Inject; | |
43 | + | |
44 | +import org.jboss.arquillian.container.test.api.Deployment; | |
45 | +import org.jboss.arquillian.junit.Arquillian; | |
46 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
47 | +import org.junit.After; | |
48 | +import org.junit.Before; | |
49 | +import org.junit.Test; | |
50 | +import org.junit.runner.RunWith; | |
51 | + | |
52 | +import test.Tests; | |
53 | +import transaction.defaultstrategy.TransactionDefaultTest; | |
54 | +import br.gov.frameworkdemoiselle.internal.configuration.PaginationConfig; | |
55 | +import br.gov.frameworkdemoiselle.internal.context.ContextManager; | |
56 | +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | |
57 | +import br.gov.frameworkdemoiselle.pagination.Pagination; | |
58 | +import br.gov.frameworkdemoiselle.pagination.PaginationContext; | |
59 | + | |
60 | +@RunWith(Arquillian.class) | |
61 | +public class PaginationContextBasicTest { | |
62 | + | |
63 | + private static final int VALID_PAGE_SIZE = 5; | |
64 | + | |
65 | + private static final int VALID_CURRENT_PAGE = 2; | |
66 | + | |
67 | + private static final int VALID_TOTAL_RESULTS = 30; | |
68 | + | |
69 | + private static final int VALID_FIRST_RESULT = 5; | |
70 | + | |
71 | + private static final int INVALID_PAGE_SIZE = -5; | |
72 | + | |
73 | + private static final int INVALID_NEGATIVE_CURRENT_PAGE = -2; | |
74 | + | |
75 | + private static final int INVALID_CURRENT_PAGE = 21; | |
76 | + | |
77 | + private static final int INVALID_TOTAL_RESULTS = -1; | |
78 | + | |
79 | + private static final int INVALID_FIRST_RESULT = VALID_TOTAL_RESULTS + 1; | |
80 | + | |
81 | + private static final int INVALID_NEGATIVE_FIRST_RESULT = -19; | |
82 | + | |
83 | + @Inject | |
84 | + private PaginationContext paginationContext; | |
85 | + | |
86 | + @Inject | |
87 | + private PaginationConfig paginationConfig; | |
88 | + | |
89 | + private Pagination pagination; | |
90 | + | |
91 | + @Deployment | |
92 | + public static JavaArchive createDeployment() { | |
93 | + JavaArchive deployment = Tests.createDeployment(TransactionDefaultTest.class); | |
94 | + return deployment; | |
95 | + } | |
96 | + | |
97 | + @Before | |
98 | + public void activeContext() { | |
99 | + ContextManager.activate(ThreadLocalContext.class, SessionScoped.class); | |
100 | + pagination = paginationContext.getPagination(DummyEntity.class, true); | |
101 | + } | |
102 | + | |
103 | + @After | |
104 | + public void deactiveContext() { | |
105 | + ContextManager.deactivate(ThreadLocalContext.class, SessionScoped.class); | |
106 | + } | |
107 | + | |
108 | + @Test | |
109 | + public void defaultPaginationContext() { | |
110 | + assertEquals(pagination.getPageSize(), paginationConfig.getPageSize()); | |
111 | + assertEquals(pagination.getCurrentPage(), 0); | |
112 | + assertEquals(pagination.getTotalResults(), 0); | |
113 | + assertEquals(pagination.getTotalPages(), | |
114 | + (int) Math.ceil(pagination.getTotalResults() * 1d / pagination.getPageSize())); | |
115 | + assertEquals(pagination.getFirstResult(), pagination.getCurrentPage() * pagination.getPageSize()); | |
116 | + } | |
117 | + | |
118 | + @Test | |
119 | + public void changeToValidValuesAttributes() { | |
120 | + pagination.setPageSize(VALID_PAGE_SIZE); | |
121 | + pagination.setCurrentPage(VALID_CURRENT_PAGE); | |
122 | + pagination.setTotalResults(VALID_TOTAL_RESULTS); | |
123 | + assertEquals(pagination.getPageSize(), VALID_PAGE_SIZE); | |
124 | + assertEquals(pagination.getCurrentPage(), VALID_CURRENT_PAGE); | |
125 | + assertEquals(pagination.getTotalResults(), VALID_TOTAL_RESULTS); | |
126 | + assertEquals(pagination.getTotalPages(), (int) Math.ceil(VALID_TOTAL_RESULTS * 1d / VALID_PAGE_SIZE)); | |
127 | + assertEquals(pagination.getFirstResult(), VALID_CURRENT_PAGE * VALID_PAGE_SIZE); | |
128 | + | |
129 | + pagination.setFirstResult(VALID_FIRST_RESULT); | |
130 | + assertEquals(pagination.getFirstResult(), VALID_FIRST_RESULT); | |
131 | + } | |
132 | + | |
133 | + @Test | |
134 | + public void currentPageGreaterThanTotalPages() { | |
135 | + pagination.setPageSize(VALID_PAGE_SIZE); | |
136 | + pagination.setCurrentPage((int) Math.ceil(VALID_TOTAL_RESULTS * 1d / VALID_PAGE_SIZE) + 1); | |
137 | + pagination.setTotalResults(VALID_TOTAL_RESULTS); | |
138 | + | |
139 | + assertEquals(pagination.getCurrentPage(), (int) Math.ceil(VALID_TOTAL_RESULTS * 1d / VALID_PAGE_SIZE) - 1); | |
140 | + } | |
141 | + | |
142 | + @Test | |
143 | + public void resetCurrentAndTotalPagesWithTotalResults() { | |
144 | + pagination.setPageSize(VALID_PAGE_SIZE); | |
145 | + pagination.setCurrentPage(VALID_CURRENT_PAGE); | |
146 | + pagination.setTotalResults(VALID_TOTAL_RESULTS); | |
147 | + | |
148 | + assertEquals(pagination.getCurrentPage(), VALID_CURRENT_PAGE); | |
149 | + assertEquals(pagination.getTotalPages(), | |
150 | + (int) Math.ceil(pagination.getTotalResults() * 1d / pagination.getPageSize())); | |
151 | + | |
152 | + pagination.setTotalResults(0); | |
153 | + | |
154 | + assertEquals(pagination.getCurrentPage(), 0); | |
155 | + assertEquals(pagination.getTotalPages(), 0); | |
156 | + } | |
157 | + | |
158 | + @Test | |
159 | + public void resetCurrentAndTotalPagesWithPageSize() { | |
160 | + pagination.setPageSize(VALID_PAGE_SIZE); | |
161 | + pagination.setCurrentPage(VALID_CURRENT_PAGE); | |
162 | + pagination.setTotalResults(VALID_TOTAL_RESULTS); | |
163 | + | |
164 | + assertEquals(pagination.getCurrentPage(), VALID_CURRENT_PAGE); | |
165 | + assertEquals(pagination.getTotalPages(), | |
166 | + (int) Math.ceil(pagination.getTotalResults() * 1d / pagination.getPageSize())); | |
167 | + | |
168 | + pagination.setPageSize(0); | |
169 | + | |
170 | + assertEquals(pagination.getCurrentPage(), 0); | |
171 | + assertEquals(pagination.getTotalPages(), 0); | |
172 | + } | |
173 | + | |
174 | + @Test | |
175 | + public void resetCurrentPageWithFirstResult() { | |
176 | + pagination.setPageSize(VALID_PAGE_SIZE); | |
177 | + pagination.setCurrentPage(VALID_CURRENT_PAGE); | |
178 | + pagination.setTotalResults(VALID_TOTAL_RESULTS); | |
179 | + | |
180 | + pagination.setFirstResult(0); | |
181 | + | |
182 | + assertEquals(pagination.getCurrentPage(), 0); | |
183 | + } | |
184 | + | |
185 | + @Test | |
186 | + public void paginationToString() { | |
187 | + assertEquals("PaginationImpl [currentPage=0, pageSize=10, totalResults=0, totalPages=0]", pagination.toString()); | |
188 | + } | |
189 | + | |
190 | + @Test(expected = IndexOutOfBoundsException.class) | |
191 | + public void changeCurrentPageToInvalidNegativeValuesAttributes() { | |
192 | + pagination.setCurrentPage(INVALID_NEGATIVE_CURRENT_PAGE); | |
193 | + } | |
194 | + | |
195 | + @Test(expected = IndexOutOfBoundsException.class) | |
196 | + public void changeCurrentPageToInvalidValuesAttributes() { | |
197 | + pagination.setPageSize(VALID_PAGE_SIZE); | |
198 | + pagination.setTotalResults(VALID_TOTAL_RESULTS); | |
199 | + | |
200 | + pagination.setCurrentPage(INVALID_CURRENT_PAGE); | |
201 | + } | |
202 | + | |
203 | + @Test(expected = IndexOutOfBoundsException.class) | |
204 | + public void changePageSizeToInvalidValuesAttributes() { | |
205 | + pagination.setPageSize(INVALID_PAGE_SIZE); | |
206 | + } | |
207 | + | |
208 | + @Test(expected = IndexOutOfBoundsException.class) | |
209 | + public void changeTotalResultsToInvalidValuesAttributes() { | |
210 | + pagination.setTotalResults(INVALID_TOTAL_RESULTS); | |
211 | + } | |
212 | + | |
213 | + @Test(expected = IndexOutOfBoundsException.class) | |
214 | + public void changeFirstResultToInvalidNegativeValuesAttributes() { | |
215 | + pagination.setFirstResult(INVALID_NEGATIVE_FIRST_RESULT); | |
216 | + } | |
217 | + | |
218 | + @Test(expected = IndexOutOfBoundsException.class) | |
219 | + public void changeFirstResultToInvalidValuesAttributes() { | |
220 | + pagination.setTotalResults(VALID_TOTAL_RESULTS); | |
221 | + pagination.setFirstResult(INVALID_FIRST_RESULT); | |
222 | + } | |
223 | + | |
224 | +} | ... | ... |
impl/core/src/test/java/pagination/PaginationContextCache.java
0 → 100644
... | ... | @@ -0,0 +1,106 @@ |
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 pagination; | |
38 | + | |
39 | +import static org.junit.Assert.assertEquals; | |
40 | + | |
41 | +import javax.enterprise.context.SessionScoped; | |
42 | +import javax.inject.Inject; | |
43 | + | |
44 | +import org.jboss.arquillian.container.test.api.Deployment; | |
45 | +import org.jboss.arquillian.junit.Arquillian; | |
46 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
47 | +import org.junit.After; | |
48 | +import org.junit.Before; | |
49 | +import org.junit.Test; | |
50 | +import org.junit.runner.RunWith; | |
51 | + | |
52 | +import test.Tests; | |
53 | +import transaction.defaultstrategy.TransactionDefaultTest; | |
54 | +import br.gov.frameworkdemoiselle.internal.context.ContextManager; | |
55 | +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | |
56 | +import br.gov.frameworkdemoiselle.pagination.Pagination; | |
57 | +import br.gov.frameworkdemoiselle.pagination.PaginationContext; | |
58 | + | |
59 | +@RunWith(Arquillian.class) | |
60 | +public class PaginationContextCache { | |
61 | + | |
62 | + @Inject | |
63 | + private PaginationContext paginationContext; | |
64 | + | |
65 | + private Pagination paginationOne; | |
66 | + | |
67 | + private Pagination paginationTwo; | |
68 | + | |
69 | + @Deployment | |
70 | + public static JavaArchive createDeployment() { | |
71 | + JavaArchive deployment = Tests.createDeployment(TransactionDefaultTest.class); | |
72 | + return deployment; | |
73 | + } | |
74 | + | |
75 | + @Before | |
76 | + public void activeContext() { | |
77 | + ContextManager.activate(ThreadLocalContext.class, SessionScoped.class); | |
78 | + } | |
79 | + | |
80 | + @After | |
81 | + public void deactiveContext() { | |
82 | + ContextManager.deactivate(ThreadLocalContext.class, SessionScoped.class); | |
83 | + } | |
84 | + | |
85 | + @Test | |
86 | + public void createTwoCachedPagination(){ | |
87 | + paginationOne = paginationContext.getPagination(DummyEntity.class, true); | |
88 | + paginationTwo = paginationContext.getPagination(DummyEntity.class, true); | |
89 | + assertEquals(paginationOne, paginationTwo); | |
90 | + } | |
91 | + | |
92 | + @Test | |
93 | + public void createOneCachedPaginationMethodOne(){ | |
94 | + paginationOne = paginationContext.getPagination(DummyEntity.class, true); | |
95 | + paginationTwo = paginationContext.getPagination(DummyEntity.class); | |
96 | + assertEquals(paginationOne, paginationTwo); | |
97 | + } | |
98 | + | |
99 | + @Test | |
100 | + public void createOneCachedPaginationMethodTwo(){ | |
101 | + paginationOne = paginationContext.getPagination(DummyEntity.class, true); | |
102 | + paginationTwo = paginationContext.getPagination(DummyEntity.class, false); | |
103 | + assertEquals(paginationOne, paginationTwo); | |
104 | + } | |
105 | +} | |
106 | + | ... | ... |
impl/core/src/test/java/pagination/PaginationContextNullTest.java
0 → 100644
... | ... | @@ -0,0 +1,94 @@ |
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 pagination; | |
38 | + | |
39 | +import static org.junit.Assert.assertNull; | |
40 | + | |
41 | +import javax.enterprise.context.SessionScoped; | |
42 | +import javax.inject.Inject; | |
43 | + | |
44 | +import org.jboss.arquillian.container.test.api.Deployment; | |
45 | +import org.jboss.arquillian.junit.Arquillian; | |
46 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
47 | +import org.junit.After; | |
48 | +import org.junit.Before; | |
49 | +import org.junit.Test; | |
50 | +import org.junit.runner.RunWith; | |
51 | + | |
52 | +import test.Tests; | |
53 | +import transaction.defaultstrategy.TransactionDefaultTest; | |
54 | +import br.gov.frameworkdemoiselle.internal.context.ContextManager; | |
55 | +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | |
56 | +import br.gov.frameworkdemoiselle.pagination.Pagination; | |
57 | +import br.gov.frameworkdemoiselle.pagination.PaginationContext; | |
58 | + | |
59 | +@RunWith(Arquillian.class) | |
60 | +public class PaginationContextNullTest { | |
61 | + | |
62 | + @Inject | |
63 | + private PaginationContext paginationContext; | |
64 | + | |
65 | + private Pagination pagination; | |
66 | + | |
67 | + @Deployment | |
68 | + public static JavaArchive createDeployment() { | |
69 | + JavaArchive deployment = Tests.createDeployment(TransactionDefaultTest.class); | |
70 | + return deployment; | |
71 | + } | |
72 | + | |
73 | + @Before | |
74 | + public void activeContext() { | |
75 | + ContextManager.activate(ThreadLocalContext.class, SessionScoped.class); | |
76 | + } | |
77 | + | |
78 | + @After | |
79 | + public void deactiveContext() { | |
80 | + ContextManager.deactivate(ThreadLocalContext.class, SessionScoped.class); | |
81 | + } | |
82 | + | |
83 | + @Test | |
84 | + public void createNullPaginationMethodOne(){ | |
85 | + pagination = paginationContext.getPagination(DummyEntity.class); | |
86 | + assertNull(pagination); | |
87 | + } | |
88 | + | |
89 | + @Test | |
90 | + public void createNullPaginationMethodTwo(){ | |
91 | + pagination = paginationContext.getPagination(DummyEntity.class, false); | |
92 | + assertNull(pagination); | |
93 | + } | |
94 | +} | ... | ... |