Search in sources :

Example 21 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class BeansXmlMergingTest method testDuplicatesAreRemoved.

@Test
public void testDuplicatesAreRemoved() {
    WeldBootstrap weldBootstrap = new WeldBootstrap();
    URL url1 = getClass().getResource("/org/jboss/weld/tests/unit/bootstrap/xml/beans1.xml");
    URL url2 = getClass().getResource("/org/jboss/weld/tests/unit/bootstrap/xml/beans2.xml");
    BeansXml beansXml = weldBootstrap.parse(Arrays.asList(url1, url1, url2), true);
    assertEquals(1, beansXml.getEnabledAlternativeStereotypes().size());
    assertEquals("org.jboss.weld.tests.unit.bootstrap.xml.Stereo", beansXml.getEnabledAlternativeStereotypes().get(0).getValue());
    assertEquals(1, beansXml.getEnabledAlternativeClasses().size());
    assertEquals("org.jboss.weld.tests.unit.bootstrap.xml.Alt", beansXml.getEnabledAlternativeClasses().get(0).getValue());
    assertEquals(1, beansXml.getEnabledInterceptors().size());
    assertEquals("org.jboss.weld.tests.unit.bootstrap.xml.Int", beansXml.getEnabledInterceptors().get(0).getValue());
    assertEquals(1, beansXml.getEnabledDecorators().size());
    assertEquals("org.jboss.weld.tests.unit.bootstrap.xml.Dec", beansXml.getEnabledDecorators().get(0).getValue());
}
Also used : WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 22 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class Validator method validateEnabledAlternativeClasses.

private void validateEnabledAlternativeClasses(BeanManagerImpl beanManager, BeanDeployment deployment) {
    BeansXml beansXml = deployment.getBeanDeploymentArchive().getBeansXml();
    if (beansXml != null && !beansXml.getEnabledAlternativeClasses().isEmpty()) {
        // prepare lookup structure
        Map<String, Class<?>> loadedClasses = buildClassNameMap(beanManager.getEnabled().getAlternativeClasses());
        // lookup structure for validation of alternatives
        Multimap<Class<?>, Bean<?>> beansByClass = SetMultimap.newSetMultimap();
        for (Bean<?> bean : beanManager.getDynamicAccessibleBeans()) {
            if (!(bean instanceof NewBean)) {
                beansByClass.put(bean.getBeanClass(), bean);
            }
        }
        for (Metadata<String> definition : beansXml.getEnabledAlternativeClasses()) {
            Class<?> enabledClass = loadedClasses.get(definition.getValue());
            if (enabledClass.isAnnotation() || enabledClass.isInterface()) {
                throw ValidatorLogger.LOG.alternativeBeanClassNotClass(definition);
            } else {
                if (!isAlternativeBean(enabledClass, beansByClass) && !isAlternativeCandidate(enabledClass, beanManager)) {
                    throw ValidatorLogger.LOG.alternativeBeanClassNotAnnotated(definition.getValue(), definition.getLocation());
                }
            }
        }
    }
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) NewBean(org.jboss.weld.bean.NewBean) SessionBean(org.jboss.weld.bean.SessionBean) AbstractClassBean(org.jboss.weld.bean.AbstractClassBean) DecorableBean(org.jboss.weld.bean.DecorableBean) AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) NewBean(org.jboss.weld.bean.NewBean) AbstractBean(org.jboss.weld.bean.AbstractBean) AbstractDecorableBuiltInBean(org.jboss.weld.bean.builtin.AbstractDecorableBuiltInBean) AbstractProducerBean(org.jboss.weld.bean.AbstractProducerBean) CommonBean(org.jboss.weld.bean.CommonBean) Bean(javax.enterprise.inject.spi.Bean)

Example 23 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class TransitiveResolutionTest method testInterceptorEnabledInWarButPackagedInEjbJar.

/*
    * WELD-507
    */
@Test
public void testInterceptorEnabledInWarButPackagedInEjbJar() {
    // Create the BDA in which we will deploy Foo. This is equivalent to a ejb
    // jar
    final BeanDeploymentArchiveImpl ejbJar = new BeanDeploymentArchiveImpl("ejb-jar", Basic.class, BasicInterceptor.class, Simple.class);
    // Create the BDA in which we will deploy Bar. This is equivalent to a war
    BeansXml beansXml = new BeansXmlImpl(null, null, null, Collections.singletonList(BasicInterceptor.class.getName()));
    final BeanDeploymentArchiveImpl war = new BeanDeploymentArchiveImpl("war", beansXml, Complex.class);
    // The war can access the ejb jar
    war.getBeanDeploymentArchives().add(ejbJar);
    // Create a deployment, any other classes are put into the ejb-jar (not
    // relevant to test)
    Deployment deployment = new FlatDeployment(new BeanDeploymentArchive[] { ejbJar, war }) {

        public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
            return ejbJar;
        }
    };
    TestContainer container = new TestContainer(deployment);
    container.startContainer();
    container.ensureRequestActive();
    // Get the bean manager for war and ejb jar
    BeanManager warBeanManager = container.getBeanManager(war);
    BeanManager ejbJarBeanManager = container.getBeanManager(ejbJar);
    BasicInterceptor.reset();
    Simple simple = getReference(ejbJarBeanManager, Simple.class);
    simple.ping("14");
    Assert.assertNull(BasicInterceptor.getTarget());
    BasicInterceptor.reset();
    Complex complex = getReference(warBeanManager, Complex.class);
    complex.ping("14");
    Assert.assertNotNull(BasicInterceptor.getTarget());
    Assert.assertTrue(BasicInterceptor.getTarget() instanceof Complex);
    assertEquals("14", ((Complex) BasicInterceptor.getTarget()).getId());
    container.stopContainer();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Deployment(org.jboss.weld.bootstrap.spi.Deployment) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeanManager(javax.enterprise.inject.spi.BeanManager) Test(org.testng.annotations.Test)

Example 24 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class BeansXmlParsingTest method testEmptyFile.

@Test
public void testEmptyFile() {
    BeansXml xml = getBeansXml("cdi11-beans5.xml");
    assertEquals(xml.getBeanDiscoveryMode(), BeanDiscoveryMode.ALL);
    assertNull(xml.getVersion());
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Test(org.testng.annotations.Test)

Example 25 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class BeansXmlParsingTest method testExplicitVersionAndMode4.

@Test
public void testExplicitVersionAndMode4() {
    BeansXml xml = getBeansXml("cdi11-beans4.xml");
    assertEquals(xml.getBeanDiscoveryMode(), BeanDiscoveryMode.ALL);
    assertEquals(xml.getVersion(), "1.1");
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Test(org.testng.annotations.Test)

Aggregations

BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)34 Test (org.testng.annotations.Test)12 URL (java.net.URL)9 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)6 ArrayList (java.util.ArrayList)5 File (java.io.File)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 Metadata (org.jboss.weld.bootstrap.spi.Metadata)3 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ZipFile (java.util.zip.ZipFile)2 Bean (javax.enterprise.inject.spi.Bean)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)2 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)2 BeanDeploymentArchiveImpl (org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl)2