Search in sources :

Example 61 with VaadinService

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

the class WebComponentProviderTest method mockRequest.

private VaadinRequest mockRequest(boolean hasConfig) {
    VaadinContext context = Mockito.mock(VaadinContext.class);
    VaadinService service = Mockito.mock(VaadinService.class);
    VaadinRequest request = Mockito.mock(VaadinRequest.class);
    Mockito.when(request.getService()).thenReturn(service);
    Mockito.when(service.getContext()).thenReturn(context);
    WebComponentConfigurationRegistry registry = Mockito.mock(WebComponentConfigurationRegistry.class);
    Mockito.when(context.getAttribute(Mockito.eq(WebComponentConfigurationRegistry.class), Mockito.any())).thenReturn(registry);
    Mockito.when(registry.hasConfigurations()).thenReturn(hasConfig);
    Mockito.when(request.getPathInfo()).thenReturn("/web-component/a-b.js");
    return request;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) WebComponentConfigurationRegistry(com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry) VaadinService(com.vaadin.flow.server.VaadinService) VaadinRequest(com.vaadin.flow.server.VaadinRequest)

Example 62 with VaadinService

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

the class StreamResourceHandlerTest method setUp.

@Before
public void setUp() throws ServletException, ServiceException {
    VaadinService service = new MockVaadinServletService();
    session = new AlwaysLockedVaadinSession(service);
    request = Mockito.mock(VaadinServletRequest.class);
    ServletContext context = Mockito.mock(ServletContext.class);
    Mockito.when(request.getServletContext()).thenReturn(context);
    response = Mockito.mock(VaadinServletResponse.class);
}
Also used : VaadinServletResponse(com.vaadin.flow.server.VaadinServletResponse) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) ServletContext(javax.servlet.ServletContext) Before(org.junit.Before)

Example 63 with VaadinService

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

the class StreamRequestHandlerTest method setUp.

@Before
public void setUp() throws ServletException, ServiceException {
    VaadinService service = new MockVaadinServletService();
    session = new AlwaysLockedVaadinSession(service) {

        @Override
        public StreamResourceRegistry getResourceRegistry() {
            return streamResourceRegistry;
        }
    };
    streamResourceRegistry = new StreamResourceRegistry(session);
    request = Mockito.mock(VaadinServletRequest.class);
    ServletContext servletContext = Mockito.mock(ServletContext.class);
    Mockito.when(servletContext.getMimeType(Mockito.anyString())).thenReturn(null);
    Mockito.when(request.getServletContext()).thenReturn(servletContext);
    response = Mockito.mock(VaadinResponse.class);
    ui = new MockUI();
    UI.setCurrent(ui);
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockUI(com.vaadin.tests.util.MockUI) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) StreamResourceRegistry(com.vaadin.flow.server.StreamResourceRegistry) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) ServletContext(javax.servlet.ServletContext) Before(org.junit.Before)

Example 64 with VaadinService

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

the class WebComponentBootstrapHandlerTest method getMockResponse.

private VaadinResponse getMockResponse(ByteArrayOutputStream stream) throws IOException {
    VaadinResponse response = Mockito.mock(VaadinResponse.class);
    VaadinService service = Mockito.mock(VaadinService.class);
    VaadinContext context = Mockito.mock(VaadinContext.class);
    Mockito.when(response.getOutputStream()).thenReturn(stream);
    Mockito.when(response.getService()).thenReturn(service);
    Mockito.when(service.getContext()).thenReturn(context);
    Mockito.when(context.getAttribute(eq(WebComponentConfigurationRegistry.class), any())).thenReturn(Mockito.mock(WebComponentConfigurationRegistry.class));
    return response;
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) VaadinContext(com.vaadin.flow.server.VaadinContext) WebComponentConfigurationRegistry(com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry) VaadinService(com.vaadin.flow.server.VaadinService)

Example 65 with VaadinService

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

the class InvalidateHttpSessionView method onAttach.

@Override
protected void onAttach(AttachEvent attachEvent) {
    VaadinService service = attachEvent.getSession().getService();
    String id = attachEvent.getSession().getSession().getId();
    Div div = new Div();
    div.setText(id);
    div.setId("current-session-id");
    add(div);
    SessionId closedSessionId = attachEvent.getSession().getService().getContext().getAttribute(SessionId.class);
    if (closedSessionId != null) {
        div = new Div();
        div.setText(closedSessionId.id);
        div.setId("invalidated-session-id");
        add(div);
    }
    service.addSessionDestroyListener(event -> {
        SessionId sessionId = new SessionId(id);
        service.getContext().setAttribute(SessionId.class, sessionId);
    });
    NativeButton button = new NativeButton("Invalidate HTTP session", event -> attachEvent.getSession().getSession().invalidate());
    add(button);
    button.setId("invalidate-session");
}
Also used : Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) VaadinService(com.vaadin.flow.server.VaadinService)

Aggregations

VaadinService (com.vaadin.flow.server.VaadinService)86 Test (org.junit.Test)39 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)19 VaadinSession (com.vaadin.flow.server.VaadinSession)18 Properties (java.util.Properties)15 VaadinContext (com.vaadin.flow.server.VaadinContext)12 Before (org.junit.Before)11 SpringInstantiatorTest (com.vaadin.flow.spring.instantiator.SpringInstantiatorTest)10 UI (com.vaadin.flow.component.UI)9 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)8 Lookup (com.vaadin.flow.di.Lookup)7 VaadinResponse (com.vaadin.flow.server.VaadinResponse)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ServletContext (javax.servlet.ServletContext)6 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)5 DefaultInstantiator (com.vaadin.flow.di.DefaultInstantiator)4 Instantiator (com.vaadin.flow.di.Instantiator)4 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)4 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)4 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)4