use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.
the class StreamResourceRegistryTest method setUp.
@Before
public void setUp() throws ServletException {
UI ui = Mockito.mock(UI.class);
UI.setCurrent(ui);
Mockito.when(ui.getUIId()).thenReturn(1);
service = servlet.getService();
session = new VaadinSession(service) {
@Override
public boolean hasLock() {
return true;
}
};
}
use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.
the class ComponentTest method testUIInitialAttach.
@Test
public void testUIInitialAttach() {
AtomicBoolean initialAttach = new AtomicBoolean(false);
UI ui = new UI();
ui.addAttachListener(e -> {
initialAttach.set(e.isInitialAttach());
});
ui.getInternals().setSession(new VaadinSession(null));
Assert.assertTrue(initialAttach.get());
// UI is never detached and reattached
}
use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.
the class ComponentTest method setup.
@Before
public void setup() {
divWithTextComponent = new TestComponent(ElementFactory.createDiv("Test component"));
parentDivComponent = new TestComponent(ElementFactory.createDiv());
child1SpanComponent = new TestComponent(ElementFactory.createSpan("Span"));
child2InputComponent = new TestComponent(ElementFactory.createInput());
parentDivComponent.getElement().appendChild(child1SpanComponent.getElement(), child2InputComponent.getElement());
VaadinSession session = Mockito.mock(VaadinSession.class);
UI ui = new UI() {
@Override
public VaadinSession getSession() {
return session;
}
};
VaadinService service = Mockito.mock(VaadinService.class);
when(session.getService()).thenReturn(service);
DefaultInstantiator instantiator = new DefaultInstantiator(service);
when(service.getInstantiator()).thenReturn(instantiator);
UI.setCurrent(ui);
}
use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.
the class DefaultTemplateParserTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
VaadinSession session = Mockito.mock(VaadinSession.class);
factory = (VaadinUriResolverFactory) vaadinRequest -> resolver;
Mockito.when(session.getAttribute(VaadinUriResolverFactory.class)).thenReturn(factory);
Mockito.when(service.getDependencyFilters()).thenReturn(Collections.emptyList());
WrappedHttpSession wrappedSession = Mockito.mock(WrappedHttpSession.class);
HttpSession httpSession = Mockito.mock(HttpSession.class);
Mockito.when(wrappedSession.getHttpSession()).thenReturn(httpSession);
servlet = new VaadinServlet() {
@Override
protected VaadinServletService createServletService() throws ServletException, ServiceException {
return service;
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
Mockito.when(service.getServlet()).thenReturn(servlet);
Mockito.when(resolver.resolveVaadinUri("/bar.html")).thenReturn("bar.html");
Mockito.when(resolver.resolveVaadinUri("/bar1.html")).thenReturn("bar1.html");
Mockito.when(resolver.resolveVaadinUri("/bundle.html")).thenReturn("bundle.html");
Mockito.when(request.getWrappedSession()).thenReturn(wrappedSession);
Mockito.when(request.getServletPath()).thenReturn("");
Mockito.when(servletContext.getResourceAsStream("/bar.html")).thenReturn(new ByteArrayInputStream("<dom-module id='bar'></dom-module>".getBytes(StandardCharsets.UTF_8)));
Mockito.when(servletContext.getResourceAsStream("/bar1.html")).thenReturn(new ByteArrayInputStream("<dom-module id='foo'></dom-module>".getBytes(StandardCharsets.UTF_8)));
Mockito.when(servletContext.getResourceAsStream("/bundle.html")).thenReturn(getBundle(), getBundle(), getBundle());
CurrentInstance.set(VaadinRequest.class, request);
CurrentInstance.set(VaadinSession.class, session);
CurrentInstance.set(VaadinService.class, service);
}
use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.
the class PolymerTemplateTest method setUp.
@SuppressWarnings("serial")
@Before
public void setUp() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
executionOrder.clear();
executionParams.clear();
Field customElements = CustomElementRegistry.class.getDeclaredField("customElements");
customElements.setAccessible(true);
customElements.set(CustomElementRegistry.getInstance(), new AtomicReference<>());
Map<String, Class<? extends Component>> map = new HashMap<>();
map.put("child-template", TemplateChild.class);
map.put("ffs", TestPolymerTemplate.class);
map.put("execution-child", ExecutionChild.class);
CustomElementRegistry.getInstance().setCustomElements(map);
VaadinSession session = Mockito.mock(VaadinSession.class);
UI ui = new UI() {
private Page page = new Page(this) {
@Override
public ExecutionCanceler executeJavaScript(String expression, Serializable... parameters) {
executionOrder.add(expression);
executionParams.add(parameters);
return () -> true;
}
};
@Override
public VaadinSession getSession() {
return session;
}
@Override
public Page getPage() {
return page;
}
};
VaadinService service = Mockito.mock(VaadinService.class);
when(session.getService()).thenReturn(service);
DefaultInstantiator instantiator = new DefaultInstantiator(service);
when(service.getInstantiator()).thenReturn(instantiator);
UI.setCurrent(ui);
}
Aggregations