Search in sources :

Example 1 with DefaultInstantiator

use of com.vaadin.flow.di.DefaultInstantiator in project flow by vaadin.

the class EventUtilTest method setUp.

@Before
public void setUp() {
    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);
}
Also used : DefaultInstantiator(com.vaadin.flow.di.DefaultInstantiator) VaadinSession(com.vaadin.flow.server.VaadinSession) UI(com.vaadin.flow.component.UI) VaadinService(com.vaadin.flow.server.VaadinService) Before(org.junit.Before)

Example 2 with DefaultInstantiator

use of com.vaadin.flow.di.DefaultInstantiator in project flow by vaadin.

the class CustomElementRegistryInitializerTest method setup.

@Before
public void setup() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    Field customElements = CustomElementRegistry.class.getDeclaredField("customElements");
    customElements.setAccessible(true);
    customElements.set(CustomElementRegistry.getInstance(), new AtomicReference<>());
    customElementRegistryInitializer = new CustomElementRegistryInitializer();
    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);
}
Also used : DefaultInstantiator(com.vaadin.flow.di.DefaultInstantiator) Field(java.lang.reflect.Field) VaadinSession(com.vaadin.flow.server.VaadinSession) UI(com.vaadin.flow.component.UI) VaadinService(com.vaadin.flow.server.VaadinService) Before(org.junit.Before)

Example 3 with DefaultInstantiator

use of com.vaadin.flow.di.DefaultInstantiator in project flow by vaadin.

the class VaadinService method createInstantiator.

/**
 * Creates an instantiator to use with this service.
 * <p>
 * A custom Vaadin service implementation can override this method to pick
 * an instantiator. The method {@link #loadInstantiators()} is used to find
 * a custom instantiator. If there is no one found then the default is used.
 * You may override this method or {@link #loadInstantiators()} in your
 * custom service.
 *
 * @return an instantiator to use, not <code>null</code>
 *
 * @throws ServiceException
 *             if there are multiple applicable instantiators
 *
 * @see #loadInstantiators()
 * @see Instantiator
 */
protected Instantiator createInstantiator() throws ServiceException {
    return loadInstantiators().orElseGet(() -> {
        DefaultInstantiator defaultInstantiator = new DefaultInstantiator(this);
        defaultInstantiator.init(this);
        return defaultInstantiator;
    });
}
Also used : DefaultInstantiator(com.vaadin.flow.di.DefaultInstantiator)

Example 4 with DefaultInstantiator

use of com.vaadin.flow.di.DefaultInstantiator 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);
}
Also used : DefaultInstantiator(com.vaadin.flow.di.DefaultInstantiator) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) Before(org.junit.Before)

Example 5 with DefaultInstantiator

use of com.vaadin.flow.di.DefaultInstantiator 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);
}
Also used : Serializable(java.io.Serializable) VaadinSession(com.vaadin.flow.server.VaadinSession) HashMap(java.util.HashMap) Page(com.vaadin.flow.component.page.Page) DefaultInstantiator(com.vaadin.flow.di.DefaultInstantiator) Field(java.lang.reflect.Field) UI(com.vaadin.flow.component.UI) VaadinService(com.vaadin.flow.server.VaadinService) Component(com.vaadin.flow.component.Component) Before(org.junit.Before)

Aggregations

DefaultInstantiator (com.vaadin.flow.di.DefaultInstantiator)5 VaadinService (com.vaadin.flow.server.VaadinService)4 VaadinSession (com.vaadin.flow.server.VaadinSession)4 Before (org.junit.Before)4 UI (com.vaadin.flow.component.UI)3 Field (java.lang.reflect.Field)2 Component (com.vaadin.flow.component.Component)1 Page (com.vaadin.flow.component.page.Page)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1