Search in sources :

Example 36 with VaadinContext

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

the class DefaultApplicationConfigurationFactoryTest method create_tokenFileIsSetViaContext_externalStatsUrlIsReadFromTokenFile_predefinedContext.

@Test
public void create_tokenFileIsSetViaContext_externalStatsUrlIsReadFromTokenFile_predefinedContext() throws MalformedURLException, IOException {
    String content = "{ 'externalStatsUrl': 'http://my.server/static/stats.json'}";
    VaadinContext context = mockTokenFileViaContextParam(content);
    DefaultApplicationConfigurationFactory factory = new DefaultApplicationConfigurationFactory();
    ApplicationConfiguration configuration = factory.create(context);
    List<String> propertyNames = Collections.list(configuration.getPropertyNames());
    Assert.assertTrue(propertyNames.contains(Constants.EXTERNAL_STATS_URL));
    Assert.assertTrue(configuration.getBooleanProperty(Constants.EXTERNAL_STATS_FILE, false));
    Assert.assertEquals("http://my.server/static/stats.json", configuration.getStringProperty(Constants.EXTERNAL_STATS_URL, null));
    Assert.assertFalse(configuration.isProductionMode());
    Assert.assertFalse(configuration.enableDevServer());
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) Test(org.junit.Test)

Example 37 with VaadinContext

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

the class DefaultApplicationConfigurationFactoryTest method getTokenFileFromClassloader_tokenFileIsRead_checkWebpackGeneratedFromContext.

@Test
public void getTokenFileFromClassloader_tokenFileIsRead_checkWebpackGeneratedFromContext() throws IOException {
    VaadinContext context = Mockito.mock(VaadinContext.class);
    VaadinConfig config = Mockito.mock(VaadinConfig.class);
    ResourceProvider resourceProvider = mockResourceProvider(config, context);
    String path = VAADIN_SERVLET_RESOURCES + TOKEN_FILE;
    String content = "{ 'foo':'bar' }";
    mockClassPathTokenFile(resourceProvider, content);
    DefaultApplicationConfigurationFactory factory = new DefaultApplicationConfigurationFactory();
    String tokenFileContent = factory.getTokenFileFromClassloader(context);
    Mockito.verify(resourceProvider).getApplicationResource(FrontendUtils.WEBPACK_GENERATED);
    Mockito.verify(resourceProvider).getApplicationResources(path);
    Assert.assertEquals(content, tokenFileContent.trim());
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinConfig(com.vaadin.flow.server.VaadinConfig) ResourceProvider(com.vaadin.flow.di.ResourceProvider) Test(org.junit.Test)

Example 38 with VaadinContext

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

the class DefaultApplicationConfigurationFactoryTest method create_tokenFileIsSetViaContext_tokenFileIsReadViaContextProperty_propertiesAreReadFromContext.

@Test
public void create_tokenFileIsSetViaContext_tokenFileIsReadViaContextProperty_propertiesAreReadFromContext() throws IOException {
    VaadinContext context = mockTokenFileViaContextParam("{ '" + SERVLET_PARAMETER_USE_V14_BOOTSTRAP + "':true }");
    DefaultApplicationConfigurationFactory factory = new DefaultApplicationConfigurationFactory();
    ApplicationConfiguration configuration = factory.create(context);
    List<String> propertyNames = Collections.list(configuration.getPropertyNames());
    Assert.assertEquals(2, propertyNames.size());
    Assert.assertEquals(FrontendUtils.PARAM_TOKEN_FILE, propertyNames.get(0));
    Assert.assertEquals(SERVLET_PARAMETER_USE_V14_BOOTSTRAP, propertyNames.get(1));
    Assert.assertTrue(configuration.useV14Bootstrap());
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) Test(org.junit.Test)

Example 39 with VaadinContext

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

the class DefaultApplicationConfigurationFactoryTest method create_tokenFileIsReadFromClassloader_externalStatsUrlIsReadFromTokenFile_predefinedContext.

@Test
public void create_tokenFileIsReadFromClassloader_externalStatsUrlIsReadFromTokenFile_predefinedContext() throws IOException {
    VaadinContext context = Mockito.mock(VaadinContext.class);
    VaadinConfig config = Mockito.mock(VaadinConfig.class);
    ResourceProvider resourceProvider = mockResourceProvider(config, context);
    mockClassPathTokenFile(resourceProvider, "{ 'externalStatsUrl': 'http://my.server/static/stats.json'}");
    DefaultApplicationConfigurationFactory factory = new DefaultApplicationConfigurationFactory();
    ApplicationConfiguration configuration = factory.create(context);
    List<String> propertyNames = Collections.list(configuration.getPropertyNames());
    Assert.assertTrue(propertyNames.contains(Constants.EXTERNAL_STATS_URL));
    Assert.assertTrue(configuration.getBooleanProperty(Constants.EXTERNAL_STATS_FILE, false));
    Assert.assertEquals("http://my.server/static/stats.json", configuration.getStringProperty(Constants.EXTERNAL_STATS_URL, null));
    Assert.assertFalse(configuration.isProductionMode());
    Assert.assertFalse(configuration.enableDevServer());
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinConfig(com.vaadin.flow.server.VaadinConfig) ResourceProvider(com.vaadin.flow.di.ResourceProvider) Test(org.junit.Test)

Example 40 with VaadinContext

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

the class TaskGenerateFeatureFlagsTest method setUp.

@Before
public void setUp() throws Exception {
    VaadinContext context = new MockVaadinContext();
    ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
    context.setAttribute(ApplicationConfiguration.class, configuration);
    File frontendFolder = temporaryFolder.newFolder(FRONTEND);
    featureFlags = FeatureFlags.get(context);
    taskGenerateFeatureFlags = new TaskGenerateFeatureFlags(frontendFolder, featureFlags);
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) VaadinContext(com.vaadin.flow.server.VaadinContext) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) File(java.io.File) Before(org.junit.Before)

Aggregations

VaadinContext (com.vaadin.flow.server.VaadinContext)42 Test (org.junit.Test)16 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)15 VaadinService (com.vaadin.flow.server.VaadinService)11 Lookup (com.vaadin.flow.di.Lookup)8 ResourceProvider (com.vaadin.flow.di.ResourceProvider)8 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)5 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)5 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)5 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)5 Properties (java.util.Properties)5 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)4 VaadinConfig (com.vaadin.flow.server.VaadinConfig)4 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)4 File (java.io.File)4 Before (org.junit.Before)4 VaadinSession (com.vaadin.flow.server.VaadinSession)3 WebComponentConfigurationRegistry (com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry)3 AppShellRegistry (com.vaadin.flow.server.AppShellRegistry)2 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)2