Search in sources :

Example 16 with VaadinServletService

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

the class SpringClassesSerializableTest method createStore.

private TestBeanStore createStore() {
    final Properties initParameters = new Properties();
    ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
    VaadinContext context = Mockito.mock(VaadinContext.class);
    Mockito.when(context.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(appConfig);
    Mockito.when(appConfig.getContext()).thenReturn(context);
    Lookup lookup = Mockito.mock(Lookup.class);
    Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
    VaadinService service = new VaadinServletService(new VaadinServlet(), new DefaultDeploymentConfiguration(appConfig, getClass(), initParameters)) {

        @Override
        public VaadinContext getContext() {
            return context;
        }
    };
    VaadinSession session = new TestSession(service);
    TestBeanStore store = new TestBeanStore(session);
    return store;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) TestBeanStore(com.vaadin.flow.spring.scopes.TestBeanStore) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServlet(com.vaadin.flow.server.VaadinServlet) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Lookup(com.vaadin.flow.di.Lookup) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 17 with VaadinServletService

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

the class WebComponentProviderTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    // same code as used for local variables in
    registry = setUpRegistry();
    // some tests
    Mockito.when(request.getService()).thenReturn(service);
    Mockito.when(session.getService()).thenReturn(service);
    Mockito.when(service.getContext()).thenReturn(context);
    Mockito.when(context.getAttribute(WebComponentConfigurationRegistry.class)).then(invocationOnMock -> registry);
    Mockito.when(context.getAttribute(eq(WebComponentConfigurationRegistry.class), any())).then(invocationOnMock -> registry);
    Mockito.doAnswer(invocationOnMock -> registry = (WebComponentConfigurationRegistry) invocationOnMock.getArguments()[0]).when(context).setAttribute(any(WebComponentConfigurationRegistry.class));
    VaadinService.setCurrent(service);
    Mockito.when(service.getInstantiator()).thenReturn(new MockInstantiator());
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    VaadinServletService service = Mockito.mock(VaadinServletService.class);
    Mockito.doCallRealMethod().when(service).getContextRootRelativePath(Mockito.any());
    Mockito.doCallRealMethod().when(service).getContextRootRelativePath(Mockito.any());
    provider = new WebComponentProvider();
}
Also used : WebComponentConfigurationRegistry(com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry) MockInstantiator(com.vaadin.flow.server.MockInstantiator) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Before(org.junit.Before)

Example 18 with VaadinServletService

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

the class PushHandlerTest method onMessage_websocketTransport_requestStartIsCalledOnServiceInstance.

@Test
public void onMessage_websocketTransport_requestStartIsCalledOnServiceInstance() {
    VaadinServletService service = runTest((handler, resource) -> {
        Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
        handler.onMessage(resource);
    });
    Mockito.verify(service).requestStart(Mockito.any(), Mockito.any());
}
Also used : MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Test(org.junit.Test)

Example 19 with VaadinServletService

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

the class PushHandlerTest method onConnect_websocketTransport_requestStartIsCalledOnServiceInstance.

@Test
public void onConnect_websocketTransport_requestStartIsCalledOnServiceInstance() {
    VaadinServletService service = runTest((handler, resource) -> {
        Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
        handler.onConnect(resource);
    });
    Mockito.verify(service).requestStart(Mockito.any(), Mockito.any());
}
Also used : MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Test(org.junit.Test)

Example 20 with VaadinServletService

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

the class IndexHtmlRequestHandlerTest method serveNotFoundIndexHtml_requestWithRootPath_failsWithIOException.

@Test
public void serveNotFoundIndexHtml_requestWithRootPath_failsWithIOException() throws IOException {
    VaadinServletService vaadinService = Mockito.mock(VaadinServletService.class);
    Mockito.when(vaadinService.getDeploymentConfiguration()).thenReturn(deploymentConfiguration);
    Mockito.when(vaadinService.getContext()).thenReturn(context);
    final Lookup lookup = Mockito.mock(Lookup.class);
    ResourceProvider resourceProvider = Mockito.mock(ResourceProvider.class);
    Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
    Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(resourceProvider);
    URL resource = Mockito.mock(URL.class);
    Mockito.when(resourceProvider.getApplicationResource(VAADIN_WEBAPP_RESOURCES + INDEX_HTML)).thenReturn(resource);
    when(resource.openStream()).thenReturn(null);
    VaadinServletRequest vaadinRequest = Mockito.mock(VaadinServletRequest.class);
    Mockito.when(vaadinRequest.getService()).thenReturn(vaadinService);
    String path = DEFAULT_FRONTEND_DIR + "index.html";
    String expectedError = String.format("Failed to load content of '%1$s'. " + "It is required to have '%1$s' file when " + "using client side bootstrapping.", path);
    exceptionRule.expect(IOException.class);
    exceptionRule.expectMessage(expectedError);
    indexHtmlRequestHandler.synchronizedHandleRequest(session, vaadinRequest, response);
}
Also used : ResourceProvider(com.vaadin.flow.di.ResourceProvider) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Lookup(com.vaadin.flow.di.Lookup) URL(java.net.URL) Test(org.junit.Test)

Aggregations

VaadinServletService (com.vaadin.flow.server.VaadinServletService)23 Test (org.junit.Test)14 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)10 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)9 VaadinSession (com.vaadin.flow.server.VaadinSession)8 Properties (java.util.Properties)7 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)6 VaadinServlet (com.vaadin.flow.server.VaadinServlet)6 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)5 VaadinService (com.vaadin.flow.server.VaadinService)5 Before (org.junit.Before)5 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)4 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)4 URL (java.net.URL)4 Collections (java.util.Collections)4 ServletContext (javax.servlet.ServletContext)4 Lookup (com.vaadin.flow.di.Lookup)3 ResourceProvider (com.vaadin.flow.di.ResourceProvider)3 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)3 VaadinResponse (com.vaadin.flow.server.VaadinResponse)3