Search in sources :

Example 1 with EntityManagerManager

use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.

the class JpaTest method setupRegistry.

// @BeforeSuite
public final void setupRegistry() {
    RegistryBuilder builder = new RegistryBuilder();
    builder.add(TapestryModule.class);
    builder.add(JpaModule.class);
    builder.add(JpaTestModule.class);
    registry = builder.build();
    // set PageTesterContext, otherwise T5 tries to load classpath assets
    ApplicationGlobals globals = registry.getObject(ApplicationGlobals.class, null);
    globals.storeContext(new PageTesterContext(""));
    registry.performRegistryStartup();
    entityManagerManager = registry.getService(EntityManagerManager.class);
    topLevelService = registry.getService(TopLevelService.class);
}
Also used : PageTesterContext(org.apache.tapestry5.internal.test.PageTesterContext) EntityManagerManager(org.apache.tapestry5.jpa.EntityManagerManager) RegistryBuilder(org.apache.tapestry5.ioc.RegistryBuilder) ApplicationGlobals(org.apache.tapestry5.http.services.ApplicationGlobals)

Example 2 with EntityManagerManager

use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.

the class JpaTransactionAdvisorImplTest method persistence_unit_missing.

@Test
public void persistence_unit_missing() {
    final VoidService delegate = newMock(VoidService.class);
    final EntityManagerManager manager = newMock(EntityManagerManager.class);
    final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
    final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
    Map<String, EntityManager> managers = CollectionFactory.newMap();
    managers.put("A", newMock(EntityManager.class));
    managers.put("B", newMock(EntityManager.class));
    final AspectInterceptorBuilder<VoidService> builder = aspectDecorator.createBuilder(VoidService.class, delegate, "foo.Bar");
    advisor.addTransactionCommitAdvice(builder);
    final VoidService interceptor = builder.build();
    expect(manager.getEntityManagers()).andReturn(managers);
    replay();
    try {
        interceptor.persistenceUnitMissing();
        TestBase.unreachable();
    } catch (Exception e) {
        assertMessageContains(e, "Unable to locate a single EntityManager");
    }
    verify();
}
Also used : EntityManager(javax.persistence.EntityManager) EntityTransactionManager(org.apache.tapestry5.jpa.EntityTransactionManager) EntityManagerManager(org.apache.tapestry5.jpa.EntityManagerManager) JpaTransactionAdvisor(org.apache.tapestry5.jpa.JpaTransactionAdvisor) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 3 with EntityManagerManager

use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.

the class JpaTransactionAdvisorImplTest method transaction_inactive.

@Test
public void transaction_inactive() {
    final VoidService delegate = newMock(VoidService.class);
    final EntityManagerManager manager = newMock(EntityManagerManager.class);
    final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
    final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
    final EntityManager entityManager = newMock(EntityManager.class);
    final EntityTransaction transaction = newMock(EntityTransaction.class);
    final AspectInterceptorBuilder<VoidService> builder = aspectDecorator.createBuilder(VoidService.class, delegate, "foo.Bar");
    advisor.addTransactionCommitAdvice(builder);
    final VoidService interceptor = builder.build();
    train_getAndBeginTransaction(manager, entityManager, transaction);
    delegate.voidMethod();
    train_commitActiveTransaction(transaction);
    replay();
    interceptor.voidMethod();
    verify();
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) EntityTransactionManager(org.apache.tapestry5.jpa.EntityTransactionManager) EntityManagerManager(org.apache.tapestry5.jpa.EntityManagerManager) JpaTransactionAdvisor(org.apache.tapestry5.jpa.JpaTransactionAdvisor) Test(org.testng.annotations.Test)

Example 4 with EntityManagerManager

use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.

the class JpaTransactionAdvisorImplTest method undecorated.

@Test
public void undecorated() {
    final VoidService delegate = newMock(VoidService.class);
    final EntityManagerManager manager = newMock(EntityManagerManager.class);
    final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
    final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
    final AspectInterceptorBuilder<VoidService> builder = aspectDecorator.createBuilder(VoidService.class, delegate, "foo.Bar");
    advisor.addTransactionCommitAdvice(builder);
    final VoidService interceptor = builder.build();
    delegate.undecorated();
    replay();
    interceptor.undecorated();
    verify();
}
Also used : EntityTransactionManager(org.apache.tapestry5.jpa.EntityTransactionManager) EntityManagerManager(org.apache.tapestry5.jpa.EntityManagerManager) JpaTransactionAdvisor(org.apache.tapestry5.jpa.JpaTransactionAdvisor) Test(org.testng.annotations.Test)

Example 5 with EntityManagerManager

use of org.apache.tapestry5.jpa.EntityManagerManager in project tapestry-5 by apache.

the class JpaTransactionAdvisorImplTest method persistence_unit_name_missing_single_unit_configured.

@Test
public void persistence_unit_name_missing_single_unit_configured() {
    final VoidService delegate = newMock(VoidService.class);
    final EntityManagerManager manager = newMock(EntityManagerManager.class);
    final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
    final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
    final EntityTransaction transaction = newMock(EntityTransaction.class);
    EntityManager em = newMock(EntityManager.class);
    Map<String, EntityManager> managers = CollectionFactory.newMap();
    managers.put("A", em);
    final AspectInterceptorBuilder<VoidService> builder = aspectDecorator.createBuilder(VoidService.class, delegate, "foo.Bar");
    advisor.addTransactionCommitAdvice(builder);
    final VoidService interceptor = builder.build();
    expect(manager.getEntityManagers()).andReturn(managers);
    train_getTransaction(em, transaction, true);
    delegate.persistenceUnitNameMissing();
    train_commitActiveTransaction(transaction);
    replay();
    interceptor.persistenceUnitNameMissing();
    verify();
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) EntityTransactionManager(org.apache.tapestry5.jpa.EntityTransactionManager) EntityManagerManager(org.apache.tapestry5.jpa.EntityManagerManager) JpaTransactionAdvisor(org.apache.tapestry5.jpa.JpaTransactionAdvisor) Test(org.testng.annotations.Test)

Aggregations

EntityManagerManager (org.apache.tapestry5.jpa.EntityManagerManager)14 Test (org.testng.annotations.Test)13 EntityManager (javax.persistence.EntityManager)12 EntityTransactionManager (org.apache.tapestry5.jpa.EntityTransactionManager)12 JpaTransactionAdvisor (org.apache.tapestry5.jpa.JpaTransactionAdvisor)12 EntityTransaction (javax.persistence.EntityTransaction)9 SQLException (java.sql.SQLException)3 PersistenceContext (javax.persistence.PersistenceContext)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 Metamodel (javax.persistence.metamodel.Metamodel)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)1 ObjectCreator (org.apache.tapestry5.commons.ObjectCreator)1 PlasticProxyFactory (org.apache.tapestry5.commons.services.PlasticProxyFactory)1 ApplicationGlobals (org.apache.tapestry5.http.services.ApplicationGlobals)1 EntityManagerManagerImpl (org.apache.tapestry5.internal.jpa.EntityManagerManagerImpl)1 JpaValueEncoder (org.apache.tapestry5.internal.jpa.JpaValueEncoder)1 PersistedEntity (org.apache.tapestry5.internal.jpa.PersistedEntity)1 PageTesterContext (org.apache.tapestry5.internal.test.PageTesterContext)1 ReadOnlyComponentFieldConduit (org.apache.tapestry5.internal.transform.ReadOnlyComponentFieldConduit)1 RegistryBuilder (org.apache.tapestry5.ioc.RegistryBuilder)1