Search in sources :

Example 56 with SpecAssertion

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());
}
Also used : Context(jakarta.enterprise.context.spi.Context) AbstractTest(org.jboss.cdi.tck.AbstractTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 57 with SpecAssertion

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);
    }
}
Also used : Context(jakarta.enterprise.context.spi.Context) AbstractTest(org.jboss.cdi.tck.AbstractTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 58 with SpecAssertion

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);
}
Also used : Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) AbstractTest(org.jboss.cdi.tck.AbstractTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 59 with SpecAssertion

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");
    }
}
Also used : Any(jakarta.enterprise.inject.Any) SE_CONTAINER(org.jboss.cdi.tck.cdi.Sections.SE_CONTAINER) EmptyAsset(org.jboss.shrinkwrap.api.asset.EmptyAsset) InjectLiteral(jakarta.enterprise.inject.literal.InjectLiteral) SeContainer(jakarta.enterprise.inject.se.SeContainer) Assert.assertEquals(org.testng.Assert.assertEquals) Pear(org.jboss.cdi.tck.tests.se.container.testPackage.nestedPackage.Pear) Test(org.testng.annotations.Test) Worm(org.jboss.cdi.tck.tests.se.container.testPackage.Worm) Instance(jakarta.enterprise.inject.Instance) Bean(jakarta.enterprise.inject.spi.Bean) SE_CONTAINER_INITIALIZER(org.jboss.cdi.tck.cdi.Sections.SE_CONTAINER_INITIALIZER) SpecVersion(org.jboss.test.audit.annotations.SpecVersion) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion) Assert.assertFalse(org.testng.Assert.assertFalse) BeanManager(jakarta.enterprise.inject.spi.BeanManager) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Arquillian(org.jboss.arquillian.testng.Arquillian) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) Set(java.util.Set) Assert.assertNotNull(org.testng.Assert.assertNotNull) Archive(org.jboss.shrinkwrap.api.Archive) ClassPath(org.jboss.arquillian.container.se.api.ClassPath) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) SE(org.jboss.cdi.tck.TestGroups.SE) SE_BOOTSTRAP(org.jboss.cdi.tck.cdi.Sections.SE_BOOTSTRAP) Assert.assertTrue(org.testng.Assert.assertTrue) Optional(java.util.Optional) Apple(org.jboss.cdi.tck.tests.se.container.testPackage.Apple) SeContainer(jakarta.enterprise.inject.se.SeContainer) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer) Bean(jakarta.enterprise.inject.spi.Bean) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) Test(org.testng.annotations.Test)

Example 60 with SpecAssertion

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);
    }
}
Also used : SeContainer(jakarta.enterprise.inject.se.SeContainer) SeContainerInitializer(jakarta.enterprise.inject.se.SeContainerInitializer) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Aggregations

SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)943 Test (org.testng.annotations.Test)893 AbstractTCKTest (org.hibernate.beanvalidation.tck.tests.AbstractTCKTest)595 ConstraintViolation (jakarta.validation.ConstraintViolation)265 Validator (jakarta.validation.Validator)216 AbstractTest (org.jboss.cdi.tck.AbstractTest)212 WebClient (com.gargoylesoftware.htmlunit.WebClient)190 Method (java.lang.reflect.Method)152 TextPage (com.gargoylesoftware.htmlunit.TextPage)80 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)73 Test (org.junit.Test)49 MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)44 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)40 ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)38 NotNull (jakarta.validation.constraints.NotNull)35 ValidatorFactory (jakarta.validation.ValidatorFactory)32 PropertyDescriptor (jakarta.validation.metadata.PropertyDescriptor)31 Context (jakarta.enterprise.context.spi.Context)30 SeContainer (jakarta.enterprise.inject.se.SeContainer)30 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)28