@IOCProducer public SyncBeanManager get() { return IOC.getBeanManager(); } }
@Override public void callback(final Foo beanInstance) { try { final Foo instance = IOC.getBeanManager().lookupBean(Foo.class).getInstance(); assertEquals(beanInstance, instance); finishTest(); } catch (IOCResolutionException e) { fail("Should have been able to perform sync lookup for instance of " + Foo.class.getSimpleName() + " after async loading."); } } });
public void testTypeWithLoadAsyncIsNotAvailableThroughSyncLookup() throws Exception { try { IOC.getBeanManager().lookupBean(Foo.class); fail("Should not have been able to lookup " + Foo.class.getSimpleName() + " with " + LoadAsync.class.getSimpleName() + " annotation via the SyncBeanManager."); } catch (IOCResolutionException e) { } }
public void testDependentBeanWithConstructorInjectionCausingCycyleDoesNotBlowUp() throws Exception { try { IOC.getBeanManager().lookupBean(DependentBeanWithConstructorCycle.class).getInstance(); } catch (final RuntimeException e) { throw new AssertionError("Could not lookup the dependent bean without error: " + e.getMessage(), e); } }
public void testDependentScopeWithPrivateConstr() throws Exception { try { IOC.getBeanManager().lookupBean(DependentWithPrivateConstr.class).getInstance(); } catch (final Throwable t) { throw new AssertionError("Could not create instance of bean with private constructor.", t); } }
public void testProducerMethodOfJsType() throws Exception { final ConsumesProducedJsType consumer = IOC.getBeanManager().lookupBean(ConsumesProducedJsType.class).getInstance(); assertNotNull(consumer.instance); assertTrue(consumer.instance instanceof ProducedJsType); assertEquals(1, IOC.getBeanManager().lookupBeans(ProducedJsType.class).size()); }
public void testBlacklistedPackage() throws Exception { try { IOC.getBeanManager().lookupBean(BlacklistedPackageBean.class).getInstance(); fail("Should not be able to resolve a bean in a blacklisted package!"); } catch (IOCResolutionException e) { // expected } } }
public void testSimpleLoggerFieldInjection() throws Exception { ClassWithLoggerField instance = IOC.getBeanManager().lookupBean(ClassWithLoggerField.class).getInstance(); assertNotNull("Logger was not injected", instance.getLogger()); assertEquals("Logger should have name of enclosing class", ClassWithLoggerField.class.getName(), instance .getLogger().getName()); }
public void testDestroyingProducedBeanOfDependentScopedProducerUsingFieldInjectedManagedInstance() throws Exception { final OtherDestructableClass producedBean = getBeanManager().lookupBean(OtherDestructableClass.class, c).getInstance(); assertFalse(producedBean.isDestroyed()); getBeanManager().destroyBean(producedBean); assertTrue(producedBean.isDestroyed()); }
public void testDisposerMethodCalledOnProviderWhenProvidedBeanIsDestroyed() throws Exception { final BeanWithProvidedBeansInjected module = IOC.getBeanManager().lookupBean(BeanWithProvidedBeansInjected.class).getInstance(); assertFalse("Bean was prematurely destroyed.", module.providedBean.isDestroyed()); IOC.getBeanManager().destroyBean(module.providedBean); assertTrue("Disposer method not called after bean was destroyed.", module.providedBean.isDestroyed()); }
public void testInitializationStatementsInvoked() throws Exception { final MyDecoratedBean instance = IOC.getBeanManager().lookupBean(MyDecoratedBean.class).getInstance(); // setFlag(true) should be called by init callback. assertTrue(instance.isFlag()); }
public void testBeanManagerInjectable() { final BeanManagerDependentBean bean = IOC.getBeanManager().lookupBean(BeanManagerDependentBean.class) .getInstance(); final ClientBeanManager beanManager = (GWT.<IOCEnvironment>create(IOCEnvironment.class).isAsync() ? IOC.getAsyncBeanManager() : IOC.getBeanManager()); assertSame(beanManager, Factory.maybeUnwrapProxy(bean.getBeanManager())); }
public void testLocalBeanSatisfiesExternalJsTypeInterfaceForDefaultInjectionSite() throws Exception { final ExternalTestModule module = IOC.getBeanManager().lookupBean(ExternalTestModule.class).getInstance(); assertNotNull(module.defaultExternalIface); assertEquals(ExternalJsTypeImpl.class.getSimpleName(), module.defaultExternalIface.message()); assertTrue(module.defaultExternalIface instanceof ExternalJsTypeImpl); }
public void testDisposerFailsToDestroyAppScope() { final SingletonBeanWithDisposer outerBean = IOC.getBeanManager().lookupBean(SingletonBeanWithDisposer.class).getInstance(); assertNotNull(outerBean); assertNotNull(outerBean.getDependentBeanDisposer()); final DependentBean innerBean = outerBean.getBean(); assertNotNull(innerBean); outerBean.dispose(); assertFalse("inner bean should have been disposed", IOC.getBeanManager().isManaged(innerBean)); assertTrue("outer bean should not have been disposed", IOC.getBeanManager().isManaged(outerBean)); assertTrue("bean's destructor should have been called", innerBean.isPreDestroyCalled()); }
public void testWindowContextBeanSatisfiesConcreteWindowScopedJsTypeForDefaultInjectionSite() throws Exception { final ExternalTestModule module = IOC.getBeanManager().lookupBean(ExternalTestModule.class).getInstance(); assertNotNull(module.defaultConcreteWindowScopedJsType); assertEquals("external", module.defaultConcreteWindowScopedJsType.message()); }
public void testWindowContextBeanSatisfiesExternalJsTypeInterfaceForExternalInjectionSite() throws Exception { final ExternalTestModule module = IOC.getBeanManager().lookupBean(ExternalTestModule.class).getInstance(); assertNotNull(module.externalExternalIface); assertEquals("external", module.externalExternalIface.message()); assertFalse(module.externalExternalIface instanceof ExternalJsTypeImpl); }
public void testInjectionFromProviderContextual() { final SimpleBean2 simpleBean2 = IOC.getBeanManager().lookupBean(SimpleBean2.class).getInstance(); assertEquals("FOO", simpleBean2.getMessage()); assertEquals("java.lang.String", simpleBean2.getbSvc().get()); }
public void testAlternativeBeanInjection() throws Exception { // AlternativeBeanA should be configured as an alternative in the ErraiApp.properties of this // test module. AlternativeDependentBean bean = IOC.getBeanManager().lookupBean(AlternativeDependentBean.class).getInstance(); assertNotNull(bean); assertNotNull(bean.getCommonInterface()); assertTrue("wrong instance of bean injected", bean.getCommonInterface() instanceof AlternativeBeanA); }
public void testSetterMethodInjection() { final SetterInjectionBean bean = IOC.getBeanManager().lookupBean(SetterInjectionBean.class) .getInstance(); assertNotNull(bean); assertNotNull(bean.getServiceA()); assertNotNull(bean.getServiceB()); }
public void testProvidedValueLookup() { final TestProviderDependentBean dependentBean = IOC.getBeanManager().lookupBean(TestProviderDependentBean.class) .getInstance(); assertNotNull(dependentBean); assertNotNull(dependentBean.getTestProvidedIface()); assertEquals("foo", dependentBean.getTestProvidedIface().getText()); }