Search in sources :

Example 1 with UI

use of com.vaadin.flow.component.UI in project flow by vaadin.

the class DataCommunicatorTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    ui = new MockUI();
    element = new Element("div");
    ui.getElement().appendChild(element);
    lastClear = null;
    lastSet = null;
    lastUpdateId = -1;
    update = new ArrayUpdater.Update() {

        @Override
        public void clear(int start, int length) {
            lastClear = Range.withLength(start, length);
        }

        @Override
        public void set(int start, List<JsonValue> items) {
            lastSet = Range.withLength(start, items.size());
        }

        @Override
        public void commit(int updateId) {
            lastUpdateId = updateId;
        }
    };
    Mockito.when(arrayUpdater.startUpdate(Mockito.anyInt())).thenReturn(update);
    dataCommunicator = new DataCommunicator<>(dataGenerator, arrayUpdater, data -> {
    }, element.getNode());
}
Also used : IntStream(java.util.stream.IntStream) VaadinSession(com.vaadin.flow.server.VaadinSession) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Mock(org.mockito.Mock) Test(org.junit.Test) VaadinRequest(com.vaadin.flow.server.VaadinRequest) Mockito(org.mockito.Mockito) MockitoAnnotations(org.mockito.MockitoAnnotations) JsonValue(elemental.json.JsonValue) List(java.util.List) Lock(java.util.concurrent.locks.Lock) Stream(java.util.stream.Stream) Element(com.vaadin.flow.dom.Element) VaadinService(com.vaadin.flow.server.VaadinService) UI(com.vaadin.flow.component.UI) Assert(org.junit.Assert) Before(org.junit.Before) Range(com.vaadin.flow.internal.Range) Element(com.vaadin.flow.dom.Element) JsonValue(elemental.json.JsonValue) Before(org.junit.Before)

Example 2 with UI

use of com.vaadin.flow.component.UI in project flow by vaadin.

the class VaadinUIScopeTest method mockUI.

private UI mockUI() {
    VaadinSession session = mockSession();
    RouterInterface routerIface = mock(RouterInterface.class);
    VaadinService service = session.getService();
    when(service.getRouter()).thenReturn(routerIface);
    ImmutableRouterConfiguration config = mock(ImmutableRouterConfiguration.class);
    when(routerIface.getConfiguration()).thenReturn(config);
    when(config.isConfigured()).thenReturn(false);
    UI ui = new UI();
    ui.getInternals().setSession(session);
    ui.doInit(null, 1);
    UI.setCurrent(ui);
    // prevent UI from being GCed.
    this.ui = ui;
    return ui;
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) SpringVaadinSession(com.vaadin.flow.spring.SpringVaadinSession) UI(com.vaadin.flow.component.UI) VaadinService(com.vaadin.flow.server.VaadinService) ImmutableRouterConfiguration(com.vaadin.flow.router.legacy.ImmutableRouterConfiguration) RouterInterface(com.vaadin.flow.router.RouterInterface)

Example 3 with UI

use of com.vaadin.flow.component.UI in project flow by vaadin.

the class InfoView method update.

