Commit 63bafd38f52cb4155d5d9c5d89585a780e93cf5a
1 parent
9ae5e3de
Exists in
master
Adição de testes para a cituação na qual a entidade não tem o mesmo nome
da classe (com a anotação @Entity(name = "outroNome"))
Showing
4 changed files
with
65 additions
and
0 deletions
Show diff stats
impl/extension/jpa/src/test/java/template/JPACrudTest.java
@@ -24,6 +24,9 @@ public class JPACrudTest { | @@ -24,6 +24,9 @@ public class JPACrudTest { | ||
24 | 24 | ||
25 | @Inject | 25 | @Inject |
26 | private MyCrud crud; | 26 | private MyCrud crud; |
27 | + | ||
28 | + @Inject | ||
29 | + private MyNamedCrud namedCrud; | ||
27 | 30 | ||
28 | @Deployment(name = "1") | 31 | @Deployment(name = "1") |
29 | public static WebArchive createDeployment() { | 32 | public static WebArchive createDeployment() { |
@@ -80,6 +83,17 @@ public class JPACrudTest { | @@ -80,6 +83,17 @@ public class JPACrudTest { | ||
80 | 83 | ||
81 | assertEquals(list.size(), 4); | 84 | assertEquals(list.size(), 4); |
82 | } | 85 | } |
86 | + | ||
87 | + @Test | ||
88 | + public void findAllNamedEntity() { | ||
89 | + populateNamedEntity(4, 0); | ||
90 | + | ||
91 | + List<MyNamedEntity> list; | ||
92 | + list = namedCrud.findAll(); | ||
93 | + | ||
94 | + assertEquals(list.size(), 4); | ||
95 | + } | ||
96 | + | ||
83 | 97 | ||
84 | private void populate(int size, int offset) { | 98 | private void populate(int size, int offset) { |
85 | MyEntity entity; | 99 | MyEntity entity; |
@@ -93,6 +107,18 @@ public class JPACrudTest { | @@ -93,6 +107,18 @@ public class JPACrudTest { | ||
93 | } | 107 | } |
94 | } | 108 | } |
95 | 109 | ||
110 | + private void populateNamedEntity(int size, int offset) { | ||
111 | + MyNamedEntity entity; | ||
112 | + | ||
113 | + for (int i = 0; i < size; i++) { | ||
114 | + entity = new MyNamedEntity(); | ||
115 | + entity.setId(createId("id-" + (i + 1 + offset))); | ||
116 | + entity.setDescription("desc-" + (i + 1 + offset)); | ||
117 | + | ||
118 | + namedCrud.insert(entity); | ||
119 | + } | ||
120 | + } | ||
121 | + | ||
96 | private String createId(String id) { | 122 | private String createId(String id) { |
97 | return this.getClass().getName() + "_" + id; | 123 | return this.getClass().getName() + "_" + id; |
98 | } | 124 | } |
impl/extension/jpa/src/test/java/template/MyNamedCrud.java
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +package template; | ||
2 | + | ||
3 | +import br.gov.frameworkdemoiselle.template.JPACrud; | ||
4 | + | ||
5 | +public class MyNamedCrud extends JPACrud<MyNamedEntity, String> { | ||
6 | + | ||
7 | + private static final long serialVersionUID = 1L; | ||
8 | + | ||
9 | +} | ||
0 | \ No newline at end of file | 10 | \ No newline at end of file |
impl/extension/jpa/src/test/java/template/MyNamedEntity.java
0 → 100644
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +package template; | ||
2 | + | ||
3 | +import javax.persistence.Entity; | ||
4 | +import javax.persistence.Id; | ||
5 | + | ||
6 | +@Entity(name = "namedEntity") | ||
7 | +public class MyNamedEntity { | ||
8 | + | ||
9 | + @Id | ||
10 | + private String id; | ||
11 | + | ||
12 | + private String description; | ||
13 | + | ||
14 | + public String getId() { | ||
15 | + return id; | ||
16 | + } | ||
17 | + | ||
18 | + public void setId(String id) { | ||
19 | + this.id = id; | ||
20 | + } | ||
21 | + | ||
22 | + public String getDescription() { | ||
23 | + return description; | ||
24 | + } | ||
25 | + | ||
26 | + public void setDescription(String description) { | ||
27 | + this.description = description; | ||
28 | + } | ||
29 | +} |
impl/extension/jpa/src/test/resources/template/persistence.xml
@@ -41,6 +41,7 @@ | @@ -41,6 +41,7 @@ | ||
41 | <non-jta-data-source>jdbc/__default</non-jta-data-source> | 41 | <non-jta-data-source>jdbc/__default</non-jta-data-source> |
42 | 42 | ||
43 | <class>template.MyEntity</class> | 43 | <class>template.MyEntity</class> |
44 | + <class>template.MyNamedEntity</class> | ||
44 | 45 | ||
45 | <properties> | 46 | <properties> |
46 | <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> | 47 | <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> |