use of org.jboss.test.audit.annotations.SpecAssertion in project cdi-tck by eclipse-ee4j.
the class ConditionalObserverTest method testConditionalObserverMethodNotInvokedIfNoActiveContext.
@Test(groups = INTEGRATION)
@SpecAssertion(section = OBSERVER_NOTIFICATION, id = "bca")
public void testConditionalObserverMethodNotInvokedIfNoActiveContext() {
Tarantula.reset();
Context requestContext = getCurrentConfiguration().getContexts().getRequestContext();
Tarantula tarantula = getContextualReference(Tarantula.class);
tarantula.ping();
Event<TarantulaEvent> tarantulaEvent = getCurrentManager().getEvent().select(TarantulaEvent.class);
try {
// Instance exists but there is no context active for its scope
setContextInactive(requestContext);
tarantulaEvent.fire(new TarantulaEvent());
// Observer method not called
assertFalse(Tarantula.isNotified());
} finally {
setContextActive(requestContext);
}
// Context is active now
tarantulaEvent.fire(new TarantulaEvent());
assertTrue(Tarantula.isNotified());
}
use of org.jboss.test.audit.annotations.SpecAssertion in project cdi-tck by eclipse-ee4j.
the class ObserverNotificationTest method testObserverMethodNotInvokedIfNoActiveContext.
@Test
@SpecAssertion(section = OBSERVER_NOTIFICATION, id = "bca")
public void testObserverMethodNotInvokedIfNoActiveContext() {
Context requestContext = getCurrentConfiguration().getContexts().getRequestContext();
resetObservers();
try {
setContextInactive(requestContext);
// Observer method not called - there is no context active for its scope
getCurrentManager().getEvent().select(AnEventType.class, new RoleLiteral("Admin", "hurray")).fire(new AnEventType());
assertFalse(AnotherObserver.wasNotified);
} finally {
setContextActive(requestContext);
}
}
use of org.jboss.test.audit.annotations.SpecAssertion in project cdi-tck by eclipse-ee4j.
the class ScopeDefinitionTest method testScopeTypeHasCorrectTarget.
@Test
@SpecAssertion(section = DEFINING_NEW_SCOPE_TYPE, id = "aa")
public void testScopeTypeHasCorrectTarget() {
assert getBeans(Mullet.class).size() == 1;
Bean<Mullet> bean = getBeans(Mullet.class).iterator().next();
Target target = bean.getScope().getAnnotation(Target.class);
List<ElementType> elements = Arrays.asList(target.value());
assert elements.contains(ElementType.TYPE);
assert elements.contains(ElementType.METHOD);
assert elements.contains(ElementType.FIELD);
}
use of org.jboss.test.audit.annotations.SpecAssertion in project cdi-tck by eclipse-ee4j.
the class BootstrapSEContainerTest method testAlternativesInSE.
@Test
@SpecAssertions({ @SpecAssertion(section = SE_CONTAINER_INITIALIZER, id = "a"), @SpecAssertion(section = SE_BOOTSTRAP, id = "db"), @SpecAssertion(section = SE_BOOTSTRAP, id = "dh"), @SpecAssertion(section = SE_BOOTSTRAP, id = "di"), @SpecAssertion(section = SE_BOOTSTRAP, id = "dm"), @SpecAssertion(section = SE_CONTAINER_INITIALIZER, id = "b") })
public void testAlternativesInSE() {
SeContainerInitializer seContainerInitializer = SeContainerInitializer.newInstance();
try (SeContainer seContainer = seContainerInitializer.disableDiscovery().addBeanClasses(Square.class, Circle.class, Foo.class, FooProducer.class).selectAlternatives(Circle.class).selectAlternativeStereotypes(AlternativeStereotype.class).initialize()) {
Shape shape = seContainer.select(Shape.class).get();
assertEquals(shape.name(), Circle.NAME);
Set<Bean<?>> foos = seContainer.getBeanManager().getBeans(Foo.class);
Optional<Bean<?>> alternativeFoo = foos.stream().filter(bean -> bean.isAlternative()).findAny();
assertTrue(alternativeFoo.isPresent());
assertEquals(alternativeFoo.get().getName(), "createFoo");
}
}
use of org.jboss.test.audit.annotations.SpecAssertion in project cdi-tck by eclipse-ee4j.
the class ActivateRequestContextByInterceptorTest method methodInterceptorRequestContextActivation.
@Test
@SpecAssertion(section = REQUEST_CONTEXT, id = "a")
@SpecAssertion(section = REQUEST_CONTEXT, id = "b")
@SpecAssertion(section = REQUEST_CONTEXT, id = "c")
@SpecAssertion(section = ACTIVATING_REQUEST_CONTEXT, id = "a")
@SpecAssertion(section = ACTIVATING_REQUEST_CONTEXT, id = "f")
public void methodInterceptorRequestContextActivation() {
SeContainerInitializer seContainerInitializer = SeContainerInitializer.newInstance();
try (SeContainer container = seContainerInitializer.initialize()) {
MethodInterceptorContextActivator activator = container.select(MethodInterceptorContextActivator.class).get();
Assert.assertEquals(activator.callRequestScopeBean(), 11);
RequestContextObserver requestContextObserver = container.select(RequestContextObserver.class).get();
Assert.assertEquals(requestContextObserver.getInitCounter(), 1);
Assert.assertEquals(requestContextObserver.getBeforeDestroyedCounter(), 1);
Assert.assertEquals(requestContextObserver.getDestroyedCounter(), 1);
}
}
Aggregations