Java Code Examples for com.vaadin.flow.server.VaadinSession#setConfiguration()

The following examples show how to use com.vaadin.flow.server.VaadinSession#setConfiguration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebComponentBootstrapHandlerTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void writeBootstrapPage_devmodeGizmoIsDisabled()
        throws IOException, ServiceException {
    TestWebComponentBootstrapHandler handler = new TestWebComponentBootstrapHandler();
    VaadinServletService service = new MockVaadinServletService();
    service.init();
    VaadinSession session = new MockVaadinSession(service);
    session.lock();
    session.setConfiguration(service.getDeploymentConfiguration());
    MockDeploymentConfiguration config = (MockDeploymentConfiguration) service
            .getDeploymentConfiguration();
    config.setEnableDevServer(false);

    VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    Mockito.when(request.getService()).thenReturn(service);
    Mockito.when(request.getServletPath()).thenReturn("/");
    VaadinResponse response = getMockResponse(null);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Mockito.when(response.getOutputStream()).thenReturn(stream);

    handler.synchronizedHandleRequest(session, request, response);

    String result = stream.toString(StandardCharsets.UTF_8.name());
    Assert.assertTrue(result.contains("\\\"devmodeGizmoEnabled\\\": false"));
}
 
Example 2
Source File: LocationObserverTest.java    From flow with Apache License 2.0 5 votes vote down vote up
private static VaadinSession createMockSession() {
    MockVaadinServletService service = new MockVaadinServletService();
    service.init();
    VaadinSession session = new AlwaysLockedVaadinSession(service);
    session.setConfiguration(service.getDeploymentConfiguration());
    return session;
}
 
Example 3
Source File: WebComponentBootstrapHandlerTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@Test
public void writeBootstrapPage_noPWA()
        throws IOException, ServiceException {
    TestWebComponentBootstrapHandler handler = new TestWebComponentBootstrapHandler();

    PwaRegistry registry = Mockito.mock(PwaRegistry.class);

    PwaConfiguration conf = Mockito.mock(PwaConfiguration.class);

    Mockito.when(registry.getPwaConfiguration()).thenReturn(conf);

    Mockito.when(conf.isEnabled()).thenReturn(true);

    Mockito.when(conf.getManifestPath()).thenReturn("bar");

    PwaIcon icon = Mockito.mock(PwaIcon.class);
    Mockito.when(icon.asElement()).thenReturn(new Element("h1"));

    Mockito.when(registry.getHeaderIcons())
            .thenReturn(Collections.singletonList(icon));

    VaadinServletService service = new MockVaadinServletService() {
        @Override
        protected PwaRegistry getPwaRegistry() {
            return registry;
        };
    };
    service.init();
    VaadinSession session = new MockVaadinSession(service);
    session.lock();
    session.setConfiguration(service.getDeploymentConfiguration());
    MockDeploymentConfiguration config = (MockDeploymentConfiguration) service
            .getDeploymentConfiguration();
    config.setEnableDevServer(false);

    VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    Mockito.when(request.getService()).thenReturn(service);
    Mockito.when(request.getServletPath()).thenReturn("/");
    VaadinResponse response = getMockResponse(null);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Mockito.when(response.getOutputStream()).thenReturn(stream);

    handler.synchronizedHandleRequest(session, request, response);

    String result = stream.toString(StandardCharsets.UTF_8.name());
    Assert.assertThat(result,
            CoreMatchers.not(CoreMatchers.containsString("bar")));
    Assert.assertThat(result,
            CoreMatchers.not(CoreMatchers.containsString("h1")));
    Assert.assertThat(result,
            CoreMatchers.not(CoreMatchers.containsString("baz")));
}
 
Example 4
Source File: MockUI.java    From flow with Apache License 2.0 4 votes vote down vote up
public static MockUI createUI() {
    DeploymentConfiguration configuration = createConfiguration();
    VaadinSession session = createSession();
    session.setConfiguration(configuration);
    return new MockUI(session);
}