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);
}
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;
}
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);
}
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);
}
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());
}
Aggregations