use of com.vaadin.tests.util.MockDeploymentConfiguration in project flow by vaadin.
the class BootstrapHandlerDependenciesTest method setup.
@Before
public void setup() {
BootstrapHandler.clientEngineFile = "foobar";
DeploymentConfiguration deploymentConfiguration = new MockDeploymentConfiguration();
service = Mockito.spy(new MockVaadinServletService(deploymentConfiguration));
when(service.getResourceAsStream(anyString())).thenAnswer(invocation -> new ByteArrayInputStream(((String) invocation.getArguments()[0]).getBytes()));
HttpServletRequest servletRequestMock = mock(HttpServletRequest.class);
VaadinServletRequest vaadinRequestMock = mock(VaadinServletRequest.class);
when(vaadinRequestMock.getHttpServletRequest()).thenReturn(servletRequestMock);
service.setCurrentInstances(vaadinRequestMock, mock(VaadinResponse.class));
Mockito.when(service.getDependencyFilters()).thenReturn(Collections.emptyList());
session = new MockVaadinSession(service);
session.lock();
session.setConfiguration(deploymentConfiguration);
VaadinUriResolverFactory factory = Mockito.mock(VaadinUriResolverFactory.class);
VaadinUriResolver vaadinUriResolver = Mockito.mock(VaadinUriResolver.class);
Mockito.when(factory.getUriResolver(Mockito.any())).thenReturn(vaadinUriResolver);
Mockito.when(vaadinUriResolver.resolveVaadinUri(Mockito.anyString())).thenAnswer(i -> i.getArguments()[0]);
Mockito.doAnswer(invocation -> invocation.getArguments()[1]).when(factory).toServletContextPath(Mockito.any(), Mockito.anyString());
session.setAttribute(VaadinUriResolverFactory.class, factory);
VaadinSession.setCurrent(session);
}
use of com.vaadin.tests.util.MockDeploymentConfiguration in project flow by vaadin.
the class BootstrapHandlerTest method setup.
@Before
public void setup() {
TestRouteRegistry routeRegistry = new TestRouteRegistry();
BootstrapHandler.clientEngineFile = "foobar";
testUI = new TestUI();
deploymentConfiguration = new MockDeploymentConfiguration("test/");
service = Mockito.spy(new MockVaadinServletService(deploymentConfiguration));
Mockito.when(service.getRouteRegistry()).thenReturn(routeRegistry);
Mockito.when(service.getRouter()).thenReturn(new Router(routeRegistry) {
@Override
public void initializeUI(UI ui, VaadinRequest initRequest) {
// injected
if (routeRegistry.hasNavigationTargets()) {
super.initializeUI(ui, initRequest);
}
}
});
session = Mockito.spy(new MockVaadinSession(service));
session.lock();
session.setConfiguration(deploymentConfiguration);
testUI.getInternals().setSession(session);
browser = Mockito.mock(WebBrowser.class);
Mockito.when(browser.isEs6Supported()).thenReturn(false);
Mockito.when(session.getBrowser()).thenReturn(browser);
}
use of com.vaadin.tests.util.MockDeploymentConfiguration in project flow by vaadin.
the class UidlWriterTest method initializeUIForDependenciesTest.
private UI initializeUIForDependenciesTest(UI ui) {
ServletContext context = Mockito.mock(ServletContext.class);
VaadinServletService service = new VaadinServletService(new VaadinServlet() {
@Override
public ServletContext getServletContext() {
return context;
}
}, new MockDeploymentConfiguration()) {
RouterInterface router = new com.vaadin.flow.router.legacy.Router();
@Override
public RouterInterface getRouter() {
return router;
}
@Override
public Iterable<DependencyFilter> getDependencyFilters() {
return Collections.emptyList();
}
};
service.getRouter().reconfigure(conf -> {
conf.setRoute("", BaseClass.class);
conf.setParentView(BaseClass.class, ParentClass.class);
conf.setParentView(ParentClass.class, SuperParentClass.class);
});
MockVaadinSession session = new MockVaadinSession(service);
session.lock();
ui.getInternals().setSession(session);
when(service.getResourceAsStream(anyString())).thenAnswer(invocation -> new ByteArrayInputStream(((String) invocation.getArguments()[0]).getBytes()));
HttpServletRequest servletRequestMock = mock(HttpServletRequest.class);
VaadinServletRequest vaadinRequestMock = mock(VaadinServletRequest.class);
when(vaadinRequestMock.getHttpServletRequest()).thenReturn(servletRequestMock);
service.setCurrentInstances(vaadinRequestMock, mock(VaadinResponse.class));
ui.doInit(vaadinRequestMock, 1);
factory = mock(VaadinUriResolverFactory.class);
VaadinUriResolver vaadinUriResolver = Mockito.mock(VaadinUriResolver.class);
Mockito.when(factory.getUriResolver(any())).thenReturn(vaadinUriResolver);
Mockito.when(vaadinUriResolver.resolveVaadinUri(anyString())).thenAnswer(invocation -> invocation.getArguments()[0]);
doAnswer(invocation -> invocation.getArguments()[1]).when(factory).toServletContextPath(any(), anyString());
session.setAttribute(VaadinUriResolverFactory.class, factory);
VaadinSession.setCurrent(session);
return ui;
}
use of com.vaadin.tests.util.MockDeploymentConfiguration in project flow by vaadin.
the class ThemeUrlResolverTest method init.
@Before
public void init() throws Exception {
assert VaadinSession.getCurrent() == null : "Required no current vaadin session.";
assert VaadinRequest.getCurrent() == null : "Required no current vaadin request.";
MockitoAnnotations.initMocks(this);
servlet = new VaadinServlet() {
@Override
protected DeploymentConfiguration createDeploymentConfiguration() throws ServletException {
return mockDeploymentConfiguration;
}
};
Properties initParameters = new Properties();
Mockito.when(servletConfig.getServletContext()).thenReturn(servletContext);
Mockito.when(servletConfig.getInitParameterNames()).thenReturn((Enumeration<String>) initParameters.propertyNames());
Mockito.when(servletContext.getInitParameterNames()).thenReturn((Enumeration<String>) initParameters.propertyNames());
Mockito.when(servletContext.getResource(Mockito.anyString())).thenAnswer(i -> new URL("http://localhost" + i.getArguments()[0]));
servlet.init(servletConfig);
Mockito.when(session.getAttribute(VaadinUriResolverFactory.class)).thenReturn(uriResolverFactory);
Mockito.when(uriResolverFactory.getUriResolver(Mockito.any())).thenReturn(vaadinUriResolver);
Mockito.when(vaadinUriResolver.resolveVaadinUri(Mockito.anyString())).thenAnswer(i -> i.getArguments()[0]);
VaadinSession.setCurrent(session);
CurrentInstance.set(VaadinRequest.class, request);
}
Aggregations