use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class AbstractSinglePropertyFieldTest method getValue_wrapExistingElement_elementHasProperty_valueIsThePropertyValue.
@Test
public void getValue_wrapExistingElement_elementHasProperty_valueIsThePropertyValue() {
Element element = new Element("tag");
element.setProperty("property", "foo");
UI ui = new UI();
UI.setCurrent(ui);
VaadinSession session = Mockito.mock(VaadinSession.class);
ui.getInternals().setSession(session);
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(session.getService()).thenReturn(service);
Instantiator instantiator = Mockito.mock(Instantiator.class);
Mockito.when(service.getInstantiator()).thenReturn(instantiator);
Mockito.when(instantiator.createComponent(StringField.class)).thenAnswer(a -> new StringField());
StringField field = Component.from(element, StringField.class);
Assert.assertEquals("foo", field.getValue());
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class CompositeTest method setup.
@Before
public void setup() {
compositeWithComponent = new CompositeWithComponent() {
@Override
public String toString() {
return "Composite";
}
};
layoutWithSingleComponentComposite = new TestLayout() {
@Override
public String toString() {
return "Layout";
}
};
layoutWithSingleComponentComposite.addComponent(compositeWithComponent);
((TracksAttachDetach) componentInsideLayoutInsideComposite).track();
compositeWithComponent.track();
layoutInsideComposite.track();
layoutWithSingleComponentComposite.track();
Assert.assertNull(VaadinService.getCurrent());
VaadinService service = Mockito.mock(VaadinService.class);
DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(configuration.isProductionMode()).thenReturn(true);
Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
VaadinService.setCurrent(service);
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class FeatureFlagsTest method mockResourcesLocation.
private void mockResourcesLocation() {
VaadinService service = Mockito.mock(VaadinService.class);
VaadinService.setCurrent(service);
VaadinContext vaadinContext = Mockito.mock(VaadinContext.class);
Mockito.when(service.getContext()).thenReturn(vaadinContext);
ApplicationConfiguration applicationConfiguration = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(vaadinContext.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(applicationConfiguration);
Mockito.when(applicationConfiguration.getJavaResourceFolder()).thenReturn(propertiesDir);
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class SpringInstantiatorTest method getService.
public static VaadinService getService(ApplicationContext context, Properties configProperties, boolean rootMapping) throws ServletException {
SpringServlet servlet = new SpringServlet(context, rootMapping) {
@Override
protected DeploymentConfiguration createDeploymentConfiguration(Properties initParameters) {
if (configProperties != null) {
configProperties.putAll(initParameters);
return super.createDeploymentConfiguration(configProperties);
}
return super.createDeploymentConfiguration(initParameters);
}
};
ServletConfig config = Mockito.mock(ServletConfig.class);
ServletContext servletContext = Mockito.mock(ServletContext.class);
Mockito.when(servletContext.getClassLoader()).thenReturn(servlet.getClass().getClassLoader());
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(appConfig.getContext()).thenReturn(new VaadinServletContext(servletContext));
Mockito.when(servletContext.getAttribute(ApplicationConfiguration.class.getName())).thenReturn(appConfig);
Lookup lookup = Mockito.mock(Lookup.class);
ResourceProvider provider = Mockito.mock(ResourceProvider.class);
Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(provider);
StaticFileHandlerFactory staticFileHandlerFactory = vaadinService -> new StaticFileServer((VaadinServletService) vaadinService);
Mockito.when(lookup.lookup(StaticFileHandlerFactory.class)).thenReturn(staticFileHandlerFactory);
Mockito.when(servletContext.getAttribute(Lookup.class.getName())).thenReturn(lookup);
Mockito.when(config.getServletContext()).thenReturn(servletContext);
Mockito.when(config.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(servletContext.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
servlet.init(config);
return servlet.getService();
}
use of com.vaadin.flow.server.VaadinService 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;
}
Aggregations