Package org.apache.geronimo.persistence.mockjpa

Examples of org.apache.geronimo.persistence.mockjpa.MockEntityManager


     * section 5.6.2
     * extended context is closed when the SFSB that caused it is removed
     */
    public void testExtendedClosedOnBeanRemove() throws Exception {
        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
        assertTrue("base EntityManager should not be closed", !pc1.isClosed());
        assertNotNull("InternalEntityManager should be registered", EntityManagerExtendedRegistry.getEntityManager(persistenceUnit));
        entityManager1.beanRemoved();
        assertTrue("base EntityManager should be closed", pc1.isClosed());
        assertNull("InternalEntityManager should not be registered", EntityManagerExtendedRegistry.getEntityManager(persistenceUnit));
    }
View Full Code Here


     * section 5.6.2.1
     * extended context is closed when the SFSB that caused it and all others that share it are removed
     */
    public void testInheritedExtendedClosedOnBeanRemove() throws Exception {
        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
        assertTrue("base EntityManager should not be closed", !pc1.isClosed());
        InternalCMPEntityManagerExtended internalEntityManager1 = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
        assertNotNull("InternalEntityManager should be registered", internalEntityManager1);
        CMPEntityManagerExtended entityManager2 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
        InternalCMPEntityManagerExtended internalEntityManager2 = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
        //we should have got an exception if this isn't true
        assertSame("2nd entity manager registering should use same internal entity manager", internalEntityManager1, internalEntityManager2);
        MockEntityManager pc2 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
        assertSame("2nd entity manager registering should use same mock entity manager", pc1, pc2);

        //remove one bean, internal and mock entity managers should not change state
        entityManager1.beanRemoved();
        assertTrue("base EntityManager should not be closed", !pc1.isClosed());
View Full Code Here

        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
        //set up the caller
        CMPEntityManagerTxScoped entityManager2 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
        tm.begin();
        //register the caller
        MockEntityManager pc1 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
        //caller calling SFSB means entityManager1 tries to join the trasaction:
        InternalCMPEntityManagerExtended internalEntityManager = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
        try {
            internalEntityManager.joinTransaction();
            fail("Expected EJBException");
View Full Code Here

     * close or cleared is called when tx commits
     */
    public void testCloseOnCommit() throws Exception {
        tm.begin();
        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
        assertTrue("entityManager should not be closed or cleared", !pc1.isClosed() & !pc1.isCleared());
        tm.commit();
        assertTrue("entityManager should be closed or cleared", pc1.isClosed() || pc1.isCleared());
        tm.begin();
        CMPEntityManagerTxScoped entityManager2 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc2 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
        assertTrue("entityManager should not be closed or cleared", !pc2.isClosed() & !pc2.isCleared());
        tm.rollback();
        assertTrue("entityManager should be closed or cleared", pc2.isClosed() || pc2.isCleared());
    }
View Full Code Here

     * when a SFSB/extended context starts a UserTransaction or a CMT tx starts the EM must join the transaction
     */
    public void testExtendedEntityManagerJoinsNewTransactions() throws Exception {
        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
        tm.begin();
        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");

        assertTrue("EntityManager was supposed to join the tx", pc1.isJoined());
    }
View Full Code Here

     * close or cleared is called when tx commits
     */
    public void testCloseOnCommit() throws Exception {
        tm.begin();
        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
        assertTrue("entityManager should not be closed or cleared", !pc1.isClosed() & !pc1.isCleared());
        tm.commit();
        assertTrue("entityManager should be closed or cleared", pc1.isClosed() || pc1.isCleared());
        tm.begin();
        CMPEntityManagerTxScoped entityManager2 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc2 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
        assertTrue("entityManager should not be closed or cleared", !pc2.isClosed() & !pc2.isCleared());
        tm.rollback();
        assertTrue("entityManager should be closed or cleared", pc2.isClosed() || pc2.isCleared());
    }
View Full Code Here

     * section 5.6.2
     * extended context is closed when the SFSB that caused it is removed
     */
    public void testExtendedClosedOnBeanRemove() throws Exception {
        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
        assertTrue("base EntityManager should not be closed", !pc1.isClosed());
        assertNotNull("InternalEntityManager should be registered", EntityManagerExtendedRegistry.getEntityManager(persistenceUnit));
        entityManager1.beanRemoved();
        assertTrue("base EntityManager should be closed", pc1.isClosed());
        assertNull("InternalEntityManager should not be registered", EntityManagerExtendedRegistry.getEntityManager(persistenceUnit));
    }
View Full Code Here

     * section 5.6.2.1
     * extended context is closed when the SFSB that caused it and all others that share it are removed
     */
    public void testInheritedExtendedClosedOnBeanRemove() throws Exception {
        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
        assertTrue("base EntityManager should not be closed", !pc1.isClosed());
        InternalCMPEntityManagerExtended internalEntityManager1 = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
        assertNotNull("InternalEntityManager should be registered", internalEntityManager1);
        CMPEntityManagerExtended entityManager2 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
        InternalCMPEntityManagerExtended internalEntityManager2 = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
        //we should have got an exception if this isn't true
        assertSame("2nd entity manager registering should use same internal entity manager", internalEntityManager1, internalEntityManager2);
        MockEntityManager pc2 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
        assertSame("2nd entity manager registering should use same mock entity manager", pc1, pc2);

        //remove one bean, internal and mock entity managers should not change state
        entityManager1.beanRemoved();
        assertTrue("base EntityManager should not be closed", !pc1.isClosed());
View Full Code Here

        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
        //set up the caller
        CMPEntityManagerTxScoped entityManager2 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
        tm.begin();
        //register the caller
        MockEntityManager pc1 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
        //caller calling SFSB means entityManager1 tries to join the trasaction:
        InternalCMPEntityManagerExtended internalEntityManager = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
        try {
            internalEntityManager.joinTransaction();
            fail("Expected EJBException");
View Full Code Here

     * close or cleared is called when tx commits
     */
    public void testCloseOnCommit() throws Exception {
        tm.begin();
        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
        assertTrue("entityManager should not be closed or cleared", !pc1.isClosed() & !pc1.isCleared());
        tm.commit();
        assertTrue("entityManager should be closed or cleared", pc1.isClosed() || pc1.isCleared());
        tm.begin();
        CMPEntityManagerTxScoped entityManager2 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
        MockEntityManager pc2 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
        assertTrue("entityManager should not be closed or cleared", !pc2.isClosed() & !pc2.isCleared());
        tm.rollback();
        assertTrue("entityManager should be closed or cleared", pc2.isClosed() || pc2.isCleared());
    }
View Full Code Here

TOP

Related Classes of org.apache.geronimo.persistence.mockjpa.MockEntityManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.