use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldSEDeployableContainer method deploy.
@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
final URL[] urls = writeFiles(archive);
final ClassLoader classLoader = new URLClassLoader(urls, getClass().getClassLoader()) {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
Enumeration<URL> resources = super.getResources(name);
Set<URL> urls = new HashSet<URL>();
while (resources.hasMoreElements()) {
final URL url = resources.nextElement();
// ignore any resources on classpath outside of the deployment
if (url.getProtocol().equalsIgnoreCase("jar")) {
urls.add(url);
}
}
return Collections.enumeration(urls);
}
};
this.weld = new Weld().setClassLoader(classLoader);
final WeldContainer container = this.weld.initialize();
beanManagerProducer.set(container.getBeanManager());
return new ProtocolMetaData();
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class StartMainEmptyArgsTest method testMainEmptyArgs.
/**
* Test of main method, of class StartMain when no command-line args are
* provided.
*/
@Test
public void testMainEmptyArgs() {
WeldContainer container = startMain.go();
MainTestBean mainTestBean = container.instance().select(MainTestBean.class).get();
assertNotNull(mainTestBean);
ParametersTestBean paramsBean = mainTestBean.getParametersTestBean();
assertNotNull(paramsBean);
assertNotNull(paramsBean.getParameters());
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class ContainerLifecyleObserverTest method testExtensionBuilder.
@SuppressWarnings({ "serial" })
@Test
public void testExtensionBuilder() {
ActionSequence.reset();
Extension myExtension = ContainerLifecycleObserver.extensionBuilder().add(beforeBeanDiscovery((e) -> addAction(BeforeBeanDiscovery.class.getSimpleName()))).add(afterTypeDiscovery().notify((e, b) -> {
addAction(AfterTypeDiscovery.class.getSimpleName());
e.addAnnotatedType(b.createAnnotatedType(Charlie.class), Charlie.class.getName());
})).add(afterBeanDiscovery((e) -> {
addAction(AfterBeanDiscovery.class.getSimpleName());
e.addObserverMethod().beanClass(Foo.class).observedType(Foo.class).notifyWith((ctx) -> {
});
e.addBean().beanClass(Integer.class).addType(Integer.class).addQualifier(Juicy.Literal.INSTANCE).createWith((ctx) -> Integer.valueOf(10));
})).add(afterDeploymentValidation((e) -> addAction(AfterDeploymentValidation.class.getSimpleName()))).add(beforeShutdown((e) -> addAction(BeforeShutdown.class.getSimpleName()))).build();
Extension myExtension2 = ContainerLifecycleObserver.extensionBuilder().add(processAnnotatedType().withAnnotations(RequestScoped.class).notify((e) -> e.veto())).add(processBeanAttributes().notify((e) -> addAction(ProcessBeanAttributes.class.getSimpleName()))).add(processSyntheticAnnotatedType(new TypeLiteral<ProcessSyntheticAnnotatedType<?>>() {
}.getType()).notify((e) -> addAction(ProcessSyntheticAnnotatedType.class.getSimpleName()))).add(processInjectionPoint().notify((e) -> addAction(ProcessInjectionPoint.class.getSimpleName()))).add(processProducer().notify((e) -> addAction(ProcessProducer.class.getSimpleName()))).add(processBean().notify((e) -> addAction(ProcessBean.class.getSimpleName()))).add(processManagedBean().notify((e) -> addAction(ProcessManagedBean.class.getSimpleName()))).add(processProducerField().notify((e) -> addAction(ProcessProducerField.class.getSimpleName()))).add(processProducerMethod().notify((e) -> {
// Weld SE defines some producer methods, e.g. ParametersFactory
addAction(ProcessProducerMethod.class.getSimpleName());
})).add(processBeanAttributes().notify((e) -> addAction(ProcessBeanAttributes.class.getSimpleName()))).add(processObserverMethod().notify((e) -> addAction(ProcessObserverMethod.class.getSimpleName()))).add(processObserverMethod(new TypeLiteral<ProcessObserverMethod<String, ?>>() {
}.getType()).notify((e) -> addAction(ProcessObserverMethod.class.getSimpleName() + String.class.getSimpleName()))).add(processSyntheticObserverMethod(new TypeLiteral<ProcessSyntheticObserverMethod<Foo, ?>>() {
}.getType()).notify((e) -> addAction(ProcessSyntheticObserverMethod.class.getSimpleName() + Foo.class.getSimpleName()))).add(processSyntheticBean(new TypeLiteral<ProcessSyntheticBean<Integer>>() {
}.getType()).notify((e) -> addAction(ProcessSyntheticBean.class.getSimpleName() + Integer.class.getSimpleName()))).build();
try (WeldContainer container = new Weld().disableDiscovery().beanClasses(Foo.class, Bravo.class).addExtension(myExtension).addExtension(myExtension2).initialize()) {
assertTrue(container.select(Foo.class).isUnsatisfied());
assertFalse(container.select(Bravo.class).isUnsatisfied());
Assert.assertEquals(Integer.valueOf(10), container.select(Integer.class, Juicy.Literal.INSTANCE).get());
}
ActionSequence.assertSequenceDataContainsAll(BeforeBeanDiscovery.class, AfterTypeDiscovery.class, AfterBeanDiscovery.class, AfterDeploymentValidation.class, BeforeShutdown.class);
ActionSequence.assertSequenceDataContainsAll(ProcessBeanAttributes.class, ProcessSyntheticAnnotatedType.class, ProcessInjectionPoint.class, ProcessObserverMethod.class, ProcessBeanAttributes.class, ProcessProducer.class);
ActionSequence.assertSequenceDataContainsAll(ProcessObserverMethod.class.getSimpleName() + String.class.getSimpleName(), ProcessSyntheticObserverMethod.class.getSimpleName() + Foo.class.getSimpleName(), ProcessSyntheticBean.class.getSimpleName() + Integer.class.getSimpleName());
ActionSequence.assertSequenceDataContainsAll(ProcessBean.class, ProcessManagedBean.class, ProcessProducerMethod.class, ProcessProducerField.class);
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldContainerCurrentTest method testCorrectContainerReturned.
@Test
public void testCorrectContainerReturned() {
String containerId = "007";
try (WeldContainer container = new Weld(containerId).disableDiscovery().addBeanClass(DumbBean.class).initialize()) {
Assert.assertTrue(container.isRunning());
Assert.assertTrue(WeldContainer.current().getId().equals(containerId));
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class ContainerEventsTest method testEventsFired.
@Test
public void testEventsFired() {
String id = "EVENT";
ActionSequence.reset();
try (WeldContainer container = new Weld(id).disableDiscovery().beanClasses(ContainerObserver.class).initialize()) {
assertFalse(container.select(ContainerObserver.class).isUnsatisfied());
}
List<String> sequenceData = ActionSequence.getSequenceData();
assertEquals(6, sequenceData.size());
assertTrue(sequenceData.contains(ContainerInitialized.class.getName() + id));
assertTrue(sequenceData.contains(ContainerInitialized.class.getName() + ApplicationScoped.class.getName() + id));
assertTrue(sequenceData.contains(ContainerBeforeShutdown.class.getName() + id));
assertTrue(sequenceData.contains(ContainerBeforeShutdown.class.getName() + ApplicationScoped.class.getName() + id));
assertTrue(sequenceData.contains(ContainerShutdown.class.getName() + id));
assertTrue(sequenceData.contains(ContainerShutdown.class.getName() + ApplicationScoped.class.getName() + id));
sequenceData = ActionSequence.getSequenceData(ApplicationScoped.class.getName());
assertEquals(3, sequenceData.size());
assertTrue(sequenceData.get(0).equals(ContainerInitialized.class.getName() + ApplicationScoped.class.getName()));
assertTrue(sequenceData.get(1).equals(ContainerBeforeShutdown.class.getName() + ApplicationScoped.class.getName()));
assertTrue(sequenceData.get(2).equals(ContainerShutdown.class.getName() + ApplicationScoped.class.getName()));
}
Aggregations