deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject deltaspike git commit: DELTASPIKE-1097 Fix Data Module tests for TomEE7
Date Tue, 22 Mar 2016 22:33:12 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 165280ed3 -> 4523b5f35


DELTASPIKE-1097 Fix Data Module tests for TomEE7

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/4523b5f3
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/4523b5f3
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/4523b5f3

Branch: refs/heads/master
Commit: 4523b5f358e7e2cc078bde232e6fec93febf87c4
Parents: 165280e
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Tue Mar 22 23:33:01 2016 +0100
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Tue Mar 22 23:33:01 2016 +0100

----------------------------------------------------------------------
 .../deltaspike/data/impl/QueryResultTest.java   | 14 +----
 .../impl/audit/AuditEntityListenerTest.java     | 27 +++------
 .../data/impl/criteria/CriteriaTest.java        | 63 ++++++++------------
 .../EntityManagerDelegateHandlerTest.java       | 10 ----
 .../data/impl/handler/EntityManagerTest.java    |  2 +-
 .../handler/EntityRepositoryHandlerTest.java    | 20 ++-----
 .../impl/handler/FullEntityRepositoryTest.java  | 12 +---
 .../data/impl/handler/QueryHandlerTest.java     | 15 +----
 .../data/impl/mapping/MappedRepositoryTest.java | 22 ++-----
 .../meta/unit/OrmXmlBasedRepositoryTest.java    | 14 +----
 .../data/impl/spi/CdiQuerySpiTest.java          | 10 ----
 .../impl/tx/TransactionalQueryRunnerTest.java   |  4 --
 .../data/test/TransactionalTestCase.java        |  8 ++-
 .../data/test/util/EntityManagerProducer.java   | 27 +++++++++
 .../data/test/util/TestDeployments.java         | 10 ++++
 15 files changed, 99 insertions(+), 159 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
index 723feca..c322cc4 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
@@ -62,10 +62,6 @@ public class QueryResultTest extends TransactionalTestCase
     @Inject
     private SimpleRepository repo;
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
-
     private SimpleBuilder builder;
 
     @Test
@@ -361,7 +357,7 @@ public class QueryResultTest extends TransactionalTestCase
     public void should_paginate_with_orderby()
     {
         // given
-        SimpleStringIdBuilder builder = new SimpleStringIdBuilder(entityManager);
+        SimpleStringIdBuilder builder = new SimpleStringIdBuilder(getEntityManager());
 
 
         final String name = "should_paginate_with_orderby";
@@ -384,13 +380,7 @@ public class QueryResultTest extends TransactionalTestCase
     @Before
     public void setup()
     {
-        builder = new SimpleBuilder(entityManager);
-    }
-
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
+        builder = new SimpleBuilder(getEntityManager());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/audit/AuditEntityListenerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/audit/AuditEntityListenerTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/audit/AuditEntityListenerTest.java
index 74f021a..293144e 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/audit/AuditEntityListenerTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/audit/AuditEntityListenerTest.java
@@ -49,9 +49,6 @@ public class AuditEntityListenerTest extends TransactionalTestCase
                 .addPackage(AuditedEntity.class.getPackage());
     }
 
-    @PersistenceContext
-    private EntityManager entityManager;
-
     private final String who = "test999";
     private final Principal principal = new Principal(who);
 
