public ELContext createELContext() { if (configuration.getManagers().getManager() instanceof BeanManagerImpl) { return EL.createELContext((BeanManagerImpl) configuration.getManagers().getManager()); } else { throw new IllegalStateException("Wrong manager"); } }
protected void setContextActive(Context context) { getCurrentConfiguration().getContexts().setActive(context); }
protected void setContextInactive(Context context) { getCurrentConfiguration().getContexts().setInactive(context); }
@Test @SpecAssertion(section = "5.4", id = "b") public void testClientProxyUsedForNormalScope() { Tuna tuna = getInstanceByType(Tuna.class); assert getCurrentConfiguration().getBeans().isProxy(tuna); }
@Test(groups = { "contexts", "el" }) @SpecAssertion(section = "6.4", id = "ca") public void testInstanceUsedForElEvaluationNotShared() throws Exception { Set<Bean<Fox>> foxBeans = getBeans(Fox.class); assert foxBeans.size() == 1; Fox fox1 = getCurrentConfiguration().getEl().evaluateValueExpression("#{fox}", Fox.class); Fox fox2 = getCurrentConfiguration().getEl().evaluateValueExpression("#{fox}", Fox.class); assert !fox1.equals(fox2); }
protected void destroyContext(Context context) { getCurrentConfiguration().getContexts().destroyContext(context); }
protected byte[] serialize(Object instance) throws IOException { return getCurrentConfiguration().getBeans().serialize(instance); }
protected Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException { return getCurrentConfiguration().getBeans().deserialize(bytes); }
public Tarantula() { dependentContextActive = ConfigurationFactory.get(JSR299Configuration.class).getContexts().getDependentContext().isActive(); }
@Test(groups = { "contexts", "el" }) @SpecAssertion(section = "6.4", id = "g") // Dependent context is now always active public void testContextIsActiveWhenEvaluatingElExpression() { String foxName = getCurrentConfiguration().getEl().evaluateMethodExpression("#{sensitiveFox.getName}", String.class, new Class[0], new Object[0]); assert foxName != null; assert SensitiveFox.isDependentContextActiveDuringEval(); }
@Test(groups={"el"}) @SpecAssertion(section="12.4", id="c") public void testUnresolvedNameReturnsNull() { assert getCurrentManager().getELResolver().getValue(getCurrentConfiguration().getEl().createELContext(), null, "nonExistingTuna") == null; }
public ELContext createELContext() { if (configuration.getManagers().getManager() instanceof BeanManagerImpl) { return EL.createELContext((BeanManagerImpl) configuration.getManagers().getManager()); } else { throw new IllegalStateException("Wrong manager"); } }
@Test @SpecAssertion(section = "5.4", id = "c") public void testSimpleBeanClientProxyIsSerializable() throws IOException, ClassNotFoundException { TunedTuna tuna = getInstanceByType(TunedTuna.class); assert getCurrentConfiguration().getBeans().isProxy(tuna); byte[] bytes = serialize(tuna); tuna = (TunedTuna) deserialize(bytes); assert getCurrentConfiguration().getBeans().isProxy(tuna); assert tuna.getState().equals("tuned"); }
@Test @SpecAssertion(section="6.4.3", id="a") public void testQualifiedNameLookup() { assert getCurrentConfiguration().getEl().evaluateValueExpression("#{(game.value == 'foo' and game.value == 'foo') ? game.value == 'foo' : false}", Boolean.class); assert getInstanceByType(Counter.class).getCount() == 1; }
protected BeanManager getCurrentManager() { return getCurrentConfiguration().getManagers().getManager(); }
@Test @SpecAssertions( { @SpecAssertion(section = "6.6.2", id = "b") }) public void testSerializeSessionScoped() throws Exception { Bream instance = getInstanceByType(Bream.class); byte[] bytes = serialize(instance); Object object = deserialize(bytes); instance = (Bream) object; assert getCurrentConfiguration().getBeans().isProxy(instance); }
@Test(groups = "el") @SpecAssertions({ @SpecAssertion(section="12.4", id="d"), @SpecAssertion(section="2.5", id="a") }) public void testELResolverReturnsContextualInstance() { Salmon salmon = getInstanceByType(Salmon.class); salmon.setAge(3); assert getCurrentConfiguration().getEl().evaluateValueExpression("#{salmon.age}", Integer.class) == 3; } }
@Test(groups = { "enterpriseBeans", "clientProxy", "lifecycle", "integration" }) @SpecAssertions( { @SpecAssertion(section = "6.6.2", id = "a") }) public void testSerializeSFSB() throws Exception { KleinStadt stadtInstance = getInstanceByType(KleinStadt.class, new AnnotationLiteral<Important>() {}); byte[] bytes = serialize(stadtInstance); Object object = deserialize(bytes); stadtInstance = (KleinStadt) object; assert getCurrentConfiguration().getBeans().isProxy(stadtInstance); }
@Test(groups = { "contexts", "el"}) @SpecAssertion(section = "6.4.2", id = "eee") public void testDependentsDestroyedWhenElEvaluationCompletes() throws Exception { // Reset test class Fox.reset(); FoxRun.setDestroyed(false); getCurrentConfiguration().getEl().evaluateValueExpression("#{foxRun}", FoxRun.class); assert FoxRun.isDestroyed(); assert Fox.isDestroyed(); }
@Test @SpecAssertions( { @SpecAssertion(section = "6.6.2", id = "b") }) public void testSerializeRequestScoped() throws Exception { Cod codInstance = getInstanceByType(Cod.class); byte[] bytes = serialize(codInstance); Object object = deserialize(bytes); codInstance = (Cod) object; assert getCurrentConfiguration().getBeans().isProxy(codInstance); }