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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations