Search in sources :

Example 1 with VaadinRequest

use of com.vaadin.flow.server.VaadinRequest in project flow by vaadin.

the class RouterTest method requestWithPathInfo.

private static VaadinRequest requestWithPathInfo(String pathInfo) {
    VaadinRequest request = Mockito.mock(VaadinRequest.class);
    Mockito.when(request.getPathInfo()).thenReturn(pathInfo);
    return request;
}
Also used : VaadinRequest(com.vaadin.flow.server.VaadinRequest)

Example 2 with VaadinRequest

use of com.vaadin.flow.server.VaadinRequest in project flow by vaadin.

the class RouterTest method testChangeLocation.

@Test
public void testChangeLocation() {
    UI ui = new RouterTestUI();
    Router router = new Router();
    TestResolver resolver = new TestResolver();
    router.reconfigure(c -> c.setResolver(resolver));
    VaadinRequest request = requestWithPathInfo(null);
    router.initializeUI(ui, request);
    Assert.assertEquals(Arrays.asList(""), resolver.resolvedLocation.get().getSegments());
    resolver.resolvedLocation.set(null);
    resolver.handledEvent.set(null);
    ui.getPage().getHistory().getHistoryStateChangeHandler().onHistoryStateChange(new HistoryStateChangeEvent(ui.getPage().getHistory(), null, new Location("foo"), NavigationTrigger.HISTORY));
    Assert.assertEquals(Arrays.asList("foo"), resolver.resolvedLocation.get().getSegments());
}
Also used : HistoryStateChangeEvent(com.vaadin.flow.component.page.History.HistoryStateChangeEvent) UI(com.vaadin.flow.component.UI) Router(com.vaadin.flow.router.legacy.Router) VaadinRequest(com.vaadin.flow.server.VaadinRequest) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 3 with VaadinRequest

use of com.vaadin.flow.server.VaadinRequest in project flow by vaadin.

the class BasicElementStateProviderTest method supportsUIRootNode.

@Test
public void supportsUIRootNode() {
    BasicElementStateProvider provider = BasicElementStateProvider.get();
    UI ui = new UI() {

        @Override
        protected void init(VaadinRequest request) {
        }
    };
    StateNode rootNode = ui.getInternals().getStateTree().getRootNode();
    Assert.assertTrue(provider.supports(rootNode));
}
Also used : UI(com.vaadin.flow.component.UI) StateNode(com.vaadin.flow.internal.StateNode) VaadinRequest(com.vaadin.flow.server.VaadinRequest) BasicElementStateProvider(com.vaadin.flow.dom.impl.BasicElementStateProvider) Test(org.junit.Test)

Example 4 with VaadinRequest

use of com.vaadin.flow.server.VaadinRequest in project flow by vaadin.

the class LocaleUtil method getLocaleMatchByLanguage.

/**
 * Get the locale matching the language of the request locale in the
 * provided locales.
 *
 * @param request
 *            request to get locale for
 * @param providedLocales
 *            application provided locales
 * @return found locale or null if no matches by language
 */
public static Optional<Locale> getLocaleMatchByLanguage(VaadinRequest request, List<Locale> providedLocales) {
    Locale foundLocale = null;
    Enumeration<Locale> locales = request.getLocales();
    while (locales.hasMoreElements()) {
        Locale locale = locales.nextElement();
        Optional<Locale> matching = providedLocales.stream().filter(providedLocale -> providedLocale.getLanguage().equals(locale.getLanguage())).findFirst();
        if (matching.isPresent()) {
            foundLocale = matching.get();
            break;
        }
    }
    return Optional.ofNullable(foundLocale);
}
Also used : Locale(java.util.Locale) List(java.util.List) Enumeration(java.util.Enumeration) Locale(java.util.Locale) Optional(java.util.Optional) VaadinRequest(com.vaadin.flow.server.VaadinRequest)

Example 5 with VaadinRequest

use of com.vaadin.flow.server.VaadinRequest in project flow by vaadin.

the class CustomUIClassLoaderTest method createRequestMock.

private static VaadinRequest createRequestMock(ClassLoader classloader) {
    // Mock a VaadinService to give the passed classloader
    VaadinService configurationMock = EasyMock.createMock(VaadinService.class);
    EasyMock.expect(configurationMock.getDeploymentConfiguration()).andReturn(createConfigurationMock());
    EasyMock.expect(configurationMock.getClassLoader()).andReturn(classloader);
    // Mock a VaadinRequest to give the mocked vaadin service
    VaadinRequest requestMock = EasyMock.createMock(VaadinRequest.class);
    EasyMock.expect(requestMock.getService()).andReturn(configurationMock);
    EasyMock.expect(requestMock.getService()).andReturn(configurationMock);
    EasyMock.expect(requestMock.getService()).andReturn(configurationMock);
    EasyMock.replay(configurationMock, requestMock);
    return requestMock;
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) VaadinRequest(com.vaadin.flow.server.VaadinRequest)

Aggregations

VaadinRequest (com.vaadin.flow.server.VaadinRequest)9 Test (org.junit.Test)5 VaadinService (com.vaadin.flow.server.VaadinService)4 UI (com.vaadin.flow.component.UI)3 Location (com.vaadin.flow.router.Location)3 Router (com.vaadin.flow.router.legacy.Router)3 VaadinResponse (com.vaadin.flow.server.VaadinResponse)3 VaadinServlet (com.vaadin.flow.server.VaadinServlet)3 ServletException (javax.servlet.ServletException)3 HistoryStateChangeEvent (com.vaadin.flow.component.page.History.HistoryStateChangeEvent)2 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)2 MockServletConfig (com.vaadin.flow.server.MockServletConfig)2 List (java.util.List)2 Optional (java.util.Optional)2 ServletConfig (javax.servlet.ServletConfig)2 NotThreadSafe (net.jcip.annotations.NotThreadSafe)2 After (org.junit.After)2 Assert (org.junit.Assert)2 Mockito (org.mockito.Mockito)2 Tag (com.vaadin.flow.component.Tag)1