Search in sources :

Example 1 with MockVaadinContext

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

the class FeatureFlagsTest method before.

@Before
public void before() throws IOException {
    propertiesDir = temporaryFolder.newFolder();
    context = new MockVaadinContext();
    configuration = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(configuration.isProductionMode()).thenReturn(false);
    context.setAttribute(ApplicationConfiguration.class, configuration);
    featureFlags = FeatureFlags.get(context);
    featureFlags.setPropertiesLocation(propertiesDir);
    mockResourcesLocation();
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Before(org.junit.Before)

Example 2 with MockVaadinContext

use of com.vaadin.flow.server.MockVaadinContext 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 3 with MockVaadinContext

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

the class UidlRequestHandlerTest method writeSessionExpired.

@Test
public void writeSessionExpired() throws Exception {
    ApplicationConfiguration config = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(config.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
    Mockito.when(config.getBuildFolder()).thenReturn(".");
    VaadinContext context = new MockVaadinContext();
    Mockito.when(config.getContext()).thenReturn(context);
    VaadinService service = new VaadinServletService(null, new DefaultDeploymentConfiguration(config, getClass(), new Properties()));
    when(request.getService()).thenReturn(service);
    when(request.getParameter(ApplicationConstants.REQUEST_TYPE_PARAMETER)).thenReturn(RequestType.UIDL.getIdentifier());
    boolean result = handler.handleSessionExpired(request, response);
    Assert.assertTrue("Result should be true", result);
    String responseContent = CommunicationUtil.getStringWhenWriteBytesOffsetLength(outputStream);
    // response shouldn't contain async
    Assert.assertEquals("Invalid response", "for(;;);[{\"meta\":{\"sessionExpired\":true}}]", responseContent);
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServletService(com.vaadin.flow.server.VaadinServletService) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 4 with MockVaadinContext

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

the class NavigationStateRendererTest method init.

@Before
public void init() {
    RouteRegistry registry = ApplicationRouteRegistry.getInstance(new MockVaadinContext());
    router = new Router(registry);
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) ApplicationRouteRegistry(com.vaadin.flow.server.startup.ApplicationRouteRegistry) RouteRegistry(com.vaadin.flow.server.RouteRegistry) Router(com.vaadin.flow.router.Router) Before(org.junit.Before)

Example 5 with MockVaadinContext

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

the class RouteConfigurationTest method init.

@Before
public void init() {
    servletContext = new MockServletContext();
    vaadinContext = new MockVaadinContext(servletContext);
    registry = ApplicationRouteRegistry.getInstance(vaadinContext);
    vaadinService = Mockito.mock(MockService.class);
    Mockito.when(vaadinService.getRouteRegistry()).thenReturn(registry);
    Mockito.when(vaadinService.getContext()).thenReturn(vaadinContext);
    VaadinService.setCurrent(vaadinService);
    session = new MockVaadinSession(vaadinService) {

        @Override
        public VaadinService getService() {
            return vaadinService;
        }
    };
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) MockServletContext(com.vaadin.flow.server.MockServletContext) Before(org.junit.Before)

Aggregations

MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)12 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)5 Before (org.junit.Before)5 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)4 VaadinContext (com.vaadin.flow.server.VaadinContext)4 VaadinService (com.vaadin.flow.server.VaadinService)4 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)4 ApplicationRouteRegistry (com.vaadin.flow.server.startup.ApplicationRouteRegistry)4 AlwaysLockedVaadinSession (com.vaadin.tests.util.AlwaysLockedVaadinSession)3 Test (org.junit.Test)3 Component (com.vaadin.flow.component.Component)2 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)2 Route (com.vaadin.flow.router.Route)2 RouteConfiguration (com.vaadin.flow.router.RouteConfiguration)2 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)2 RouteRegistry (com.vaadin.flow.server.RouteRegistry)2 VaadinResponse (com.vaadin.flow.server.VaadinResponse)2 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)2 VaadinServletService (com.vaadin.flow.server.VaadinServletService)2 Properties (java.util.Properties)2