use of com.vaadin.flow.shared.VaadinUriResolver in project flow by vaadin.
the class BootstrapHandlerDependenciesTest method setup.
@Before
public void setup() {
BootstrapHandler.clientEngineFile = "foobar";
DeploymentConfiguration deploymentConfiguration = new MockDeploymentConfiguration();
service = Mockito.spy(new MockVaadinServletService(deploymentConfiguration));
when(service.getResourceAsStream(anyString())).thenAnswer(invocation -> new ByteArrayInputStream(((String) invocation.getArguments()[0]).getBytes()));
HttpServletRequest servletRequestMock = mock(HttpServletRequest.class);
VaadinServletRequest vaadinRequestMock = mock(VaadinServletRequest.class);
when(vaadinRequestMock.getHttpServletRequest()).thenReturn(servletRequestMock);
service.setCurrentInstances(vaadinRequestMock, mock(VaadinResponse.class));
Mockito.when(service.getDependencyFilters()).thenReturn(Collections.emptyList());
session = new MockVaadinSession(service);
session.lock();
session.setConfiguration(deploymentConfiguration);
VaadinUriResolverFactory factory = Mockito.mock(VaadinUriResolverFactory.class);
VaadinUriResolver vaadinUriResolver = Mockito.mock(VaadinUriResolver.class);
Mockito.when(factory.getUriResolver(Mockito.any())).thenReturn(vaadinUriResolver);
Mockito.when(vaadinUriResolver.resolveVaadinUri(Mockito.anyString())).thenAnswer(i -> i.getArguments()[0]);
Mockito.doAnswer(invocation -> invocation.getArguments()[1]).when(factory).toServletContextPath(Mockito.any(), Mockito.anyString());
session.setAttribute(VaadinUriResolverFactory.class, factory);
VaadinSession.setCurrent(session);
}
use of com.vaadin.flow.shared.VaadinUriResolver in project flow by vaadin.
the class BootstrapHandlerTest method testBootstrapListener.
@Test
public void testBootstrapListener() throws ServiceException {
List<BootstrapListener> listeners = new ArrayList<>(3);
AtomicReference<VaadinUriResolver> resolver = new AtomicReference<>();
listeners.add(evt -> evt.getDocument().head().getElementsByTag("script").remove());
listeners.add(evt -> {
resolver.set(evt.getUriResolver());
evt.getDocument().head().appendElement("script").attr("src", "testing.1");
});
listeners.add(evt -> evt.getDocument().head().appendElement("script").attr("src", "testing.2"));
Mockito.when(service.createInstantiator()).thenReturn(new MockInstantiator(event -> listeners.forEach(event::addBootstrapListener)));
initUI(testUI);
BootstrapContext bootstrapContext = new BootstrapContext(request, null, session, testUI);
Document page = BootstrapHandler.getBootstrapPage(bootstrapContext);
Elements scripts = page.head().getElementsByTag("script");
assertEquals(2, scripts.size());
assertEquals("testing.1", scripts.get(0).attr("src"));
assertEquals("testing.2", scripts.get(1).attr("src"));
Assert.assertNotNull(resolver.get());
Assert.assertEquals(bootstrapContext.getUriResolver(), resolver.get());
}
use of com.vaadin.flow.shared.VaadinUriResolver in project flow by vaadin.
the class UidlWriterTest method initializeUIForDependenciesTest.
private UI initializeUIForDependenciesTest(UI ui) {
ServletContext context = Mockito.mock(ServletContext.class);
VaadinServletService service = new VaadinServletService(new VaadinServlet() {
@Override
public ServletContext getServletContext() {
return context;
}
}, new MockDeploymentConfiguration()) {
RouterInterface router = new com.vaadin.flow.router.legacy.Router();
@Override
public RouterInterface getRouter() {
return router;
}
@Override
public Iterable<DependencyFilter> getDependencyFilters() {
return Collections.emptyList();
}
};
service.getRouter().reconfigure(conf -> {
conf.setRoute("", BaseClass.class);
conf.setParentView(BaseClass.class, ParentClass.class);
conf.setParentView(ParentClass.class, SuperParentClass.class);
});
MockVaadinSession session = new MockVaadinSession(service);
session.lock();
ui.getInternals().setSession(session);
when(service.getResourceAsStream(anyString())).thenAnswer(invocation -> new ByteArrayInputStream(((String) invocation.getArguments()[0]).getBytes()));
HttpServletRequest servletRequestMock = mock(HttpServletRequest.class);
VaadinServletRequest vaadinRequestMock = mock(VaadinServletRequest.class);
when(vaadinRequestMock.getHttpServletRequest()).thenReturn(servletRequestMock);
service.setCurrentInstances(vaadinRequestMock, mock(VaadinResponse.class));
ui.doInit(vaadinRequestMock, 1);
factory = mock(VaadinUriResolverFactory.class);
VaadinUriResolver vaadinUriResolver = Mockito.mock(VaadinUriResolver.class);
Mockito.when(factory.getUriResolver(any())).thenReturn(vaadinUriResolver);
Mockito.when(vaadinUriResolver.resolveVaadinUri(anyString())).thenAnswer(invocation -> invocation.getArguments()[0]);
doAnswer(invocation -> invocation.getArguments()[1]).when(factory).toServletContextPath(any(), anyString());
session.setAttribute(VaadinUriResolverFactory.class, factory);
VaadinSession.setCurrent(session);
return ui;
}
use of com.vaadin.flow.shared.VaadinUriResolver in project flow by vaadin.
the class VaadinUriResolverTest method testContextProtocol.
@Test
public void testContextProtocol() {
resolver = new VaadinUriResolver() {
@Override
protected String getFrontendRootUrl() {
return null;
}
@Override
protected String getContextRootUrl() {
return "http://someplace/";
}
};
assertEquals("http://someplace/my-component.html", resolver.resolveVaadinUri("context://my-component.html"));
}
use of com.vaadin.flow.shared.VaadinUriResolver in project flow by vaadin.
the class VaadinUriResolverTest method testFrontendProtocol.
@Test
public void testFrontendProtocol() {
resolver = new VaadinUriResolver() {
@Override
protected String getFrontendRootUrl() {
return "http://someplace/";
}
@Override
protected String getContextRootUrl() {
return null;
}
};
assertEquals("http://someplace/my-component.html", resolver.resolveVaadinUri("frontend://my-component.html"));
}
Aggregations