WorkbenchMenuBarPresenter extends WorkbenchBaseMenuPresenter implements WorkbenchMenuBar { public void onPerspectiveChange(final PerspectiveChange perspectiveChange) { final Activity activity = activityManager.getActivity(perspectiveChange.getPlaceRequest()); if (activity != null && activity.isType(ActivityResourceType.PERSPECTIVE.name())) { addPerspectiveMenus((PerspectiveActivity) activity); } view.selectMenuItem(perspectiveChange.getPlaceRequest().getIdentifier()); } WorkbenchMenuBarPresenter(final AuthorizationManager authzManager,
                              final PerspectiveManager perspectiveManager,
                              final PlaceManager placeManager,
                              final ActivityManager activityManager,
                              final User identity,
                              final View view,
                              final ExperimentalActivitiesAuthorizationManager experimentalActivitiesAuthorizationManager); IsWidget getView(); void onPerspectiveChange(final PerspectiveChange perspectiveChange); @Override void clear(); @Override void expand(); @Override boolean isUseExpandedMode(); @Override boolean isExpanded(); @Override void collapse(); @Override void addCollapseHandler(final Command command); @Override void addExpandHandler(final Command command);  }
@Test public void testPerspectiveChangeEvent() { final Menus menus = MenuFactory.newSimpleItem(NAME).perspective(PERSPECTIVE_ID).endMenu().build(); final PlaceRequest placeRequest = new DefaultPlaceRequest(PERSPECTIVE_ID); final PerspectiveActivity perspectiveActivity = mock(PerspectiveActivity.class); final PerspectiveChange perspectiveChange = new PerspectiveChange(placeRequest, null, null, PERSPECTIVE_ID); when(perspectiveActivity.getPlace()).thenReturn(placeRequest); when(perspectiveActivity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(authzManager.authorize(any(Resource.class), eq(identity))).thenReturn(true); presenter.addMenus(menus); presenter.onPerspectiveChange(perspectiveChange); verify(view).selectMenuItem(PERSPECTIVE_ID); }
@Test public void testAddContextMenuWithPermission() { final MenuPosition position = MenuPosition.LEFT; final Menus contextMenus = MenuFactory.newSimpleItem(NAME).endMenu().build(); final PerspectiveActivity activity = mock(PerspectiveActivity.class); final PlaceRequest placeRequest = mock(PlaceRequest.class); when(activity.getIdentifier()).thenReturn(PERSPECTIVE_ID); doAnswer(invocationOnMock -> { invocationOnMock.getArgumentAt(0, Consumer.class).accept(contextMenus); return null; }).when(activity).getMenus(any()); when(activity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(authzManager.authorize(contextMenus.getItems().get(0), identity)).thenReturn(true); when(activityManager.getActivity(placeRequest)).thenReturn(activity); presenter.onPerspectiveChange(new PerspectiveChange(placeRequest, null, contextMenus, PERSPECTIVE_ID)); verify(authzManager).authorize(contextMenus.getItems().get(0), identity); verify(view).clearContextMenu(); verify(view).addContextMenuItem(eq(PERSPECTIVE_ID), anyString(), eq(NAME), isNull(String.class), any(Command.class), eq(position)); }
@Test public void testAddContextMenuWithoutPermission() { final Menus contextMenus = MenuFactory.newSimpleItem(NAME).endMenu().build(); final PerspectiveActivity activity = mock(PerspectiveActivity.class); final PlaceRequest placeRequest = mock(PlaceRequest.class); when(activity.getIdentifier()).thenReturn(PERSPECTIVE_ID); doAnswer(invocationOnMock -> { invocationOnMock.getArgumentAt(0, Consumer.class).accept(contextMenus); return null; }).when(activity).getMenus(any()); when(activity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(authzManager.authorize(contextMenus.getItems().get(0), identity)).thenReturn(false); when(activityManager.getActivity(placeRequest)).thenReturn(activity); presenter.onPerspectiveChange(new PerspectiveChange(placeRequest, null, contextMenus, PERSPECTIVE_ID)); verify(authzManager).authorize(contextMenus.getItems().get(0), identity); verify(view).clearContextMenu(); verify(view, never()).addContextMenuItem(anyString(), anyString(), anyString(), anyString(), any(Command.class), any(MenuPosition.class)); }
@Test public void testSetupEnableDisableContextMenuItem() { final Menus contextMenus = MenuFactory.newSimpleItem(NAME).endMenu().build(); final PerspectiveActivity activity = mock(PerspectiveActivity.class); final PlaceRequest placeRequest = mock(PlaceRequest.class); when(activity.getIdentifier()).thenReturn(PERSPECTIVE_ID); doAnswer(invocationOnMock -> { invocationOnMock.getArgumentAt(0, Consumer.class).accept(contextMenus); return null; }).when(activity).getMenus(any()); when(activity.isType(ActivityResourceType.PERSPECTIVE.name())).thenReturn(true); when(authzManager.authorize(contextMenus.getItems().get(0), identity)).thenReturn(true); when(activityManager.getActivity(placeRequest)).thenReturn(activity); presenter.onPerspectiveChange(new PerspectiveChange(placeRequest, null, contextMenus, PERSPECTIVE_ID)); verify(view).enableContextMenuItem(anyString(), eq(true)); contextMenus.getItems().get(0).setEnabled(true); verify(view, times(2)).enableContextMenuItem(anyString(), eq(true)); contextMenus.getItems().get(0).setEnabled(false); verify(view).enableContextMenuItem(anyString(), eq(false)); }