private void update(UI ui) {
    VaadinSession session = ui.getSession();
    WebBrowser webBrowser = session.getBrowser();
    DeploymentConfiguration deploymentConfiguration = session.getConfiguration();
    List<String> device = new ArrayList<>();
    List<String> os = new ArrayList<>();
    List<String> browser = new ArrayList<>();
    removeAll();
    add(new NativeButton("Refresh", e -> {
        update(ui);
    }));
    header("Browser");
    info("Address", webBrowser.getAddress());
    add(device, "Android", webBrowser.isAndroid());
    add(device, "iOS", webBrowser.isIOS());
    add(device, "iPad", webBrowser.isIPad());
    add(device, "iPhone", webBrowser.isIPhone());
    add(device, "Windows Phone", webBrowser.isWindowsPhone());
    info("Device", device.stream().collect(Collectors.joining(", ")));
    add(os, "Linux", webBrowser.isLinux());
    add(os, "Mac", webBrowser.isMacOSX());
    add(os, "Windows", webBrowser.isWindows());
    info("Os", os.stream().collect(Collectors.joining(", ")));
    add(browser, "Touch device", webBrowser.isTouchDevice());
    add(browser, "Chrome", webBrowser.isChrome());
    add(browser, "Edge", webBrowser.isEdge());
    add(browser, "Firefox", webBrowser.isFirefox());
    add(browser, "IE", webBrowser.isIE());
    add(browser, "Safari", webBrowser.isSafari());
    info("Browser", browser.stream().collect(Collectors.joining(", ")));
    if (webBrowser.isTooOldToFunctionProperly()) {
        header("Browser is too old to function properly");
    }
    info("User-agent", webBrowser.getBrowserApplication());
    info("Browser major", webBrowser.getBrowserMajorVersion());
    info("Browser minor", webBrowser.getBrowserMinorVersion());
    info("Screen height", webBrowser.getScreenHeight());
    info("Screen width", webBrowser.getScreenWidth());
    info("Locale", webBrowser.getLocale());
    info("Secure connection (https)", webBrowser.isSecureConnection());
    separator();
    header("Push configuration");
    info("Push mode", ui.getPushConfiguration().getPushMode());
    info("Push transport", ui.getPushConfiguration().getTransport());
    separator();
    header("Deployment configuration");
    info("Heartbeat interval", deploymentConfiguration.getHeartbeatInterval());
    info("Router configurator class", deploymentConfiguration.getRouterConfiguratorClassName());
    info("UI class", deploymentConfiguration.getUIClassName());
    info("Close idle sessions", deploymentConfiguration.isCloseIdleSessions());
    info("Send URLs as parameters", deploymentConfiguration.isSendUrlsAsParameters());
    info("Sync id enabled", deploymentConfiguration.isSyncIdCheckEnabled());
    info("XSRF protection enabled", deploymentConfiguration.isXsrfProtectionEnabled());
    info("Production mode", deploymentConfiguration.isProductionMode());
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) Html(com.vaadin.flow.component.Html) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) ViewTestLayout(com.vaadin.flow.uitest.servlet.ViewTestLayout) Hr(com.vaadin.flow.component.html.Hr) Collectors(java.util.stream.Collectors) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) List(java.util.List) WebBrowser(com.vaadin.flow.server.WebBrowser) UI(com.vaadin.flow.component.UI) AttachEvent(com.vaadin.flow.component.AttachEvent) NativeButton(com.vaadin.flow.component.html.NativeButton) VaadinSession(com.vaadin.flow.server.VaadinSession) WebBrowser(com.vaadin.flow.server.WebBrowser) ArrayList(java.util.ArrayList) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 4 with UI

use of com.vaadin.flow.component.UI in project flow by vaadin.

the class BootstrapHandlerTest method uiInitialization_allRegisteredListenersAreNotified.

// UIInitListeners
@Test
public void uiInitialization_allRegisteredListenersAreNotified() {
    BootstrapHandler bootstrapHandler = new BootstrapHandler();
    VaadinResponse response = Mockito.mock(VaadinResponse.class);
    AtomicReference<UI> uiReference = new AtomicReference<>();
    Registration registration = service.addUIInitListener(event -> Assert.assertTrue("Atomic reference was not empty.", uiReference.compareAndSet(null, event.getUI())));
    final BootstrapContext context = bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
    Assert.assertEquals("Event UI didn't match initialized UI instance.", context.getUI(), uiReference.get());
    // unregister listener
    registration.remove();
    AtomicReference<UI> secondListenerReference = new AtomicReference<>();
    service.addUIInitListener(event -> Assert.assertTrue("Atomic reference did not contain previous UI.", uiReference.compareAndSet(context.getUI(), event.getUI())));
    service.addUIInitListener(event -> Assert.assertTrue("Atomic reference was not empty.", secondListenerReference.compareAndSet(null, event.getUI())));
    final BootstrapContext secondInit = bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
    Assert.assertEquals("Event UI didn't match initialized UI instance.", secondInit.getUI(), uiReference.get());
    Assert.assertEquals("Second event UI didn't match initialized UI instance.", secondInit.getUI(), secondListenerReference.get());
}
Also used : UI(com.vaadin.flow.component.UI) Registration(com.vaadin.flow.shared.Registration) AtomicReference(java.util.concurrent.atomic.AtomicReference) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Test(org.junit.Test)

Example 5 with UI

use of com.vaadin.flow.component.UI in project flow by vaadin.

