DeploymentConfigurationFactory implements Serializable { public static DeploymentConfiguration createDeploymentConfiguration( Class<?> systemPropertyBaseClass, VaadinConfig vaadinConfig) throws VaadinConfigurationException { return new DefaultDeploymentConfiguration(systemPropertyBaseClass, createInitParameters(systemPropertyBaseClass, vaadinConfig)); } private  DeploymentConfigurationFactory(); static DeploymentConfiguration createDeploymentConfiguration(
            Class<?> systemPropertyBaseClass, VaadinConfig vaadinConfig); static DeploymentConfiguration createPropertyDeploymentConfiguration(
            Class<?> systemPropertyBaseClass, VaadinConfig vaadinConfig); static final Object FALLBACK_CHUNK; static final String ERROR_DEV_MODE_NO_FILES; static final String DEV_FOLDER_MISSING_MESSAGE; }
@Test public void servletWithEnclosingUI_hasItsNameInConfig() throws Exception { Class<TestUI.ServletWithEnclosingUi> servlet = TestUI.ServletWithEnclosingUi.class; Map<String, String> servletConfigParams = new HashMap<>( new HashMap<>(defaultServletParams)); DeploymentConfiguration config = DeploymentConfigurationFactory .createDeploymentConfiguration(servlet, createVaadinConfigMock(servletConfigParams, Collections.singletonMap(PARAM_TOKEN_FILE, tokenFile.getPath()))); Class<?> customUiClass = servlet.getEnclosingClass(); assertTrue(String.format( "Servlet '%s' should have its enclosing class to be UI subclass, but got: '%s'", customUiClass, servlet), UI.class.isAssignableFrom(customUiClass)); assertEquals(String.format( "Expected DeploymentConfiguration for servlet '%s' to have its enclosing UI class", servlet), customUiClass.getName(), config.getUIClassName()); }
@Test public void servletWithNoEnclosingUI_hasDefaultUiInConfig() throws Exception { Class<NoSettings> servlet = NoSettings.class; Map<String, String> servletConfigParams = new HashMap<>( defaultServletParams); DeploymentConfiguration config = 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()); }
@Test public void vaadinServletConfigurationRead() throws Exception { Class<VaadinSettings> servlet = VaadinSettings.class; Map<String, String> servletConfigParams = new HashMap<>( defaultServletParams); DeploymentConfiguration config = DeploymentConfigurationFactory .createDeploymentConfiguration(servlet, createVaadinConfigMock( servletConfigParams, emptyMap())); assertTrue(String.format( "Unexpected value for production mode, check '%s' class annotation", servlet), config.isProductionMode()); assertEquals(String.format( "Unexpected value for heartbeat interval, check '%s' class annotation", servlet), 222, config.getHeartbeatInterval()); }
@Test public void servletConfigParametersOverrideVaadinParameters() throws Exception { Class<VaadinSettings> servlet = VaadinSettings.class; boolean overridingProductionModeValue = false; int overridingHeartbeatIntervalValue = 444; Map<String, String> servletConfigParams = new HashMap<>( defaultServletParams); servletConfigParams.put(SERVLET_PARAMETER_PRODUCTION_MODE, Boolean.toString(overridingProductionModeValue)); servletConfigParams.put(InitParameters.SERVLET_PARAMETER_HEARTBEAT_INTERVAL, Integer.toString(overridingHeartbeatIntervalValue)); DeploymentConfiguration config = DeploymentConfigurationFactory .createDeploymentConfiguration(servlet, createVaadinConfigMock( servletConfigParams, emptyMap())); assertEquals( "Unexpected value for production mode, should be the same as in servlet config parameters", overridingProductionModeValue, config.isProductionMode()); assertEquals( "Unexpected value for heartbeat interval, should be the same as in servlet config parameters", overridingHeartbeatIntervalValue, config.getHeartbeatInterval()); }
@Test public void servletContextParametersOverrideVaadinParameters() throws Exception { Class<VaadinSettings> servlet = VaadinSettings.class; boolean overridingProductionModeValue = false; int overridingHeartbeatIntervalValue = 444; Map<String, String> servletContextParams = new HashMap<>( defaultServletParams); servletContextParams.put(SERVLET_PARAMETER_PRODUCTION_MODE, Boolean.toString(overridingProductionModeValue)); servletContextParams.put(InitParameters.SERVLET_PARAMETER_HEARTBEAT_INTERVAL, Integer.toString(overridingHeartbeatIntervalValue)); DeploymentConfiguration config = DeploymentConfigurationFactory .createDeploymentConfiguration(servlet, createVaadinConfigMock( emptyMap(), servletContextParams)); assertEquals( "Unexpected value for production mode, should be the same as in servlet context parameters", overridingProductionModeValue, config.isProductionMode()); assertEquals( "Unexpected value for heartbeat interval, should be the same as in servlet context parameters", overridingHeartbeatIntervalValue, config.getHeartbeatInterval()); }
@Test public void servletConfigParametersOverrideServletContextParameters() throws Exception { Class<NoSettings> servlet = NoSettings.class; boolean servletConfigProductionModeValue = true; int servletConfigHeartbeatIntervalValue = 333; Map<String, String> servletConfigParams = new HashMap<>( defaultServletParams); servletConfigParams.put(SERVLET_PARAMETER_PRODUCTION_MODE, Boolean.toString(servletConfigProductionModeValue)); servletConfigParams.put(InitParameters.SERVLET_PARAMETER_HEARTBEAT_INTERVAL, Integer.toString(servletConfigHeartbeatIntervalValue)); boolean servletContextProductionModeValue = false; int servletContextHeartbeatIntervalValue = 444; Map<String, String> servletContextParams = new HashMap<>(); servletContextParams.put(SERVLET_PARAMETER_PRODUCTION_MODE, Boolean.toString(servletContextProductionModeValue)); servletContextParams.put(InitParameters.SERVLET_PARAMETER_HEARTBEAT_INTERVAL, Integer.toString(servletContextHeartbeatIntervalValue)); DeploymentConfiguration config = DeploymentConfigurationFactory .createDeploymentConfiguration(servlet, createVaadinConfigMock( servletConfigParams, servletContextParams)); assertEquals( "Unexpected value for production mode, should be the same as in servlet context parameters", servletConfigProductionModeValue, config.isProductionMode()); assertEquals( "Unexpected value for heartbeat interval, should be the same as in servlet context parameters", servletConfigHeartbeatIntervalValue, config.getHeartbeatInterval()); }
@Test public void shouldNotThrow_noTokenFile_correctWebPackConfigExists() throws Exception { Map<String, String> map = new HashMap<>(); map.put(FrontendUtils.PROJECT_BASEDIR, temporaryFolder.getRoot().getAbsolutePath()); File webPack = new File(temporaryFolder.getRoot().getAbsolutePath(), FrontendUtils.WEBPACK_CONFIG); FileUtils.writeLines(webPack, Arrays.asList("./webpack.generated.js")); DeploymentConfigurationFactory.createDeploymentConfiguration( VaadinServlet.class, createVaadinConfigMock(map, emptyMap())); }