Search in sources :

Example 56 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class DeploymentConfigurationFactoryTest method servletWithNoEnclosingUI_hasDefaultUiInConfig.

@Test
public void servletWithNoEnclosingUI_hasDefaultUiInConfig() throws Exception {
    Class<NoSettings> servlet = NoSettings.class;
    Map<String, String> servletConfigParams = new HashMap<>(defaultServletParams);
    DeploymentConfiguration config = new DeploymentConfigurationFactory().createDeploymentConfiguration(servlet, createVaadinConfigMock(servletConfigParams, emptyMap()));
    Class<?> notUiClass = servlet.getEnclosingClass();
    assertFalse(String.format("Servlet '%s' should not have its enclosing class to be UI subclass, but got: '%s'", notUiClass, servlet), UI.class.isAssignableFrom(notUiClass));
    assertEquals(String.format("Expected DeploymentConfiguration for servlet '%s' to have its enclosing UI class", servlet), UI.class.getName(), config.getUIClassName());
}
Also used : UI(com.vaadin.flow.component.UI) HashMap(java.util.HashMap) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 57 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class DeploymentConfigurationFactoryTest method externalStatsFileTrue_predefinedValuesAreNotOverridden.

@Test
public void externalStatsFileTrue_predefinedValuesAreNotOverridden() throws Exception {
    // note that this situation shouldn't happen that the other
    // settings
    // would be against the external usage.
    FileUtils.writeLines(tokenFile, Arrays.asList("{", "\"enableDevServer\": true,", // are used
    "\"productionMode\": true,", "\"externalStatsFile\": true", "}"));
    DeploymentConfiguration config = createConfig(Collections.singletonMap(PARAM_TOKEN_FILE, tokenFile.getPath()));
    assertEquals(true, config.isProductionMode());
    assertEquals(false, config.enableDevServer());
    assertEquals(true, config.isStatsExternal());
    assertEquals(Constants.DEFAULT_EXTERNAL_STATS_URL, config.getExternalStatsUrl());
}
Also used : DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 58 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class MockUI method createUI.

public static MockUI createUI() {
    DeploymentConfiguration configuration = createConfiguration();
    VaadinSession session = createSession();
    session.setConfiguration(configuration);
    return new MockUI(session);
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 59 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class ServletDeployer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    Collection<DeploymentConfiguration> servletConfigurations = getServletConfigurations(context);
    VaadinServletContext vaadinContext = new VaadinServletContext(context);
    ApplicationConfiguration config = ApplicationConfiguration.get(vaadinContext);
    boolean enableServlets = !config.disableAutomaticServletRegistration();
    boolean productionMode = false;
    for (DeploymentConfiguration configuration : servletConfigurations) {
        productionMode = productionMode || configuration.isProductionMode();
    }
    VaadinServletCreation servletCreation = enableServlets ? createAppServlet(context) : null;
    logServletCreation(servletCreation, context, productionMode);
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) ServletContext(javax.servlet.ServletContext) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 60 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class ServletDeployer method getServletConfigurations.

private Collection<DeploymentConfiguration> getServletConfigurations(ServletContext context) {
    Collection<? extends ServletRegistration> registrations = context.getServletRegistrations().values();
    Collection<DeploymentConfiguration> result = new ArrayList<>(registrations.size());
    for (ServletRegistration registration : registrations) {
        loadClass(context.getClassLoader(), registration.getClassName()).ifPresent(servletClass -> result.add(StubServletConfig.createDeploymentConfiguration(context, registration, servletClass)));
    }
    return result;
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) ArrayList(java.util.ArrayList) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Aggregations

DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)63 Test (org.junit.Test)24 VaadinService (com.vaadin.flow.server.VaadinService)23 VaadinSession (com.vaadin.flow.server.VaadinSession)9 UI (com.vaadin.flow.component.UI)8 Before (org.junit.Before)8 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)6 URL (java.net.URL)6 Properties (java.util.Properties)6 VaadinContext (com.vaadin.flow.server.VaadinContext)5 PushConfiguration (com.vaadin.flow.component.PushConfiguration)4 HashMap (java.util.HashMap)4 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)3 Location (com.vaadin.flow.router.Location)3 VaadinServletService (com.vaadin.flow.server.VaadinServletService)3 Method (java.lang.reflect.Method)3 Set (java.util.Set)3 ServletConfig (javax.servlet.ServletConfig)3 ServletException (javax.servlet.ServletException)3 Div (com.vaadin.flow.component.html.Div)2