the class BootstrapHandlerTest method uiInitialization_changingListenersOnEventWorks.

// UIInitListeners
@Test
public void uiInitialization_changingListenersOnEventWorks() {
    BootstrapHandler bootstrapHandler = new BootstrapHandler();
    VaadinResponse response = Mockito.mock(VaadinResponse.class);
    AtomicReference<UI> uiReference = new AtomicReference<>();
    Registration registration = service.addUIInitListener(event -> service.addUIInitListener(laterEvent -> uiReference.compareAndSet(null, laterEvent.getUI())));
    bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
    Assert.assertEquals("Event UI didn't match initialized UI instance.", null, uiReference.get());
    // unregister listener
    registration.remove();
    service.addUIInitListener(event -> registration.remove());
    final BootstrapContext secondInit = bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
    Assert.assertEquals("Event UI didn't match initialized UI instance.", secondInit.getUI(), uiReference.get());
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) Component(com.vaadin.flow.component.Component) JavaScript(com.vaadin.flow.component.dependency.JavaScript) Inline(com.vaadin.flow.component.page.Inline) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) TargetElement(com.vaadin.flow.component.page.TargetElement) Registration(com.vaadin.flow.shared.Registration) PageTitle(com.vaadin.flow.router.PageTitle) Router(com.vaadin.flow.router.Router) Route(com.vaadin.flow.router.Route) RouteAlias(com.vaadin.flow.router.RouteAlias) Theme(com.vaadin.flow.theme.Theme) Assert.assertThat(org.junit.Assert.assertThat) Locale(java.util.Locale) Element(org.jsoup.nodes.Element) After(org.junit.After) UI(com.vaadin.flow.component.UI) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Document(org.jsoup.nodes.Document) LoadMode(com.vaadin.flow.shared.ui.LoadMode) BodySize(com.vaadin.flow.component.page.BodySize) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Elements(org.jsoup.select.Elements) ApplicationConstants(com.vaadin.flow.shared.ApplicationConstants) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) Matchers(org.mockito.Matchers) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) VaadinUriResolver(com.vaadin.flow.shared.VaadinUriResolver) Dependency(com.vaadin.flow.shared.ui.Dependency) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) Tag(com.vaadin.flow.component.Tag) AbstractTheme(com.vaadin.flow.theme.AbstractTheme) Before(org.junit.Before) Text(com.vaadin.flow.component.Text) RouterLayout(com.vaadin.flow.router.RouterLayout) Html(com.vaadin.flow.component.Html) StyleSheet(com.vaadin.flow.component.dependency.StyleSheet) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) InlineTemplate(com.vaadin.flow.template.angular.InlineTemplate) HtmlImport(com.vaadin.flow.component.dependency.HtmlImport) Mockito(org.mockito.Mockito) Assert(org.junit.Assert) Collections(java.util.Collections) Viewport(com.vaadin.flow.component.page.Viewport) ParentLayout(com.vaadin.flow.router.ParentLayout) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) UI(com.vaadin.flow.component.UI) Registration(com.vaadin.flow.shared.Registration) AtomicReference(java.util.concurrent.atomic.AtomicReference) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Test(org.junit.Test)

Aggregations

UI (com.vaadin.flow.component.UI)128 Test (org.junit.Test)94 Element (com.vaadin.flow.dom.Element)38 Location (com.vaadin.flow.router.Location)16 StreamResource (com.vaadin.flow.server.StreamResource)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 Router (com.vaadin.flow.router.legacy.Router)12 Before (org.junit.Before)12 VaadinSession (com.vaadin.flow.server.VaadinSession)11 AngularTemplate (com.vaadin.flow.template.angular.AngularTemplate)11 JsonObject (elemental.json.JsonObject)11 StateNode (com.vaadin.flow.internal.StateNode)9 NavigationEvent (com.vaadin.flow.router.NavigationEvent)9 VaadinService (com.vaadin.flow.server.VaadinService)9 ArrayList (java.util.ArrayList)9 List (java.util.List)8 ClientDelegateHandlers (com.vaadin.flow.internal.nodefeature.ClientDelegateHandlers)7 IOException (java.io.IOException)7 WeakReference (java.lang.ref.WeakReference)7 Component (com.vaadin.flow.component.Component)6