Search in sources :

Example 1 with DefaultDeploymentConfiguration

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

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

the class AbstractUIScopedTest method mockUI.

protected UI mockUI() {
    VaadinSession session = mockSession();
    Router router = mock(Router.class);
    VaadinService service = session.getService();
    when(service.getRouter()).thenReturn(router);
    Properties initParameters = new Properties();
    ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
    when(service.getMainDivId(Mockito.any(), Mockito.any())).thenReturn(" - ");
    final Map<String, Object> attributeMap = new HashMap<>();
    ServletContext servletContext = Mockito.mock(ServletContext.class);
    Mockito.when(servletContext.getAttribute(Mockito.anyString())).then(invocationOnMock -> attributeMap.get(invocationOnMock.getArguments()[0].toString()));
    Mockito.doAnswer(invocationOnMock -> attributeMap.put(invocationOnMock.getArguments()[0].toString(), invocationOnMock.getArguments()[1])).when(servletContext).setAttribute(Mockito.anyString(), Mockito.any());
    VaadinServletContext context = new VaadinServletContext(servletContext);
    Mockito.when(service.getContext()).thenReturn(context);
    Lookup lookup = Mockito.mock(Lookup.class);
    Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
    Mockito.when(appConfig.getContext()).thenReturn(context);
    DefaultDeploymentConfiguration config = new DefaultDeploymentConfiguration(appConfig, getClass(), initParameters);
    when(service.getDeploymentConfiguration()).thenReturn(config);
    ui = new UI();
    ui.getInternals().setSession(session);
    ui.doInit(null, 1);
    UI.setCurrent(ui);
    return ui;
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) VaadinSession(com.vaadin.flow.server.VaadinSession) HashMap(java.util.HashMap) Router(com.vaadin.flow.router.Router) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) UI(com.vaadin.flow.component.UI) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) ServletContext(javax.servlet.ServletContext) Lookup(com.vaadin.flow.di.Lookup) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 3 with DefaultDeploymentConfiguration

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

the class WebComponentProviderTest method providesDifferentGeneratedHTMLForEachExportedComponent.

@Test
public void providesDifferentGeneratedHTMLForEachExportedComponent() throws IOException {
    ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
    registry = setupConfigurations(MyComponentExporter.class, OtherComponentExporter.class);
    ByteArrayOutputStream out = Mockito.mock(ByteArrayOutputStream.class);
    DefaultDeploymentConfiguration configuration = Mockito.mock(DefaultDeploymentConfiguration.class);
    Mockito.when(response.getOutputStream()).thenReturn(out);
    Mockito.when(session.getConfiguration()).thenReturn(configuration);
    Mockito.when(request.getPathInfo()).thenReturn("/web-component/my-component.js");
    Assert.assertTrue("Provider should handle first web-component request", provider.synchronizedHandleRequest(session, request, response));
    Mockito.when(request.getPathInfo()).thenReturn("/web-component/other-component.js");
    Assert.assertTrue("Provider should handle second web-component request", provider.synchronizedHandleRequest(session, request, response));
    Mockito.verify(response, times(2)).getOutputStream();
    Mockito.verify(out, times(2)).write(captor.capture());
    byte[] first = captor.getAllValues().get(0);
    byte[] second = captor.getAllValues().get(1);
    Assert.assertNotEquals("Stream output should not match", first, second);
}
Also used : DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with DefaultDeploymentConfiguration

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

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

the class BundleFilterInitializerTest method init.

@Before
public void init() throws MalformedURLException {
    event = Mockito.mock(ServiceInitEvent.class);
    VaadinServletService service = Mockito.mock(VaadinServletService.class);
    VaadinServlet servlet = Mockito.mock(VaadinServlet.class);
    Mockito.when(event.getSource()).thenReturn(service);
    Mockito.when(service.getServlet()).thenReturn(servlet);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(new DefaultDeploymentConfiguration(BundleFilterInitializerTest.class, new Properties(), (base, consumer) -> {
    }) {

        @Override
        public boolean isProductionMode() {
            return true;
        }
    });
    Mockito.doAnswer(invocation -> {
        dependencyFilterAddHandler.accept(invocation.getArgumentAt(0, DependencyFilter.class));
        return null;
    }).when(event).addDependencyFilter(Mockito.any(DependencyFilter.class));
    Mockito.doAnswer(invocation -> {
        return inputStreamProducer.apply(invocation.getArgumentAt(0, String.class));
    }).when(service).getResourceAsStream("/frontend-es6/vaadin-flow-bundle-manifest.json");
    Mockito.doAnswer(invocation -> {
        return resourceProducer.apply(invocation.getArgumentAt(0, String.class));
    }).when(service).getResource(Mockito.anyString());
}
Also used : ServiceInitEvent(com.vaadin.flow.server.ServiceInitEvent) IntStream(java.util.stream.IntStream) URL(java.net.URL) Dependency(com.vaadin.flow.shared.ui.Dependency) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) DependencyFilter(com.vaadin.flow.server.DependencyFilter) Before(org.junit.Before) JsonException(elemental.json.JsonException) ServiceInitEvent(com.vaadin.flow.server.ServiceInitEvent) Properties(java.util.Properties) MalformedURLException(java.net.MalformedURLException) VaadinServlet(com.vaadin.flow.server.VaadinServlet) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) LoadMode(com.vaadin.flow.shared.ui.LoadMode) ServletContext(javax.servlet.ServletContext) Assert(org.junit.Assert) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VaadinServletService(com.vaadin.flow.server.VaadinServletService) InputStream(java.io.InputStream) VaadinServlet(com.vaadin.flow.server.VaadinServlet) VaadinServletService(com.vaadin.flow.server.VaadinServletService) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) DependencyFilter(com.vaadin.flow.server.DependencyFilter) Properties(java.util.Properties) Before(org.junit.Before)

Aggregations

DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)10 Properties (java.util.Properties)8 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)6 VaadinContext (com.vaadin.flow.server.VaadinContext)5 VaadinServletService (com.vaadin.flow.server.VaadinServletService)5 Lookup (com.vaadin.flow.di.Lookup)4 VaadinService (com.vaadin.flow.server.VaadinService)4 VaadinSession (com.vaadin.flow.server.VaadinSession)4 Test (org.junit.Test)4 Before (org.junit.Before)3 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)2 VaadinServlet (com.vaadin.flow.server.VaadinServlet)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ServletContext (javax.servlet.ServletContext)2 UI (com.vaadin.flow.component.UI)1 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)1 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)1 Router (com.vaadin.flow.router.Router)1 Attributes (com.vaadin.flow.server.Attributes)1 DependencyFilter (com.vaadin.flow.server.DependencyFilter)1