Search in sources :

Example 1 with MockServletServiceSessionSetup

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();
}
Also used : MockServletServiceSessionSetup(com.vaadin.flow.server.MockServletServiceSessionSetup) Before(org.junit.Before)

Example 2 with MockServletServiceSessionSetup

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;
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) VaadinSession(com.vaadin.flow.server.VaadinSession) RouteConfiguration(com.vaadin.flow.router.RouteConfiguration) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) RoutePathProviderImpl(com.vaadin.flow.server.MockVaadinContext.RoutePathProviderImpl) Lookup(com.vaadin.flow.di.Lookup) MockServletServiceSessionSetup(com.vaadin.flow.server.MockServletServiceSessionSetup)

Example 3 with MockServletServiceSessionSetup

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();
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) VaadinContext(com.vaadin.flow.server.VaadinContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MockServletServiceSessionSetup(com.vaadin.flow.server.MockServletServiceSessionSetup) Before(org.junit.Before)

Example 4 with MockServletServiceSessionSetup

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);
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) PushConfiguration(com.vaadin.flow.component.PushConfiguration) AppShellConfigurator(com.vaadin.flow.component.page.AppShellConfigurator) ServletRegistration(javax.servlet.ServletRegistration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Lookup(com.vaadin.flow.di.Lookup) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockServletServiceSessionSetup(com.vaadin.flow.server.MockServletServiceSessionSetup) Before(org.junit.Before)

Example 5 with MockServletServiceSessionSetup

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);
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) MockUI(com.vaadin.tests.util.MockUI) MockServletServiceSessionSetup(com.vaadin.flow.server.MockServletServiceSessionSetup) Before(org.junit.Before)

Aggregations

MockServletServiceSessionSetup (com.vaadin.flow.server.MockServletServiceSessionSetup)7 Before (org.junit.Before)6 Lookup (com.vaadin.flow.di.Lookup)2 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)2 VaadinSession (com.vaadin.flow.server.VaadinSession)2 PushConfiguration (com.vaadin.flow.component.PushConfiguration)1 AppShellConfigurator (com.vaadin.flow.component.page.AppShellConfigurator)1 RouteConfiguration (com.vaadin.flow.router.RouteConfiguration)1 RoutePathProviderImpl (com.vaadin.flow.server.MockVaadinContext.RoutePathProviderImpl)1 VaadinContext (com.vaadin.flow.server.VaadinContext)1 VaadinResponse (com.vaadin.flow.server.VaadinResponse)1 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)1 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)1 MockUI (com.vaadin.tests.util.MockUI)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ServletRegistration (javax.servlet.ServletRegistration)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1