use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class FeatureView method getFeatureFile.
private File getFeatureFile() {
final VaadinContext context = VaadinSession.getCurrent().getService().getContext();
final ApplicationConfiguration configuration = ApplicationConfiguration.get(context);
final File file = new File(configuration.getJavaResourceFolder(), FeatureFlags.PROPERTIES_FILENAME);
return file;
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class DefaultBindingExceptionHandlerTest method mockUI.
private UI mockUI(boolean productionMode) {
UI ui = new UI();
VaadinService service = Mockito.mock(VaadinService.class);
VaadinSession session = Mockito.mock(VaadinSession.class);
ui.getInternals().setSession(session);
Mockito.when(session.getService()).thenReturn(service);
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(service.getContext()).thenReturn(context);
ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(context.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(configuration);
Mockito.when(configuration.isProductionMode()).thenReturn(productionMode);
return ui;
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class AbstractDnDUnitTest method setup.
@Before
public void setup() {
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(appConfig.getBuildFolder()).thenReturn(".");
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(appConfig.getContext()).thenReturn(context);
Lookup lookup = Mockito.mock(Lookup.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
DefaultDeploymentConfiguration configuration = new DefaultDeploymentConfiguration(appConfig, VaadinServlet.class, new Properties());
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(service.resolveResource(Mockito.anyString())).thenReturn("");
VaadinSession session = Mockito.mock(VaadinSession.class);
Mockito.when(session.getConfiguration()).thenReturn(configuration);
Mockito.when(session.getService()).thenReturn(service);
ui = new MockUI(session);
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class UIInternals method addFallbackDependencies.
private void addFallbackDependencies(DependencyInfo dependency) {
if (isFallbackChunkLoaded) {
return;
}
VaadinContext context = ui.getSession().getService().getContext();
FallbackChunk chunk = context.getAttribute(FallbackChunk.class);
if (chunk == null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Fallback chunk is not available, skipping fallback dependencies load");
}
return;
}
Set<String> modules = chunk.getModules();
Set<CssImportData> cssImportsData = chunk.getCssImports();
if (modules.isEmpty() && cssImportsData.isEmpty()) {
getLogger().debug("Fallback chunk is empty, skipping fallback dependencies load");
return;
}
List<CssImport> cssImports = dependency.getCssImports();
List<JavaScript> javaScripts = dependency.getJavaScripts();
List<JsModule> jsModules = dependency.getJsModules();
if (jsModules.stream().map(JsModule::value).anyMatch(modules::contains)) {
loadFallbackChunk();
return;
}
if (javaScripts.stream().map(JavaScript::value).anyMatch(modules::contains)) {
loadFallbackChunk();
return;
}
if (cssImports.stream().map(this::buildData).anyMatch(cssImportsData::contains)) {
loadFallbackChunk();
return;
}
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class UIInternalsTest method init.
@Before
public void init() {
MockitoAnnotations.initMocks(this);
Mockito.when(ui.getUI()).thenReturn(Optional.of(ui));
Element body = new Element("body");
Mockito.when(ui.getElement()).thenReturn(body);
internals = new UIInternals(ui);
AlwaysLockedVaadinSession session = new AlwaysLockedVaadinSession(vaadinService);
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(vaadinService.getContext()).thenReturn(context);
Mockito.when(vaadinService.getInstantiator()).thenReturn(new DefaultInstantiator(vaadinService));
internals.setSession(session);
Mockito.when(ui.getSession()).thenReturn(session);
}
Aggregations