Commit 0e745c2bf51a389647c5191b21a4519a7a0f4f98
Exists in
master
Merge branch '2.4.0' of https://github.com/demoiselle/framework.git into 2.4.0
Showing
9 changed files
with
648 additions
and
2 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/message/DefaultMessage.java
... | ... | @@ -41,6 +41,9 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; |
41 | 41 | import br.gov.frameworkdemoiselle.util.Strings; |
42 | 42 | |
43 | 43 | /** |
44 | + * An implementation of the Message that uses resource files the application for | |
45 | + * obtaining the description of the messages. | |
46 | + * | |
44 | 47 | * @author SERPRO |
45 | 48 | */ |
46 | 49 | public class DefaultMessage implements Message { |
... | ... | @@ -57,6 +60,14 @@ public class DefaultMessage implements Message { |
57 | 60 | |
58 | 61 | public static final SeverityType DEFAULT_SEVERITY = SeverityType.INFO; |
59 | 62 | |
63 | + /** | |
64 | + * Create a new DefaultMessage with text, severity and parameters. | |
65 | + * | |
66 | + * @param text: the text of the message. | |
67 | + * @param severity: represents the kind of message. | |
68 | + * @param params: parameters of the message. | |
69 | + * | |
70 | + * */ | |
60 | 71 | public DefaultMessage(String text, SeverityType severity, Object... params) { |
61 | 72 | this.originalText = text; |
62 | 73 | this.severity = (severity == null ? DEFAULT_SEVERITY : severity); |
... | ... | @@ -66,6 +77,13 @@ public class DefaultMessage implements Message { |
66 | 77 | initParsedText(); |
67 | 78 | } |
68 | 79 | |
80 | + /** | |
81 | + * Create a new DefaultMessage with text and parameters. | |
82 | + * | |
83 | + * @param text: the text of the message. | |
84 | + * @param params: parameters of the message. | |
85 | + * | |
86 | + * */ | |
69 | 87 | public DefaultMessage(String text, Object... params) { |
70 | 88 | this(text, null, (Object[]) params); |
71 | 89 | } |
... | ... | @@ -98,8 +116,10 @@ public class DefaultMessage implements Message { |
98 | 116 | public int hashCode() { |
99 | 117 | final int prime = 31; |
100 | 118 | int result = 1; |
101 | - result = prime * result + ((parsedText == null) ? 0 : parsedText.hashCode()); | |
102 | - result = prime * result + ((severity == null) ? 0 : severity.hashCode()); | |
119 | + result = prime * result | |
120 | + + ((parsedText == null) ? 0 : parsedText.hashCode()); | |
121 | + result = prime * result | |
122 | + + ((severity == null) ? 0 : severity.hashCode()); | |
103 | 123 | return result; |
104 | 124 | } |
105 | 125 | ... | ... |
impl/core/src/test/java/message/MessageContextTest.java
... | ... | @@ -134,6 +134,16 @@ public class MessageContextTest { |
134 | 134 | } |
135 | 135 | |
136 | 136 | @Test |
137 | + public void testRecoverStringMessageWithParams() { | |
138 | + ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
139 | + DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
140 | + | |
141 | + messageContext.add("Message with {0} param", 1); | |
142 | + assertTrue(appender.getMessages().get(0).getText().equals("Message with 1 param")); | |
143 | + ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
144 | + } | |
145 | + | |
146 | + @Test | |
137 | 147 | public void testRecoverMessageWithParams() { |
138 | 148 | ContextManager.activate(ManagedContext.class, RequestScoped.class); |
139 | 149 | Message message = new DefaultMessage("Message with {0} param"); | ... | ... |
... | ... | @@ -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 | +} | ... | ... |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ParameterImpl.java
... | ... | @@ -41,6 +41,7 @@ import java.util.Map; |
41 | 41 | |
42 | 42 | import javax.enterprise.context.RequestScoped; |
43 | 43 | import javax.enterprise.context.SessionScoped; |
44 | +import javax.enterprise.inject.Alternative; | |
44 | 45 | import javax.enterprise.inject.spi.InjectionPoint; |
45 | 46 | import javax.faces.convert.Converter; |
46 | 47 | import javax.inject.Inject; |
... | ... | @@ -53,6 +54,7 @@ import br.gov.frameworkdemoiselle.util.Faces; |
53 | 54 | import br.gov.frameworkdemoiselle.util.Parameter; |
54 | 55 | import br.gov.frameworkdemoiselle.util.Reflections; |
55 | 56 | |
57 | +@Alternative | |
56 | 58 | public class ParameterImpl<T extends Serializable> implements Parameter<T>, Serializable { |
57 | 59 | |
58 | 60 | private static final long serialVersionUID = 1L; | ... | ... |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/procuder/ParameterProducer.java
0 → 100644
... | ... | @@ -0,0 +1,76 @@ |
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 | + * Demoiselle Framework Copyright (c) 2010 Serpro and other contributors as indicated by the @author tag. See the | |
39 | + * copyright.txt in the distribution for a full listing of contributors. Demoiselle Framework is an open source Java EE | |
40 | + * library designed to accelerate the development of transactional database Web applications. Demoiselle Framework is | |
41 | + * released under the terms of the LGPL license 3 http://www.gnu.org/licenses/lgpl.html LGPL License 3 This file is part | |
42 | + * of Demoiselle Framework. Demoiselle Framework is free software: you can redistribute it and/or modify it under the | |
43 | + * terms of the GNU Lesser General Public License 3 as published by the Free Software Foundation. Demoiselle Framework | |
44 | + * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
45 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You | |
46 | + * should have received a copy of the GNU Lesser General Public License along with Demoiselle Framework. If not, see | |
47 | + * <http://www.gnu.org/licenses/>. | |
48 | + */ | |
49 | +package br.gov.frameworkdemoiselle.internal.procuder; | |
50 | + | |
51 | +import java.io.Serializable; | |
52 | + | |
53 | +import javax.enterprise.inject.Default; | |
54 | +import javax.enterprise.inject.Produces; | |
55 | +import javax.enterprise.inject.spi.InjectionPoint; | |
56 | + | |
57 | +import br.gov.frameworkdemoiselle.annotation.Name; | |
58 | +import br.gov.frameworkdemoiselle.internal.implementation.ParameterImpl; | |
59 | +import br.gov.frameworkdemoiselle.util.Parameter; | |
60 | + | |
61 | +public class ParameterProducer implements Serializable { | |
62 | + | |
63 | + private static final long serialVersionUID = 1L; | |
64 | + | |
65 | + @Default | |
66 | + @Produces | |
67 | + public <T extends Serializable> Parameter<T> createDefault(final InjectionPoint ip) { | |
68 | + return new ParameterImpl<T>(ip); | |
69 | + } | |
70 | + | |
71 | + @Name("") | |
72 | + @Produces | |
73 | + public <T extends Serializable> Parameter<T> createNamed(final InjectionPoint ip) { | |
74 | + return new ParameterImpl<T>(ip); | |
75 | + } | |
76 | +} | ... | ... |