Search in sources :

Example 16 with VaadinContext

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;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) File(java.io.File)

Example 17 with VaadinContext

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;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) UI(com.vaadin.flow.component.UI) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 18 with VaadinContext

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);
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) Lookup(com.vaadin.flow.di.Lookup) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Before(org.junit.Before)

Example 19 with VaadinContext

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;
    }
}
Also used : JsModule(com.vaadin.flow.component.dependency.JsModule) CssImport(com.vaadin.flow.component.dependency.CssImport) VaadinContext(com.vaadin.flow.server.VaadinContext) FallbackChunk(com.vaadin.flow.server.frontend.FallbackChunk) JavaScript(com.vaadin.flow.component.dependency.JavaScript) CssImportData(com.vaadin.flow.server.frontend.FallbackChunk.CssImportData)

Example 20 with VaadinContext

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);
}
Also used : DefaultInstantiator(com.vaadin.flow.di.DefaultInstantiator) VaadinContext(com.vaadin.flow.server.VaadinContext) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) Element(com.vaadin.flow.dom.Element) HasElement(com.vaadin.flow.component.HasElement) Before(org.junit.Before)

Aggregations

VaadinContext (com.vaadin.flow.server.VaadinContext)42 Test (org.junit.Test)16 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)15 VaadinService (com.vaadin.flow.server.VaadinService)11 Lookup (com.vaadin.flow.di.Lookup)8 ResourceProvider (com.vaadin.flow.di.ResourceProvider)8 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)5 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)5 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)5 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)5 Properties (java.util.Properties)5 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)4 VaadinConfig (com.vaadin.flow.server.VaadinConfig)4 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)4 File (java.io.File)4 Before (org.junit.Before)4 VaadinSession (com.vaadin.flow.server.VaadinSession)3 WebComponentConfigurationRegistry (com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry)3 AppShellRegistry (com.vaadin.flow.server.AppShellRegistry)2 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)2