Search in sources :

Example 1 with WrappedHttpSession

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

the class DefaultTemplateParserTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    VaadinSession session = Mockito.mock(VaadinSession.class);
    factory = (VaadinUriResolverFactory) vaadinRequest -> resolver;
    Mockito.when(session.getAttribute(VaadinUriResolverFactory.class)).thenReturn(factory);
    Mockito.when(service.getDependencyFilters()).thenReturn(Collections.emptyList());
    WrappedHttpSession wrappedSession = Mockito.mock(WrappedHttpSession.class);
    HttpSession httpSession = Mockito.mock(HttpSession.class);
    Mockito.when(wrappedSession.getHttpSession()).thenReturn(httpSession);
    servlet = new VaadinServlet() {

        @Override
        protected VaadinServletService createServletService() throws ServletException, ServiceException {
            return service;
        }

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }
    };
    Mockito.when(service.getServlet()).thenReturn(servlet);
    Mockito.when(resolver.resolveVaadinUri("/bar.html")).thenReturn("bar.html");
    Mockito.when(resolver.resolveVaadinUri("/bar1.html")).thenReturn("bar1.html");
    Mockito.when(resolver.resolveVaadinUri("/bundle.html")).thenReturn("bundle.html");
    Mockito.when(request.getWrappedSession()).thenReturn(wrappedSession);
    Mockito.when(request.getServletPath()).thenReturn("");
    Mockito.when(servletContext.getResourceAsStream("/bar.html")).thenReturn(new ByteArrayInputStream("<dom-module id='bar'></dom-module>".getBytes(StandardCharsets.UTF_8)));
    Mockito.when(servletContext.getResourceAsStream("/bar1.html")).thenReturn(new ByteArrayInputStream("<dom-module id='foo'></dom-module>".getBytes(StandardCharsets.UTF_8)));
    Mockito.when(servletContext.getResourceAsStream("/bundle.html")).thenReturn(getBundle(), getBundle(), getBundle());
    CurrentInstance.set(VaadinRequest.class, request);
    CurrentInstance.set(VaadinSession.class, session);
    CurrentInstance.set(VaadinService.class, service);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TemplateData(com.vaadin.flow.component.polymertemplate.TemplateParser.TemplateData) WrappedHttpSession(com.vaadin.flow.server.WrappedHttpSession) ServletException(javax.servlet.ServletException) Mock(org.mockito.Mock) CurrentInstance(com.vaadin.flow.internal.CurrentInstance) VaadinUriResolverFactory(com.vaadin.flow.server.VaadinUriResolverFactory) Comment(org.jsoup.nodes.Comment) VaadinUriResolver(com.vaadin.flow.shared.VaadinUriResolver) Dependency(com.vaadin.flow.shared.ui.Dependency) Type(com.vaadin.flow.shared.ui.Dependency.Type) Assert.assertThat(org.junit.Assert.assertThat) MockitoAnnotations(org.mockito.MockitoAnnotations) Tag(com.vaadin.flow.component.Tag) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(org.jsoup.nodes.Element) After(org.junit.After) DependencyFilter(com.vaadin.flow.server.DependencyFilter) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) Before(org.junit.Before) HttpSession(javax.servlet.http.HttpSession) VaadinSession(com.vaadin.flow.server.VaadinSession) Matchers.empty(org.hamcrest.Matchers.empty) VaadinServlet(com.vaadin.flow.server.VaadinServlet) Test(org.junit.Test) VaadinRequest(com.vaadin.flow.server.VaadinRequest) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) NotThreadSafe(net.jcip.annotations.NotThreadSafe) HtmlImport(com.vaadin.flow.component.dependency.HtmlImport) Node(org.jsoup.nodes.Node) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) VaadinService(com.vaadin.flow.server.VaadinService) LoadMode(com.vaadin.flow.shared.ui.LoadMode) ServletContext(javax.servlet.ServletContext) ModelClass(com.vaadin.flow.component.polymertemplate.PolymerTemplateTest.ModelClass) ServiceException(com.vaadin.flow.server.ServiceException) Assert(org.junit.Assert) Collections(java.util.Collections) VaadinServletService(com.vaadin.flow.server.VaadinServletService) ServletException(javax.servlet.ServletException) VaadinSession(com.vaadin.flow.server.VaadinSession) ServiceException(com.vaadin.flow.server.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream) WrappedHttpSession(com.vaadin.flow.server.WrappedHttpSession) HttpSession(javax.servlet.http.HttpSession) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinServlet(com.vaadin.flow.server.VaadinServlet) VaadinServletService(com.vaadin.flow.server.VaadinServletService) ServletContext(javax.servlet.ServletContext) WrappedHttpSession(com.vaadin.flow.server.WrappedHttpSession) Before(org.junit.Before)

Aggregations

Tag (com.vaadin.flow.component.Tag)1 HtmlImport (com.vaadin.flow.component.dependency.HtmlImport)1 ModelClass (com.vaadin.flow.component.polymertemplate.PolymerTemplateTest.ModelClass)1 TemplateData (com.vaadin.flow.component.polymertemplate.TemplateParser.TemplateData)1 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)1 DependencyFilter (com.vaadin.flow.server.DependencyFilter)1 ServiceException (com.vaadin.flow.server.ServiceException)1 VaadinRequest (com.vaadin.flow.server.VaadinRequest)1 VaadinService (com.vaadin.flow.server.VaadinService)1 VaadinServlet (com.vaadin.flow.server.VaadinServlet)1 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)1 VaadinServletService (com.vaadin.flow.server.VaadinServletService)1 VaadinSession (com.vaadin.flow.server.VaadinSession)1 VaadinUriResolverFactory (com.vaadin.flow.server.VaadinUriResolverFactory)1 WrappedHttpSession (com.vaadin.flow.server.WrappedHttpSession)1 VaadinUriResolver (com.vaadin.flow.shared.VaadinUriResolver)1 Dependency (com.vaadin.flow.shared.ui.Dependency)1 Type (com.vaadin.flow.shared.ui.Dependency.Type)1 LoadMode (com.vaadin.flow.shared.ui.LoadMode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1