use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class PushAtmosphereHandlerTest method setup.
@Before
public void setup() throws IOException {
request = Mockito.mock(AtmosphereRequest.class);
response = Mockito.mock(AtmosphereResponse.class);
printWriter = Mockito.mock(PrintWriter.class);
Mockito.when(response.getWriter()).thenReturn(printWriter);
resource = Mockito.mock(AtmosphereResource.class);
Mockito.when(resource.getRequest()).thenReturn(request);
Mockito.when(resource.getResponse()).thenReturn(response);
VaadinContext context = new MockVaadinContext();
ApplicationConfiguration config = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(config.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(config.getContext()).thenReturn(context);
VaadinServletService service = new VaadinServletService(null, new DefaultDeploymentConfiguration(config, getClass(), new Properties()));
PushHandler handler = new PushHandler(service);
atmosphereHandler = new PushAtmosphereHandler();
atmosphereHandler.setPushHandler(handler);
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class DefaultApplicationConfigurationFactoryTest method mockTokenFileViaContextParam.
private VaadinContext mockTokenFileViaContextParam(String content) throws IOException {
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(context.getContextParameterNames()).thenReturn(Collections.enumeration(Collections.singleton(FrontendUtils.PARAM_TOKEN_FILE)));
File tmpFile = temporaryFolder.newFile();
Files.write(tmpFile.toPath(), Collections.singletonList(content));
Mockito.when(context.getContextParameter(FrontendUtils.PARAM_TOKEN_FILE)).thenReturn(tmpFile.getPath());
return context;
}
use of com.vaadin.flow.server.VaadinContext 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.VaadinContext in project flow by vaadin.
the class DefaultApplicationConfigurationFactoryTest method create_tokenFileIsSetViaContext_externalStatsFileIsReadFromTokenFile_predefinedContext.
@Test
public void create_tokenFileIsSetViaContext_externalStatsFileIsReadFromTokenFile_predefinedContext() throws MalformedURLException, IOException {
String content = "{ 'externalStatsFile':true }";
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_FILE));
Assert.assertTrue(configuration.getBooleanProperty(Constants.EXTERNAL_STATS_FILE, false));
Assert.assertFalse(configuration.isProductionMode());
Assert.assertFalse(configuration.enableDevServer());
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class ApplicationConfigurationTest method get_contextHasNoLookup_iseIsThrown.
@Test(expected = IllegalStateException.class)
public void get_contextHasNoLookup_iseIsThrown() {
VaadinContext context = Mockito.spy(VaadinContext.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(null);
Mockito.doAnswer(invocation -> invocation.getArgument(1, Supplier.class).get()).when(context).getAttribute(Mockito.any(), Mockito.any());
ApplicationConfiguration.get(context);
}
Aggregations