// Generic method that creates necessary VaadinSessin mock environment to be // able to test the BeanStoreRetrievalStrategy class. // To use it, call this method and write your test logic inside the // test method implemented from BeanStoreRetrievalStrategyTest interface. private synchronized void beanStoreTest( BeanStoreRetrievalStrategyTest test, boolean openVaadinSession) { WrappedSession wrappedSession = mock(WrappedSession.class); VaadinService vaadinService = mock(VaadinService.class); VaadinSession session = mock(VaadinSession.class); if (openVaadinSession) { when(session.getState()).thenReturn(VaadinSession.State.OPEN); } else { when(session.getState()).thenReturn(VaadinSession.State.CLOSED); } when(session.getSession()).thenReturn(wrappedSession); when(session.getService()).thenReturn(vaadinService); when(session.getSession().getId()).thenReturn(TEST_SESSION_ID); UIID uiid = new UIID(TEST_UIID); BeanStore beanStore = new BeanStore(TEST_BEAN_NAME); UIStore uiStore = mock(UIStore.class); when(session.getAttribute(UIStore.class)).thenReturn(uiStore); when(uiStore.getBeanStore(uiid)).thenReturn(beanStore); try { CurrentInstance.set(VaadinSession.class, session); CurrentInstance.set(UIID.class, uiid); test.test(session, uiStore, uiid); } finally { CurrentInstance.clearAll(); } }
private static WrappedSession getCurrentHttpSession() { VaadinSession s = VaadinSession.getCurrent(); if (s == null) { throw new IllegalStateException("No session found for current thread"); } return s.getSession(); }
/* (non-Javadoc) * @see com.mapping.configuration.ui.action.Action#exectuteAction() */ @Override public void exectuteAction() { IkasanAuthentication ikasanAuthentication = (IkasanAuthentication) VaadinService.getCurrentRequest() .getWrappedSession() .getAttribute(DashboardSessionValueConstants.USER); VaadinService.getCurrentRequest() .getWrappedSession() .setAttribute(DashboardSessionValueConstants.USER, null); this.visibilityGroup.setVisible(); this.editableGroup.setEditable(false); layout.removeComponent(this.logOutButton); layout.addComponent(this.loginButton, 2, 0); layout.addComponent(this.setupButton, 3, 0); layout.setComponentAlignment(this.setupButton, Alignment.MIDDLE_RIGHT); layout.setComponentAlignment(this.loginButton, Alignment.MIDDLE_RIGHT); this.layout.removeComponent(userLabel); VaadinSession vSession = VaadinSession.getCurrent(); WrappedSession httpSession = vSession.getSession(); this.navigationPanel.reset(); // Invalidate HttpSession httpSession.invalidate(); vSession.close(); systemEventService.logSystemEvent( SystemEventConstants.DASHBOARD_LOGOUT_CONSTANTS, "User logging out: " + ikasanAuthentication.getName(), ikasanAuthentication.getName()); // Redirect the user to the login/default Page Page.getCurrent().setLocation("/ikasan-dashboard"); }