Commit 05be04e12a1762460c51e376fe6cab5e228b1e43
1 parent
40b5ce2b
Exists in
master
Modificando a estrutura do teste de template
Showing
7 changed files
with
247 additions
and
246 deletions
Show diff stats
... | ... | @@ -0,0 +1,132 @@ |
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 template; | |
38 | + | |
39 | +import java.util.ArrayList; | |
40 | +import java.util.List; | |
41 | + | |
42 | +import javax.enterprise.context.RequestScoped; | |
43 | + | |
44 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
45 | +import br.gov.frameworkdemoiselle.template.Crud; | |
46 | + | |
47 | +@RequestScoped | |
48 | +public class CrudImpl implements Crud<DummyEntity, Long> { | |
49 | + | |
50 | + private static final long serialVersionUID = 1L; | |
51 | + | |
52 | + private List<DummyEntity> entities; | |
53 | + | |
54 | + public CrudImpl() { | |
55 | + | |
56 | + super(); | |
57 | + | |
58 | + this.entities = new ArrayList<DummyEntity>(); | |
59 | + | |
60 | + } | |
61 | + | |
62 | + public void resetEntities() { | |
63 | + | |
64 | + this.entities.clear(); | |
65 | + | |
66 | + this.entities.add(new DummyEntity(1L, "Dummy1 Label 1")); | |
67 | + this.entities.add(new DummyEntity(2L, "Dummy1 Label 2")); | |
68 | + this.entities.add(new DummyEntity(3L, "Dummy1 Label 3")); | |
69 | + this.entities.add(new DummyEntity(4L, "Dummy1 Label 4")); | |
70 | + this.entities.add(new DummyEntity(5L, "Dummy1 Label 5")); | |
71 | + this.entities.add(new DummyEntity(6L, "Dummy1 Label 6")); | |
72 | + this.entities.add(new DummyEntity(7L, "Dummy1 Label 7")); | |
73 | + this.entities.add(new DummyEntity(8L, "Dummy1 Label 8")); | |
74 | + this.entities.add(new DummyEntity(9L, "Dummy1 Label 9")); | |
75 | + this.entities.add(new DummyEntity(10L, "Dummy1 Label 10")); | |
76 | + | |
77 | + } | |
78 | + | |
79 | + @Override | |
80 | + public void delete(Long id) { | |
81 | + | |
82 | + this.entities.remove(this.load(id)); | |
83 | + | |
84 | + } | |
85 | + | |
86 | + @Override | |
87 | + public List<DummyEntity> findAll() { | |
88 | + | |
89 | + return this.entities; | |
90 | + | |
91 | + } | |
92 | + | |
93 | + @Override | |
94 | + public DummyEntity insert(DummyEntity bean) { | |
95 | + | |
96 | + if (this.entities.add(bean)) { | |
97 | + return bean; | |
98 | + } else { | |
99 | + throw new DemoiselleException("Erro ao inserir entity"); | |
100 | + } | |
101 | + | |
102 | + } | |
103 | + | |
104 | + @Override | |
105 | + public DummyEntity load(Long id) { | |
106 | + | |
107 | + for (DummyEntity dummyEntity : this.entities) { | |
108 | + | |
109 | + if (dummyEntity.getId().equals(id)) { | |
110 | + | |
111 | + return dummyEntity; | |
112 | + | |
113 | + } | |
114 | + | |
115 | + } | |
116 | + | |
117 | + return null; | |
118 | + | |
119 | + } | |
120 | + | |
121 | + @Override | |
122 | + public DummyEntity update(DummyEntity bean) { | |
123 | + | |
124 | + DummyEntity dummyEntity = this.load(bean.getId()); | |
125 | + | |
126 | + dummyEntity.setName(bean.getName()); | |
127 | + | |
128 | + return dummyEntity; | |
129 | + | |
130 | + } | |
131 | + | |
132 | +} | ... | ... |
... | ... | @@ -0,0 +1,100 @@ |
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 template; | |
38 | + | |
39 | +public class DummyEntity { | |
40 | + | |
41 | + private Long id; | |
42 | + private String name; | |
43 | + | |
44 | + public DummyEntity(Long id, String name) { | |
45 | + | |
46 | + super(); | |
47 | + | |
48 | + this.id = id; | |
49 | + this.name = name; | |
50 | + | |
51 | + } | |
52 | + | |
53 | + public String getName() { | |
54 | + return name; | |
55 | + } | |
56 | + | |
57 | + public void setName(String name) { | |
58 | + this.name = name; | |
59 | + } | |
60 | + | |
61 | + public Long getId() { | |
62 | + return id; | |
63 | + } | |
64 | + | |
65 | + public void setId(Long id) { | |
66 | + this.id = id; | |
67 | + } | |
68 | + | |
69 | + @Override | |
70 | + public int hashCode() { | |
71 | + final int prime = 31; | |
72 | + int result = 1; | |
73 | + result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
74 | + result = prime * result + ((name == null) ? 0 : name.hashCode()); | |
75 | + return result; | |
76 | + } | |
77 | + | |
78 | + @Override | |
79 | + public boolean equals(Object obj) { | |
80 | + if (this == obj) | |
81 | + return true; | |
82 | + if (obj == null) | |
83 | + return false; | |
84 | + if (getClass() != obj.getClass()) | |
85 | + return false; | |
86 | + DummyEntity other = (DummyEntity) obj; | |
87 | + if (id == null) { | |
88 | + if (other.id != null) | |
89 | + return false; | |
90 | + } else if (!id.equals(other.id)) | |
91 | + return false; | |
92 | + if (name == null) { | |
93 | + if (other.name != null) | |
94 | + return false; | |
95 | + } else if (!name.equals(other.name)) | |
96 | + return false; | |
97 | + return true; | |
98 | + } | |
99 | + | |
100 | +} | ... | ... |
impl/core/src/test/java/template/TemplateDelegateCrud.java
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +package template; | |
2 | + | |
3 | +import br.gov.frameworkdemoiselle.stereotype.BusinessController; | |
4 | +import br.gov.frameworkdemoiselle.template.DelegateCrud; | |
5 | + | |
6 | +@BusinessController | |
7 | +public class TemplateDelegateCrud extends DelegateCrud<DummyEntity, Long, CrudImpl>{ | |
8 | + | |
9 | + private static final long serialVersionUID = 1L; | |
10 | + | |
11 | +} | ... | ... |
impl/core/src/test/java/template/TemplateTest.java
... | ... | @@ -36,7 +36,10 @@ |
36 | 36 | */ |
37 | 37 | package template; |
38 | 38 | |
39 | -import static junit.framework.Assert.*; | |
39 | +import static junit.framework.Assert.assertEquals; | |
40 | +import static junit.framework.Assert.assertFalse; | |
41 | +import static junit.framework.Assert.assertNotNull; | |
42 | +import static junit.framework.Assert.assertNull; | |
40 | 43 | |
41 | 44 | import java.util.List; |
42 | 45 | |
... | ... | @@ -51,9 +54,6 @@ import org.junit.Before; |
51 | 54 | import org.junit.Test; |
52 | 55 | import org.junit.runner.RunWith; |
53 | 56 | |
54 | -import template.business.TemplateDelegateCrud; | |
55 | -import template.crud.CrudImpl; | |
56 | -import template.model.DummyEntity; | |
57 | 57 | import test.Tests; |
58 | 58 | import br.gov.frameworkdemoiselle.internal.context.ContextManager; |
59 | 59 | import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | ... | ... |
impl/core/src/test/java/template/business/TemplateDelegateCrud.java
... | ... | @@ -1,11 +0,0 @@ |
1 | -package template.business; | |
2 | - | |
3 | -import template.crud.CrudImpl; | |
4 | -import template.model.DummyEntity; | |
5 | -import br.gov.frameworkdemoiselle.stereotype.BusinessController; | |
6 | -import br.gov.frameworkdemoiselle.template.DelegateCrud; | |
7 | - | |
8 | -@BusinessController | |
9 | -public class TemplateDelegateCrud extends DelegateCrud<DummyEntity, Long, CrudImpl>{ | |
10 | - | |
11 | -} |
impl/core/src/test/java/template/crud/CrudImpl.java
... | ... | @@ -1,131 +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 template.crud; | |
38 | - | |
39 | -import java.util.ArrayList; | |
40 | -import java.util.List; | |
41 | - | |
42 | -import javax.enterprise.context.RequestScoped; | |
43 | - | |
44 | -import template.model.DummyEntity; | |
45 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
46 | -import br.gov.frameworkdemoiselle.template.Crud; | |
47 | - | |
48 | -@RequestScoped | |
49 | -public class CrudImpl implements Crud<DummyEntity, Long> { | |
50 | - | |
51 | - private List<DummyEntity> entities; | |
52 | - | |
53 | - public CrudImpl() { | |
54 | - | |
55 | - super(); | |
56 | - | |
57 | - this.entities = new ArrayList<DummyEntity>(); | |
58 | - | |
59 | - } | |
60 | - | |
61 | - public void resetEntities() { | |
62 | - | |
63 | - this.entities.clear(); | |
64 | - | |
65 | - this.entities.add(new DummyEntity(1L, "Dummy1 Label 1")); | |
66 | - this.entities.add(new DummyEntity(2L, "Dummy1 Label 2")); | |
67 | - this.entities.add(new DummyEntity(3L, "Dummy1 Label 3")); | |
68 | - this.entities.add(new DummyEntity(4L, "Dummy1 Label 4")); | |
69 | - this.entities.add(new DummyEntity(5L, "Dummy1 Label 5")); | |
70 | - this.entities.add(new DummyEntity(6L, "Dummy1 Label 6")); | |
71 | - this.entities.add(new DummyEntity(7L, "Dummy1 Label 7")); | |
72 | - this.entities.add(new DummyEntity(8L, "Dummy1 Label 8")); | |
73 | - this.entities.add(new DummyEntity(9L, "Dummy1 Label 9")); | |
74 | - this.entities.add(new DummyEntity(10L, "Dummy1 Label 10")); | |
75 | - | |
76 | - } | |
77 | - | |
78 | - @Override | |
79 | - public void delete(Long id) { | |
80 | - | |
81 | - this.entities.remove(this.load(id)); | |
82 | - | |
83 | - } | |
84 | - | |
85 | - @Override | |
86 | - public List<DummyEntity> findAll() { | |
87 | - | |
88 | - return this.entities; | |
89 | - | |
90 | - } | |
91 | - | |
92 | - @Override | |
93 | - public DummyEntity insert(DummyEntity bean) { | |
94 | - | |
95 | - if (this.entities.add(bean)) { | |
96 | - return bean; | |
97 | - } else { | |
98 | - throw new DemoiselleException("Erro ao inserir entity"); | |
99 | - } | |
100 | - | |
101 | - } | |
102 | - | |
103 | - @Override | |
104 | - public DummyEntity load(Long id) { | |
105 | - | |
106 | - for (DummyEntity dummyEntity : this.entities) { | |
107 | - | |
108 | - if (dummyEntity.getId().equals(id)) { | |
109 | - | |
110 | - return dummyEntity; | |
111 | - | |
112 | - } | |
113 | - | |
114 | - } | |
115 | - | |
116 | - return null; | |
117 | - | |
118 | - } | |
119 | - | |
120 | - @Override | |
121 | - public DummyEntity update(DummyEntity bean) { | |
122 | - | |
123 | - DummyEntity dummyEntity = this.load(bean.getId()); | |
124 | - | |
125 | - dummyEntity.setName(bean.getName()); | |
126 | - | |
127 | - return dummyEntity; | |
128 | - | |
129 | - } | |
130 | - | |
131 | -} |
impl/core/src/test/java/template/model/DummyEntity.java
... | ... | @@ -1,100 +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 template.model; | |
38 | - | |
39 | -public class DummyEntity { | |
40 | - | |
41 | - private Long id; | |
42 | - private String name; | |
43 | - | |
44 | - public DummyEntity(Long id, String name) { | |
45 | - | |
46 | - super(); | |
47 | - | |
48 | - this.id = id; | |
49 | - this.name = name; | |
50 | - | |
51 | - } | |
52 | - | |
53 | - public String getName() { | |
54 | - return name; | |
55 | - } | |
56 | - | |
57 | - public void setName(String name) { | |
58 | - this.name = name; | |
59 | - } | |
60 | - | |
61 | - public Long getId() { | |
62 | - return id; | |
63 | - } | |
64 | - | |
65 | - public void setId(Long id) { | |
66 | - this.id = id; | |
67 | - } | |
68 | - | |
69 | - @Override | |
70 | - public int hashCode() { | |
71 | - final int prime = 31; | |
72 | - int result = 1; | |
73 | - result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
74 | - result = prime * result + ((name == null) ? 0 : name.hashCode()); | |
75 | - return result; | |
76 | - } | |
77 | - | |
78 | - @Override | |
79 | - public boolean equals(Object obj) { | |
80 | - if (this == obj) | |
81 | - return true; | |
82 | - if (obj == null) | |
83 | - return false; | |
84 | - if (getClass() != obj.getClass()) | |
85 | - return false; | |
86 | - DummyEntity other = (DummyEntity) obj; | |
87 | - if (id == null) { | |
88 | - if (other.id != null) | |
89 | - return false; | |
90 | - } else if (!id.equals(other.id)) | |
91 | - return false; | |
92 | - if (name == null) { | |
93 | - if (other.name != null) | |
94 | - return false; | |
95 | - } else if (!name.equals(other.name)) | |
96 | - return false; | |
97 | - return true; | |
98 | - } | |
99 | - | |
100 | -} |