Search in sources :

Example 71 with VaadinService

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

the class UidlRequestHandler method handleSessionExpired.

/*
     * (non-Javadoc)
     *
     * @see
     * com.vaadin.server.SessionExpiredHandler#handleSessionExpired(com.vaadin
     * .server.VaadinRequest, com.vaadin.server.VaadinResponse)
     */
@Override
public boolean handleSessionExpired(VaadinRequest request, VaadinResponse response) throws IOException {
    if (!HandlerHelper.isRequestType(request, RequestType.UIDL)) {
        return false;
    }
    VaadinService service = request.getService();
    service.writeUncachedStringResponse(response, JsonConstants.JSON_CONTENT_TYPE, VaadinService.createSessionExpiredJSON(false));
    return true;
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService)

Example 72 with VaadinService

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

the class MockUI method createSession.

private static VaadinSession createSession(Router router) {
    VaadinService service = Mockito.mock(VaadinService.class);
    if (router != null) {
        Mockito.when(service.getRouter()).thenReturn(router);
    }
    VaadinSession session = new AlwaysLockedVaadinSession(service);
    VaadinSession.setCurrent(session);
    return session;
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService)

Example 73 with VaadinService

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

the class WebComponentConfigurationRegistryTest method init.

@Before
public void init() {
    VaadinService service = mock(VaadinService.class);
    context = mock(VaadinContext.class);
    VaadinService.setCurrent(service);
    Mockito.when(service.getContext()).thenReturn(context);
    WebComponentConfigurationRegistry instance = createRegistry();
    Mockito.when(context.getAttribute(WebComponentConfigurationRegistry.class)).thenReturn(instance);
    Mockito.when(context.getAttribute(eq(WebComponentConfigurationRegistry.class), any())).thenReturn(instance);
    registry = WebComponentConfigurationRegistry.getInstance(context);
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinService(com.vaadin.flow.server.VaadinService) Before(org.junit.Before)

Example 74 with VaadinService

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

the class RouterLinkTest method setUp.

@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException, InvalidRouteConfigurationException {
    registry = new TestRouteRegistry();
    RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(registry);
    routeConfiguration.update(() -> {
        routeConfiguration.getHandledRegistry().clean();
        Arrays.asList(TestView.class, FooNavigationTarget.class, ParameterNavigationTarget.class, GreetingNavigationTarget.class).forEach(routeConfiguration::setAnnotatedRoute);
    });
    router = new Router(registry);
    ui = new RoutingTestBase.RouterTestUI(router);
    VaadinService service = VaadinService.getCurrent();
    Mockito.when(service.getRouter()).thenReturn(router);
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Before(org.junit.Before)

Example 75 with VaadinService

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

the class FrontendUtilsTest method assetsByChunkIsCorrectlyParsedFromStats.

@Test
public void assetsByChunkIsCorrectlyParsedFromStats() throws IOException, ServiceException {
    VaadinService service = setupStatsAssetMocks("ValidStats.json");
    String statsAssetsByChunkName = FrontendUtils.getStatsAssetsByChunkName(service);
    Assert.assertEquals("{\"bundle\": \"build/vaadin-bundle-1111.cache.js\",\"export\": \"build/vaadin-export-2222.cache.js\"}", statsAssetsByChunkName);
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Test(org.junit.Test)

Aggregations

VaadinService (com.vaadin.flow.server.VaadinService)86 Test (org.junit.Test)39 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)19 VaadinSession (com.vaadin.flow.server.VaadinSession)18 Properties (java.util.Properties)15 VaadinContext (com.vaadin.flow.server.VaadinContext)12 Before (org.junit.Before)11 SpringInstantiatorTest (com.vaadin.flow.spring.instantiator.SpringInstantiatorTest)10 UI (com.vaadin.flow.component.UI)9 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)8 Lookup (com.vaadin.flow.di.Lookup)7 VaadinResponse (com.vaadin.flow.server.VaadinResponse)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ServletContext (javax.servlet.ServletContext)6 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)5 DefaultInstantiator (com.vaadin.flow.di.DefaultInstantiator)4 Instantiator (com.vaadin.flow.di.Instantiator)4 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)4 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)4 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)4