use of com.vaadin.flow.server.MockServletServiceSessionSetup in project flow by vaadin.
the class JavaScriptBootstrapHandlerTest method setup.
@Before
public void setup() throws Exception {
mocks = new MockServletServiceSessionSetup();
response = mocks.createResponse();
session = mocks.getSession();
jsInitHandler = new JavaScriptBootstrapHandler();
}
use of com.vaadin.flow.server.MockServletServiceSessionSetup in project flow by vaadin.
the class UidlWriterTest method initializeUIForDependenciesTest.
private UI initializeUIForDependenciesTest(UI ui) throws Exception {
mocks = new MockServletServiceSessionSetup();
VaadinServletContext context = (VaadinServletContext) mocks.getService().getContext();
Lookup lookup = context.getAttribute(Lookup.class);
Mockito.when(lookup.lookup(RoutePathProvider.class)).thenReturn(new RoutePathProviderImpl());
VaadinSession session = mocks.getSession();
session.lock();
ui.getInternals().setSession(session);
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getInternals().getRouter().getRegistry());
routeConfiguration.update(() -> {
routeConfiguration.getHandledRegistry().clean();
routeConfiguration.setAnnotatedRoute(BaseClass.class);
});
for (String type : new String[] { "html", "js", "css" }) {
mocks.getServlet().addServletContextResource("inline." + type, "inline." + type);
}
HttpServletRequest servletRequestMock = mock(HttpServletRequest.class);
VaadinServletRequest vaadinRequestMock = mock(VaadinServletRequest.class);
when(vaadinRequestMock.getHttpServletRequest()).thenReturn(servletRequestMock);
ui.doInit(vaadinRequestMock, 1);
ui.getInternals().getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(vaadinRequestMock));
return ui;
}
use of com.vaadin.flow.server.MockServletServiceSessionSetup in project flow by vaadin.
the class IndexHtmlRequestHandlerTest method setUp.
@Before
public void setUp() throws Exception {
mocks = new MockServletServiceSessionSetup();
service = mocks.getService();
session = mocks.getSession();
response = Mockito.mock(VaadinResponse.class);
responseOutput = new ByteArrayOutputStream();
Mockito.when(response.getOutputStream()).thenReturn(responseOutput);
deploymentConfiguration = mocks.getDeploymentConfiguration();
deploymentConfiguration.setEnableDevServer(false);
deploymentConfiguration.useDeprecatedV14Bootstrapping(false);
indexHtmlRequestHandler = new IndexHtmlRequestHandler();
context = Mockito.mock(VaadinContext.class);
springTokenString = UUID.randomUUID().toString();
}
use of com.vaadin.flow.server.MockServletServiceSessionSetup in project flow by vaadin.
the class VaadinAppShellInitializerTest method setup.
@Before
public void setup() throws Exception {
logger = mockLog(VaadinAppShellInitializer.class);
mocks = new MockServletServiceSessionSetup();
servletContext = mocks.getServletContext();
appConfig = mockApplicationConfiguration();
Lookup lookup = (Lookup) servletContext.getAttribute(Lookup.class.getName());
Mockito.when(lookup.lookup(AppShellPredicate.class)).thenReturn(AppShellConfigurator.class::isAssignableFrom);
attributeMap.put(Lookup.class.getName(), servletContext.getAttribute(Lookup.class.getName()));
attributeMap.put(ApplicationConfiguration.class.getName(), appConfig);
service = mocks.getService();
Mockito.when(servletContext.getAttribute(Mockito.anyString())).then(invocationOnMock -> attributeMap.get(invocationOnMock.getArguments()[0].toString()));
Mockito.doAnswer(invocationOnMock -> attributeMap.put(invocationOnMock.getArguments()[0].toString(), invocationOnMock.getArguments()[1])).when(servletContext).setAttribute(Mockito.anyString(), Mockito.any());
ServletRegistration registration = Mockito.mock(ServletRegistration.class);
context = new VaadinServletContext(servletContext);
classes = new HashSet<>();
Map<String, ServletRegistration> registry = new HashMap<>();
registry.put("foo", registration);
Mockito.when(servletContext.getServletRegistrations()).thenReturn((Map) registry);
Mockito.when(servletContext.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
initializer = new VaadinAppShellInitializer();
document = Document.createShell("");
pushConfiguration = Mockito.mock(PushConfiguration.class);
}
use of com.vaadin.flow.server.MockServletServiceSessionSetup in project flow by vaadin.
the class ComponentTest method setup.
@Before
public void setup() throws Exception {
divWithTextComponent = new TestComponent(ElementFactory.createDiv("Test component"));
parentDivComponent = new TestComponent(ElementFactory.createDiv());
child1SpanComponent = new TestComponent(ElementFactory.createSpan("Span"));
child2InputComponent = new TestComponent(ElementFactory.createInput());
parentDivComponent.getElement().appendChild(child1SpanComponent.getElement(), child2InputComponent.getElement());
mocks = new MockServletServiceSessionSetup();
VaadinSession session = mocks.getSession();
ui = new UI() {
@Override
public VaadinSession getSession() {
return session;
}
};
ui.getInternals().setSession(session);
UI.setCurrent(ui);
}
Aggregations