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;
}
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());
}
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));
}
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);
}
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;
}
Aggregations