Search in sources :

Example 1 with TestBeanStore

use of com.vaadin.flow.spring.scopes.TestBeanStore in project flow by vaadin.

the class SpringClassesSerializableTest method storeSerializableCallback_callbackIsRestoredAfterDeserialization.

@Test
public void storeSerializableCallback_callbackIsRestoredAfterDeserialization() throws Throwable {
    TestBeanStore store = createStore();
    Callback callback = new Callback();
    Assert.assertNull(CAPTURE);
    store.registerDestructionCallback("foo", callback);
    TestBeanStore deserialized = serializeAndDeserialize(store);
    deserialized.destroy();
    Assert.assertEquals("bar", CAPTURE);
}
Also used : TestBeanStore(com.vaadin.flow.spring.scopes.TestBeanStore) Test(org.junit.Test) ClassesSerializableTest(com.vaadin.flow.testutil.ClassesSerializableTest)

Example 2 with TestBeanStore

use of com.vaadin.flow.spring.scopes.TestBeanStore in project flow by vaadin.

the class SpringClassesSerializableTest method storeSerializableObject_objectIsRestoredAfterDeserialization.

@Test
public void storeSerializableObject_objectIsRestoredAfterDeserialization() throws Throwable {
    TestBeanStore store = createStore();
    store.get("foo", () -> "bar");
    TestBeanStore deserialized = serializeAndDeserialize(store);
    Object object = deserialized.get("foo", () -> null);
    Assert.assertEquals("bar", object);
}
Also used : TestBeanStore(com.vaadin.flow.spring.scopes.TestBeanStore) Test(org.junit.Test) ClassesSerializableTest(com.vaadin.flow.testutil.ClassesSerializableTest)

Example 3 with TestBeanStore

use of com.vaadin.flow.spring.scopes.TestBeanStore in project flow by vaadin.

the class SpringClassesSerializableTest method createStore.

private TestBeanStore createStore() {
    final Properties initParameters = new Properties();
    ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
    VaadinContext context = Mockito.mock(VaadinContext.class);
    Mockito.when(context.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(appConfig);
    Mockito.when(appConfig.getContext()).thenReturn(context);
    Lookup lookup = Mockito.mock(Lookup.class);
    Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
    VaadinService service = new VaadinServletService(new VaadinServlet(), new DefaultDeploymentConfiguration(appConfig, getClass(), initParameters)) {

        @Override
        public VaadinContext getContext() {
            return context;
        }
    };
    VaadinSession session = new TestSession(service);
    TestBeanStore store = new TestBeanStore(session);
    return store;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) TestBeanStore(com.vaadin.flow.spring.scopes.TestBeanStore) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServlet(com.vaadin.flow.server.VaadinServlet) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Lookup(com.vaadin.flow.di.Lookup) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Aggregations

TestBeanStore (com.vaadin.flow.spring.scopes.TestBeanStore)3 ClassesSerializableTest (com.vaadin.flow.testutil.ClassesSerializableTest)2 Test (org.junit.Test)2 Lookup (com.vaadin.flow.di.Lookup)1 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)1 VaadinContext (com.vaadin.flow.server.VaadinContext)1 VaadinService (com.vaadin.flow.server.VaadinService)1 VaadinServlet (com.vaadin.flow.server.VaadinServlet)1 VaadinServletService (com.vaadin.flow.server.VaadinServletService)1 VaadinSession (com.vaadin.flow.server.VaadinSession)1 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)1 Properties (java.util.Properties)1