Search in sources :

Example 1 with VaadinContext

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);
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) VaadinContext(com.vaadin.flow.server.VaadinContext) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) VaadinServletService(com.vaadin.flow.server.VaadinServletService) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 2 with VaadinContext

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;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) File(java.io.File)

Example 3 with VaadinContext

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));
}
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 4 with VaadinContext

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());
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) Test(org.junit.Test)

Example 5 with VaadinContext

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);
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) Test(org.junit.Test)

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