Commit 3ca502636b43cc134a5304b9d185c813a9027a9e

Authored by Cleverson Sacramento
1 parent 05be04e1
Exists in master

Resolução de conflitos

Showing 35 changed files with 149 additions and 2970 deletions   Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
@@ -48,7 +48,7 @@ public class ManagementBootstrap implements Extension { @@ -48,7 +48,7 @@ public class ManagementBootstrap implements Extension {
48 48
49 @SuppressWarnings("unchecked") 49 @SuppressWarnings("unchecked")
50 public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event, BeanManager beanManager) { 50 public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event, BeanManager beanManager) {
51 - ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); 51 + ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-core-bundle", Locale.getDefault());
52 52
53 Management monitoringManager = Beans.getReference(Management.class); 53 Management monitoringManager = Beans.getReference(Management.class);
54 for (AnnotatedType<?> type : types) { 54 for (AnnotatedType<?> type : types) {
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagedType.java
@@ -77,7 +77,7 @@ public class ManagedType { @@ -77,7 +77,7 @@ public class ManagedType {
77 private String description; 77 private String description;
78 78
79 public ManagedType(Class<?> type) { 79 public ManagedType(Class<?> type) {
80 - bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); 80 + bundle = new ResourceBundleProducer().create("demoiselle-core-bundle");
81 81
82 if (type == null) { 82 if (type == null) {
83 throw new DemoiselleException(bundle.getString("management-null-class-defined")); 83 throw new DemoiselleException(bundle.getString("management-null-class-defined"));
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
@@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
36 */ 36 */
37 package br.gov.frameworkdemoiselle.internal.management; 37 package br.gov.frameworkdemoiselle.internal.management;
38 38
  39 +import java.io.Serializable;
39 import java.lang.reflect.Method; 40 import java.lang.reflect.Method;
40 import java.util.ArrayList; 41 import java.util.ArrayList;
41 import java.util.Collection; 42 import java.util.Collection;
@@ -73,7 +74,9 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; @@ -73,7 +74,9 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle;
73 * @author serpro 74 * @author serpro
74 */ 75 */
75 @ApplicationScoped 76 @ApplicationScoped
76 -public class Management { 77 +public class Management implements Serializable {
  78 +
  79 + private static final long serialVersionUID = 1L;
77 80
78 @Inject 81 @Inject
79 private Logger logger; 82 private Logger logger;
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java
@@ -63,7 +63,7 @@ public class ResourceBundleProducer implements Serializable { @@ -63,7 +63,7 @@ public class ResourceBundleProducer implements Serializable {
63 * baseName 63 * baseName
64 */ 64 */
65 @Deprecated 65 @Deprecated
66 - public static ResourceBundle create(String baseName) { 66 + public ResourceBundle create(String baseName) {
67 return create(baseName, Beans.getReference(Locale.class)); 67 return create(baseName, Beans.getReference(Locale.class));
68 } 68 }
69 69
@@ -74,7 +74,7 @@ public class ResourceBundleProducer implements Serializable { @@ -74,7 +74,7 @@ public class ResourceBundleProducer implements Serializable {
74 * baseName 74 * baseName
75 */ 75 */
76 @Deprecated 76 @Deprecated
77 - public static ResourceBundle create(String baseName, Locale locale) { 77 + public ResourceBundle create(String baseName, Locale locale) {
78 return new ResourceBundle(baseName, locale); 78 return new ResourceBundle(baseName, locale);
79 } 79 }
80 80
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionalInterceptor.java
@@ -189,7 +189,7 @@ public class TransactionalInterceptor implements Serializable { @@ -189,7 +189,7 @@ public class TransactionalInterceptor implements Serializable {
189 } 189 }
190 190
191 @RequestScoped 191 @RequestScoped
192 - static class TransactionInfo implements Serializable { 192 + public static class TransactionInfo implements Serializable {
193 193
194 private static final long serialVersionUID = 1L; 194 private static final long serialVersionUID = 1L;
195 195
impl/core/src/test/resources/arquillian.xml
@@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
40 40
41 <!-- 41 <!--
42 <engine> 42 <engine>
43 - <property name="deploymentExportPath">target/arquillian</property> 43 + <property name="deploymentExportPath">target/deployments</property>
44 </engine> 44 </engine>
45 --> 45 -->
46 46
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/DynamicMBeanProxy.java
@@ -79,7 +79,7 @@ public class DynamicMBeanProxy implements DynamicMBean { @@ -79,7 +79,7 @@ public class DynamicMBeanProxy implements DynamicMBean {
79 79
80 private ManagedType managedType; 80 private ManagedType managedType;
81 81
82 - private ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-jmx-bundle", Locale.getDefault()); 82 + private ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-jmx-bundle", Locale.getDefault());
83 83
84 public DynamicMBeanProxy(ManagedType type) { 84 public DynamicMBeanProxy(ManagedType type) {
85 if (type == null) { 85 if (type == null) {
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/MBeanHelper.java
@@ -59,7 +59,7 @@ public class MBeanHelper { @@ -59,7 +59,7 @@ public class MBeanHelper {
59 59
60 private static final Logger logger = LoggerProducer.create(MBeanHelper.class); 60 private static final Logger logger = LoggerProducer.create(MBeanHelper.class);
61 61
62 - private static ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-jmx-bundle", Locale.getDefault()); 62 + private static ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-jmx-bundle", Locale.getDefault());
63 63
64 private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); 64 private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
65 65
impl/extension/jpa/.gitignore
@@ -4,3 +4,4 @@ @@ -4,3 +4,4 @@
4 /.settings 4 /.settings
5 /.externalToolBuilders 5 /.externalToolBuilders
6 /.DS_Store 6 /.DS_Store
  7 +/*.log
impl/extension/jpa/pom.xml
@@ -36,7 +36,6 @@ @@ -36,7 +36,6 @@
36 --> 36 -->
37 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 37 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
38 38
39 -  
40 <modelVersion>4.0.0</modelVersion> 39 <modelVersion>4.0.0</modelVersion>
41 40
42 <artifactId>demoiselle-jpa</artifactId> 41 <artifactId>demoiselle-jpa</artifactId>
@@ -45,7 +44,7 @@ @@ -45,7 +44,7 @@
45 <parent> 44 <parent>
46 <groupId>br.gov.frameworkdemoiselle</groupId> 45 <groupId>br.gov.frameworkdemoiselle</groupId>
47 <artifactId>demoiselle-extension-parent</artifactId> 46 <artifactId>demoiselle-extension-parent</artifactId>
48 - <version>2.4.0-BETA3-SNAPSHOT</version> 47 + <version>2.4.0-BETA4-SNAPSHOT</version>
49 <relativePath>../../../parent/extension</relativePath> 48 <relativePath>../../../parent/extension</relativePath>
50 </parent> 49 </parent>
51 50
@@ -67,27 +66,143 @@ @@ -67,27 +66,143 @@
67 <url>http://www.serpro.gov.br</url> 66 <url>http://www.serpro.gov.br</url>
68 </organization> 67 </organization>
69 68
  69 + <!--
  70 + <build>
  71 + <plugins>
  72 + <plugin>
  73 + <groupId>org.apache.maven.plugins</groupId>
  74 + <artifactId>maven-surefire-plugin</artifactId>
  75 + <version>2.12</version>
  76 + <configuration>
  77 + <systemPropertyVariables>
  78 + <java.util.logging.config.file>
  79 + ${project.build.testOutputDirectory}/logging.properties
  80 + </java.util.logging.config.file>
  81 + <derby.stream.error.file>
  82 + ${project.build.directory}/derby.log
  83 + </derby.stream.error.file>
  84 + </systemPropertyVariables>
  85 + </configuration>
  86 + </plugin>
  87 + </plugins>
  88 + </build>
  89 + -->
  90 +
70 <dependencies> 91 <dependencies>
71 <dependency> 92 <dependency>
72 <groupId>org.eclipse.persistence</groupId> 93 <groupId>org.eclipse.persistence</groupId>
73 <artifactId>javax.persistence</artifactId> 94 <artifactId>javax.persistence</artifactId>
74 </dependency> 95 </dependency>
  96 +
  97 + <!-- for tests -->
75 <dependency> 98 <dependency>
76 - <groupId>org.hibernate</groupId>  
77 - <artifactId>hibernate-entitymanager</artifactId> 99 + <groupId>junit</groupId>
  100 + <artifactId>junit</artifactId>
78 <scope>test</scope> 101 <scope>test</scope>
79 </dependency> 102 </dependency>
80 <dependency> 103 <dependency>
81 - <groupId>org.hibernate</groupId>  
82 - <artifactId>hibernate-validator</artifactId> 104 + <groupId>org.jboss.arquillian.junit</groupId>
  105 + <artifactId>arquillian-junit-container</artifactId>
83 <scope>test</scope> 106 <scope>test</scope>
84 </dependency> 107 </dependency>
85 108
  109 + <!--
  110 + <dependency>
  111 + <groupId>org.jboss.as</groupId>
  112 + <artifactId>jboss-as-arquillian-container-embedded</artifactId>
  113 + <version>7.2.0.Final</version>
  114 + <scope>test</scope>
  115 + </dependency>
  116 + -->
  117 +
  118 +
  119 + <dependency>
  120 + <groupId>org.jboss.arquillian.container</groupId>
  121 + <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
  122 + <scope>test</scope>
  123 + </dependency>
  124 + <!--
  125 + <dependency>
  126 + <groupId>org.glassfish.main.extras</groupId>
  127 + <artifactId>glassfish-embedded-web</artifactId>
  128 + <scope>test</scope>
  129 + </dependency>
  130 + -->
  131 +
  132 + <dependency>
  133 + <groupId>org.glassfish.main.extras</groupId>
  134 + <artifactId>glassfish-embedded-all</artifactId>
  135 + <version>3.1.2</version>
  136 + <scope>test</scope>
  137 + </dependency>
  138 +
  139 + <dependency>
  140 + <groupId>org.jboss.shrinkwrap.resolver</groupId>
  141 + <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
  142 + <scope>test</scope>
  143 + </dependency>
  144 + <dependency>
  145 + <groupId>org.jboss.shrinkwrap.resolver</groupId>
  146 + <artifactId>shrinkwrap-resolver-depchain</artifactId>
  147 + <type>pom</type>
  148 + </dependency>
  149 +
  150 + <!--
  151 + <dependency>
  152 + <groupId>org.apache.openejb</groupId>
  153 + <artifactId>arquillian-tomee-embedded</artifactId>
  154 + <version>1.5.2</version>
  155 + </dependency>
  156 + <dependency>
  157 + <groupId>org.apache.openejb</groupId>
  158 + <artifactId>tomee-embedded</artifactId>
  159 + <version>1.5.2</version>
  160 + </dependency>
  161 + -->
  162 +
  163 + <!--
  164 + <dependency>
  165 + <groupId>org.jboss.arquillian.extension</groupId>
  166 + <artifactId>arquillian-persistence-impl</artifactId>
  167 + <scope>test</scope>
  168 + <exclusions>
  169 + <exclusion>
  170 + <artifactId>log4j</artifactId>
  171 + <groupId>log4j</groupId>
  172 + </exclusion>
  173 + </exclusions>
  174 + </dependency>
  175 + -->
  176 +
  177 + <!--
86 <dependency> 178 <dependency>
87 <groupId>hsqldb</groupId> 179 <groupId>hsqldb</groupId>
88 <artifactId>hsqldb</artifactId> 180 <artifactId>hsqldb</artifactId>
89 <scope>test</scope> 181 <scope>test</scope>
90 </dependency> 182 </dependency>
  183 + -->
  184 +
  185 + <!--
  186 + <dependency>
  187 + <groupId>org.slf4j</groupId>
  188 + <artifactId>slf4j-log4j12</artifactId>
  189 + <scope>test</scope>
  190 + </dependency>
  191 + -->
  192 +
  193 + <!--
  194 + <dependency>
  195 + <groupId>org.hibernate</groupId>
  196 + <artifactId>hibernate-entitymanager</artifactId>
  197 + <scope>test</scope>
  198 + </dependency>
  199 + <dependency>
  200 + <groupId>org.hibernate</groupId>
  201 + <artifactId>hibernate-validator</artifactId>
  202 + <scope>test</scope>
  203 + </dependency>
  204 +
  205 + -->
91 </dependencies> 206 </dependencies>
92 207
93 <repositories> 208 <repositories>
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java
@@ -26,6 +26,7 @@ import br.gov.frameworkdemoiselle.annotation.Name; @@ -26,6 +26,7 @@ import br.gov.frameworkdemoiselle.annotation.Name;
26 import br.gov.frameworkdemoiselle.util.ResourceBundle; 26 import br.gov.frameworkdemoiselle.util.ResourceBundle;
27 27
28 @ApplicationScoped 28 @ApplicationScoped
  29 +// @StaticScoped
29 public class EntityManagerFactoryProducer implements Serializable { 30 public class EntityManagerFactoryProducer implements Serializable {
30 31
31 private static final long serialVersionUID = 1L; 32 private static final long serialVersionUID = 1L;
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/transaction/JPATransaction.java
@@ -124,8 +124,11 @@ public class JPATransaction implements Transaction { @@ -124,8 +124,11 @@ public class JPATransaction implements Transaction {
124 public boolean isActive() { 124 public boolean isActive() {
125 boolean active = false; 125 boolean active = false;
126 126
  127 + EntityTransaction transaction;
127 for (EntityManager entityManager : getDelegate()) { 128 for (EntityManager entityManager : getDelegate()) {
128 - if (entityManager.getTransaction().isActive()) { 129 + transaction = entityManager.getTransaction();
  130 +
  131 + if (transaction.isActive()) {
129 active = true; 132 active = true;
130 break; 133 break;
131 } 134 }
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/domain/Client.java
@@ -1,65 +0,0 @@ @@ -1,65 +0,0 @@
1 -package br.gov.frameworkdemoiselle.domain;  
2 -  
3 -import java.io.Serializable;  
4 -import java.util.Date;  
5 -  
6 -import javax.persistence.Entity;  
7 -import javax.persistence.GeneratedValue;  
8 -import javax.persistence.Id;  
9 -import javax.persistence.Temporal;  
10 -import javax.persistence.TemporalType;  
11 -  
12 -/**  
13 - * Simle entity for test classes  
14 - * @author serpro  
15 - *  
16 - */  
17 -@Entity  
18 -public class Client implements Serializable {  
19 -  
20 - private static final long serialVersionUID = 1L;  
21 -  
22 - private Long id;  
23 -  
24 - private String name;  
25 -  
26 - private Date birthDate;  
27 -  
28 - @Id  
29 - @GeneratedValue  
30 - public Long getId() {  
31 - return id;  
32 - }  
33 -  
34 -  
35 - public void setId(Long id) {  
36 - this.id = id;  
37 - }  
38 -  
39 -  
40 - public String getName() {  
41 - return name;  
42 - }  
43 -  
44 -  
45 - public void setName(String name) {  
46 - this.name = name;  
47 - }  
48 -  
49 -  
50 - @Temporal(TemporalType.DATE)  
51 - public Date getBirthDate() {  
52 - return birthDate;  
53 - }  
54 -  
55 -  
56 -  
57 - public void setBirthDate(Date birthDate) {  
58 - this.birthDate = birthDate;  
59 - }  
60 -  
61 -  
62 -  
63 -  
64 -  
65 -}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/domain/Contact.java
@@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
1 -package br.gov.frameworkdemoiselle.domain;  
2 -  
3 -import java.io.Serializable;  
4 -  
5 -import javax.persistence.Column;  
6 -import javax.persistence.Entity;  
7 -import javax.persistence.GeneratedValue;  
8 -import javax.persistence.Id;  
9 -  
10 -@Entity  
11 -public class Contact implements Serializable {  
12 -  
13 - private static final long serialVersionUID = 1L;  
14 -  
15 - @Id  
16 - @GeneratedValue  
17 - @Column  
18 - private Long id;  
19 -  
20 - public void setId(Long id) {  
21 - this.id = id;  
22 - }  
23 -  
24 - public Long getId() {  
25 - return id;  
26 - }  
27 -  
28 -}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java
@@ -1,102 +0,0 @@ @@ -1,102 +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 br.gov.frameworkdemoiselle.internal.configuration;  
38 -//import static org.easymock.EasyMock.createMock;  
39 -//import static org.easymock.EasyMock.expect;  
40 -//import static org.junit.Assert.assertEquals;  
41 -//  
42 -//import java.util.Locale;  
43 -//  
44 -//import org.junit.After;  
45 -//import org.junit.Before;  
46 -//import org.junit.Test;  
47 -//import org.junit.runner.RunWith;  
48 -//import org.powermock.api.easymock.PowerMock;  
49 -//import org.powermock.core.classloader.annotations.PrepareForTest;  
50 -//import org.powermock.modules.junit4.PowerMockRunner;  
51 -//import org.powermock.reflect.Whitebox;  
52 -//import org.slf4j.Logger;  
53 -//import org.slf4j.LoggerFactory;  
54 -//  
55 -//import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap;  
56 -//import br.gov.frameworkdemoiselle.util.ResourceBundle;  
57 -//  
58 -///**  
59 -// * @author e-saito  
60 -// */  
61 -///**  
62 -// * @author 80342167553  
63 -// */  
64 -//@RunWith(PowerMockRunner.class)  
65 -//@PrepareForTest(CoreBootstrap.class)  
66 -//public class EntityManagerConfigTest {  
67 -//  
68 -// private EntityManagerConfig config = new EntityManagerConfig();  
69 -//  
70 -// @Before  
71 -// public void setUp() throws Exception {  
72 -// Logger logger = LoggerFactory.getLogger(this.getClass());  
73 -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault());  
74 -//  
75 -// ConfigurationLoader configurationLoader = new ConfigurationLoader();  
76 -//  
77 -// Whitebox.setInternalState(configurationLoader, "bundle", bundle);  
78 -// Whitebox.setInternalState(configurationLoader, "logger", logger);  
79 -//  
80 -// CoreBootstrap bootstrap = createMock(CoreBootstrap.class);  
81 -// expect(bootstrap.isAnnotatedType(config.getClass())).andReturn(true);  
82 -// PowerMock.replay(bootstrap);  
83 -//  
84 -// Whitebox.setInternalState(configurationLoader, "bootstrap", bootstrap);  
85 -//  
86 -// configurationLoader.load(config);  
87 -// }  
88 -//  
89 -// @After  
90 -// public void tearDown() throws Exception {  
91 -// config = null;  
92 -// }  
93 -//  
94 -// /**  
95 -// * Test method for  
96 -// * {@link br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig#getDefaultPersistenceUnitName()}.  
97 -// */  
98 -// @Test  
99 -// public void testGetDefaultPersistenceUnitName() {  
100 -// assertEquals("PersistenceUnitName", config.getDefaultPersistenceUnitName());  
101 -// }  
102 -//}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducerTest.java
@@ -1,176 +0,0 @@ @@ -1,176 +0,0 @@
1 -package br.gov.frameworkdemoiselle.internal.producer;  
2 -  
3 -import static org.easymock.EasyMock.createMock;  
4 -import static org.easymock.EasyMock.expect;  
5 -import static org.easymock.EasyMock.verify;  
6 -import static org.powermock.api.easymock.PowerMock.mockStatic;  
7 -import static org.powermock.api.easymock.PowerMock.replay;  
8 -import static org.powermock.reflect.Whitebox.setInternalState;  
9 -  
10 -import java.util.Collections;  
11 -import java.util.HashMap;  
12 -import java.util.Locale;  
13 -import java.util.Map;  
14 -  
15 -import javax.persistence.EntityManagerFactory;  
16 -import javax.persistence.Persistence;  
17 -  
18 -import junit.framework.Assert;  
19 -  
20 -import org.junit.Before;  
21 -import org.junit.Test;  
22 -import org.junit.runner.RunWith;  
23 -import org.powermock.core.classloader.annotations.PrepareForTest;  
24 -import org.powermock.modules.junit4.PowerMockRunner;  
25 -import org.slf4j.Logger;  
26 -  
27 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
28 -  
29 -@RunWith(PowerMockRunner.class)  
30 -@PrepareForTest(Persistence.class)  
31 -public class EntityManagerFactoryProducerTest {  
32 -  
33 - private EntityManagerFactory emFactory;  
34 -  
35 - private EntityManagerFactoryProducer producer;  
36 -  
37 - private Map<ClassLoader, Map<String, EntityManagerFactory>> cache;  
38 -  
39 - private Logger logger;  
40 -  
41 - private ResourceBundle bundle;  
42 -  
43 - @Before  
44 - public void setUp() {  
45 - logger = createMock(Logger.class);  
46 - bundle = ResourceBundleProducer.create("demoiselle-jpa-bundle", Locale.getDefault());  
47 - producer = new EntityManagerFactoryProducer();  
48 - cache = Collections.synchronizedMap(new HashMap<ClassLoader, Map<String, EntityManagerFactory>>());  
49 - setInternalState(producer, "factoryCache", cache);  
50 - setInternalState(producer, Logger.class, logger);  
51 - setInternalState(producer, ResourceBundle.class, bundle);  
52 - emFactory = createMock(EntityManagerFactory.class);  
53 - }  
54 -  
55 - @Test  
56 - public void testCreateWithUnitPersistenceExisting() {  
57 - ClassLoader cl = this.getClass().getClassLoader();  
58 - HashMap<String, EntityManagerFactory> emEntry = new HashMap<String, EntityManagerFactory>();  
59 - emEntry.put("pu1", emFactory);  
60 - cache.put(cl, emEntry);  
61 -  
62 - Assert.assertEquals(emFactory, producer.create("pu1"));  
63 - }  
64 -  
65 - @Test  
66 - public void testCreateWithUnitPersistenceNotExisting() {  
67 -  
68 - mockStatic(Persistence.class);  
69 - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory);  
70 -  
71 - replay(Persistence.class);  
72 -  
73 - Assert.assertEquals(emFactory, producer.create("pu1"));  
74 - }  
75 -  
76 - /**  
77 - * Test if after producing an entity manager, the EntityManagerFactory is correctly stored in the cache associated  
78 - * with the current class loader.  
79 - */  
80 - @Test  
81 - public void testStorageCacheAfterCreate() {  
82 - mockStatic(Persistence.class);  
83 - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory);  
84 - replay(Persistence.class);  
85 -  
86 - Map<String, EntityManagerFactory> producerCache = producer.getCache();  
87 - Assert.assertNotNull(producerCache);  
88 - Assert.assertTrue(producerCache.containsKey("pu1"));  
89 - Assert.assertTrue(producerCache.containsValue(emFactory));  
90 - }  
91 -  
92 - @Test  
93 - public void testInitWithoutError() {  
94 - mockStatic(Persistence.class);  
95 - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory);  
96 - replay(Persistence.class);  
97 -  
98 - producer.loadPersistenceUnits();  
99 -  
100 - ClassLoader cl = this.getClass().getClassLoader();  
101 - Map<String, EntityManagerFactory> internalCache = cache.get(cl);  
102 -  
103 - Assert.assertNotNull(internalCache);  
104 - Assert.assertEquals(emFactory, internalCache.get("pu1"));  
105 - }  
106 -  
107 - /*  
108 - * @Test public void testInitWithError() { try { producer.loadPersistenceUnits(); Assert.fail();  
109 - * }catch(DemoiselleException cause) { Assert.assertTrue(true); } }  
110 - */  
111 -  
112 - @Test  
113 - public void testGetCache() {  
114 - ClassLoader cl = this.getClass().getClassLoader();  
115 - HashMap<String, EntityManagerFactory> emEntry = new HashMap<String, EntityManagerFactory>();  
116 - emEntry.put("pu1", emFactory);  
117 - cache.put(cl, emEntry);  
118 -  
119 - mockStatic(Persistence.class);  
120 - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory);  
121 - replay(Persistence.class);  
122 -  
123 - Assert.assertEquals(cache.get(this.getClass().getClassLoader()), producer.getCache());  
124 - }  
125 -  
126 - @Test  
127 - public void testClose() {  
128 - ClassLoader cl = this.getClass().getClassLoader();  
129 - HashMap<String, EntityManagerFactory> emEntry = new HashMap<String, EntityManagerFactory>();  
130 - emEntry.put("pu1", emFactory);  
131 - cache.put(cl, emEntry);  
132 -  
133 - emFactory.close();  
134 - replay(emFactory);  
135 - producer.close();  
136 - verify(emFactory);  
137 - }  
138 -  
139 - /**  
140 - * Test if detecting the persistence unit with an empty name throws correct error.  
141 - */  
142 - // @Test  
143 - // public void testEmptyPersistenceUnitName(){  
144 - // EntityManagerFactoryProducer.ENTITY_MANAGER_RESOURCE = "persistence-empty-name.xml";  
145 - //  
146 - // try{  
147 - // producer.getCache();  
148 - // Assert.fail();  
149 - // }  
150 - // catch(DemoiselleException de){  
151 - // //  
152 - // }  
153 - // }  
154 -  
155 - /**  
156 - * Test if asking to create an entity manager still not in the cache will correctly create it and put it in the  
157 - * cache.  
158 - */  
159 - @Test  
160 - public void testCreatePersistenceUnitNotInCache() {  
161 - mockStatic(Persistence.class);  
162 - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory);  
163 - replay(Persistence.class);  
164 -  
165 - ClassLoader cl = this.getClass().getClassLoader();  
166 - HashMap<String, EntityManagerFactory> emEntry = new HashMap<String, EntityManagerFactory>();  
167 - cache.put(cl, emEntry);  
168 -  
169 - producer.create("pu1");  
170 -  
171 - Map<String, EntityManagerFactory> producerCache = producer.getCache();  
172 - Assert.assertNotNull(producerCache);  
173 - Assert.assertTrue(producerCache.containsKey("pu1"));  
174 - Assert.assertTrue(producerCache.containsValue(emFactory));  
175 - }  
176 -}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducerTest.java
@@ -1,189 +0,0 @@ @@ -1,189 +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 br.gov.frameworkdemoiselle.internal.producer;  
38 -  
39 -import static org.easymock.EasyMock.createMock;  
40 -import static org.easymock.EasyMock.expect;  
41 -import static org.easymock.EasyMock.verify;  
42 -import static org.powermock.api.easymock.PowerMock.mockStatic;  
43 -import static org.powermock.api.easymock.PowerMock.replay;  
44 -import static org.powermock.reflect.Whitebox.setInternalState;  
45 -  
46 -import java.util.Collections;  
47 -import java.util.HashMap;  
48 -import java.util.Locale;  
49 -import java.util.Map;  
50 -  
51 -import javax.enterprise.inject.spi.Annotated;  
52 -import javax.enterprise.inject.spi.InjectionPoint;  
53 -import javax.persistence.EntityManager;  
54 -import javax.persistence.EntityManagerFactory;  
55 -import javax.persistence.Persistence;  
56 -  
57 -import junit.framework.Assert;  
58 -  
59 -import org.junit.After;  
60 -import org.junit.Before;  
61 -import org.junit.Test;  
62 -import org.junit.runner.RunWith;  
63 -import org.powermock.core.classloader.annotations.PrepareForTest;  
64 -import org.powermock.modules.junit4.PowerMockRunner;  
65 -import org.slf4j.Logger;  
66 -  
67 -import br.gov.frameworkdemoiselle.annotation.Name;  
68 -import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig;  
69 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
70 -  
71 -@RunWith(PowerMockRunner.class)  
72 -@PrepareForTest(Persistence.class)  
73 -public class EntityManagerProducerTest {  
74 -  
75 - private EntityManagerProducer producer;  
76 -  
77 - private Logger logger;  
78 -  
79 - private ResourceBundle bundle;  
80 -  
81 - private InjectionPoint ip;  
82 -  
83 - private EntityManagerConfig config;  
84 -  
85 - private Annotated annotated;  
86 -  
87 - private Name name;  
88 -  
89 - private EntityManagerFactory emf;  
90 -  
91 - private Map<String, EntityManager> cache;  
92 -  
93 - private EntityManager em;  
94 -  
95 - @Before  
96 - public void setUp() {  
97 - emf = createMock(EntityManagerFactory.class);  
98 - em = createMock(EntityManager.class);  
99 -  
100 - mockStatic(Persistence.class);  
101 - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emf);  
102 - expect(emf.createEntityManager()).andReturn(em);  
103 -  
104 - replay(emf, Persistence.class);  
105 -  
106 - producer = new EntityManagerProducer();  
107 - bundle = ResourceBundleProducer.create("demoiselle-jpa-bundle", Locale.getDefault());  
108 - logger = createMock(Logger.class);  
109 -  
110 - setInternalState(producer, ResourceBundle.class, bundle);  
111 - setInternalState(producer, Logger.class, logger);  
112 -  
113 - ip = createMock(InjectionPoint.class);  
114 - config = createMock(EntityManagerConfig.class);  
115 - annotated = createMock(Annotated.class);  
116 - }  
117 -  
118 - @Test  
119 - public void testClose() {  
120 - em.close();  
121 - replay(em);  
122 - cache = Collections.synchronizedMap(new HashMap<String, EntityManager>());  
123 - cache.put("pu1", em);  
124 - setInternalState(producer, Map.class, cache);  
125 - producer.close();  
126 - verify(em);  
127 - }  
128 -  
129 - @Test  
130 - public void testGetCache() {  
131 - cache = Collections.synchronizedMap(new HashMap<String, EntityManager>());  
132 - setInternalState(producer, Map.class, cache);  
133 - Assert.assertEquals(cache, producer.getCache());  
134 - }  
135 -  
136 - @After  
137 - public void tearDown() {  
138 - producer = null;  
139 - }  
140 -  
141 - // @Test  
142 - // public void testCreateWithEntityManagerAnnotatedWithName() {  
143 - // name = createMock(Name.class);  
144 - // expect(name.value()).andReturn("pu1");  
145 - // expect(annotated.isAnnotationPresent(Name.class)).andReturn(true);  
146 - // expect(annotated.getAnnotation(Name.class)).andReturn(name);  
147 - // expect(ip.getAnnotated()).andReturn(annotated).anyTimes();  
148 - // replay(name, annotated, ip);  
149 - //  
150 - // EntityManagerProxy entityManagerProxy = (EntityManagerProxy) producer.create(ip, config);  
151 - // assertNotNull(entityManagerProxy);  
152 - // }  
153 -  
154 - // @Test  
155 - // public void testCreateWithPersistenceUnitNameFromDemoiselleProperties() {  
156 - // expect(annotated.isAnnotationPresent(Name.class)).andReturn(false);  
157 - // expect(ip.getAnnotated()).andReturn(annotated).anyTimes();  
158 - // expect(config.getDefaultPersistenceUnitName()).andReturn("pu1");  
159 - //  
160 - // replay(annotated, ip, config);  
161 - //  
162 - // EntityManagerProxy entityManagerProxy = (EntityManagerProxy) producer.create(ip, config);  
163 - // assertNotNull(entityManagerProxy);  
164 - // }  
165 -  
166 - // @Test  
167 - // public void testCreateWithPersistenceUnitNameFromPersistenceXML() {  
168 - //  
169 - // Map<String, EntityManagerFactory> cache = Collections  
170 - // .synchronizedMap(new HashMap<String, EntityManagerFactory>());  
171 - //  
172 - // cache.put("pu1", emf);  
173 - //  
174 - // EntityManagerFactoryProducer entityManagerFactoryProducer = createMock(EntityManagerFactoryProducer.class);  
175 - //  
176 - // expect(entityManagerFactoryProducer.getCache()).andReturn(cache);  
177 - //  
178 - // expect(annotated.isAnnotationPresent(Name.class)).andReturn(false);  
179 - // expect(ip.getAnnotated()).andReturn(annotated).anyTimes();  
180 - // expect(config.getDefaultPersistenceUnitName()).andReturn(null);  
181 - //  
182 - // replay(annotated, ip, config, entityManagerFactoryProducer);  
183 - //  
184 - // setInternalState(producer, EntityManagerFactoryProducer.class, entityManagerFactoryProducer);  
185 - //  
186 - // EntityManagerProxy entityManagerProxy = (EntityManagerProxy) producer.create(ip, config);  
187 - // assertNotNull(entityManagerProxy);  
188 - // }  
189 -}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/producer/FakeEntityManager.java
@@ -1,277 +0,0 @@ @@ -1,277 +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 br.gov.frameworkdemoiselle.internal.producer;  
38 -  
39 -import java.util.Map;  
40 -  
41 -import javax.enterprise.inject.Alternative;  
42 -import javax.persistence.EntityManager;  
43 -import javax.persistence.EntityManagerFactory;  
44 -import javax.persistence.EntityTransaction;  
45 -import javax.persistence.FlushModeType;  
46 -import javax.persistence.LockModeType;  
47 -import javax.persistence.Query;  
48 -import javax.persistence.TypedQuery;  
49 -import javax.persistence.criteria.CriteriaBuilder;  
50 -import javax.persistence.criteria.CriteriaQuery;  
51 -import javax.persistence.metamodel.Metamodel;  
52 -  
53 -@Alternative  
54 -public class FakeEntityManager implements EntityManager {  
55 -  
56 - private boolean closed = false;  
57 -  
58 - private boolean equals = true;  
59 -  
60 - private int hashCode = 1;  
61 -  
62 - private String toString = "";  
63 -  
64 - @Override  
65 - public void clear() {  
66 - }  
67 -  
68 - @Override  
69 - public void close() {  
70 - closed = true;  
71 - }  
72 -  
73 - @Override  
74 - public boolean contains(Object arg0) {  
75 - return false;  
76 - }  
77 -  
78 - @Override  
79 - public Query createNamedQuery(String arg0) {  
80 - return null;  
81 - }  
82 -  
83 - @Override  
84 - public <T> TypedQuery<T> createNamedQuery(String arg0, Class<T> arg1) {  
85 - return null;  
86 - }  
87 -  
88 - @Override  
89 - public Query createNativeQuery(String arg0) {  
90 - return null;  
91 - }  
92 -  
93 - @Override  
94 - public Query createNativeQuery(String arg0, @SuppressWarnings("rawtypes") Class arg1) {  
95 - return null;  
96 - }  
97 -  
98 - @Override  
99 - public Query createNativeQuery(String arg0, String arg1) {  
100 - return null;  
101 - }  
102 -  
103 - @Override  
104 - public Query createQuery(String arg0) {  
105 - return null;  
106 - }  
107 -  
108 - @Override  
109 - public <T> TypedQuery<T> createQuery(CriteriaQuery<T> arg0) {  
110 - return null;  
111 - }  
112 -  
113 - @Override  
114 - public <T> TypedQuery<T> createQuery(String arg0, Class<T> arg1) {  
115 - return null;  
116 - }  
117 -  
118 - @Override  
119 - public void detach(Object arg0) {  
120 - }  
121 -  
122 - @Override  
123 - public <T> T find(Class<T> arg0, Object arg1) {  
124 - return null;  
125 - }  
126 -  
127 - @Override  
128 - public <T> T find(Class<T> arg0, Object arg1, Map<String, Object> arg2) {  
129 - return null;  
130 - }  
131 -  
132 - @Override  
133 - public <T> T find(Class<T> arg0, Object arg1, LockModeType arg2) {  
134 - return null;  
135 - }  
136 -  
137 - @Override  
138 - public <T> T find(Class<T> arg0, Object arg1, LockModeType arg2, Map<String, Object> arg3) {  
139 - return null;  
140 - }  
141 -  
142 - @Override  
143 - public void flush() {  
144 - }  
145 -  
146 - @Override  
147 - public CriteriaBuilder getCriteriaBuilder() {  
148 - return null;  
149 - }  
150 -  
151 - @Override  
152 - public Object getDelegate() {  
153 - return null;  
154 - }  
155 -  
156 - @Override  
157 - public EntityManagerFactory getEntityManagerFactory() {  
158 - return null;  
159 - }  
160 -  
161 - @Override  
162 - public FlushModeType getFlushMode() {  
163 - return null;  
164 - }  
165 -  
166 - @Override  
167 - public LockModeType getLockMode(Object arg0) {  
168 - return null;  
169 - }  
170 -  
171 - @Override  
172 - public Metamodel getMetamodel() {  
173 - return null;  
174 - }  
175 -  
176 - @Override  
177 - public Map<String, Object> getProperties() {  
178 - return null;  
179 - }  
180 -  
181 - @Override  
182 - public <T> T getReference(Class<T> arg0, Object arg1) {  
183 - return null;  
184 - }  
185 -  
186 - @Override  
187 - public EntityTransaction getTransaction() {  
188 - return null;  
189 - }  
190 -  
191 - @Override  
192 - public boolean isOpen() {  
193 - return !closed;  
194 - }  
195 -  
196 - @Override  
197 - public void joinTransaction() {  
198 - }  
199 -  
200 - @Override  
201 - public void lock(Object arg0, LockModeType arg1) {  
202 - }  
203 -  
204 - @Override  
205 - public void lock(Object arg0, LockModeType arg1, Map<String, Object> arg2) {  
206 - }  
207 -  
208 - @Override  
209 - public <T> T merge(T arg0) {  
210 - return null;  
211 - }  
212 -  
213 - @Override  
214 - public void persist(Object arg0) {  
215 - }  
216 -  
217 - @Override  
218 - public void refresh(Object arg0) {  
219 - }  
220 -  
221 - @Override  
222 - public void refresh(Object arg0, Map<String, Object> arg1) {  
223 - }  
224 -  
225 - @Override  
226 - public void refresh(Object arg0, LockModeType arg1) {  
227 - }  
228 -  
229 - @Override  
230 - public void refresh(Object arg0, LockModeType arg1, Map<String, Object> arg2) {  
231 - }  
232 -  
233 - @Override  
234 - public void remove(Object arg0) {  
235 - }  
236 -  
237 - @Override  
238 - public void setFlushMode(FlushModeType arg0) {  
239 - }  
240 -  
241 - @Override  
242 - public void setProperty(String arg0, Object arg1) {  
243 - }  
244 -  
245 - @Override  
246 - public <T> T unwrap(Class<T> arg0) {  
247 - return null;  
248 - }  
249 -  
250 - @Override  
251 - public boolean equals(Object obj) {  
252 - return equals;  
253 - }  
254 -  
255 - public void setEquals(boolean equals) {  
256 - this.equals = equals;  
257 - }  
258 -  
259 - @Override  
260 - public int hashCode() {  
261 - return hashCode;  
262 - }  
263 -  
264 - public void setHashCode(int hash) {  
265 - this.hashCode = hash;  
266 - }  
267 -  
268 - @Override  
269 - public String toString() {  
270 - return toString;  
271 - }  
272 -  
273 - public void setToString(String toString) {  
274 - this.toString = toString;  
275 - }  
276 -  
277 -}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/EntityManagerProxyTest.java
@@ -1,536 +0,0 @@ @@ -1,536 +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 br.gov.frameworkdemoiselle.internal.proxy;  
38 -import static org.easymock.EasyMock.expect;  
39 -import static org.easymock.EasyMock.replay;  
40 -import static org.easymock.EasyMock.verify;  
41 -import static org.junit.Assert.assertEquals;  
42 -import static org.junit.Assert.assertTrue;  
43 -import static org.powermock.api.easymock.PowerMock.mockStatic;  
44 -import static org.powermock.api.easymock.PowerMock.replayAll;  
45 -  
46 -import java.util.Map;  
47 -  
48 -import javax.persistence.EntityManager;  
49 -import javax.persistence.EntityManagerFactory;  
50 -import javax.persistence.EntityTransaction;  
51 -import javax.persistence.FlushModeType;  
52 -import javax.persistence.LockModeType;  
53 -import javax.persistence.Query;  
54 -import javax.persistence.TypedQuery;  
55 -import javax.persistence.criteria.CriteriaBuilder;  
56 -import javax.persistence.criteria.CriteriaQuery;  
57 -import javax.persistence.metamodel.Metamodel;  
58 -  
59 -import org.easymock.EasyMock;  
60 -import org.junit.Before;  
61 -import org.junit.Test;  
62 -import org.junit.runner.RunWith;  
63 -import org.powermock.core.classloader.annotations.PrepareForTest;  
64 -import org.powermock.modules.junit4.PowerMockRunner;  
65 -  
66 -import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer;  
67 -import br.gov.frameworkdemoiselle.internal.producer.FakeEntityManager;  
68 -import br.gov.frameworkdemoiselle.util.Beans;  
69 -  
70 -@RunWith(PowerMockRunner.class)  
71 -@PrepareForTest({ Beans.class })  
72 -public class EntityManagerProxyTest {  
73 -  
74 - private EntityManagerProxy entityManagerProxy;  
75 -  
76 - private EntityManager entityManager;  
77 -  
78 - private EntityManagerProducer entityManagerContext;  
79 -  
80 - @Before  
81 - public void setUp() throws Exception {  
82 - mockStatic(Beans.class);  
83 - this.entityManager = EasyMock.createMock(EntityManager.class);  
84 - this.entityManagerContext = EasyMock.createMock(EntityManagerProducer.class);  
85 -  
86 - expect(Beans.getReference(EntityManagerProducer.class)).andReturn(this.entityManagerContext).anyTimes();  
87 - expect(this.entityManagerContext.getEntityManager("teste")).andReturn(this.entityManager).anyTimes();  
88 - replay(this.entityManagerContext);  
89 - //expect(this.entityManager.getTransaction()).andReturn(transaction).anyTimes();  
90 - //replay(this.entityManager);  
91 - replayAll();  
92 -  
93 - this.entityManagerProxy = new EntityManagerProxy("teste");  
94 -  
95 - }  
96 -  
97 - @Test  
98 - public void testJoinTransactionIfNecessaryException() {  
99 - this.entityManager.persist("teste");  
100 - expect(this.entityManager.getTransaction()).andThrow(new IllegalStateException()).anyTimes();  
101 - this.entityManager.joinTransaction();  
102 - replay(this.entityManager);  
103 -  
104 - this.entityManagerProxy.persist("teste");  
105 - verify(this.entityManager);  
106 - }  
107 -  
108 - @Test  
109 - public void testPersist() {  
110 - this.entityManager.persist("teste");  
111 - expect(this.entityManager.getTransaction()).andReturn(null);  
112 - replay(this.entityManager);  
113 - this.entityManagerProxy.persist("teste");  
114 - verify(this.entityManager);  
115 - }  
116 -  
117 - @Test  
118 - public void testRemove() {  
119 - this.entityManager.remove("teste");  
120 - expect(this.entityManager.getTransaction()).andReturn(null);  
121 - replay(this.entityManager);  
122 - this.entityManagerProxy.remove("teste");  
123 - verify(this.entityManager);  
124 - }  
125 -  
126 - @Test  
127 - public void testFlush() {  
128 - this.entityManager.flush();  
129 - replay(this.entityManager);  
130 - this.entityManagerProxy.flush();  
131 - verify(this.entityManager);  
132 - }  
133 -  
134 - @Test  
135 - public void testSetFlushMode() {  
136 - FlushModeType flushModeType = null;  
137 - this.entityManager.setFlushMode(flushModeType);  
138 - replay(this.entityManager);  
139 - this.entityManagerProxy.setFlushMode(flushModeType);  
140 - verify(this.entityManager);  
141 - }  
142 -  
143 - @Test  
144 - public void testLockWithParamsStringAndLockModeType() {  
145 - LockModeType lockMode = null;  
146 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
147 - this.entityManager.lock("teste", lockMode);  
148 - replay(this.entityManager);  
149 - this.entityManagerProxy.lock("teste", lockMode);  
150 - verify(this.entityManager);  
151 - }  
152 -  
153 - @Test  
154 - public void testLockWithParamsStringLockModeTypeAndMap() {  
155 - LockModeType lockMode = null;  
156 - Map<String, Object> map = null;  
157 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
158 - this.entityManager.lock("teste", lockMode, map);  
159 - replay(this.entityManager);  
160 - this.entityManagerProxy.lock("teste", lockMode, map);  
161 - verify(this.entityManager);  
162 - }  
163 -  
164 - @Test  
165 - public void testRefresh() {  
166 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
167 - this.entityManager.refresh("teste");  
168 - replay(this.entityManager);  
169 - this.entityManagerProxy.refresh("teste");  
170 - verify(this.entityManager);  
171 - }  
172 -  
173 - @Test  
174 - public void testRefreshWithParamsStringAndMap() {  
175 - Map<String, Object> map = null;  
176 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
177 - this.entityManager.refresh("teste", map);  
178 - replay(this.entityManager);  
179 - this.entityManagerProxy.refresh("teste", map);  
180 - verify(this.entityManager);  
181 - }  
182 -  
183 - @Test  
184 - public void testRefreshWithParamsStringAndLockModeType() {  
185 - LockModeType lockMode = null;  
186 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
187 - this.entityManager.refresh("teste", lockMode);  
188 - replay(this.entityManager);  
189 - this.entityManagerProxy.refresh("teste", lockMode);  
190 - verify(this.entityManager);  
191 - }  
192 -  
193 - @Test  
194 - public void testRefreshWithParamsStringLockModeTypeAndMap() {  
195 - LockModeType lockMode = null;  
196 - Map<String, Object> map = null;  
197 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
198 - this.entityManager.refresh("teste", lockMode, map);  
199 - replay(this.entityManager);  
200 - this.entityManagerProxy.refresh("teste", lockMode, map);  
201 - verify(this.entityManager);  
202 - }  
203 -  
204 - @Test  
205 - public void testClear() {  
206 - this.entityManager.clear();  
207 - replay(this.entityManager);  
208 - this.entityManagerProxy.clear();  
209 - verify(this.entityManager);  
210 - }  
211 -  
212 - @Test  
213 - public void testDetach() {  
214 - this.entityManager.detach("teste");  
215 - replay(this.entityManager);  
216 - this.entityManagerProxy.detach("teste");  
217 - verify(this.entityManager);  
218 - }  
219 -  
220 - @Test  
221 - public void testSetProperty() {  
222 - this.entityManager.setProperty("teste", "teste");  
223 - replay(this.entityManager);  
224 - this.entityManagerProxy.setProperty("teste", "teste");  
225 - verify(this.entityManager);  
226 - }  
227 -  
228 - @Test  
229 - public void testJoinTransaction() {  
230 - this.entityManager.joinTransaction();  
231 - replay(this.entityManager);  
232 - this.entityManagerProxy.joinTransaction();  
233 - verify(this.entityManager);  
234 - }  
235 -  
236 - @Test  
237 - public void testClose() {  
238 - this.entityManager.close();  
239 - replay(this.entityManager);  
240 - this.entityManagerProxy.close();  
241 - verify(this.entityManager);  
242 - }  
243 -  
244 - @Test  
245 - public void testMerge() {  
246 - expect(this.entityManager.merge("teste")).andReturn("xxx");  
247 - expect(this.entityManager.getTransaction()).andReturn(null);  
248 - replay(this.entityManager);  
249 - assertEquals("xxx", this.entityManagerProxy.merge("teste"));  
250 - verify(this.entityManager);  
251 - }  
252 -  
253 - @Test  
254 - public void testFindWithParamsClassAndObject() {  
255 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
256 - expect(this.entityManager.find(String.class, "teste")).andReturn("retorno");  
257 - replay(this.entityManager);  
258 - assertEquals("retorno", this.entityManagerProxy.find(String.class, "teste"));  
259 - verify(this.entityManager);  
260 - }  
261 -  
262 - @Test  
263 - public void testFindWithParamsClassObjectAndMap() {  
264 - Map<String, Object> map = null;  
265 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
266 - expect(this.entityManager.find(String.class, "teste", map)).andReturn("retorno");  
267 - replay(this.entityManager);  
268 - assertEquals("retorno", this.entityManagerProxy.find(String.class, "teste", map));  
269 - verify(this.entityManager);  
270 - }  
271 -  
272 - @Test  
273 - public void testFindWithParamsClassObjectAndLockModeType() {  
274 - LockModeType lock = null;  
275 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
276 - expect(this.entityManager.find(String.class, "teste", lock)).andReturn("retorno");  
277 - replay(this.entityManager);  
278 - assertEquals("retorno", this.entityManagerProxy.find(String.class, "teste", lock));  
279 - verify(this.entityManager);  
280 - }  
281 -  
282 - @Test  
283 - public void testFindWithParamsClassObjectLockModeTypeAndMap() {  
284 - Map<String, Object> map = null;  
285 - LockModeType lock = null;  
286 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
287 - expect(this.entityManager.find(String.class, "teste", lock, map)).andReturn("retorno");  
288 - replay(this.entityManager);  
289 - assertEquals("retorno", this.entityManagerProxy.find(String.class, "teste", lock, map));  
290 - verify(this.entityManager);  
291 - }  
292 -  
293 - @Test  
294 - public void testGetReference() {  
295 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
296 - expect(this.entityManager.getReference(String.class, "teste")).andReturn("retorno");  
297 - replay(this.entityManager);  
298 - assertEquals("retorno", this.entityManagerProxy.getReference(String.class, "teste"));  
299 - verify(this.entityManager);  
300 - }  
301 -  
302 - @Test  
303 - public void testGetFlushMode() {  
304 - FlushModeType flushModeType = null;  
305 - expect(this.entityManager.getFlushMode()).andReturn(flushModeType);  
306 - replay(this.entityManager);  
307 - assertEquals(flushModeType, this.entityManagerProxy.getFlushMode());  
308 - verify(this.entityManager);  
309 - }  
310 -  
311 - @Test  
312 - public void testContains() {  
313 - expect(this.entityManager.contains("teste")).andReturn(true);  
314 - replay(this.entityManager);  
315 - assertTrue(this.entityManagerProxy.contains("teste"));  
316 - verify(this.entityManager);  
317 - }  
318 -  
319 - @Test  
320 - public void testGetLockMode() {  
321 - LockModeType lockModeType = null;  
322 - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes();  
323 - expect(this.entityManager.getLockMode("teste")).andReturn(lockModeType);  
324 - replay(this.entityManager);  
325 - assertEquals(lockModeType, this.entityManagerProxy.getLockMode("teste"));  
326 - verify(this.entityManager);  
327 - }  
328 -  
329 - @Test  
330 - public void testGetProperties() {  
331 - Map<String, Object> map = null;  
332 - expect(this.entityManager.getProperties()).andReturn(map);  
333 - replay(this.entityManager);  
334 - assertEquals(map, this.entityManagerProxy.getProperties());  
335 - verify(this.entityManager);  
336 - }  
337 -  
338 - @Test  
339 - public void testCreateQuery() {  
340 - Query query = EasyMock.createMock(Query.class);  
341 - expect(this.entityManager.createQuery("teste")).andReturn(query);  
342 - replay(this.entityManager);  
343 - assertTrue(Query.class.isAssignableFrom(this.entityManagerProxy.createQuery("teste").getClass()) );  
344 - verify(this.entityManager);  
345 - }  
346 -  
347 - @Test  
348 - public void testCreateQueryWithParamCriteria() {  
349 - @SuppressWarnings("unchecked")  
350 - TypedQuery<Object> typedQuery = EasyMock.createMock(TypedQuery.class);  
351 -  
352 - CriteriaQuery<Object> criteriaQuery = null;  
353 - expect(this.entityManager.createQuery(criteriaQuery)).andReturn(typedQuery);  
354 - replay(this.entityManager);  
355 - assertTrue(TypedQuery.class.isAssignableFrom(this.entityManagerProxy.createQuery(criteriaQuery).getClass()));  
356 - verify(this.entityManager);  
357 - }  
358 -  
359 - @Test  
360 - public void testCreateQueryWithParamStringAndClass() {  
361 - @SuppressWarnings("unchecked")  
362 - TypedQuery<String> typeQuery = EasyMock.createMock(TypedQuery.class);  
363 -  
364 - expect(this.entityManager.createQuery("teste", String.class)).andReturn(typeQuery);  
365 - replay(this.entityManager);  
366 - assertTrue(TypedQuery.class.isAssignableFrom(this.entityManagerProxy.createQuery("teste", String.class).getClass()));  
367 - verify(this.entityManager);  
368 - }  
369 -  
370 - @Test  
371 - public void testCreateNamedQuery() {  
372 - Query query = EasyMock.createMock(Query.class);  
373 - expect(this.entityManager.createNamedQuery("teste")).andReturn(query);  
374 - replay(this.entityManager);  
375 - assertTrue(Query.class.isAssignableFrom(this.entityManagerProxy.createNamedQuery("teste").getClass()));  
376 - verify(this.entityManager);  
377 - }  
378 -  
379 - @Test  
380 - public void testCreateNamedQueryWithParamsStringAndClass() {  
381 - @SuppressWarnings("unchecked")  
382 - TypedQuery<String> typedQuery = EasyMock.createMock(TypedQuery.class);  
383 - expect(this.entityManager.createNamedQuery("teste", String.class)).andReturn(typedQuery);  
384 - replay(this.entityManager);  
385 - assertEquals(typedQuery, this.entityManagerProxy.createNamedQuery("teste", String.class));  
386 - verify(this.entityManager);  
387 - }  
388 -  
389 - @Test  
390 - public void testCreateNativeQuery() {  
391 - Query query = null;  
392 - expect(this.entityManager.createNativeQuery("teste")).andReturn(query);  
393 - replay(this.entityManager);  
394 - assertEquals(QueryProxy.class, this.entityManagerProxy.createNativeQuery("teste").getClass());  
395 - verify(this.entityManager);  
396 - }  
397 -  
398 - @Test  
399 - public void testCreateNativeQueryWithParamsStringAndClass() {  
400 - Query query = null;  
401 - expect(this.entityManager.createNativeQuery("teste", String.class)).andReturn(query);  
402 - replay(this.entityManager);  
403 - assertEquals(QueryProxy.class, this.entityManagerProxy.createNativeQuery("teste", String.class).getClass());  
404 - verify(this.entityManager);  
405 - }  
406 -  
407 - @Test  
408 - public void testCreateNativeQueryWithParamsStringAndString() {  
409 - Query query = null;  
410 - expect(this.entityManager.createNativeQuery("teste", "teste")).andReturn(query);  
411 - replay(this.entityManager);  
412 - assertEquals(QueryProxy.class, this.entityManagerProxy.createNativeQuery("teste", "teste").getClass());  
413 - verify(this.entityManager);  
414 - }  
415 -  
416 - @Test  
417 - public void testUnwrap() {  
418 - String query = null;  
419 - expect(this.entityManager.unwrap(String.class)).andReturn(query);  
420 - replay(this.entityManager);  
421 - assertEquals(query, this.entityManagerProxy.unwrap(String.class));  
422 - verify(this.entityManager);  
423 - }  
424 -  
425 - @Test  
426 - public void testGetDelegate() {  
427 - Object obj = null;  
428 - expect(this.entityManager.getDelegate()).andReturn(obj);  
429 - replay(this.entityManager);  
430 - assertEquals(obj, this.entityManagerProxy.getDelegate());  
431 - verify(this.entityManager);  
432 - }  
433 -  
434 - @Test  
435 - public void testIsOpen() {  
436 - expect(this.entityManager.isOpen()).andReturn(true);  
437 - replay(this.entityManager);  
438 - assertTrue(this.entityManagerProxy.isOpen());  
439 - verify(this.entityManager);  
440 - }  
441 -  
442 - @Test  
443 - public void testGetTransaction() {  
444 - EntityTransaction entityTransaction = null;  
445 - expect(this.entityManager.getTransaction()).andReturn(entityTransaction);  
446 - replay(this.entityManager);  
447 - assertEquals(entityTransaction, this.entityManagerProxy.getTransaction());  
448 - verify(this.entityManager);  
449 - }  
450 -  
451 - @Test  
452 - public void testGetEntityManagerFactory() {  
453 - EntityManagerFactory entityManagerFactory = null;  
454 - expect(this.entityManager.getEntityManagerFactory()).andReturn(entityManagerFactory);  
455 - replay(this.entityManager);  
456 - assertEquals(entityManagerFactory, this.entityManagerProxy.getEntityManagerFactory());  
457 - verify(this.entityManager);  
458 - }  
459 -  
460 - @Test  
461 - public void testGetCriteriaBuilder() {  
462 - CriteriaBuilder criteriaBuilder = null;  
463 - expect(this.entityManager.getCriteriaBuilder()).andReturn(criteriaBuilder);  
464 - replay(this.entityManager);  
465 - assertEquals(criteriaBuilder, this.entityManagerProxy.getCriteriaBuilder());  
466 - verify(this.entityManager);  
467 - }  
468 -  
469 - @Test  
470 - public void testGetMetamodel() {  
471 - Metamodel metamodel = null;  
472 - expect(this.entityManager.getMetamodel()).andReturn(metamodel);  
473 - replay(this.entityManager);  
474 - assertEquals(metamodel, this.entityManagerProxy.getMetamodel());  
475 - verify(this.entityManager);  
476 - }  
477 -  
478 - @Test  
479 - public void testEquals() {  
480 - Object obj = null;  
481 -  
482 - mockStatic(Beans.class);  
483 - // Method "equals" can't be mocked...  
484 - EntityManager em = new FakeEntityManager();  
485 - ((FakeEntityManager) em).setEquals(true);  
486 -  
487 - this.entityManagerContext = EasyMock.createMock(EntityManagerProducer.class);  
488 - expect(this.entityManagerContext.getEntityManager("teste")).andReturn(em).anyTimes();  
489 -  
490 - expect(Beans.getReference(EntityManagerProducer.class)).andReturn(this.entityManagerContext).anyTimes();  
491 - replay(this.entityManagerContext);  
492 - replayAll();  
493 -  
494 - EntityManagerProxy emp = new EntityManagerProxy("teste");  
495 -  
496 - assertTrue(emp.equals(obj));  
497 - }  
498 -  
499 - @Test  
500 - public void testHashCode() {  
501 - mockStatic(Beans.class);  
502 - // Method "hashCode" can't be mocked...  
503 - EntityManager em = new FakeEntityManager();  
504 - ((FakeEntityManager) em).setHashCode(1);  
505 -  
506 - this.entityManagerContext = EasyMock.createMock(EntityManagerProducer.class);  
507 - expect(this.entityManagerContext.getEntityManager("teste")).andReturn(em).anyTimes();  
508 -  
509 - expect(Beans.getReference(EntityManagerProducer.class)).andReturn(this.entityManagerContext).anyTimes();  
510 - replay(this.entityManagerContext);  
511 - replayAll();  
512 -  
513 - EntityManagerProxy emp = new EntityManagerProxy("teste");  
514 -  
515 - assertEquals(1, emp.hashCode());  
516 - }  
517 -  
518 - @Test  
519 - public void testToString() {  
520 - mockStatic(Beans.class);  
521 - // Method "toString" can't be mocked...  
522 - EntityManager em = new FakeEntityManager();  
523 - ((FakeEntityManager) em).setToString("testing");  
524 -  
525 - this.entityManagerContext = EasyMock.createMock(EntityManagerProducer.class);  
526 - expect(this.entityManagerContext.getEntityManager("teste")).andReturn(em).anyTimes();  
527 -  
528 - expect(Beans.getReference(EntityManagerProducer.class)).andReturn(this.entityManagerContext).anyTimes();  
529 - replay(this.entityManagerContext);  
530 - replayAll();  
531 -  
532 - EntityManagerProxy emp = new EntityManagerProxy("teste");  
533 -  
534 - assertEquals("testing", emp.toString());  
535 - }  
536 -}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/QueryProxyTest.java
@@ -1,294 +0,0 @@ @@ -1,294 +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 br.gov.frameworkdemoiselle.internal.proxy;  
38 -  
39 -import static junit.framework.Assert.assertTrue;  
40 -import static org.easymock.EasyMock.expect;  
41 -import static org.junit.Assert.assertEquals;  
42 -import static org.powermock.api.easymock.PowerMock.replay;  
43 -import static org.powermock.api.easymock.PowerMock.verifyAll;  
44 -  
45 -import java.util.ArrayList;  
46 -import java.util.Calendar;  
47 -import java.util.Collections;  
48 -import java.util.Date;  
49 -import java.util.HashMap;  
50 -import java.util.List;  
51 -import java.util.Map;  
52 -  
53 -import javax.persistence.EntityManager;  
54 -import javax.persistence.EntityManagerFactory;  
55 -import javax.persistence.FlushModeType;  
56 -import javax.persistence.LockModeType;  
57 -import javax.persistence.Parameter;  
58 -import javax.persistence.Persistence;  
59 -import javax.persistence.Query;  
60 -import javax.persistence.TemporalType;  
61 -  
62 -import org.easymock.EasyMock;  
63 -import org.junit.Before;  
64 -import org.junit.Test;  
65 -import org.junit.runner.RunWith;  
66 -import org.powermock.api.easymock.PowerMock;  
67 -import org.powermock.core.classloader.annotations.PrepareForTest;  
68 -import org.powermock.modules.junit4.PowerMockRunner;  
69 -import org.powermock.reflect.Whitebox;  
70 -  
71 -import br.gov.frameworkdemoiselle.domain.Client;  
72 -import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer;  
73 -import br.gov.frameworkdemoiselle.util.Beans;  
74 -  
75 -/**  
76 - * Test the proxied {@link Query} class, {@link QueryProxy}.  
77 - *  
78 - * @author 81986912515  
79 - */  
80 -@RunWith(PowerMockRunner.class)  
81 -@PrepareForTest({ Beans.class })  
82 -public class QueryProxyTest {  
83 -  
84 - private EntityManager manager;  
85 -  
86 - private EntityManagerProducer producer;  
87 -  
88 - private QueryProxy queryProxy;  
89 -  
90 - @Before  
91 - public void setUp() {  
92 -  
93 - Map<String, Object> configOverrides = new HashMap<String, Object>();  
94 - configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence");  
95 -  
96 - configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:.");  
97 - configOverrides.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver");  
98 - configOverrides.put("javax.persistence.jdbc.user", "sa");  
99 - configOverrides.put("javax.persistence.jdbc.password", "");  
100 -  
101 - configOverrides.put("hibernate.show_sql", "true");  
102 - configOverrides.put("hibernate.hbm2ddl.auto", "create-drop");  
103 -  
104 - EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides);  
105 - EntityManager delegate = factory.createEntityManager();  
106 -  
107 - Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>());  
108 - cache.put("pu1", delegate);  
109 -  
110 - producer = new EntityManagerProducer();  
111 - Whitebox.setInternalState(producer, "cache", cache);  
112 -  
113 - PowerMock.mockStatic(Beans.class);  
114 - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).anyTimes();  
115 - PowerMock.replayAll();  
116 -  
117 - manager = new EntityManagerProxy("pu1");  
118 - }  
119 -  
120 - @Test  
121 - public void testGetResultList() {  
122 - Query queryDelegate = PowerMock.createMock(Query.class);  
123 - List<String> result = new ArrayList<String>();  
124 - result.add("x");  
125 - EasyMock.expect(queryDelegate.getResultList()).andReturn(result).anyTimes();  
126 -  
127 - replay(queryDelegate);  
128 -  
129 - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager);  
130 - queryProxy.getResultList();  
131 - assertEquals(queryProxy.getResultList().size(), queryDelegate.getResultList().size());  
132 -  
133 - verifyAll();  
134 - }  
135 -  
136 - @Test  
137 - public void testSingleResult() {  
138 - Query queryDelegate = PowerMock.createMock(Query.class);  
139 - String result = "Resultado";  
140 - EasyMock.expect(queryDelegate.getSingleResult()).andReturn(result).anyTimes();  
141 -  
142 - replay(queryDelegate);  
143 -  
144 - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager);  
145 - assertEquals(queryProxy.getSingleResult(), queryDelegate.getSingleResult());  
146 -  
147 - verifyAll();  
148 - }  
149 -  
150 - @Test  
151 - public void testExecuteUpdate() {  
152 - Query queryDelegate = PowerMock.createMock(Query.class);  
153 - EasyMock.expect(queryDelegate.executeUpdate()).andReturn(1).anyTimes();  
154 -  
155 - replay(queryDelegate);  
156 -  
157 - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager);  
158 - assertEquals(queryProxy.executeUpdate(), 1);  
159 -  
160 - verifyAll();  
161 - }  
162 -  
163 - @Test  
164 - public void testPagination() {  
165 - Query queryDelegate = PowerMock.createMock(Query.class);  
166 - expect(queryDelegate.getMaxResults()).andReturn(4).times(2);  
167 - expect(queryDelegate.getFirstResult()).andReturn(2).times(2);  
168 - expect(queryDelegate.setMaxResults(EasyMock.anyInt())).andReturn(queryDelegate);  
169 - expect(queryDelegate.setFirstResult(EasyMock.anyInt())).andReturn(queryDelegate);  
170 - replay(queryDelegate);  
171 -  
172 - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager);  
173 - queryProxy.setMaxResults(4);  
174 - queryProxy.setFirstResult(2);  
175 - assertEquals(queryProxy.getMaxResults(), queryDelegate.getMaxResults());  
176 - assertEquals(queryProxy.getFirstResult(), queryDelegate.getFirstResult());  
177 -  
178 - verifyAll();  
179 - }  
180 -  
181 - @Test  
182 - public void testHint() {  
183 - Query queryDelegate = PowerMock.createMock(Query.class);  
184 - Map<String, Object> map = new HashMap<String, Object>();  
185 - Client client = new Client();  
186 - map.put("1", client);  
187 - expect(queryDelegate.getHints()).andReturn(map).times(2);  
188 - expect(queryDelegate.setHint(EasyMock.anyObject(String.class), EasyMock.anyObject())).andReturn(queryDelegate);  
189 - replay(queryDelegate);  
190 -  
191 - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager);  
192 - queryProxy.setHint("1", client);  
193 - assertEquals(queryProxy.getHints(), queryDelegate.getHints());  
194 -  
195 - verifyAll();  
196 - }  
197 -  
198 - @SuppressWarnings({ "unused", "rawtypes", "unchecked" })  
199 - @Test  
200 - public void testParameters() {  
201 - Query queryDelegate = PowerMock.createMock(Query.class);  
202 - Date dateValue = new Date();  
203 - Calendar calendar = PowerMock.createMock(Calendar.class);  
204 - Class<Date> type = Date.class;  
205 - Parameter parameter = PowerMock.createMock(Parameter.class);  
206 -  
207 - expect(queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class)))  
208 - .andReturn(queryDelegate);  
209 - expect(queryDelegate.getParameterValue(EasyMock.anyObject(String.class))).andReturn("Named Parameter")  
210 - .anyTimes();  
211 - expect(queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(String.class)))  
212 - .andReturn(queryDelegate);  
213 - expect(queryDelegate.getParameterValue(EasyMock.anyInt())).andReturn("Client").anyTimes();  
214 - expect(  
215 - queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Date.class),  
216 - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate);  
217 - expect(  
218 - queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Date.class),  
219 - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate);  
220 - expect(queryDelegate.setParameter(EasyMock.anyObject(Parameter.class), EasyMock.anyObject())).andReturn(  
221 - queryDelegate);  
222 - expect(queryDelegate.getParameterValue(EasyMock.anyObject(Parameter.class))).andReturn(parameter).anyTimes();  
223 - expect(  
224 - queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Calendar.class),  
225 - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate);  
226 - expect(  
227 - queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Calendar.class),  
228 - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate);  
229 -  
230 - replay(queryDelegate, parameter, calendar);  
231 -  
232 - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager);  
233 - queryProxy.setParameter("name", "Named Parameter");  
234 - assertEquals(queryProxy.getParameterValue("name"), queryDelegate.getParameterValue("name"));  
235 - queryProxy.setParameter(1, "Client");  
236 - assertEquals(queryProxy.getParameterValue("1"), queryDelegate.getParameterValue("1"));  
237 - queryProxy.setParameter("dateName", dateValue, TemporalType.DATE);  
238 - queryProxy.setParameter(2, dateValue, TemporalType.DATE);  
239 - queryProxy.setParameter(parameter, "X");  
240 - queryProxy.getParameterValue(parameter);  
241 - assertEquals(queryProxy.getParameterValue(parameter), parameter);  
242 - queryProxy.setParameter("dateName", calendar, TemporalType.DATE);  
243 - queryProxy.setParameter(2, calendar, TemporalType.DATE);  
244 -  
245 - verifyAll();  
246 - }  
247 -  
248 - @SuppressWarnings("rawtypes")  
249 - @Test  
250 - public void testIsBound() {  
251 - Query queryDelegate = PowerMock.createMock(Query.class);  
252 - Parameter parameter = PowerMock.createMock(Parameter.class);  
253 - expect(queryDelegate.isBound(EasyMock.anyObject(Parameter.class))).andReturn(true);  
254 -  
255 - replay(queryDelegate, parameter);  
256 -  
257 - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager);  
258 - assertTrue(queryProxy.isBound(parameter));  
259 -  
260 - verifyAll();  
261 - }  
262 -  
263 - @Test  
264 - public void testFlushMode() {  
265 - Query queryDelegate = PowerMock.createMock(Query.class);  
266 - FlushModeType flushModeType = FlushModeType.AUTO;  
267 -  
268 - expect(queryDelegate.setFlushMode(FlushModeType.AUTO)).andReturn(queryDelegate);  
269 - expect(queryDelegate.getFlushMode()).andReturn(flushModeType).anyTimes();  
270 -  
271 - replay(queryDelegate);  
272 -  
273 - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager);  
274 - queryProxy.setFlushMode(FlushModeType.AUTO);  
275 - assertEquals(queryProxy.getFlushMode(), queryDelegate.getFlushMode());  
276 - verifyAll();  
277 - }  
278 -  
279 - @Test  
280 - public void testLockMode() {  
281 - Query queryDelegate = PowerMock.createMock(Query.class);  
282 - LockModeType lockModeType = LockModeType.OPTIMISTIC;  
283 -  
284 - expect(queryDelegate.setLockMode(lockModeType)).andReturn(queryDelegate);  
285 - expect(queryDelegate.getLockMode()).andReturn(lockModeType).anyTimes();  
286 -  
287 - replay(queryDelegate);  
288 -  
289 - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager);  
290 - queryProxy.setLockMode(lockModeType);  
291 - assertEquals(queryProxy.getLockMode(), queryDelegate.getLockMode());  
292 - verifyAll();  
293 - }  
294 -}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/TypedQueryProxyTest.java
@@ -1,258 +0,0 @@ @@ -1,258 +0,0 @@
1 -package br.gov.frameworkdemoiselle.internal.proxy;  
2 -  
3 -import static junit.framework.Assert.assertTrue;  
4 -import static org.easymock.EasyMock.expect;  
5 -import static org.junit.Assert.assertEquals;  
6 -import static org.powermock.api.easymock.PowerMock.replay;  
7 -import static org.powermock.api.easymock.PowerMock.verifyAll;  
8 -  
9 -import java.util.ArrayList;  
10 -import java.util.Calendar;  
11 -import java.util.Collections;  
12 -import java.util.Date;  
13 -import java.util.HashMap;  
14 -import java.util.List;  
15 -import java.util.Map;  
16 -  
17 -import javax.persistence.EntityManager;  
18 -import javax.persistence.EntityManagerFactory;  
19 -import javax.persistence.FlushModeType;  
20 -import javax.persistence.LockModeType;  
21 -import javax.persistence.Parameter;  
22 -import javax.persistence.Persistence;  
23 -import javax.persistence.Query;  
24 -import javax.persistence.TemporalType;  
25 -import javax.persistence.TypedQuery;  
26 -  
27 -import org.easymock.EasyMock;  
28 -import org.junit.Before;  
29 -import org.junit.Test;  
30 -import org.junit.runner.RunWith;  
31 -import org.powermock.api.easymock.PowerMock;  
32 -import org.powermock.core.classloader.annotations.PrepareForTest;  
33 -import org.powermock.modules.junit4.PowerMockRunner;  
34 -import org.powermock.reflect.Whitebox;  
35 -  
36 -import br.gov.frameworkdemoiselle.domain.Client;  
37 -import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer;  
38 -import br.gov.frameworkdemoiselle.util.Beans;  
39 -  
40 -/**  
41 - * Test the proxied {@link Query} class, {@link TypedQueryProxy}.  
42 - *  
43 - * @author 81986912515  
44 - * @param <X>  
45 - */  
46 -  
47 -@SuppressWarnings("rawtypes")  
48 -@RunWith(PowerMockRunner.class)  
49 -@PrepareForTest({ Beans.class })  
50 -public class TypedQueryProxyTest {  
51 -  
52 - private EntityManager manager;  
53 -  
54 - private EntityManagerProducer producer;  
55 -  
56 - private TypedQueryProxy typedQueryProxy;  
57 -  
58 - @Before  
59 - public void setUp() {  
60 -  
61 - Map<String, Object> configOverrides = new HashMap<String, Object>();  
62 - configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence");  
63 -  
64 - configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:.");  
65 - configOverrides.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver");  
66 - configOverrides.put("javax.persistence.jdbc.user", "sa");  
67 - configOverrides.put("javax.persistence.jdbc.password", "");  
68 -  
69 - configOverrides.put("hibernate.show_sql", "true");  
70 - configOverrides.put("hibernate.hbm2ddl.auto", "create-drop");  
71 -  
72 - EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides);  
73 - EntityManager delegate = factory.createEntityManager();  
74 -  
75 - Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>());  
76 - cache.put("pu1", delegate);  
77 -  
78 - producer = new EntityManagerProducer();  
79 - Whitebox.setInternalState(producer, "cache", cache);  
80 -  
81 - PowerMock.mockStatic(Beans.class);  
82 - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).anyTimes();  
83 - PowerMock.replayAll();  
84 -  
85 - manager = new EntityManagerProxy("pu1");  
86 -  
87 - // PowerMock.resetAll();  
88 - }  
89 -  
90 - @SuppressWarnings("unchecked")  
91 - @Test  
92 - public void testResultList() {  
93 -  
94 - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class);  
95 - List<String> result = new ArrayList<String>();  
96 - result.add("x");  
97 - EasyMock.expect(queryDelegate.getResultList()).andReturn(result).anyTimes();  
98 -  
99 - replay(queryDelegate);  
100 -  
101 - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager);  
102 - assertEquals(typedQueryProxy.getResultList().size(), queryDelegate.getResultList().size());  
103 -  
104 - verifyAll();  
105 - }  
106 -  
107 - @SuppressWarnings("unchecked")  
108 - @Test  
109 - public void testSingleResult() {  
110 - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class);  
111 - String result = "Resultado";  
112 - EasyMock.expect(queryDelegate.getSingleResult()).andReturn(result).anyTimes();  
113 -  
114 - replay(queryDelegate);  
115 -  
116 - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager);  
117 - assertEquals(typedQueryProxy.getSingleResult(), queryDelegate.getSingleResult());  
118 -  
119 - verifyAll();  
120 - }  
121 -  
122 - @SuppressWarnings("unchecked")  
123 - @Test  
124 - public void testPagination() {  
125 - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class);  
126 - expect(queryDelegate.getMaxResults()).andReturn(4).times(2);  
127 - expect(queryDelegate.getFirstResult()).andReturn(2).times(2);  
128 - expect(queryDelegate.setMaxResults(EasyMock.anyInt())).andReturn(queryDelegate);  
129 - expect(queryDelegate.setFirstResult(EasyMock.anyInt())).andReturn(queryDelegate);  
130 - replay(queryDelegate);  
131 -  
132 - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager);  
133 - typedQueryProxy.setMaxResults(4);  
134 - typedQueryProxy.setFirstResult(2);  
135 - assertEquals(typedQueryProxy.getMaxResults(), queryDelegate.getMaxResults());  
136 - assertEquals(typedQueryProxy.getFirstResult(), queryDelegate.getFirstResult());  
137 -  
138 - verifyAll();  
139 - }  
140 -  
141 - @SuppressWarnings("unchecked")  
142 - @Test  
143 - public void testHint() {  
144 - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class);  
145 - Map<String, Object> map = new HashMap<String, Object>();  
146 - Client client = new Client();  
147 - map.put("1", client);  
148 - expect(queryDelegate.getHints()).andReturn(map).times(2);  
149 - expect(queryDelegate.setHint(EasyMock.anyObject(String.class), EasyMock.anyObject())).andReturn(queryDelegate);  
150 - replay(queryDelegate);  
151 -  
152 - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager);  
153 - typedQueryProxy.setHint("1", client);  
154 - assertEquals(typedQueryProxy.getHints(), queryDelegate.getHints());  
155 -  
156 - verifyAll();  
157 - }  
158 -  
159 - @SuppressWarnings({ "unchecked", "unused" })  
160 - @Test  
161 - public void testParameters() {  
162 - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class);  
163 - Date dateValue = new Date();  
164 - Calendar calendar = PowerMock.createMock(Calendar.class);  
165 - Class<Date> type = Date.class;  
166 - Parameter parameter = PowerMock.createMock(Parameter.class);  
167 -  
168 - expect(queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class)))  
169 - .andReturn(queryDelegate);  
170 - expect(queryDelegate.getParameterValue(EasyMock.anyObject(String.class))).andReturn("Named Parameter")  
171 - .anyTimes();  
172 - expect(queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(String.class)))  
173 - .andReturn(queryDelegate);  
174 - expect(queryDelegate.getParameterValue(EasyMock.anyInt())).andReturn("Client").anyTimes();  
175 - expect(  
176 - queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Date.class),  
177 - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate);  
178 - expect(  
179 - queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Date.class),  
180 - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate);  
181 - expect(queryDelegate.setParameter(EasyMock.anyObject(Parameter.class), EasyMock.anyObject())).andReturn(  
182 - queryDelegate);  
183 - expect(queryDelegate.getParameterValue(EasyMock.anyObject(Parameter.class))).andReturn(parameter).anyTimes();  
184 - expect(  
185 - queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Calendar.class),  
186 - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate);  
187 - expect(  
188 - queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Calendar.class),  
189 - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate);  
190 -  
191 - replay(queryDelegate, parameter, calendar);  
192 -  
193 - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager);  
194 - typedQueryProxy.setParameter("name", "Named Parameter");  
195 - assertEquals(typedQueryProxy.getParameterValue("name"), queryDelegate.getParameterValue("name"));  
196 - typedQueryProxy.setParameter(1, "Client");  
197 - assertEquals(typedQueryProxy.getParameterValue("1"), queryDelegate.getParameterValue("1"));  
198 - typedQueryProxy.setParameter("dateName", dateValue, TemporalType.DATE);  
199 - typedQueryProxy.setParameter(2, dateValue, TemporalType.DATE);  
200 - typedQueryProxy.setParameter(parameter, "X");  
201 - typedQueryProxy.getParameterValue(parameter);  
202 - assertEquals(typedQueryProxy.getParameterValue(parameter), parameter);  
203 - typedQueryProxy.setParameter("dateName", calendar, TemporalType.DATE);  
204 - typedQueryProxy.setParameter(2, calendar, TemporalType.DATE);  
205 -  
206 - verifyAll();  
207 - }  
208 -  
209 - @SuppressWarnings("unchecked")  
210 - @Test  
211 - public void testIsBound() {  
212 - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class);  
213 - Parameter parameter = PowerMock.createMock(Parameter.class);  
214 - expect(queryDelegate.isBound(EasyMock.anyObject(Parameter.class))).andReturn(true);  
215 -  
216 - replay(queryDelegate, parameter);  
217 -  
218 - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager);  
219 - assertTrue(typedQueryProxy.isBound(parameter));  
220 -  
221 - verifyAll();  
222 - }  
223 -  
224 - @SuppressWarnings("unchecked")  
225 - @Test  
226 - public void testFlushMode() {  
227 - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class);  
228 - FlushModeType flushModeType = FlushModeType.AUTO;  
229 -  
230 - expect(queryDelegate.setFlushMode(FlushModeType.AUTO)).andReturn(queryDelegate);  
231 - expect(queryDelegate.getFlushMode()).andReturn(flushModeType).anyTimes();  
232 -  
233 - replay(queryDelegate);  
234 -  
235 - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager);  
236 - typedQueryProxy.setFlushMode(FlushModeType.AUTO);  
237 - assertEquals(typedQueryProxy.getFlushMode(), queryDelegate.getFlushMode());  
238 - verifyAll();  
239 - }  
240 -  
241 - @SuppressWarnings("unchecked")  
242 - @Test  
243 - public void testLockMode() {  
244 - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class);  
245 - LockModeType lockModeType = LockModeType.OPTIMISTIC;  
246 -  
247 - expect(queryDelegate.setLockMode(lockModeType)).andReturn(queryDelegate);  
248 - expect(queryDelegate.getLockMode()).andReturn(lockModeType).anyTimes();  
249 -  
250 - replay(queryDelegate);  
251 -  
252 - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager);  
253 - typedQueryProxy.setLockMode(lockModeType);  
254 - assertEquals(typedQueryProxy.getLockMode(), queryDelegate.getLockMode());  
255 - verifyAll();  
256 - }  
257 -  
258 -}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/template/JPACrudTest.java
@@ -1,434 +0,0 @@ @@ -1,434 +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 br.gov.frameworkdemoiselle.template;  
38 -import static org.easymock.EasyMock.expect;  
39 -import static org.easymock.EasyMock.replay;  
40 -import static org.easymock.EasyMock.verify;  
41 -import static org.junit.Assert.assertEquals;  
42 -import static org.junit.Assert.assertTrue;  
43 -import static org.junit.Assert.fail;  
44 -import static org.powermock.api.easymock.PowerMock.replayAll;  
45 -import static org.powermock.api.easymock.PowerMock.verifyAll;  
46 -import static org.powermock.reflect.Whitebox.setInternalState;  
47 -  
48 -import java.util.ArrayList;  
49 -import java.util.HashMap;  
50 -import java.util.List;  
51 -import java.util.Map;  
52 -  
53 -import javax.enterprise.inject.Instance;  
54 -import javax.persistence.EntityManager;  
55 -import javax.persistence.EntityManagerFactory;  
56 -import javax.persistence.Persistence;  
57 -import javax.persistence.Query;  
58 -import javax.persistence.TransactionRequiredException;  
59 -import javax.persistence.TypedQuery;  
60 -import javax.persistence.criteria.CriteriaBuilder;  
61 -import javax.persistence.criteria.CriteriaQuery;  
62 -import javax.persistence.criteria.Predicate;  
63 -import javax.persistence.criteria.Root;  
64 -  
65 -import junit.framework.Assert;  
66 -  
67 -import org.easymock.EasyMock;  
68 -import org.junit.Before;  
69 -import org.junit.Test;  
70 -import org.junit.runner.RunWith;  
71 -import org.powermock.api.easymock.PowerMock;  
72 -import org.powermock.core.classloader.annotations.PrepareForTest;  
73 -import org.powermock.modules.junit4.PowerMockRunner;  
74 -import org.powermock.reflect.Whitebox;  
75 -  
76 -import br.gov.frameworkdemoiselle.DemoiselleException;  
77 -import br.gov.frameworkdemoiselle.configuration.Configuration;  
78 -import br.gov.frameworkdemoiselle.domain.Contact;  
79 -import br.gov.frameworkdemoiselle.internal.implementation.PaginationImpl;  
80 -import br.gov.frameworkdemoiselle.pagination.Pagination;  
81 -import br.gov.frameworkdemoiselle.pagination.PaginationContext;  
82 -import br.gov.frameworkdemoiselle.util.Beans;  
83 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
84 -  
85 -@RunWith(PowerMockRunner.class)  
86 -@PrepareForTest({ ResourceBundle.class, Instance.class, Beans.class })  
87 -public class JPACrudTest {  
88 -  
89 - private EntityManager entityManager;  
90 -  
91 - private Contact contact;  
92 -  
93 - private ContactDAO contactDAO;  
94 -  
95 - class ContactDAO extends JPACrud<Contact, Long> {  
96 -  
97 - private static final long serialVersionUID = 1L;  
98 -  
99 - }  
100 -  
101 - @Before  
102 - public void setUp() throws Exception {  
103 - this.entityManager = EasyMock.createMock(EntityManager.class);  
104 - this.contact = new Contact();  
105 - this.contactDAO = new ContactDAO();  
106 - setInternalState(this.contactDAO, EntityManager.class, this.entityManager);  
107 - }  
108 -  
109 - @Test  
110 - public void testDelete() {  
111 - expect(this.entityManager.getReference(Contact.class, null)).andReturn(null);  
112 - this.entityManager.remove(null);  
113 - replay(this.entityManager);  
114 - this.contactDAO.delete(this.contact.getId());  
115 - verify(this.entityManager);  
116 - }  
117 -  
118 - private TypedQuery<Contact> makeTypedQuery() {  
119 - @SuppressWarnings("unchecked")  
120 - TypedQuery<Contact> typeQuery = EasyMock.createMock(TypedQuery.class);  
121 - expect(typeQuery.setFirstResult(EasyMock.anyInt())).andReturn(null);  
122 - expect(typeQuery.setMaxResults(EasyMock.anyInt())).andReturn(null);  
123 - expect(typeQuery.getResultList()).andReturn(createContacts(1));  
124 - return typeQuery;  
125 - }  
126 -  
127 - @Test  
128 - public void testCountAll() {  
129 -  
130 - Pagination pagination = new PaginationImpl();  
131 - pagination.setPageSize(10);  
132 - setInternalState(this.contactDAO, "pagination", pagination);  
133 -  
134 - TypedQuery<Contact> typeQuery = makeTypedQuery();  
135 -  
136 - Query query = EasyMock.createMock(Query.class);  
137 - expect(query.getSingleResult()).andReturn(10L);  
138 -  
139 - expect(this.entityManager.createQuery("select this from Contact this", Contact.class)).andReturn(typeQuery);  
140 - //expect(this.entityManager.createQuery("SELECT COUNT(THIS) FROM CONTACT THIS")).andReturn(query);  
141 - expect(this.entityManager.createQuery("select COUNT(this) from Contact this")).andReturn(query);  
142 -  
143 - replayAll(typeQuery, query, this.entityManager);  
144 -  
145 - List<Contact> find = this.contactDAO.findAll();  
146 -  
147 - assertEquals(1, find.size());  
148 - assertTrue(find.iterator().next().getId().equals(1L));  
149 -  
150 - verifyAll();  
151 - }  
152 -  
153 - @Test  
154 - public void testFailCountAll() {  
155 -  
156 - Pagination pagination = new PaginationImpl();  
157 - setInternalState(this.contactDAO, "pagination", pagination);  
158 -  
159 - TypedQuery<Contact> typeQuery = makeTypedQuery();  
160 -  
161 - Query query = EasyMock.createMock(Query.class);  
162 -  
163 - expect(query.getSingleResult()).andThrow(new DemoiselleException(""));  
164 - expect(this.entityManager.createQuery("select this from Contact this", Contact.class)).andReturn(typeQuery);  
165 - expect(this.entityManager.createQuery("select COUNT(this) from Contact this")).andReturn(query);  
166 -  
167 - replayAll(query, this.entityManager);  
168 -  
169 - try {  
170 - this.contactDAO.findAll();  
171 - fail();  
172 - } catch (DemoiselleException exception) {  
173 - }  
174 -  
175 - verifyAll();  
176 - }  
177 -  
178 - @SuppressWarnings("unchecked")  
179 - @Test  
180 - public void testHandleException() throws Throwable {  
181 - try {  
182 - TransactionRequiredException throwed = new TransactionRequiredException();  
183 - ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class);  
184 - Instance<ResourceBundle> instance = PowerMock.createMock(Instance.class);  
185 - expect(  
186 - bundle.getString("no-transaction-active", "frameworkdemoiselle.transaction.class",  
187 - Configuration.DEFAULT_RESOURCE)).andReturn("message");  
188 - expect(instance.get()).andReturn(bundle);  
189 - setInternalState(contactDAO, "bundle", instance);  
190 - replayAll();  
191 - contactDAO.handleException(throwed);  
192 - fail();  
193 - } catch (DemoiselleException exception) {  
194 - assertEquals(exception.getMessage(), "message");  
195 - }  
196 - verifyAll();  
197 - }  
198 -  
199 - @SuppressWarnings("unchecked")  
200 - @Test  
201 - public void testFailFindByExample() {  
202 -  
203 - CriteriaBuilder criteriaBuilder = PowerMock.createMock(CriteriaBuilder.class);  
204 - CriteriaQuery<Contact> criteriaQuery = PowerMock.createMock(CriteriaQuery.class);  
205 - Root<Contact> root = PowerMock.createMock(Root.class);  
206 -  
207 - expect(this.entityManager.getCriteriaBuilder()).andReturn(criteriaBuilder);  
208 - expect(criteriaBuilder.createQuery(Contact.class)).andReturn(criteriaQuery);  
209 - expect(criteriaQuery.from(Contact.class)).andReturn(root);  
210 -  
211 - expect(this.entityManager.createQuery(criteriaQuery)).andThrow(new DemoiselleException(""));  
212 -  
213 - Predicate predicate = PowerMock.createMock(Predicate.class);  
214 -  
215 - expect(root.get("id")).andReturn(null);  
216 - expect(criteriaBuilder.equal(EasyMock.anyObject(Predicate.class), EasyMock.anyObject())).andReturn(predicate);  
217 - expect(criteriaQuery.where(new Predicate[] { EasyMock.anyObject(Predicate.class) })).andReturn(criteriaQuery);  
218 - expect(criteriaQuery.select(EasyMock.anyObject(Root.class))).andReturn(criteriaQuery);  
219 -  
220 - replayAll(criteriaBuilder, criteriaQuery, root, this.entityManager);  
221 -  
222 - Contact example = new Contact();  
223 - example.setId(1L);  
224 - try {  
225 - this.contactDAO.findByExample(example);  
226 - fail();  
227 - } catch (DemoiselleException ce) {  
228 - }  
229 -  
230 - verifyAll();  
231 - }  
232 -  
233 - @SuppressWarnings("unchecked")  
234 - @Test  
235 - public void testFindByExample() {  
236 -  
237 - TypedQuery<Contact> typedQuery = EasyMock.createMock(TypedQuery.class);  
238 - CriteriaBuilder criteriaBuilder = PowerMock.createMock(CriteriaBuilder.class);  
239 - CriteriaQuery<Contact> criteriaQuery = PowerMock.createMock(CriteriaQuery.class);  
240 - Root<Contact> root = PowerMock.createMock(Root.class);  
241 -  
242 - expect(this.entityManager.getCriteriaBuilder()).andReturn(criteriaBuilder);  
243 - expect(criteriaBuilder.createQuery(Contact.class)).andReturn(criteriaQuery);  
244 - expect(criteriaQuery.from(Contact.class)).andReturn(root);  
245 -  
246 - expect(this.entityManager.createQuery(criteriaQuery)).andReturn(typedQuery);  
247 - expect(typedQuery.getResultList()).andReturn(createContacts(1));  
248 -  
249 - Predicate predicate = PowerMock.createMock(Predicate.class);  
250 -  
251 - expect(root.get("id")).andReturn(null);  
252 - expect(criteriaBuilder.equal(EasyMock.anyObject(Predicate.class), EasyMock.anyObject())).andReturn(predicate);  
253 - expect(criteriaQuery.where(new Predicate[] { EasyMock.anyObject(Predicate.class) })).andReturn(criteriaQuery);  
254 - expect(criteriaQuery.select(EasyMock.anyObject(Root.class))).andReturn(criteriaQuery);  
255 -  
256 - replayAll(typedQuery, criteriaBuilder, criteriaQuery, root, this.entityManager);  
257 -  
258 - Contact example = new Contact();  
259 - example.setId(1L);  
260 - List<Contact> find = this.contactDAO.findByExample(example);  
261 -  
262 - assertEquals(1, find.size());  
263 - assertTrue(find.iterator().next().getId().equals(1L));  
264 -  
265 - verifyAll();  
266 - }  
267 -  
268 - @Test  
269 - public void testFindAll() {  
270 -  
271 - Pagination pagination = new PaginationImpl();  
272 - pagination.setPageSize(10);  
273 - setInternalState(this.contactDAO, "pagination", pagination);  
274 -  
275 - TypedQuery<Contact> typeQuery = makeTypedQuery();  
276 -  
277 - Query query = EasyMock.createMock(Query.class);  
278 - expect(query.getSingleResult()).andReturn(10L);  
279 -  
280 - expect(this.entityManager.createQuery("select this from Contact this", Contact.class)).andReturn(typeQuery);  
281 - expect(this.entityManager.createQuery("select COUNT(this) from Contact this")).andReturn(query);  
282 -  
283 - replayAll(typeQuery, query, this.entityManager);  
284 -  
285 - List<Contact> find = this.contactDAO.findAll();  
286 -  
287 - assertEquals(1, find.size());  
288 - assertTrue(find.iterator().next().getId().equals(1L));  
289 -  
290 - verifyAll();  
291 - }  
292 -  
293 - @Test  
294 - public void testFailFindAll() {  
295 -  
296 - PaginationContext actualContext = PowerMock.createMock(PaginationContext.class);  
297 - expect(actualContext.getPagination(Contact.class)).andReturn(null);  
298 - /*@SuppressWarnings("unchecked")  
299 - Instance<PaginationContext> paginationContext = PowerMock.createMock(Instance.class);  
300 - expect(paginationContext.get()).andReturn(actualContext);*/  
301 -  
302 - PowerMock.mockStatic(Beans.class);  
303 - expect(Beans.getReference(PaginationContext.class)).andReturn(actualContext);  
304 -  
305 - @SuppressWarnings("unchecked")  
306 - TypedQuery<Contact> typeQuery = EasyMock.createMock(TypedQuery.class);  
307 - expect(typeQuery.getResultList()).andThrow(new DemoiselleException(""));  
308 -  
309 - Query query = EasyMock.createMock(Query.class);  
310 - expect(this.entityManager.createQuery("select this from Contact this", Contact.class)).andReturn(typeQuery);  
311 -  
312 - replayAll(typeQuery, query, this.entityManager);  
313 -  
314 - try {  
315 - this.contactDAO.findAll();  
316 - fail();  
317 - } catch (DemoiselleException exception) {  
318 - }  
319 -  
320 - verifyAll();  
321 - }  
322 -  
323 - private List<Contact> createContacts(int quantity) {  
324 - List<Contact> contacts = new ArrayList<Contact>();  
325 - for (int i = 0; i < quantity; i++) {  
326 - Contact contact = new Contact();  
327 - contact.setId((long) quantity);  
328 - contacts.add(contact);  
329 - }  
330 - return contacts;  
331 - }  
332 -  
333 - @Test  
334 - public void testFailInsert() {  
335 - this.entityManager.persist(null);  
336 - EasyMock.expectLastCall().andThrow(new DemoiselleException(""));  
337 - replay(this.entityManager);  
338 - try {  
339 - this.contactDAO.insert(null);  
340 - fail();  
341 - } catch (DemoiselleException exc) {  
342 - }  
343 - verify(this.entityManager);  
344 - }  
345 -  
346 - @Test  
347 - public void testInsert() {  
348 - this.entityManager.persist(this.contact);  
349 - replay(this.entityManager);  
350 - setInternalState(this.contactDAO, EntityManager.class, this.entityManager);  
351 - this.contactDAO.insert(this.contact);  
352 - verify(this.entityManager);  
353 - }  
354 -  
355 - @Test  
356 - public void testLoad() {  
357 - Contact contact = new Contact();  
358 - expect(this.entityManager.find(Contact.class, 1L)).andReturn(contact);  
359 - replay(this.entityManager);  
360 - Contact returnedContact = this.contactDAO.load(1L);  
361 - assertEquals(contact.hashCode(), returnedContact.hashCode());  
362 - verify(this.entityManager);  
363 - }  
364 -  
365 - @Test  
366 - public void testFailLoad() {  
367 - expect(this.entityManager.find(Contact.class, 1L)).andThrow(new DemoiselleException(""));  
368 - replay(this.entityManager);  
369 - try {  
370 - this.contactDAO.load(1L);  
371 - fail();  
372 - } catch (DemoiselleException exc) {  
373 - }  
374 - verify(this.entityManager);  
375 - }  
376 -  
377 - @Test  
378 - public void testUpdate() {  
379 - expect(this.entityManager.merge(this.contact)).andReturn(null);  
380 - replay(this.entityManager);  
381 - setInternalState(this.contactDAO, EntityManager.class, this.entityManager);  
382 - this.contactDAO.update(this.contact);  
383 - verify(this.entityManager);  
384 - }  
385 -  
386 - @Test  
387 - public void testFailUpdate() {  
388 - this.entityManager.merge(null);  
389 - EasyMock.expectLastCall().andThrow(new DemoiselleException(""));  
390 - replay(this.entityManager);  
391 - try {  
392 - this.contactDAO.update(null);  
393 - fail();  
394 - } catch (DemoiselleException exc) {  
395 - }  
396 - verify(this.entityManager);  
397 - }  
398 -  
399 - /**  
400 - * Test if the JPACrud will correctly obtain a new entity manager the first  
401 - * time it is called and the entity manager is still null.  
402 - */  
403 - @Test  
404 - public void testCreateEntityManagerIfNotExist(){  
405 - PowerMock.mockStatic(Beans.class);  
406 - expect(Beans.getReference(EntityManager.class)).andReturn(entityManager);  
407 - PowerMock.replay(Beans.class);  
408 -  
409 - setInternalState(this.contactDAO, EntityManager.class, (EntityManager)null);  
410 - Assert.assertNotNull(this.contactDAO.getEntityManager());  
411 - }  
412 -  
413 - @Test  
414 - public void testCriteriaQuery(){  
415 - Map<String, Object> configOverrides = new HashMap<String, Object>();  
416 - configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence");  
417 - configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:hsql:.");  
418 - configOverrides.put("hibernate.show_sql", "true");  
419 - configOverrides.put("hibernate.hbm2ddl.auto", "create-drop");  
420 -  
421 - EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides);  
422 - this.entityManager = factory.createEntityManager();  
423 - Whitebox.setInternalState(this.contactDAO, EntityManager.class, (EntityManager)null);  
424 -  
425 - PowerMock.mockStatic(Beans.class);  
426 - expect(Beans.getReference(EntityManager.class)).andReturn(entityManager);  
427 - PowerMock.replay(Beans.class);  
428 -  
429 - CriteriaQuery<Contact> query = this.contactDAO.createCriteriaQuery();  
430 - query.select( query.from(Contact.class) );  
431 -  
432 - }  
433 -  
434 -}  
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/transaction/JPATransactionTest.java
@@ -1,222 +0,0 @@ @@ -1,222 +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 br.gov.frameworkdemoiselle.transaction;  
38 -import static org.easymock.EasyMock.createMock;  
39 -import static org.easymock.EasyMock.expect;  
40 -import static org.easymock.EasyMock.replay;  
41 -import static org.junit.Assert.assertEquals;  
42 -import static org.powermock.api.easymock.PowerMock.replayAll;  
43 -import static org.powermock.api.easymock.PowerMock.verifyAll;  
44 -import static org.powermock.reflect.Whitebox.setInternalState;  
45 -  
46 -import java.util.HashMap;  
47 -import java.util.Map;  
48 -  
49 -import javax.persistence.EntityManager;  
50 -import javax.persistence.EntityTransaction;  
51 -  
52 -import org.easymock.EasyMock;  
53 -import org.junit.After;  
54 -import org.junit.Before;  
55 -import org.junit.Test;  
56 -import org.omg.CORBA.SystemException;  
57 -  
58 -import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer;  
59 -  
60 -/**  
61 - * @author SERPRO  
62 - * @see JPATransaction  
63 - */  
64 -public class JPATransactionTest {  
65 -  
66 - private JPATransaction tx;  
67 -  
68 - private EntityManager em;  
69 -  
70 - private EntityTransaction et;  
71 -  
72 - private Map<String, EntityManager> cache;  
73 -  
74 - private EntityManagerProducer producer;  
75 -  
76 - @Before  
77 - public void setUp() {  
78 - et = createMock(EntityTransaction.class);  
79 - em = createMock(EntityManager.class);  
80 - cache = new HashMap<String, EntityManager>();  
81 - producer = EasyMock.createMock(EntityManagerProducer.class);  
82 -  
83 - tx = new JPATransaction();  
84 - setInternalState(tx, EntityManagerProducer.class, producer);  
85 - }  
86 -  
87 - @After  
88 - public void tearDown() {  
89 - tx = null;  
90 - em = null;  
91 - et = null;  
92 - cache = null;  
93 - producer = null;  
94 - }  
95 -  
96 - @Test  
97 - public void testBegin() throws SystemException {  
98 - et.begin();  
99 - expect(et.isActive()).andReturn(false);  
100 - expect(em.getTransaction()).andReturn(et).anyTimes();  
101 - cache.put("teste", em);  
102 - expect(producer.getCache()).andReturn(cache);  
103 - replay(producer);  
104 - replayAll();  
105 - replay(em);  
106 - replay(et);  
107 -  
108 - tx.begin();  
109 - verifyAll();  
110 - }  
111 -  
112 - @Test  
113 - public void testCommit() throws Exception {  
114 - et.commit();  
115 - expect(et.isActive()).andReturn(true);  
116 - expect(em.getTransaction()).andReturn(et).anyTimes();  
117 - cache.put("teste", em);  
118 - expect(producer.getCache()).andReturn(cache);  
119 - replay(producer);  
120 - replayAll();  
121 - replay(em);  
122 - replay(et);  
123 -  
124 - tx.commit();  
125 - verifyAll();  
126 - }  
127 -  
128 - @Test  
129 - public void testRollback() throws Exception {  
130 - et.rollback();  
131 - expect(et.isActive()).andReturn(true);  
132 - expect(em.getTransaction()).andReturn(et).anyTimes();  
133 - em.clear();  
134 - cache.put("teste", em);  
135 - expect(producer.getCache()).andReturn(cache);  
136 - replay(producer);  
137 - replayAll();  
138 - replay(em);  
139 - replay(et);  
140 -  
141 - tx.rollback();  
142 - verifyAll();  
143 - }  
144 -  
145 - @Test  
146 - public void testSetRollbackOnly() throws Exception {  
147 - et.setRollbackOnly();  
148 - expect(et.isActive()).andReturn(true);  
149 - expect(em.getTransaction()).andReturn(et).anyTimes();  
150 - cache.put("teste", em);  
151 - expect(producer.getCache()).andReturn(cache);  
152 - replay(producer);  
153 - replayAll();  
154 - replay(em);  
155 - replay(et);  
156 -  
157 - tx.setRollbackOnly();  
158 - verifyAll();  
159 - }  
160 -  
161 - @Test  
162 - public void testIsActiveTrue() throws Exception {  
163 - expect(et.isActive()).andReturn(true).anyTimes();  
164 - expect(em.getTransaction()).andReturn(et).anyTimes();  
165 - cache.put("teste", em);  
166 - expect(producer.getCache()).andReturn(cache);  
167 - replay(producer);  
168 - replayAll();  
169 - replay(em);  
170 - replay(et);  
171 -  
172 - assertEquals(true, tx.isActive());  
173 - verifyAll();  
174 - }  
175 -  
176 - @Test  
177 - public void testIsActiveFalse() throws Exception {  
178 - expect(et.isActive()).andReturn(false).anyTimes();  
179 - expect(em.getTransaction()).andReturn(et).anyTimes();  
180 - cache.put("teste", em);  
181 - expect(producer.getCache()).andReturn(cache);  
182 - replay(producer);  
183 - replayAll();  
184 - replay(em);  
185 - replay(et);  
186 -  
187 - assertEquals(false, tx.isActive());  
188 - verifyAll();  
189 - }  
190 -  
191 - @Test  
192 - public void testIsMarkedRollbackTrue() throws Exception {  
193 - expect(et.isActive()).andReturn(true);  
194 - expect(et.getRollbackOnly()).andReturn(true).anyTimes();  
195 - expect(em.getTransaction()).andReturn(et).anyTimes();  
196 - cache.put("teste", em);  
197 - expect(producer.getCache()).andReturn(cache);  
198 - replay(producer);  
199 - replayAll();  
200 - replay(em);  
201 - replay(et);  
202 -  
203 - assertEquals(true, tx.isMarkedRollback());  
204 - verifyAll();  
205 - }  
206 -  
207 - @Test  
208 - public void testIsMarkedRollbackFalse() throws Exception {  
209 - expect(et.isActive()).andReturn(true);  
210 - expect(et.getRollbackOnly()).andReturn(false).anyTimes();  
211 - expect(em.getTransaction()).andReturn(et).anyTimes();  
212 - cache.put("teste", em);  
213 - expect(producer.getCache()).andReturn(cache);  
214 - replay(producer);  
215 - replayAll();  
216 - replay(em);  
217 - replay(et);  
218 -  
219 - assertEquals(false, tx.isMarkedRollback());  
220 - verifyAll();  
221 - }  
222 -}  
impl/extension/jpa/src/test/resources/META-INF/persistence.xml
@@ -1,48 +0,0 @@ @@ -1,48 +0,0 @@
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<!--  
3 - Demoiselle Framework  
4 - Copyright (C) 2010 SERPRO  
5 - ============================================================================  
6 - This file is part of Demoiselle Framework.  
7 -  
8 - Demoiselle Framework is free software; you can redistribute it and/or  
9 - modify it under the terms of the GNU Lesser General Public License version 3  
10 - as published by the Free Software Foundation.  
11 -  
12 - This program is distributed in the hope that it will be useful,  
13 - but WITHOUT ANY WARRANTY; without even the implied warranty of  
14 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
15 - GNU General Public License for more details.  
16 -  
17 - You should have received a copy of the GNU Lesser General Public License version 3  
18 - along with this program; if not, see <http://www.gnu.org/licenses/>  
19 - or write to the Free Software Foundation, Inc., 51 Franklin Street,  
20 - Fifth Floor, Boston, MA 02110-1301, USA.  
21 - ============================================================================  
22 - Este arquivo é parte do Framework Demoiselle.  
23 -  
24 - O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
25 - modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
26 - do Software Livre (FSF).  
27 -  
28 - Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
29 - GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
30 - APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
31 - para maiores detalhes.  
32 -  
33 - Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
34 - "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
35 - ou escreva para a Fundação do Software Livre (FSF) Inc.,  
36 - 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
37 --->  
38 -<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
39 - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">  
40 - <persistence-unit name="pu1" transaction-type="RESOURCE_LOCAL">  
41 - <properties>  
42 - <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />  
43 - <property name="javax.persistence.jdbc.user" value="sa" />  
44 - <property name="javax.persistence.jdbc.password" value="" />  
45 - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql:." />  
46 - </properties>  
47 - </persistence-unit>  
48 -</persistence>  
49 \ No newline at end of file 0 \ No newline at end of file
impl/extension/jpa/src/test/resources/demoiselle-jpa-bundle.properties
@@ -1,45 +0,0 @@ @@ -1,45 +0,0 @@
1 -# Demoiselle Framework  
2 -# Copyright (C) 2010 SERPRO  
3 -# ----------------------------------------------------------------------------  
4 -# This file is part of Demoiselle Framework.  
5 -#  
6 -# Demoiselle Framework is free software; you can redistribute it and/or  
7 -# modify it under the terms of the GNU Lesser General Public License version 3  
8 -# as published by the Free Software Foundation.  
9 -#  
10 -# This program is distributed in the hope that it will be useful,  
11 -# but WITHOUT ANY WARRANTY; without even the implied warranty of  
12 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13 -# GNU General Public License for more details.  
14 -#  
15 -# You should have received a copy of the GNU Lesser General Public License version 3  
16 -# along with this program; if not, see <http://www.gnu.org/licenses/>  
17 -# or write to the Free Software Foundation, Inc., 51 Franklin Street,  
18 -# Fifth Floor, Boston, MA 02110-1301, USA.  
19 -# ----------------------------------------------------------------------------  
20 -# Este arquivo é parte do Framework Demoiselle.  
21 -#  
22 -# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
23 -# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
24 -# do Software Livre (FSF).  
25 -#  
26 -# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
27 -# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
28 -# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
29 -# para maiores detalhes.  
30 -#  
31 -# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
32 -# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
33 -# ou escreva para a Fundação do Software Livre (FSF) Inc.,  
34 -# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
35 -  
36 -entity-manager-was-created=Gerenciador de entidades criado a partir da unidade de persist\u00EAncia "{0}".  
37 -entity-manager-factory-not-found-in-cache=Entity Manager Factory n\u00E3o encontrado para contexto atual, criando um agora.  
38 -operation-not-supported=Esta operação não é suportada.  
39 -getting-persistence-unit-from-properties=Obtendo a unidade de persist\u00EAncia a partir do arquivo de configura\u00E7\u00E3o "{0}".  
40 -getting-persistence-unit-from-persistence=Obtendo a unidade de persist\u00EAncia a partir do arquivo "persistence.xml".  
41 -can-not-get-persistence-unit-from-persistence=N\u00E3o foi poss\u00EDvel obter a unidade de persist\u00EAncia a partir do arquivo "persistence.xml".  
42 -more-than-one-persistence-unit-defined=Existe mais de uma unidade de persist\u00EAncia definida. Utilize @{0} no ponto de inje\u00E7\u00E3o ou defina o atributo "frameworkdemoiselle.persistence.unit.name" no arquivo demoiselle.properties.  
43 -persistence-unit-name-found=Unidade de persist\u00EAncia "{0}" encontrada.  
44 -entity-manager-closed=O gerenciador de entidades foi fechado.  
45 -no-transaction-active=Nenhuma transa\u00E7\u00E3o est\u00E1 ativa, verifique a configura\u00E7\u00E3o "{0}" no arquivo "{1}" e defina a sua estrat\u00E9gia de transa\u00E7\u00E3o.  
46 \ No newline at end of file 0 \ No newline at end of file
impl/extension/jpa/src/test/resources/demoiselle.properties
@@ -1,36 +0,0 @@ @@ -1,36 +0,0 @@
1 -# Demoiselle Framework  
2 -# Copyright (C) 2010 SERPRO  
3 -# ----------------------------------------------------------------------------  
4 -# This file is part of Demoiselle Framework.  
5 -#  
6 -# Demoiselle Framework is free software; you can redistribute it and/or  
7 -# modify it under the terms of the GNU Lesser General Public License version 3  
8 -# as published by the Free Software Foundation.  
9 -#  
10 -# This program is distributed in the hope that it will be useful,  
11 -# but WITHOUT ANY WARRANTY; without even the implied warranty of  
12 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13 -# GNU General Public License for more details.  
14 -#  
15 -# You should have received a copy of the GNU Lesser General Public License version 3  
16 -# along with this program; if not, see <http://www.gnu.org/licenses/>  
17 -# or write to the Free Software Foundation, Inc., 51 Franklin Street,  
18 -# Fifth Floor, Boston, MA 02110-1301, USA.  
19 -# ----------------------------------------------------------------------------  
20 -# Este arquivo é parte do Framework Demoiselle.  
21 -#  
22 -# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
23 -# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
24 -# do Software Livre (FSF).  
25 -#  
26 -# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
27 -# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
28 -# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
29 -# para maiores detalhes.  
30 -#  
31 -# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
32 -# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
33 -# ou escreva para a Fundação do Software Livre (FSF) Inc.,  
34 -# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
35 -  
36 -frameworkdemoiselle.persistence.default.unit.name=PersistenceUnitName  
37 \ No newline at end of file 0 \ No newline at end of file
impl/extension/jpa/src/test/resources/empty-persistence.xml
@@ -1,42 +0,0 @@ @@ -1,42 +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 -<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=""></persistence-unit>  
41 -  
42 -</persistence>  
43 \ No newline at end of file 0 \ No newline at end of file
impl/extension/jpa/src/test/resources/log4j.properties
@@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
1 -# Demoiselle Framework  
2 -# Copyright (C) 2010 SERPRO  
3 -# ----------------------------------------------------------------------------  
4 -# This file is part of Demoiselle Framework.  
5 -#  
6 -# Demoiselle Framework is free software; you can redistribute it and/or  
7 -# modify it under the terms of the GNU Lesser General Public License version 3  
8 -# as published by the Free Software Foundation.  
9 -#  
10 -# This program is distributed in the hope that it will be useful,  
11 -# but WITHOUT ANY WARRANTY; without even the implied warranty of  
12 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13 -# GNU General Public License for more details.  
14 -#  
15 -# You should have received a copy of the GNU Lesser General Public License version 3  
16 -# along with this program; if not, see <http://www.gnu.org/licenses/>  
17 -# or write to the Free Software Foundation, Inc., 51 Franklin Street,  
18 -# Fifth Floor, Boston, MA 02110-1301, USA.  
19 -# ----------------------------------------------------------------------------  
20 -# Este arquivo é parte do Framework Demoiselle.  
21 -#  
22 -# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
23 -# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
24 -# do Software Livre (FSF).  
25 -#  
26 -# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
27 -# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
28 -# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
29 -# para maiores detalhes.  
30 -#  
31 -# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
32 -# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
33 -# ou escreva para a Fundação do Software Livre (FSF) Inc.,  
34 -# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
35 -  
36 -log4j.rootCategory=INFO, stdout  
37 -  
38 -log4j.logger.br.gov.frameworkdemoiselle=TRACE  
39 -  
40 -log4j.appender.stdout=org.apache.log4j.ConsoleAppender  
41 -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  
42 -log4j.appender.stdout.layout.ConversionPattern=%-5p [%c{1}] %m%n  
impl/extension/jpa/src/test/resources/persistence-empty-name.xml
@@ -1,48 +0,0 @@ @@ -1,48 +0,0 @@
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<!--  
3 - Demoiselle Framework  
4 - Copyright (C) 2010 SERPRO  
5 - ============================================================================  
6 - This file is part of Demoiselle Framework.  
7 -  
8 - Demoiselle Framework is free software; you can redistribute it and/or  
9 - modify it under the terms of the GNU Lesser General Public License version 3  
10 - as published by the Free Software Foundation.  
11 -  
12 - This program is distributed in the hope that it will be useful,  
13 - but WITHOUT ANY WARRANTY; without even the implied warranty of  
14 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
15 - GNU General Public License for more details.  
16 -  
17 - You should have received a copy of the GNU Lesser General Public License version 3  
18 - along with this program; if not, see <http://www.gnu.org/licenses/>  
19 - or write to the Free Software Foundation, Inc., 51 Franklin Street,  
20 - Fifth Floor, Boston, MA 02110-1301, USA.  
21 - ============================================================================  
22 - Este arquivo é parte do Framework Demoiselle.  
23 -  
24 - O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
25 - modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
26 - do Software Livre (FSF).  
27 -  
28 - Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
29 - GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
30 - APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
31 - para maiores detalhes.  
32 -  
33 - Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
34 - "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
35 - ou escreva para a Fundação do Software Livre (FSF) Inc.,  
36 - 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
37 --->  
38 -<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
39 - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">  
40 - <persistence-unit name="" transaction-type="RESOURCE_LOCAL">  
41 - <properties>  
42 - <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />  
43 - <property name="javax.persistence.jdbc.user" value="sa" />  
44 - <property name="javax.persistence.jdbc.password" value="" />  
45 - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql://localhost:9001/contactlist" />  
46 - </properties>  
47 - </persistence-unit>  
48 -</persistence>  
49 \ No newline at end of file 0 \ No newline at end of file
impl/extension/jpa/src/test/resources/persistence-two-units.xml
@@ -1,56 +0,0 @@ @@ -1,56 +0,0 @@
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<!--  
3 - Demoiselle Framework  
4 - Copyright (C) 2010 SERPRO  
5 - ============================================================================  
6 - This file is part of Demoiselle Framework.  
7 -  
8 - Demoiselle Framework is free software; you can redistribute it and/or  
9 - modify it under the terms of the GNU Lesser General Public License version 3  
10 - as published by the Free Software Foundation.  
11 -  
12 - This program is distributed in the hope that it will be useful,  
13 - but WITHOUT ANY WARRANTY; without even the implied warranty of  
14 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
15 - GNU General Public License for more details.  
16 -  
17 - You should have received a copy of the GNU Lesser General Public License version 3  
18 - along with this program; if not, see <http://www.gnu.org/licenses/>  
19 - or write to the Free Software Foundation, Inc., 51 Franklin Street,  
20 - Fifth Floor, Boston, MA 02110-1301, USA.  
21 - ============================================================================  
22 - Este arquivo é parte do Framework Demoiselle.  
23 -  
24 - O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
25 - modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
26 - do Software Livre (FSF).  
27 -  
28 - Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
29 - GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
30 - APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
31 - para maiores detalhes.  
32 -  
33 - Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
34 - "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
35 - ou escreva para a Fundação do Software Livre (FSF) Inc.,  
36 - 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
37 --->  
38 -<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
39 - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">  
40 - <persistence-unit name="pu1" transaction-type="RESOURCE_LOCAL">  
41 - <properties>  
42 - <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />  
43 - <property name="javax.persistence.jdbc.user" value="sa" />  
44 - <property name="javax.persistence.jdbc.password" value="" />  
45 - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql://localhost:9001/contactlist" />  
46 - </properties>  
47 - </persistence-unit>  
48 - <persistence-unit name="pu2" transaction-type="RESOURCE_LOCAL">  
49 - <properties>  
50 - <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />  
51 - <property name="javax.persistence.jdbc.user" value="sa" />  
52 - <property name="javax.persistence.jdbc.password" value="" />  
53 - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql://localhost:9001/contactlist" />  
54 - </properties>  
55 - </persistence-unit>  
56 -</persistence>  
57 \ No newline at end of file 0 \ No newline at end of file
impl/extension/jpa/src/test/resources/persistence.xml
@@ -1,48 +0,0 @@ @@ -1,48 +0,0 @@
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<!--  
3 - Demoiselle Framework  
4 - Copyright (C) 2010 SERPRO  
5 - ============================================================================  
6 - This file is part of Demoiselle Framework.  
7 -  
8 - Demoiselle Framework is free software; you can redistribute it and/or  
9 - modify it under the terms of the GNU Lesser General Public License version 3  
10 - as published by the Free Software Foundation.  
11 -  
12 - This program is distributed in the hope that it will be useful,  
13 - but WITHOUT ANY WARRANTY; without even the implied warranty of  
14 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
15 - GNU General Public License for more details.  
16 -  
17 - You should have received a copy of the GNU Lesser General Public License version 3  
18 - along with this program; if not, see <http://www.gnu.org/licenses/>  
19 - or write to the Free Software Foundation, Inc., 51 Franklin Street,  
20 - Fifth Floor, Boston, MA 02110-1301, USA.  
21 - ============================================================================  
22 - Este arquivo é parte do Framework Demoiselle.  
23 -  
24 - O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
25 - modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
26 - do Software Livre (FSF).  
27 -  
28 - Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
29 - GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
30 - APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
31 - para maiores detalhes.  
32 -  
33 - Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
34 - "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
35 - ou escreva para a Fundação do Software Livre (FSF) Inc.,  
36 - 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
37 --->  
38 -<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
39 - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">  
40 - <persistence-unit name="pu1" transaction-type="RESOURCE_LOCAL">  
41 - <properties>  
42 - <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />  
43 - <property name="javax.persistence.jdbc.user" value="sa" />  
44 - <property name="javax.persistence.jdbc.password" value="" />  
45 - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql://localhost:9001/contactlist" />  
46 - </properties>  
47 - </persistence-unit>  
48 -</persistence>  
49 \ No newline at end of file 0 \ No newline at end of file
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBeanTest.java
@@ -82,7 +82,7 @@ public class AbstractEditPageBeanTest { @@ -82,7 +82,7 @@ public class AbstractEditPageBeanTest {
82 82
83 @Before 83 @Before
84 public void before() { 84 public void before() {
85 - bundle = ResourceBundleProducer.create("demoiselle-jsf-bundle", Locale.getDefault()); 85 + bundle = new ResourceBundleProducer().create("demoiselle-jsf-bundle", Locale.getDefault());
86 86
87 pageBean = new AbstractEditPageBean<Contact, Object>() { 87 pageBean = new AbstractEditPageBean<Contact, Object>() {
88 88
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthenticator.java
@@ -44,8 +44,8 @@ import javax.servlet.ServletException; @@ -44,8 +44,8 @@ import javax.servlet.ServletException;
44 import javax.servlet.http.HttpServletRequest; 44 import javax.servlet.http.HttpServletRequest;
45 45
46 import br.gov.frameworkdemoiselle.annotation.Priority; 46 import br.gov.frameworkdemoiselle.annotation.Priority;
47 -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;  
48 import br.gov.frameworkdemoiselle.util.Beans; 47 import br.gov.frameworkdemoiselle.util.Beans;
  48 +import br.gov.frameworkdemoiselle.util.NameQualifier;
49 import br.gov.frameworkdemoiselle.util.ResourceBundle; 49 import br.gov.frameworkdemoiselle.util.ResourceBundle;
50 50
51 @Priority(L2_PRIORITY) 51 @Priority(L2_PRIORITY)
@@ -58,7 +58,7 @@ public class ServletAuthenticator implements Authenticator { @@ -58,7 +58,7 @@ public class ServletAuthenticator implements Authenticator {
58 @Override 58 @Override
59 public void authenticate() throws AuthenticationException { 59 public void authenticate() throws AuthenticationException {
60 try { 60 try {
61 - if (this.getUser()==null){ 61 + if (this.getUser() == null) {
62 getRequest().login(getCredentials().getUsername(), getCredentials().getPassword()); 62 getRequest().login(getCredentials().getUsername(), getCredentials().getPassword());
63 } 63 }
64 } catch (ServletException cause) { 64 } catch (ServletException cause) {
@@ -72,7 +72,7 @@ public class ServletAuthenticator implements Authenticator { @@ -72,7 +72,7 @@ public class ServletAuthenticator implements Authenticator {
72 try { 72 try {
73 getRequest().logout(); 73 getRequest().logout();
74 } catch (ServletException e) { 74 } catch (ServletException e) {
75 - //Logout já havia sido efetuado 75 + // Logout já havia sido efetuado
76 } 76 }
77 getRequest().getSession().invalidate(); 77 getRequest().getSession().invalidate();
78 } 78 }
@@ -92,7 +92,7 @@ public class ServletAuthenticator implements Authenticator { @@ -92,7 +92,7 @@ public class ServletAuthenticator implements Authenticator {
92 92
93 private static ResourceBundle getBundle() { 93 private static ResourceBundle getBundle() {
94 if (bundle == null) { 94 if (bundle == null) {
95 - bundle = ResourceBundleProducer.create("demoiselle-servlet-bundle"); 95 + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-servlet-bundle"));
96 } 96 }
97 97
98 return bundle; 98 return bundle;
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthorizer.java
@@ -70,7 +70,7 @@ public class ServletAuthorizer implements Authorizer { @@ -70,7 +70,7 @@ public class ServletAuthorizer implements Authorizer {
70 70
71 private static ResourceBundle getBundle() { 71 private static ResourceBundle getBundle() {
72 if (bundle == null) { 72 if (bundle == null) {
73 - bundle = ResourceBundleProducer.create("demoiselle-servlet-bundle"); 73 + bundle = new ResourceBundleProducer().create("demoiselle-servlet-bundle");
74 } 74 }
75 75
76 return bundle; 76 return bundle;
parent/extension/pom.xml
@@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
44 <parent> 44 <parent>
45 <groupId>br.gov.frameworkdemoiselle</groupId> 45 <groupId>br.gov.frameworkdemoiselle</groupId>
46 <artifactId>demoiselle-framework-parent</artifactId> 46 <artifactId>demoiselle-framework-parent</artifactId>
47 - <version>2.4.0-BETA3-SNAPSHOT</version> 47 + <version>2.4.0-BETA4-SNAPSHOT</version>
48 <relativePath>../framework</relativePath> 48 <relativePath>../framework</relativePath>
49 </parent> 49 </parent>
50 50
@@ -71,7 +71,7 @@ @@ -71,7 +71,7 @@
71 <dependency> 71 <dependency>
72 <groupId>br.gov.frameworkdemoiselle</groupId> 72 <groupId>br.gov.frameworkdemoiselle</groupId>
73 <artifactId>demoiselle-framework-bom</artifactId> 73 <artifactId>demoiselle-framework-bom</artifactId>
74 - <version>2.4.0-BETA3-SNAPSHOT</version> 74 + <version>2.4.0-BETA4-SNAPSHOT</version>
75 <scope>import</scope> 75 <scope>import</scope>
76 <type>pom</type> 76 <type>pom</type>
77 </dependency> 77 </dependency>
@@ -126,11 +126,13 @@ @@ -126,11 +126,13 @@
126 <artifactId>powermock-api-easymock</artifactId> 126 <artifactId>powermock-api-easymock</artifactId>
127 <scope>test</scope> 127 <scope>test</scope>
128 </dependency> 128 </dependency>
  129 + <!--
129 <dependency> 130 <dependency>
130 <groupId>org.slf4j</groupId> 131 <groupId>org.slf4j</groupId>
131 <artifactId>slf4j-log4j12</artifactId> 132 <artifactId>slf4j-log4j12</artifactId>
132 <scope>test</scope> 133 <scope>test</scope>
133 </dependency> 134 </dependency>
  135 + -->
134 </dependencies> 136 </dependencies>
135 137
136 <repositories> 138 <repositories>