use of javax.enterprise.context.spi.AlterableContext in project core by weld.
the class StatefulSessionBeanRecreatedAfterDestroyTest method testWithSpi.
@Test
public void testWithSpi() {
assertEquals("pong", bean.ping());
// cause SFSB to be removed
try {
bean.throwException();
Assert.fail();
} catch (EJBException expected) {
}
// verify that every access causes NoSuchEJBException
try {
bean.ping();
Assert.fail();
} catch (NoSuchEJBException expected) {
}
// try to destroy the bean
Bean<?> contextual = manager.resolve(manager.getBeans(StatefulBean.class));
AlterableContext context = (AlterableContext) manager.getContext(ApplicationScoped.class);
context.destroy(contextual);
assertEquals("pong", bean.ping());
}
use of javax.enterprise.context.spi.AlterableContext in project core by weld.
the class AlterableContextTest method testNothingHappensIfNoInstanceToDestroy.
@Test
public void testNothingHappensIfNoInstanceToDestroy(ApplicationScopedComponent application) {
Bean<?> bean = manager.resolve(manager.getBeans(ApplicationScopedComponent.class));
AlterableContext context = (AlterableContext) manager.getContext(bean.getScope());
AbstractComponent.reset();
application.setValue("value");
context.destroy(bean);
assertTrue(AbstractComponent.isDestroyed());
// make sure subsequent calls do not raise exception
context.destroy(bean);
context.destroy(bean);
}
use of javax.enterprise.context.spi.AlterableContext in project core by weld.
the class InstanceImpl method destroy.
@Override
public void destroy(T instance) {
checkNotNull(instance);
// Attempt to destroy instance which is either a client proxy or a dependent session bean proxy
if (instance instanceof ProxyObject) {
ProxyObject proxy = (ProxyObject) instance;
if (proxy.getHandler() instanceof ProxyMethodHandler) {
ProxyMethodHandler handler = (ProxyMethodHandler) proxy.getHandler();
Bean<?> bean = handler.getBean();
if (isSessionBeanProxy(instance) && Dependent.class.equals(bean.getScope())) {
// Destroy internal reference to a dependent session bean
destroyDependentInstance(instance);
return;
} else {
// Destroy contextual instance of a normal-scoped bean
Context context = getBeanManager().getContext(bean.getScope());
if (context instanceof AlterableContext) {
AlterableContext alterableContext = (AlterableContext) context;
alterableContext.destroy(bean);
return;
} else {
throw BeanLogger.LOG.destroyUnsupported(context);
}
}
}
}
// Attempt to destroy dependent instance which is neither a client proxy nor a dependent session bean proxy
destroyDependentInstance(instance);
}
use of javax.enterprise.context.spi.AlterableContext in project core by weld.
the class DestroyingNormalScopedInstanceTest method testNothingHappensIfNoInstanceToDestroy.
@Test
public void testNothingHappensIfNoInstanceToDestroy(ApplicationScopedComponent application) {
Bean<?> bean = manager.resolve(manager.getBeans(ApplicationScopedComponent.class));
AlterableContext context = (AlterableContext) manager.getContext(bean.getScope());
AbstractComponent.reset();
application.setValue("value");
context.destroy(bean);
assertTrue(AbstractComponent.isDestroyed());
// make sure subsequent calls do not raise exception
context.destroy(bean);
context.destroy(bean);
}
use of javax.enterprise.context.spi.AlterableContext in project core by weld.
the class AlterableContextTest method testComponent.
private <T extends AbstractComponent> void testComponent(Class<T> javaClass) {
Bean<?> bean = manager.resolve(manager.getBeans(javaClass));
@SuppressWarnings("unchecked") T reference = (T) manager.getReference(bean, javaClass, manager.createCreationalContext(bean));
AlterableContext context = (AlterableContext) manager.getContext(bean.getScope());
for (String string : VALUES) {
assertNull(reference.getValue());
reference.setValue(string);
assertEquals(string, reference.getValue());
AbstractComponent.reset();
context.destroy(bean);
assertTrue(AbstractComponent.isDestroyed());
assertNull(reference.getValue(), reference.getValue());
}
}
Aggregations