Java Code Examples for com.vaadin.ui.UI#setCurrent()

The following examples show how to use com.vaadin.ui.UI#setCurrent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HawkbitCommonUtilTest.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@Description("getCurrentLocale should return the set Locale in the UI if found, otherwise the default System Locale")
public void getCurrentLocaleShouldReturnSetUILocaleOrDefaultSystemLocale() {
    final UI ui = Mockito.mock(UI.class);

    // GIVEN
    UI.setCurrent(null);
    // WHEN
    final Locale currentLocale = HawkbitCommonUtil.getCurrentLocale();
    // THEN
    assertEquals(Locale.getDefault(), currentLocale);

    // GIVEN
    UI.setCurrent(ui);
    doReturn(Locale.GERMAN).when(ui).getLocale();
    // WHEN
    final Locale currentLocale2 = HawkbitCommonUtil.getCurrentLocale();
    // THEN
    assertEquals(Locale.GERMAN, currentLocale2);
}
 
Example 2
Source File: DecisionFlowValueChangeListenerTest.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Selection value change test.
 */
@Test
public void selectionValueChangeTest() {
	final String pageName = "pageName";
	final String pageId = "pageId";
	final DecisionFlowValueChangeListener listener = new DecisionFlowValueChangeListener(pageName, pageId);
	final UI uiMock = Mockito.mock(UI.class);
	UI.setCurrent(uiMock);
	
	final Navigator navigatorMock = Mockito.mock(Navigator.class);
	Mockito.when(uiMock.getNavigator()).thenReturn(navigatorMock);		
			
	final ValueChangeEvent event = Mockito.mock(ValueChangeEvent.class);
	
	final HasValue hasValue = Mockito.mock(HasValue.class);
	Mockito.when(hasValue.isEmpty()).thenReturn(false);
	
	Mockito.when(event.getSource()).thenReturn(hasValue);
	
	final String value = "value";
	Mockito.when(event.getValue()).thenReturn("value");
		
	listener.valueChange(event);
	
	Mockito.verify(navigatorMock, times(1)).navigateTo(pageName + "/CHARTS/DECISION_FLOW_CHART/" + pageId + "[" +value + "]");
}
 
Example 3
Source File: RuleViolationPageItemRendererClickListenerTest.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Click party test.
 */
@Test
public void clickPartyTest() {
	final RuleViolationPageItemRendererClickListener listener = new RuleViolationPageItemRendererClickListener();
	final UI uiMock = Mockito.mock(UI.class);
	UI.setCurrent(uiMock);
	
	final Navigator navigatorMock = Mockito.mock(Navigator.class);
	Mockito.when(uiMock.getNavigator()).thenReturn(navigatorMock);		
			
	final RendererClickEvent event = Mockito.mock(RendererClickEvent.class);
	Mockito.when(event.getItem()).thenReturn(new RuleViolation("partyid", null, ResourceType.PARTY, null, null, null, null, null));
		
	listener.click(event);
	
	Mockito.verify(navigatorMock, times(1)).navigateTo("party/partyid");
}
 
Example 4
Source File: RuleViolationPageItemRendererClickListenerTest.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Click politician test.
 */
@Test
public void clickPoliticianTest() {
	final RuleViolationPageItemRendererClickListener listener = new RuleViolationPageItemRendererClickListener();
	final UI uiMock = Mockito.mock(UI.class);
	UI.setCurrent(uiMock);
	
	final Navigator navigatorMock = Mockito.mock(Navigator.class);
	Mockito.when(uiMock.getNavigator()).thenReturn(navigatorMock);		
			
	final RendererClickEvent event = Mockito.mock(RendererClickEvent.class);
	Mockito.when(event.getItem()).thenReturn(new RuleViolation("personid", null, ResourceType.POLITICIAN, null, null, null, null, null));
		
	listener.click(event);
	
	Mockito.verify(navigatorMock, times(1)).navigateTo("politician/personid");
}
 
Example 5
Source File: PageItemPropertyClickListenerTest.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Check correct page id click success test.
 */
@Test
public void checkCorrectPageIdClickSuccessTest() {
	final PageItemPropertyClickListener pageItemPropertyClickListener = new PageItemPropertyClickListener(UserViews.POLITICIAN_VIEW_NAME,"personId");

	final String personIdValue = "personId";
	final ViewRiksdagenPolitician riksdagenPolitician = new ViewRiksdagenPolitician().withPersonId(personIdValue);
	final String pageId = pageItemPropertyClickListener.getPageId(riksdagenPolitician);

	assertEquals(personIdValue, pageId);
	
	final UI uiMock = Mockito.mock(UI.class);
	UI.setCurrent(uiMock);
	
	final Navigator navigatorMock = Mockito.mock(Navigator.class);
	Mockito.when(uiMock.getNavigator()).thenReturn(navigatorMock);		
			
	pageItemPropertyClickListener.click(new RendererClickEvent(new Grid(), riksdagenPolitician, null, null) {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;});
	
	Mockito.verify(navigatorMock, times(1)).navigateTo(UserViews.POLITICIAN_VIEW_NAME + "/personId");
}
 
