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 | 24 | |
25 | 25 | @Inject |
26 | 26 | private MyCrud crud; |
27 | + | |
28 | + @Inject | |
29 | + private MyNamedCrud namedCrud; | |
27 | 30 | |
28 | 31 | @Deployment(name = "1") |
29 | 32 | public static WebArchive createDeployment() { |
... | ... | @@ -80,6 +83,17 @@ public class JPACrudTest { |
80 | 83 | |
81 | 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 | 98 | private void populate(int size, int offset) { |
85 | 99 | MyEntity entity; |
... | ... | @@ -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 | 122 | private String createId(String id) { |
97 | 123 | return this.getClass().getName() + "_" + id; |
98 | 124 | } | ... | ... |
impl/extension/jpa/src/test/java/template/MyNamedCrud.java
0 → 100644
impl/extension/jpa/src/test/java/template/MyNamedEntity.java
0 → 100644
... | ... | @@ -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