@@ -68,7 +65,7 @@ public class AuditEntityListenerTest extends TransactionalTestCase
     {
         try
         {
-            entityManager.persist(principal);
+            getEntityManager().persist(principal);
         }
         catch (Throwable e)
         {
@@ -83,8 +80,8 @@ public class AuditEntityListenerTest extends TransactionalTestCase
         AuditedEntity entity = new AuditedEntity();
 
         // when
-        entityManager.persist(entity);
-        entityManager.flush();
+        getEntityManager().persist(entity);
+        getEntityManager().flush();
 
         // then
         assertNotNull(entity.getCreated());
@@ -97,13 +94,13 @@ public class AuditEntityListenerTest extends TransactionalTestCase
     {
         // given
         AuditedEntity entity = new AuditedEntity();
-        entityManager.persist(entity);
-        entityManager.flush();
+        getEntityManager().persist(entity);
+        getEntityManager().flush();
 
         // when
-        entity = entityManager.find(AuditedEntity.class, entity.getId());
+        entity = getEntityManager().find(AuditedEntity.class, entity.getId());
         entity.setName("test");
-        entityManager.flush();
+        getEntityManager().flush();
 
         // then
         assertNotNull(entity.getGregorianModified());
@@ -117,8 +114,8 @@ public class AuditEntityListenerTest extends TransactionalTestCase
         AuditedEntity entity = new AuditedEntity();
 
         // when
-        entityManager.persist(entity);
-        entityManager.flush();
+        getEntityManager().persist(entity);
+        getEntityManager().flush();
 
         // then
         assertNotNull(entity.getChanger());
@@ -127,10 +124,4 @@ public class AuditEntityListenerTest extends TransactionalTestCase
         assertEquals(who, entity.getPrincipal().getName());
     }
 
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
index 1461fea..f87db17 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/criteria/CriteriaTest.java
@@ -66,10 +66,6 @@ public class CriteriaTest extends TransactionalTestCase
     @Inject
     private ParentRepository parentRepo;
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
-
     @Test
     public void should_create_criteria_query()
     {
@@ -119,8 +115,8 @@ public class CriteriaTest extends TransactionalTestCase
         parent.setOne(new OneToOne(nameOne));
         parent.add(new OneToMany(nameMany));
 
-        entityManager.persist(parent);
-        entityManager.flush();
+        getEntityManager().persist(parent);
+        getEntityManager().flush();
 
         // when
         List<Parent> result = parentRepo.joinQuery(name, nameOne, nameMany);
@@ -151,11 +147,11 @@ public class CriteriaTest extends TransactionalTestCase
         Parent parent4 = new Parent(name + "1");
         parent4.setValue(75L);
 
-        entityManager.persist(parent1);
-        entityManager.persist(parent2);
-        entityManager.persist(parent3);
-        entityManager.persist(parent4);
-        entityManager.flush();
+        getEntityManager().persist(parent1);
+        getEntityManager().persist(parent2);
+        getEntityManager().persist(parent3);
+        getEntityManager().persist(parent4);
+        getEntityManager().flush();
 
         // when
         List<Parent> result = parentRepo.orQuery(name + "1", name + "2");
@@ -174,11 +170,11 @@ public class CriteriaTest extends TransactionalTestCase
         Parent parent3 = new Parent(name + "19");
         Parent parent4 = new Parent(name + "02");
 
-        entityManager.persist(parent1);
-        entityManager.persist(parent2);
-        entityManager.persist(parent3);
-        entityManager.persist(parent4);
-        entityManager.flush();
+        getEntityManager().persist(parent1);
+        getEntityManager().persist(parent2);
+        getEntityManager().persist(parent3);
+        getEntityManager().persist(parent4);
+        getEntityManager().flush();
 
         // when
         List<Parent> result = parentRepo.orderedQuery();
@@ -198,8 +194,8 @@ public class CriteriaTest extends TransactionalTestCase
         final String name = "testCreateQueryWihtoutNulls";
         Parent parent = new Parent(name);
 
-        entityManager.persist(parent);
-        entityManager.flush();
+        getEntityManager().persist(parent);
+        getEntityManager().flush();
 
         // when
         List<Parent> result = parentRepo.nullAwareQuery(name, null, null);
@@ -218,8 +214,8 @@ public class CriteriaTest extends TransactionalTestCase
         parent.add(new OneToMany(name + "-1"));
         parent.add(new OneToMany(name + "-2"));
 
-        entityManager.persist(parent);
-        entityManager.flush();
+        getEntityManager().persist(parent);
+        getEntityManager().flush();
 
         // when
         Parent result = parentRepo.fetchQuery(name);
@@ -240,10 +236,10 @@ public class CriteriaTest extends TransactionalTestCase
         Parent parent2 = new Parent(name + "-2");
         Parent parent3 = new Parent(name + "-3");
 
-        entityManager.persist(parent1);
-        entityManager.persist(parent2);
-        entityManager.persist(parent3);
-        entityManager.flush();
+        getEntityManager().persist(parent1);
+        getEntityManager().persist(parent2);
+        getEntityManager().persist(parent3);
+        getEntityManager().flush();
 
         // when
         List<Parent> result = parentRepo.fetchByName(name + "-1", name + "-2", name
+ "-3");
@@ -384,8 +380,8 @@ public class CriteriaTest extends TransactionalTestCase
         final String name = "should_create_date_criteria";
         final Simple simple = new Simple(name);
         simple.setTemporal(new Date());
-        entityManager.persist(simple);
-        entityManager.flush();
+        getEntityManager().persist(simple);
+        getEntityManager().flush();
 
         Calendar cal = Calendar.getInstance();
         cal.setTime(simple.getTemporal());
@@ -410,8 +406,8 @@ public class CriteriaTest extends TransactionalTestCase
         final String superName = "super_should_create_date_criteria";
         final Simple simple = new Simple(name);
         simple.setSuperName(superName);
-        entityManager.persist(simple);
-        entityManager.flush();
+        getEntityManager().persist(simple);
+        getEntityManager().flush();
 
         // when
         final Simple result = repo.findBySuperName(superName);
@@ -450,19 +446,12 @@ public class CriteriaTest extends TransactionalTestCase
         assertEquals("should_apply_trim ", objects[2]);
     }
 
-
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
-    }
-
     private Simple createSimple(String name, Integer counter)
     {
         Simple result = new Simple(name);
         result.setCounter(counter);
-        entityManager.persist(result);
-        entityManager.flush();
+        getEntityManager().persist(result);
+        getEntityManager().flush();
         return result;
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerDelegateHandlerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerDelegateHandlerTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerDelegateHandlerTest.java
index ab6a56a..5193096 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerDelegateHandlerTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerDelegateHandlerTest.java
@@ -50,10 +50,6 @@ public class EntityManagerDelegateHandlerTest extends TransactionalTestCase
     @Inject
     private ExtendedRepositoryInterface repository;
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
-
     @Test
     public void should_delete_detached_entity() {
         // given
@@ -70,10 +66,4 @@ public class EntityManagerDelegateHandlerTest extends TransactionalTestCase
         assertNull(search);
     }
 
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerTest.java
index d607694..608052a 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityManagerTest.java
@@ -49,7 +49,7 @@ public class EntityManagerTest
     @Deployment
     public static Archive<?> deployment()
     {
-        return initDeployment()
+        return initDeployment(false)
                 .addPackage(Simple.class.getPackage())
                 .addClasses(SimpleRepositoryWithEntityManager.class,
                         SimpleRepositoryWithEntityManagerResolver.class,

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
index 8e522d0..8ebc1fb 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
@@ -79,10 +79,6 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
     @Inject
     private SimpleStringIdRepository stringIdRepo;
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
-
     @Test
     public void should_save() throws Exception
     {
@@ -121,7 +117,7 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
 
         // when
         simple = repo.saveAndFlush(simple);
-        Simple fetch = (Simple) entityManager
+        Simple fetch = (Simple) getEntityManager()
                 .createNativeQuery("select * from SIMPLE_TABLE where id = ?", Simple.class)
                 .setParameter(1, simple.getId())
                 .getSingleResult();
@@ -369,7 +365,7 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
         // when
         repo.remove(simple);
         repo.flush();
-        Simple lookup = entityManager.find(Simple.class, simple.getId());
+        Simple lookup = getEntityManager().find(Simple.class, simple.getId());
 
         // then
         assertNull(lookup);
@@ -382,7 +378,7 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
 
         // when
         repo.removeAndFlush(simple);
-        Simple lookup = entityManager.find(Simple.class, simple.getId());
+        Simple lookup = getEntityManager().find(Simple.class, simple.getId());
 
         // then
         assertNull(lookup);
@@ -397,7 +393,7 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
         repo.detach(simple);
         repo.attachAndRemove(simple);
         repo.flush();
-        Simple lookup = entityManager.find(Simple.class, simple.getId());
+        Simple lookup = getEntityManager().find(Simple.class, simple.getId());
 
         // then
         assertNull(lookup);
@@ -459,7 +455,7 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
         Long id = simple.getId();
 
         //when
-        entityManager.detach(simple);
+        getEntityManager().detach(simple);
         Long primaryKey = repo.getPrimaryKey(simple);
 
         // then
@@ -467,10 +463,4 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
         assertEquals(id, primaryKey);
     }
 
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/FullEntityRepositoryTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/FullEntityRepositoryTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/FullEntityRepositoryTest.java
index 277ff49..8235e2e 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/FullEntityRepositoryTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/FullEntityRepositoryTest.java
@@ -56,10 +56,6 @@ public class FullEntityRepositoryTest extends TransactionalTestCase
     @Inject
     private FullRepositoryAbstract repoAbstract;
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
-
     @Test
     public void should_save() throws Exception
     {
@@ -188,7 +184,7 @@ public class FullEntityRepositoryTest extends TransactionalTestCase
 
         // when
         simple = repo.saveAndFlush(simple);
-        Simple fetch = (Simple) entityManager
+        Simple fetch = (Simple) getEntityManager()
                 .createNativeQuery("select * from SIMPLE_TABLE where id = ?", Simple.class)
                 .setParameter(1, simple.getId())
                 .getSingleResult();
@@ -211,10 +207,4 @@ public class FullEntityRepositoryTest extends TransactionalTestCase
         assertEquals(simple.getId(), fetch.getId());
     }
 
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
index d78138b..934f892 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/QueryHandlerTest.java
@@ -64,9 +64,6 @@ public class QueryHandlerTest extends TransactionalTestCase
     @Inject
     private Simple2Repository repo2;
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
 
     private SimpleBuilder builder;
 
@@ -435,20 +432,14 @@ public class QueryHandlerTest extends TransactionalTestCase
     @Before
     public void setup()
     {
-        builder = new SimpleBuilder(entityManager);
-    }
-
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
+        builder = new SimpleBuilder(getEntityManager());
     }
 
     private Simple2 createSimple2(String name)
     {
         Simple2 result = new Simple2(name);
-        entityManager.persist(result);
-        entityManager.flush();
+        getEntityManager().persist(result);
+        getEntityManager().flush();
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/mapping/MappedRepositoryTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/mapping/MappedRepositoryTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/mapping/MappedRepositoryTest.java
index afea777..868becc 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/mapping/MappedRepositoryTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/mapping/MappedRepositoryTest.java
@@ -72,10 +72,6 @@ public class MappedRepositoryTest extends TransactionalTestCase
     @Inject
     private SimpleMappedDtoRepository dtoRepository;
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
-
     @Test
     public void should_map_entityrepo_methods()
     {
@@ -87,7 +83,7 @@ public class MappedRepositoryTest extends TransactionalTestCase
         // when
         SimpleDto saved = repository.saveAndFlush(dto);
         SimpleDto loadedDto = repository.findBy(saved.getId());
-        Simple loaded = entityManager.find(Simple.class, saved.getId().getId());
+        Simple loaded = getEntityManager().find(Simple.class, saved.getId().getId());
 
         // then
         assertNotNull(loadedDto);
@@ -102,7 +98,7 @@ public class MappedRepositoryTest extends TransactionalTestCase
         // given
         Simple simple = new Simple("should_map_method_expression");
         simple.setEnabled(Boolean.TRUE);
-        entityManager.persist(simple);
+        getEntityManager().persist(simple);
 
         // when
         List<SimpleDto> result = repository.findByEnabled(Boolean.TRUE);
@@ -126,7 +122,7 @@ public class MappedRepositoryTest extends TransactionalTestCase
         // given
         Simple simple = new Simple("should_map_method_expression");
         simple.setEnabled(Boolean.TRUE);
-        entityManager.persist(simple);
+        getEntityManager().persist(simple);
 
         // when
         List<SimpleDto> result = repository.findByEnabled(new BooleanWrapper(Boolean.TRUE));
@@ -151,7 +147,7 @@ public class MappedRepositoryTest extends TransactionalTestCase
         final String name = "should_find_with_queryresult";
         Simple simple = new Simple(name);
         simple.setEnabled(Boolean.TRUE);
-        entityManager.persist(simple);
+        getEntityManager().persist(simple);
 
         // when
         List<SimpleDto> result = repository.findByNameToo(name)
@@ -185,7 +181,7 @@ public class MappedRepositoryTest extends TransactionalTestCase
         final String name = "should_update_existing_entity_with_simplemapper";
         Simple simple = new Simple(name);
         simple.setEnabled(Boolean.TRUE);
-        entityManager.persist(simple);
+        getEntityManager().persist(simple);
 
         SimpleDto dto = new SimpleDto();
         dto.setName(name + "_updated");
@@ -194,17 +190,11 @@ public class MappedRepositoryTest extends TransactionalTestCase
 
         // when
         dtoRepository.save(dto);
-        Simple lookup = entityManager.find(Simple.class, simple.getId());
+        Simple lookup = getEntityManager().find(Simple.class, simple.getId());
 
         // then
         assertNotNull(lookup);
         assertEquals(name + "_updated", lookup.getName());
     }
 
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/OrmXmlBasedRepositoryTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/OrmXmlBasedRepositoryTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/OrmXmlBasedRepositoryTest.java
index 8e072af..58e0e7d 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/OrmXmlBasedRepositoryTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/OrmXmlBasedRepositoryTest.java
@@ -57,10 +57,6 @@ public class OrmXmlBasedRepositoryTest extends TransactionalTestCase
                 .addAsWebInfResource("test-default-orm.xml", ArchivePaths.create("classes/META-INF/orm.xml"));
     }
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
-
     @Inject
     private MappedOneRepository mappedOneRepository;
 
@@ -79,17 +75,11 @@ public class OrmXmlBasedRepositoryTest extends TransactionalTestCase
         assertEquals(one.getId(), byName.getId());
     }
 
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
-    }
-
     private MappedOne createMappedOne(String name)
     {
         MappedOne result = new MappedOne(name);
-        entityManager.persist(result);
-        entityManager.flush();
+        getEntityManager().persist(result);
+        getEntityManager().flush();
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/spi/CdiQuerySpiTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/spi/CdiQuerySpiTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/spi/CdiQuerySpiTest.java
index df057f4..7ad3842 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/spi/CdiQuerySpiTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/spi/CdiQuerySpiTest.java
@@ -51,10 +51,6 @@ public class CdiQuerySpiTest extends TransactionalTestCase
                 .addPackage(Simple.class.getPackage());
     }
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
-
     @Inject
     private MySimpleRepository repo;
 
@@ -70,10 +66,4 @@ public class CdiQuerySpiTest extends TransactionalTestCase
         // then
         assertNotNull(simple.getId());
     }
