Search in sources :

Example 56 with VaadinService

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

the class DefaultBindingExceptionHandlerTest method mockUI.

private UI mockUI(boolean productionMode) {
    UI ui = new UI();
    VaadinService service = Mockito.mock(VaadinService.class);
    VaadinSession session = Mockito.mock(VaadinSession.class);
    ui.getInternals().setSession(session);
    Mockito.when(session.getService()).thenReturn(service);
    VaadinContext context = Mockito.mock(VaadinContext.class);
    Mockito.when(service.getContext()).thenReturn(context);
    ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(context.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(configuration);
    Mockito.when(configuration.isProductionMode()).thenReturn(productionMode);
    return ui;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) UI(com.vaadin.flow.component.UI) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 57 with VaadinService

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

the class AbstractDnDUnitTest method setup.

@Before
public void setup() {
    ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
    Mockito.when(appConfig.getBuildFolder()).thenReturn(".");
    VaadinContext context = Mockito.mock(VaadinContext.class);
    Mockito.when(appConfig.getContext()).thenReturn(context);
    Lookup lookup = Mockito.mock(Lookup.class);
    Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
    DefaultDeploymentConfiguration configuration = new DefaultDeploymentConfiguration(appConfig, VaadinServlet.class, new Properties());
    VaadinService service = Mockito.mock(VaadinService.class);
    Mockito.when(service.resolveResource(Mockito.anyString())).thenReturn("");
    VaadinSession session = Mockito.mock(VaadinSession.class);
    Mockito.when(session.getConfiguration()).thenReturn(configuration);
    Mockito.when(session.getService()).thenReturn(service);
    ui = new MockUI(session);
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) Lookup(com.vaadin.flow.di.Lookup) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Before(org.junit.Before)

Example 58 with VaadinService

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

the class UITest method initUI.

private static void initUI(UI ui, String initialLocation, ArgumentCaptor<Integer> statusCodeCaptor) throws InvalidRouteConfigurationException {
    VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    VaadinResponse response = Mockito.mock(VaadinResponse.class);
    String pathInfo;
    if (initialLocation.isEmpty()) {
        pathInfo = null;
    } else {
        Assert.assertFalse(initialLocation.startsWith("/"));
        pathInfo = "/" + initialLocation;
    }
    Mockito.when(request.getPathInfo()).thenReturn(pathInfo);
    VaadinService service = new MockVaadinServletService() {

        @Override
        public VaadinContext getContext() {
            return new MockVaadinContext();
        }
    };
    service.setCurrentInstances(request, response);
    MockVaadinSession session = new AlwaysLockedVaadinSession(service);
    DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(config.isProductionMode()).thenReturn(false);
    session.lock();
    session.setConfiguration(config);
    ui.getInternals().setSession(session);
    RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getInternals().getRouter().getRegistry());
    routeConfiguration.update(() -> {
        routeConfiguration.getHandledRegistry().clean();
        Arrays.asList(RootNavigationTarget.class, FooBarNavigationTarget.class, Parameterized.class, FooBarParamNavigationTarget.class).forEach(routeConfiguration::setAnnotatedRoute);
    });
    ui.doInit(request, 0);
    ui.getInternals().getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(request));
    session.unlock();
    if (statusCodeCaptor != null) {
        Mockito.verify(response).setStatus(statusCodeCaptor.capture());
    }
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) RouteConfiguration(com.vaadin.flow.router.RouteConfiguration) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 59 with VaadinService

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

the class LookupInitializerTest method initialize_noStaticFileHandlerFactory_defaultStaticFileHandlerFactoryCreated.

@Test
public void initialize_noStaticFileHandlerFactory_defaultStaticFileHandlerFactoryCreated() throws ServletException {
    AtomicReference<Lookup> capture = new AtomicReference<>();
    initializer.initialize(null, new HashMap<>(), capture::set);
    Lookup lookup = capture.get();
    StaticFileHandlerFactory factory = lookup.lookup(StaticFileHandlerFactory.class);
    VaadinService service = Mockito.mock(VaadinService.class);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    ClassLoader loader = Mockito.mock(ClassLoader.class);
    Mockito.when(service.getClassLoader()).thenReturn(loader);
    StaticFileHandler handler = factory.createHandler(service);
    Assert.assertNotNull(handler);
    Assert.assertEquals(StaticFileServer.class, handler.getClass());
}
Also used : StaticFileHandler(com.vaadin.flow.server.StaticFileHandler) StaticFileHandlerFactory(com.vaadin.flow.server.StaticFileHandlerFactory) VaadinService(com.vaadin.flow.server.VaadinService) AtomicReference(java.util.concurrent.atomic.AtomicReference) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 60 with VaadinService

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

the class InvalidUrlTest method initUI.

private static void initUI(UI ui, String initialLocation, ArgumentCaptor<Integer> statusCodeCaptor) throws InvalidRouteConfigurationException, ServiceException {
    VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    VaadinResponse response = Mockito.mock(VaadinResponse.class);
    String pathInfo;
    if (initialLocation.isEmpty()) {
        pathInfo = null;
    } else {
        Assert.assertFalse(initialLocation.startsWith("/"));
        pathInfo = "/" + initialLocation;
    }
    Mockito.when(request.getPathInfo()).thenReturn(pathInfo);
    VaadinService service = new MockVaadinServletService() {

        @Override
        public VaadinContext getContext() {
            return new MockVaadinContext();
        }
    };
    service.setCurrentInstances(request, response);
    MockVaadinSession session = new AlwaysLockedVaadinSession(service);
    DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(config.isProductionMode()).thenReturn(false);
    session.lock();
    session.setConfiguration(config);
    ui.getInternals().setSession(session);
    RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getRouter().getRegistry());
    routeConfiguration.update(() -> {
        routeConfiguration.getHandledRegistry().clean();
        Arrays.asList(UITest.RootNavigationTarget.class, UITest.FooBarNavigationTarget.class).forEach(routeConfiguration::setAnnotatedRoute);
    });
    ui.doInit(request, 0);
    ui.getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(request));
    session.unlock();
    if (statusCodeCaptor != null) {
        Mockito.verify(response).setStatus(statusCodeCaptor.capture());
    }
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) RouteConfiguration(com.vaadin.flow.router.RouteConfiguration) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

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