use of com.vaadin.flow.server.VaadinConfig in project flow by vaadin.
the class DefaultApplicationConfigurationFactoryTest method create_propertiesAreReadFromContext.
@Test
public void create_propertiesAreReadFromContext() throws IOException {
VaadinContext context = Mockito.mock(VaadinContext.class);
VaadinConfig config = Mockito.mock(VaadinConfig.class);
ResourceProvider resourceProvider = mockResourceProvider(config, context);
Mockito.when(context.getContextParameterNames()).thenReturn(Collections.enumeration(Collections.singleton("foo")));
Mockito.when(context.getContextParameter("foo")).thenReturn("bar");
mockClassPathTokenFile(resourceProvider, "{}");
DefaultApplicationConfigurationFactory factory = new DefaultApplicationConfigurationFactory();
ApplicationConfiguration configuration = factory.create(context);
List<String> propertyNames = Collections.list(configuration.getPropertyNames());
Assert.assertEquals(1, propertyNames.size());
Assert.assertEquals("foo", propertyNames.get(0));
Assert.assertEquals("bar", configuration.getStringProperty("foo", null));
}
use of com.vaadin.flow.server.VaadinConfig in project flow by vaadin.
the class DefaultApplicationConfigurationFactoryTest method create_tokenFileIsReadFromClassloader_externalStatsFileIsReadFromTokenFile_predefinedContext.
@Test
public void create_tokenFileIsReadFromClassloader_externalStatsFileIsReadFromTokenFile_predefinedContext() throws MalformedURLException, IOException {
VaadinContext context = Mockito.mock(VaadinContext.class);
VaadinConfig config = Mockito.mock(VaadinConfig.class);
ResourceProvider resourceProvider = mockResourceProvider(config, context);
String content = "{ 'externalStatsFile':true }";
mockClassPathTokenFile(resourceProvider, content);
DefaultApplicationConfigurationFactory factory = new DefaultApplicationConfigurationFactory();
ApplicationConfiguration configuration = factory.create(context);
List<String> propertyNames = Collections.list(configuration.getPropertyNames());
Assert.assertTrue(propertyNames.contains(Constants.EXTERNAL_STATS_FILE));
Assert.assertTrue(configuration.getBooleanProperty(Constants.EXTERNAL_STATS_FILE, false));
Assert.assertFalse(configuration.isProductionMode());
Assert.assertFalse(configuration.enableDevServer());
}
use of com.vaadin.flow.server.VaadinConfig 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.VaadinConfig 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());
}
Aggregations