use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldInstanceSelectTypeTest method testInvalidSelect.
@Test
public void testInvalidSelect() {
Type secondType = SomeOtherBean.class;
try (WeldContainer container = new Weld().initialize()) {
// get more specific instance than Object and try again
WeldInstance<SomeInterface> someInterfaceInstance = container.select(SomeInterface.class);
// selecting from anything else than Object is not allowed
try {
someInterfaceInstance.select(secondType);
Assert.fail("Selecting by type from any other type than Object should fail with IllegalStateException!");
} catch (IllegalStateException e) {
// expected
}
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldInstanceSelectTypeTest method testSelectOnTypedBean.
@Test
public void testSelectOnTypedBean() {
// typed bean has no Object type, from bean selection perspective, it isn't hierarchical select from WeldInstance<Object>
Type type = TypedBean.class;
try (WeldContainer container = new Weld().initialize()) {
// should work
TypedBean bean = container.<TypedBean>select(type).get();
Assert.assertNotNull(bean);
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class EEResourceInjectionIgnoredTest method testInjection.
@Test
public void testInjection() {
try (WeldContainer container = new Weld().initialize()) {
Golf golf = container.select(Golf.class).get();
assertNull(golf.getEntityManager());
assertEquals(10, golf.getDelta().ping());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class ExplicitResourceLoaderExtensionScanningTest method testScanning.
@Test
public void testScanning() {
ClassLoader classLoader = new URLClassLoader(new URL[] {}, Alpha.class.getClassLoader()) {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
if ("META-INF/services/javax.enterprise.inject.spi.Extension".equals(name)) {
// Load only AlphaExtension
return super.getResources("META-INF/services/" + MyExtension.class.getName());
}
return super.getResources(name);
}
};
try (WeldContainer container = new Weld().setResourceLoader(new ClassLoaderResourceLoader(classLoader)).initialize()) {
container.select(Alpha.class).get().ping();
assertTrue(container.select(Bravo.class).isUnsatisfied());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class StartMainObserversTest method testObservers.
@Test
public void testObservers() {
InitObserverTestBean.reset();
ObserverTestBean.reset();
WeldContainer container = startMain.go();
BeanManager manager = container.getBeanManager();
manager.fireEvent(new CustomEvent());
assertTrue(ObserverTestBean.isBuiltInObserved());
assertTrue(ObserverTestBean.isCustomObserved());
assertTrue(ObserverTestBean.isInitObserved());
assertTrue(InitObserverTestBean.isInitObserved());
}
Aggregations