Search in sources :

Example 36 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class VaadinServletTest method resolveTranslation_for_servlet_with_muliple_path_parts.

@Test
public void resolveTranslation_for_servlet_with_muliple_path_parts() throws MalformedURLException {
    request = Mockito.mock(VaadinServletRequest.class);
    CurrentInstance.set(VaadinRequest.class, request);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(((VaadinServletRequest) request).getServletPath()).thenReturn("/app/sub/");
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    Mockito.when(configuration.isProductionMode()).thenReturn(false);
    Mockito.when(factory.getUriResolver(request)).thenReturn(vaadinUriResolver);
    String path = "/src/foo";
    String resolved = "./../../src/bar";
    Mockito.when(vaadinUriResolver.resolveVaadinUri(path)).thenReturn(resolved);
    Mockito.when(vaadinUriResolver.resolveVaadinUri("/theme/foo")).thenReturn("./../../theme/foo");
    Mockito.when(context.getResource("/./theme/foo")).thenReturn(new URL("http://theme/foo"));
    String urlTranslation = servlet.getUrlTranslation(new MyTheme(), path);
    Assert.assertEquals("/theme/foo", urlTranslation);
}
Also used : DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 37 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class VaadinServletTest method resolveResource_webJarResource_resolvedAsWebJarsResource.

@Test
public void resolveResource_webJarResource_resolvedAsWebJarsResource() throws ServletException, MalformedURLException {
    String path = "foo";
    String frontendPrefix = "context://baz/";
    String resolved = "/baz/bower_components/";
    Mockito.when(vaadinUriResolver.resolveVaadinUri(path)).thenReturn(resolved);
    service = Mockito.mock(VaadinServletService.class);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(configuration.getDevelopmentFrontendPrefix()).thenReturn(frontendPrefix);
    Mockito.when(configuration.areWebJarsEnabled()).thenReturn(true);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    ServletConfig config = Mockito.mock(ServletConfig.class);
    servlet.init(config);
    CurrentInstance.set(VaadinRequest.class, request);
    CurrentInstance.set(VaadinSession.class, session);
    URL url = new URL("http://example.com");
    String webjars = "/webjars/";
    Mockito.when(context.getResource(webjars)).thenReturn(url);
    Assert.assertEquals(webjars, servlet.resolveResource(path));
}
Also used : ServletConfig(javax.servlet.ServletConfig) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 38 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class TemplateInitializerTest method createService.

@Override
protected VaadinService createService() {
    VaadinService service = mock(VaadinService.class);
    DeploymentConfiguration configuration = mock(DeploymentConfiguration.class);
    when(configuration.isProductionMode()).thenReturn(false);
    when(service.getDeploymentConfiguration()).thenReturn(configuration);
    return service;
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 39 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class PolymerPublishedEventRpcHandlerTest method setup.

@Before
public void setup() {
    service = Mockito.mock(VaadinService.class);
    VaadinService.setCurrent(service);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    handler = new PolymerPublishedEventRpcHandler();
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Before(org.junit.Before)

Example 40 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class AbstractTemplateTest method init.

@Before
public void init() throws Exception {
    service = Mockito.mock(VaadinService.class);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    VaadinSession session = Mockito.mock(VaadinSession.class);
    ui = new UI();
    ui.getInternals().setSession(session);
    Mockito.when(session.getService()).thenReturn(service);
    Instantiator instantiator = Mockito.mock(Instantiator.class);
    Mockito.when(instantiator.createComponent(Mockito.any())).thenAnswer(invocation -> ReflectTools.createInstance(invocation.getArgument(0)));
    Mockito.when(service.getInstantiator()).thenReturn(instantiator);
    CurrentInstance.setCurrent(ui);
    VaadinService.setCurrent(service);
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) Instantiator(com.vaadin.flow.di.Instantiator) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Before(org.junit.Before)

Aggregations

DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)63 Test (org.junit.Test)24 VaadinService (com.vaadin.flow.server.VaadinService)23 VaadinSession (com.vaadin.flow.server.VaadinSession)9 UI (com.vaadin.flow.component.UI)8 Before (org.junit.Before)8 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)6 URL (java.net.URL)6 Properties (java.util.Properties)6 VaadinContext (com.vaadin.flow.server.VaadinContext)5 PushConfiguration (com.vaadin.flow.component.PushConfiguration)4 HashMap (java.util.HashMap)4 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)3 Location (com.vaadin.flow.router.Location)3 VaadinServletService (com.vaadin.flow.server.VaadinServletService)3 Method (java.lang.reflect.Method)3 Set (java.util.Set)3 ServletConfig (javax.servlet.ServletConfig)3 ServletException (javax.servlet.ServletException)3 Div (com.vaadin.flow.component.html.Div)2