public void testQualifiedLookup() { final QualA qualA = new QualA() { @Override public Class<? extends Annotation> annotationType() { return QualA.class; } }; final QualB qualB = new QualB() { @Override public Class<? extends Annotation> annotationType() { return QualB.class; } }; final Collection<SyncBeanDef<CommonInterface>> beans = IOC.getBeanManager().lookupBeans(CommonInterface.class); assertEquals("wrong number of beans", 2, beans.size()); final SyncBeanDef<CommonInterface> beanA = IOC.getBeanManager().lookupBean(CommonInterface.class, qualA); assertNotNull("no bean found", beanA); assertTrue("wrong bean looked up", beanA.getInstance() instanceof QualAppScopeBeanA); final SyncBeanDef<CommonInterface> beanB = IOC.getBeanManager().lookupBean(CommonInterface.class, qualB); assertNotNull("no bean found", beanB); assertTrue("wrong bean looked up", beanB.getInstance() instanceof QualAppScopeBeanB); }
@Before public void setup() { when(authzManager.authorize(any(Resource.class), any(User.class))).thenReturn(true); activatedActivity = mock(Activity.class); when(activatedActivity.getIdentifier()).thenReturn("activated activity"); when(activatedActivityBean.getInstance()).thenReturn(activatedActivity); when(activatedActivityBean.isActivated()).thenReturn(true); when(nonActivatedActivityBean.isActivated()).thenReturn(false); Collection<SyncBeanDef<Activity>> activityList = new ArrayList<SyncBeanDef<Activity>>(); activityList.add(activatedActivityBean); activityList.add(nonActivatedActivityBean); // This covers the case where the activity manager goes directly to the Errai bean manager. // The list includes all beans, active or otherwise, and the activity manager has to filter // them. when(iocManager.lookupBeans(Activity.class)).thenReturn(activityList); // And this covers the case where the activity manager does the lookup via the // ActivityBeansCache. // We set this up assuming ActivityBeansCache is well-behaved, and hides the existence of // inactive beans. // (of course this assumption is verified in a separate test) ActivityAndMetaInfo activatedActivityAndMetaInfo = activityBeansCache .new ActivityAndMetaInfo(activatedActivityBean, 0, Collections.<String>emptyList()); when(activityBeansCache.getResourceActivities()) .thenReturn(singletonList(activatedActivityAndMetaInfo)); when(activityBeansCache.getActivity("activated activity")).thenReturn(activatedActivityBean); }
private static boolean containsInstanceOf( final Collection<SyncBeanDef> defs, final Class<?> clazz) { for (final SyncBeanDef def : defs) { if (def.getType().equals(clazz)) return true; } return false; }
public void testBeanManagerAPIs() { final SyncBeanManager mgr = IOC.getBeanManager(); final SyncBeanDef<QualAppScopeBeanA> bean = mgr.lookupBean(QualAppScopeBeanA.class, anyAnno); final Set<Annotation> a = bean.getQualifiers(); assertEquals("there should be two qualifiers", 2, a.size()); assertTrue("wrong qualifiers", annotationSetMatches(a, QualA.class, Any.class)); }
public void testReportedScopeCorrect() { final SyncBeanDef<ApplicationScopedBean> appScopeBean = IOC.getBeanManager().lookupBean(ApplicationScopedBean.class); final SyncBeanDef<DependentScopedBean> dependentIOCBean = IOC.getBeanManager().lookupBean(DependentScopedBean.class); assertEquals(ApplicationScoped.class, appScopeBean.getScope()); assertEquals(Dependent.class, dependentIOCBean.getScope()); }
public void testLookupByName() { final Collection<SyncBeanDef> beans = IOC.getBeanManager().lookupBeans("animal"); assertEquals("wrong number of beans", 2, beans.size()); assertTrue("should contain a pig", containsInstanceOf(beans, Pig.class)); assertTrue("should contain a cow", containsInstanceOf(beans, Cow.class)); for (SyncBeanDef<?> bean : beans) { assertEquals("animal", bean.getName()); } }
public void testBeanManagerLookupBeanFromAbstractRootType() { final SyncBeanDef<AbstractBean> bean = IOC.getBeanManager().lookupBean(AbstractBean.class); assertNotNull("did not find any beans matching", bean); final AbstractBean beanInst = bean.getInstance(); assertNotNull("bean instance is null", beanInst); assertTrue( "bean is incorrect instance: " + beanInst.getClass(), beanInst instanceof InheritedFromAbstractBean); }
public void testNameAvailableThroughInterfaceLookup() { Collection<SyncBeanDef<CreditCard>> beans = IOC.getBeanManager().lookupBeans(CreditCard.class); for (SyncBeanDef<CreditCard> bean : beans) { if (bean.getBeanClass().getName().endsWith("Visa")) { assertEquals("visa", bean.getName()); } else if (bean.getBeanClass().getName().endsWith("Amex")) { assertEquals("amex", bean.getName()); } else { fail("Unexpected bean was returned from lookup: " + bean); } } }
public void testQualifierLookupWithAnnoAttribFailure() { final QualV qualOrange = new QualV() { @Override public QualEnum value() { return QualEnum.ORANGES; } @Override public Class<? extends Annotation> annotationType() { return QualV.class; } @Override public int amount() { return 5; } }; final QualV qualApple = new QualV() { @Override public QualEnum value() { return QualEnum.APPLES; } @Override public Class<? extends Annotation> annotationType() { return QualV.class; } @Override public int amount() { return 6; } }; final Collection<SyncBeanDef<CommonInterfaceB>> beans = IOC.getBeanManager().lookupBeans(CommonInterfaceB.class); assertEquals("wrong number of beans", 2, beans.size()); final SyncBeanDef<CommonInterfaceB> beanA = IOC.getBeanManager().lookupBean(CommonInterfaceB.class, qualOrange); assertNotNull("no bean found", beanA); assertFalse("wrong bean looked up", beanA.getInstance() instanceof QualParmAppScopeBeanApples); final SyncBeanDef<CommonInterfaceB> beanB = IOC.getBeanManager().lookupBean(CommonInterfaceB.class, qualApple); assertNotNull("no bean found", beanB); assertFalse("wrong bean looked up", beanB.getInstance() instanceof QualParmAppScopeBeanOranges); }
/** * Adds a new notification message to the system, asking the notification presenter to display it, * and storing it in the list of existing notifications. This method can be invoked directly, or * it can be invoked indirectly by firing a CDI {@link NotificationEvent}. * * @param event The notification to display and store in the notification system. */ public void addNotification(@Observes final NotificationEvent event) { // If an explicit container has not been specified use the RootPanel PlaceRequest placeRequest = event.getPlaceRequest(); IsWidget notificationsContainer = RootPanel.get(); if (placeRequest == null) { placeRequest = rootPlaceRequest; } else { final Activity activity = placeManager.getActivity(placeRequest); if (activity instanceof WorkbenchActivity) { notificationsContainer = ((WorkbenchActivity) activity).getWidget(); } } // Lookup, or create, a View specific to the container View notificationsContainerView = notificationsContainerViewMap.get(placeRequest); if (notificationsContainerView == null) { final SyncBeanDef<View> containerViewBeanDef = iocManager.lookupBean(View.class); if (containerViewBeanDef != null) { notificationsContainerView = containerViewBeanDef.getInstance(); notificationsContainerView.setContainer(notificationsContainer); if (event.getInitialTopOffset() != null) { notificationsContainerView.setInitialSpacing(event.getInitialTopOffset()); } else { notificationsContainerView.setInitialSpacing(workbenchLayoutInfo.getHeaderHeight()); } notificationsContainerViewMap.put(placeRequest, notificationsContainerView); } } if (notificationsContainerView == null) { return; } // Show notification in the container if (!event.isSingleton() || !notificationsContainerView.isShowing(event)) { HideNotificationCommand hideCommand = new HideNotificationCommand(notificationsContainerView); NotificationPopupHandle handle = notificationsContainerView.show(event, hideCommand); hideCommand.setHandle(handle); } }
public void testBeanManagerLookupInheritedScopeBean() { final SyncBeanDef<InheritedApplicationScopedBean> bean = IOC.getBeanManager().lookupBean(InheritedApplicationScopedBean.class, anyAnno); assertNotNull("inherited application scoped bean did not lookup", bean); final InheritedApplicationScopedBean beanInst = bean.getInstance(); assertNotNull("bean instance is null", beanInst); final DependentScopedBean bean1 = beanInst.getBean1(); assertNotNull("bean1 is null", bean1); final DependentScopedBeanWithDependencies beanWithDependencies = beanInst.getBeanWithDependencies(); assertNotNull("beanWithDependencies is null", beanWithDependencies); final DependentScopedBean bean2 = beanWithDependencies.getBean(); assertNotSame("bean1 and bean2 should be different", bean1, bean2); final InheritedApplicationScopedBean beanInst2 = bean.getInstance(); assertSame("bean is not observing application scope", beanInst, beanInst2); }
@Override public void onOpenProjectContext() { SyncBeanDef<PlaceManager> placeManagerSyncBeanDef = iocManager.lookupBean(PlaceManager.class); placeManagerSyncBeanDef.getInstance().goTo("repositoryStructureScreen"); }
public void testNameAvailableThroughConcreteTypeLookup() { Collection<SyncBeanDef<Visa>> beans = IOC.getBeanManager().lookupBeans(Visa.class); for (SyncBeanDef<Visa> bean : beans) { assertNotNull("Missing name on " + bean, bean.getName()); } }