Commit d3da23962bdfdfe923a1fbc4cc7f374f7400f387
1 parent
9fe4174c
Exists in
master
Implementados testes do produtor de EntityManager.
Showing
4 changed files
with
174 additions
and
0 deletions
Show diff stats
impl/extension/jpa/src/test/java/productor/MyEntity.java
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +package productor; | |
2 | + | |
3 | +import javax.persistence.Entity; | |
4 | +import javax.persistence.Id; | |
5 | + | |
6 | +@Entity | |
7 | +public class MyEntity { | |
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/java/productor/ProductorTest.java
0 → 100644
... | ... | @@ -0,0 +1,80 @@ |
1 | +package productor; | |
2 | + | |
3 | +import javax.persistence.EntityManager; | |
4 | + | |
5 | +import org.jboss.arquillian.container.test.api.Deployment; | |
6 | +import org.jboss.arquillian.junit.Arquillian; | |
7 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | |
8 | +import org.junit.Assert; | |
9 | +import org.junit.Test; | |
10 | +import org.junit.runner.RunWith; | |
11 | + | |
12 | +import test.Tests; | |
13 | +import br.gov.frameworkdemoiselle.internal.proxy.EntityManagerProxy; | |
14 | +import br.gov.frameworkdemoiselle.util.Beans; | |
15 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
16 | + | |
17 | + | |
18 | +@RunWith(Arquillian.class) | |
19 | +public class ProductorTest { | |
20 | + | |
21 | + private static final String PATH = "src/test/resources/productor"; | |
22 | + | |
23 | + @Deployment | |
24 | + public static WebArchive createDeployment() { | |
25 | + WebArchive deployment = Tests.createDeployment(ProductorTest.class); | |
26 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/persistence.xml"), "META-INF/persistence.xml"); | |
27 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | |
28 | + | |
29 | + return deployment; | |
30 | + } | |
31 | + | |
32 | + @Test | |
33 | + public void produceEntityManager(){ | |
34 | + | |
35 | + EntityManager manager = Beans.getReference(EntityManager.class); | |
36 | + Assert.assertNotNull(manager); | |
37 | + Assert.assertEquals(EntityManagerProxy.class,manager.getClass()); | |
38 | + | |
39 | + } | |
40 | + | |
41 | + @Test | |
42 | + public void produceMultipleEntityManagers(){ | |
43 | + | |
44 | + EntityManager m1 = Beans.getReference(EntityManager.class,new NameQualifier("pu")); | |
45 | + | |
46 | + Assert.assertNotNull(m1); | |
47 | + Assert.assertEquals(EntityManagerProxy.class,m1.getClass()); | |
48 | + | |
49 | + EntityManager m2 = Beans.getReference(EntityManager.class,new NameQualifier("pu2")); | |
50 | + | |
51 | + Assert.assertNotNull(m2); | |
52 | + Assert.assertEquals(EntityManagerProxy.class,m2.getClass()); | |
53 | + | |
54 | + } | |
55 | + | |
56 | + @Test | |
57 | + public void produceOneEntityManagerPerRequest(){ | |
58 | + EntityManager m1 = Beans.getReference(EntityManager.class,new NameQualifier("pu")); | |
59 | + | |
60 | + Assert.assertNotNull(m1); | |
61 | + Assert.assertEquals(EntityManagerProxy.class,m1.getClass()); | |
62 | + | |
63 | + EntityManager m2 = Beans.getReference(EntityManager.class,new NameQualifier("pu")); | |
64 | + | |
65 | + Assert.assertNotNull(m2); | |
66 | + Assert.assertEquals(EntityManagerProxy.class,m2.getClass()); | |
67 | + | |
68 | + MyEntity entity = new MyEntity(); | |
69 | + entity.setId(createId("testID")); | |
70 | + | |
71 | + m1.persist(entity); | |
72 | + | |
73 | + Assert.assertTrue( m2.contains(entity) ); | |
74 | + } | |
75 | + | |
76 | + private String createId(String id) { | |
77 | + return this.getClass().getName() + "_" + id; | |
78 | + } | |
79 | + | |
80 | +} | ... | ... |
impl/extension/jpa/src/test/resources/productor/demoiselle.properties
0 → 100644
impl/extension/jpa/src/test/resources/productor/persistence.xml
0 → 100644
... | ... | @@ -0,0 +1,64 @@ |
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 | +<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
38 | + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> | |
39 | + | |
40 | + <persistence-unit name="pu" transaction-type="RESOURCE_LOCAL"> | |
41 | + <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source> | |
42 | + | |
43 | + <class>productor.MyEntity</class> | |
44 | + | |
45 | + <properties> | |
46 | + <property name="hibernate.show_sql" value="true" /> | |
47 | + <property name="hibernate.format_sql" value="false" /> | |
48 | + <property name="hibernate.hbm2ddl.auto" value="create-drop" /> | |
49 | + </properties> | |
50 | + </persistence-unit> | |
51 | + | |
52 | + <persistence-unit name="pu2" transaction-type="RESOURCE_LOCAL"> | |
53 | + <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source> | |
54 | + | |
55 | + <class>productor.MyEntity</class> | |
56 | + | |
57 | + <properties> | |
58 | + <property name="hibernate.show_sql" value="true" /> | |
59 | + <property name="hibernate.format_sql" value="false" /> | |
60 | + <property name="hibernate.hbm2ddl.auto" value="create-drop" /> | |
61 | + </properties> | |
62 | + </persistence-unit> | |
63 | + | |
64 | +</persistence> | |
0 | 65 | \ No newline at end of file | ... | ... |