Search in sources :

Example 21 with VaadinService

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

the class VaadinRouteScopeTest method mockServletContext.

private void mockServletContext(UI ui) {
    VaadinService service = ui.getSession().getService();
    VaadinServletContext context = ((VaadinServletContext) service.getContext());
    ServletContext servletContext = context.getContext();
    WebApplicationContext appContext = Mockito.mock(WebApplicationContext.class);
    Mockito.when(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).thenReturn(appContext);
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) ServletContext(javax.servlet.ServletContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 22 with VaadinService

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

the class RequestUtil method isAnonymousRoute.

/**
 * Checks whether the request targets a Flow route that is public, i.e.
 * marked as @{@link AnonymousAllowed}.
 *
 * @param request
 *            the servlet request
 * @return {@code true} if the request is targeting an anonymous route,
 *         {@code false} otherwise
 */
public boolean isAnonymousRoute(HttpServletRequest request) {
    String vaadinMapping = configurationProperties.getUrlMapping();
    String requestedPath = HandlerHelper.getRequestPathInsideContext(request);
    Optional<String> maybePath = HandlerHelper.getPathIfInsideServlet(vaadinMapping, requestedPath);
    if (!maybePath.isPresent()) {
        return false;
    }
    String path = maybePath.get();
    if (path.startsWith("/")) {
        // Requested path includes a beginning "/" but route mapping is done
        // without one
        path = path.substring(1);
    }
    SpringServlet servlet = springServletRegistration.getServlet();
    VaadinService service = servlet.getService();
    Router router = service.getRouter();
    RouteRegistry routeRegistry = router.getRegistry();
    NavigationRouteTarget target = routeRegistry.getNavigationRouteTarget(path);
    if (target == null) {
        return false;
    }
    RouteTarget routeTarget = target.getRouteTarget();
    if (routeTarget == null) {
        return false;
    }
    Class<? extends com.vaadin.flow.component.Component> targetView = routeTarget.getTarget();
    if (targetView == null) {
        return false;
    }
    // Check if a not authenticated user can access the view
    boolean result = accessAnnotationChecker.hasAccess(targetView, null, role -> false);
    if (result) {
        getLogger().debug(path + " refers to a public view");
    }
    return result;
}
Also used : RouteRegistry(com.vaadin.flow.server.RouteRegistry) NavigationRouteTarget(com.vaadin.flow.router.internal.NavigationRouteTarget) VaadinService(com.vaadin.flow.server.VaadinService) Router(com.vaadin.flow.router.Router) NavigationRouteTarget(com.vaadin.flow.router.internal.NavigationRouteTarget) RouteTarget(com.vaadin.flow.router.internal.RouteTarget) SpringServlet(com.vaadin.flow.spring.SpringServlet)

Example 23 with VaadinService

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

the class SpringServletTest method readUniformNameProperty_propertyNameContainsDash_propertyNameIsConvertedToCamelCaseAndReadProperly.

@Test
public void readUniformNameProperty_propertyNameContainsDash_propertyNameIsConvertedToCamelCaseAndReadProperly() throws ServletException {
    VaadinService service = SpringInstantiatorTest.getService(context, new Properties());
    PushMode pushMode = service.getDeploymentConfiguration().getPushMode();
    Assert.assertEquals(PushMode.MANUAL, pushMode);
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Properties(java.util.Properties) PushMode(com.vaadin.flow.shared.communication.PushMode) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringInstantiatorTest(com.vaadin.flow.spring.instantiator.SpringInstantiatorTest)

Example 24 with VaadinService

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

the class SpringServletTest method fallbackChunk_givenInInitParameter_passedOnToDeploymentConfiguration.

// #662
@Test
public void fallbackChunk_givenInInitParameter_passedOnToDeploymentConfiguration() throws ServletException {
    FallbackChunk fallbackChunk = new FallbackChunk(Collections.emptyList(), Collections.emptyList());
    final Properties properties = new Properties();
    properties.put(DeploymentConfigurationFactory.FALLBACK_CHUNK, fallbackChunk);
    VaadinService service = SpringInstantiatorTest.getService(context, properties, true);
    Assert.assertSame(fallbackChunk, service.getDeploymentConfiguration().getInitParameters().get(DeploymentConfigurationFactory.FALLBACK_CHUNK));
}
Also used : FallbackChunk(com.vaadin.flow.server.frontend.FallbackChunk) VaadinService(com.vaadin.flow.server.VaadinService) Properties(java.util.Properties) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringInstantiatorTest(com.vaadin.flow.spring.instantiator.SpringInstantiatorTest)

Example 25 with VaadinService

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

the class SpringVaadinServletServiceTest method getInstantiator_javaSPIClass_instantiatorPojoReturned.

@Test
public void getInstantiator_javaSPIClass_instantiatorPojoReturned() throws ServletException {
    Properties properties = new Properties(BASE_PROPERTIES);
    properties.setProperty(FOO, Boolean.FALSE.toString());
    VaadinService service = SpringInstantiatorTest.getService(context, properties);
    Instantiator instantiator = service.getInstantiator();
    Assert.assertEquals(JavaSPIInstantiator.class, instantiator.getClass());
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Instantiator(com.vaadin.flow.di.Instantiator) Properties(java.util.Properties) Test(org.junit.Test) SpringInstantiatorTest(com.vaadin.flow.spring.instantiator.SpringInstantiatorTest)

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