-
-    @Override
-    protected EntityManager getEntityManager()
-    {
-        return entityManager;
-    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunnerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunnerTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunnerTest.java
index 1170457..f799879 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunnerTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/tx/TransactionalQueryRunnerTest.java
@@ -58,10 +58,6 @@ public class TransactionalQueryRunnerTest
     @Inject
     private ExtendedRepositoryInterface repository;
 
-    @Produces
-    @PersistenceContext
-    private EntityManager entityManager;
-
     @Inject
     private TransactionalQueryRunnerWrapper wrapper;
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/TransactionalTestCase.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/TransactionalTestCase.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/TransactionalTestCase.java
index 184a9e9..c655b4b 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/TransactionalTestCase.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/TransactionalTestCase.java
@@ -19,6 +19,7 @@
 package org.apache.deltaspike.data.test;
 
 import javax.annotation.Resource;
+import javax.inject.Inject;
 import javax.persistence.EntityManager;
 import javax.transaction.UserTransaction;
 
@@ -57,6 +58,11 @@ public abstract class TransactionalTestCase
         ut.rollback();
     }
 
-    protected abstract EntityManager getEntityManager();
+    @Inject private EntityManager entityManager;
+    
+    protected EntityManager getEntityManager()
+    {
+        return entityManager;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/util/EntityManagerProducer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/util/EntityManagerProducer.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/util/EntityManagerProducer.java
new file mode 100644
index 0000000..e57fb93
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/util/EntityManagerProducer.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.deltaspike.data.test.util;
+
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+public class EntityManagerProducer
+{
+    @Produces
+    @PersistenceContext
+    private EntityManager entityManager;
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4523b5f3/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/util/TestDeployments.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/util/TestDeployments.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/util/TestDeployments.java
index c2358e2..c15ad3c 100755
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/util/TestDeployments.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/util/TestDeployments.java
@@ -44,6 +44,11 @@ public abstract class TestDeployments {
      */
     public static WebArchive initDeployment()
     {
+        return initDeployment(true);
+    }
+
+    public static WebArchive initDeployment(boolean addDefaultEntityManagerProducer)
+    {
         Logging.reconfigure();
 
         WebArchive archive = ShrinkWrap
@@ -57,6 +62,11 @@ public abstract class TestDeployments {
                 .addAsWebInfResource(new StringAsset(DS_PROPERTIES_WITH_ENV_AWARE_TX_STRATEGY),
                         "classes/META-INF/apache-deltaspike.properties");
 
+        if (addDefaultEntityManagerProducer)
+        {
+            archive.addClass(EntityManagerProducer.class);
+        }
+        
         return archive;
     }
 


Mime
View raw message