Example 6
Source File: ComplianceCheckPageItemRendererClickListenerTest.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Click party test.
 */
@Test
public void clickPartyTest() {
	final ComplianceCheckPageItemRendererClickListener listener = new ComplianceCheckPageItemRendererClickListener();
	final UI uiMock = Mockito.mock(UI.class);
	UI.setCurrent(uiMock);
	
	final Navigator navigatorMock = Mockito.mock(Navigator.class);
	Mockito.when(uiMock.getNavigator()).thenReturn(navigatorMock);		
			
	final RendererClickEvent event = Mockito.mock(RendererClickEvent.class);
	Mockito.when(event.getItem()).thenReturn(new PartyComplianceCheckImpl(new ViewRiksdagenPartySummary().withParty("partyid"), null, null, null));
		
	listener.click(event);
	
	Mockito.verify(navigatorMock, times(1)).navigateTo("party/partyid");
}
 
Example 7
Source File: ComplianceCheckPageItemRendererClickListenerTest.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Click politician test.
 */
@Test
public void clickPoliticianTest() {
	final ComplianceCheckPageItemRendererClickListener listener = new ComplianceCheckPageItemRendererClickListener();
	final UI uiMock = Mockito.mock(UI.class);
	UI.setCurrent(uiMock);
	
	final Navigator navigatorMock = Mockito.mock(Navigator.class);
	Mockito.when(uiMock.getNavigator()).thenReturn(navigatorMock);		
			
	final RendererClickEvent event = Mockito.mock(RendererClickEvent.class);
	Mockito.when(event.getItem()).thenReturn(new PoliticianComplianceCheckImpl(new ViewRiksdagenPolitician().withPersonId("personid"), null, null, null));
		
	listener.click(event);
	
	Mockito.verify(navigatorMock, times(1)).navigateTo("politician/personid");
}
 
Example 8
Source File: TestUiEnvironment.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void setupVaadinUi() {
    AutowireCapableBeanFactory injector = getInjector();

    app = new DefaultApp();
    setThemeConstants(app, new ThemeConstants(new HashMap<>()));
    setCookies(app, new AppCookies());

    Connection connection = new ConnectionImpl();
    injector.autowireBean(connection);

    setConnection(app, connection);

    VaadinSession vaadinSession = new TestVaadinSession(new WebBrowser(), getLocale());

    vaadinSession.setAttribute(App.class, app);
    vaadinSession.setAttribute(App.NAME, app);
    vaadinSession.setAttribute(Connection.class, connection);
    vaadinSession.setAttribute(Connection.NAME, connection);
    vaadinSession.setAttribute(UserSession.class, sessionSource.getSession());

    VaadinSession.setCurrent(vaadinSession);

    injector.autowireBean(app);

    ui = new AppUI();
    injector.autowireBean(ui);

    // setup UI

    ConnectorTracker connectorTracker = new TestConnectorTracker(ui);

    try {
        getDeclaredField(UI.class, "connectorTracker", true)
                .set(ui, connectorTracker);
        getDeclaredField(UI.class, "session", true)
                .set(ui, vaadinSession);
    } catch (Exception e) {
        throw new RuntimeException("Unable to init Vaadin UI state", e);
    }

    UI.setCurrent(ui);

    VaadinRequest vaadinRequest = new TestVaadinRequest();
    ui.getPage().init(vaadinRequest);

    initUi(ui, vaadinRequest);
}
 
Example 9
Source File: AutoCompleteTextFieldComponent.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void run() {
    UI.setCurrent(current);
    eventBus.publish(this, CustomFilterUIEvent.FILTER_TARGET_BY_QUERY);
}
 
Example 10
Source File: TestUiEnvironment.java    From cuba with Apache License 2.0 3 votes vote down vote up
protected void cleanupEnvironment() {
    resetScreens();

    UI.setCurrent(null);
    VaadinSession.setCurrent(null);

    TestServiceProxy.clear();

    sessionSource.setSession(null);

    TestClientCacheManager clientCacheManager = container.getBean(ClientCacheManager.NAME);
    clientCacheManager.getCache().remove(DynamicAttributesCacheStrategy.NAME);

    container.after();
}