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);
}
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);
}
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;
}
Aggregations