* 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());