|
13 | 13 | import org.junit.Test; |
14 | 14 | import org.mockito.Mockito; |
15 | 15 |
|
| 16 | +import com.vaadin.flow.server.StreamRegistration; |
| 17 | +import com.vaadin.flow.server.StreamResource; |
16 | 18 | import com.vaadin.flow.server.VaadinContext; |
17 | 19 | import com.vaadin.flow.server.VaadinRequest; |
18 | 20 | import com.vaadin.flow.server.VaadinService; |
@@ -49,6 +51,43 @@ public void testSerializeVaadinSession_notProductionMode_disableDevModeSerializa |
49 | 51 | session.getUIs().isEmpty()); |
50 | 52 | } |
51 | 53 |
|
| 54 | + @Test |
| 55 | + public void testSerializeVaadinSession_notProductionMode_disableDevModeSerialization_streamResources_deserializedSessionHasNoUIs() |
| 56 | + throws Exception { |
| 57 | + |
| 58 | + VaadinService vaadinService = new MockVaadinService(false, false); |
| 59 | + VaadinSession session = new VaadinSession(vaadinService); |
| 60 | + // This is done only for test purpose to init the session lock, |
| 61 | + // should be called by Flow internally as soon as the session has |
| 62 | + // been created. |
| 63 | + session.refreshTransients(null, vaadinService); |
| 64 | + MockUI ui = new MockUI(session); |
| 65 | + ui.doInit(null, 42); |
| 66 | + session.addUI(ui); |
| 67 | + |
| 68 | + session.lock(); |
| 69 | + final StreamRegistration name = session.getResourceRegistry() |
| 70 | + .registerResource(new StreamResource("name", |
| 71 | + () -> new ByteArrayInputStream(new byte[0]))); |
| 72 | + session.unlock(); |
| 73 | + |
| 74 | + session = serializeAndDeserialize(session); |
| 75 | + // This is done only for test purpose to refresh the session lock, |
| 76 | + // should be called by Flow internally as soon as the session has |
| 77 | + // been retrieved from http session. |
| 78 | + session.refreshTransients(null, vaadinService); |
| 79 | + |
| 80 | + Assert.assertNotNull( |
| 81 | + "UIs map should be available after devmode deserialization", |
| 82 | + session.getUIs()); |
| 83 | + Assert.assertTrue("UIs should be empty after devmode deserialization", |
| 84 | + session.getUIs().isEmpty()); |
| 85 | + Assert.assertTrue( |
| 86 | + "StreamResources should be empty after devmode deserialization", |
| 87 | + session.getResourceRegistry().getResource(name.getResourceUri()) |
| 88 | + .isEmpty()); |
| 89 | + } |
| 90 | + |
52 | 91 | @Test |
53 | 92 | public void testSerializeVaadinSession_notProductionMode_enableDevModeSerialization_deserializedSessionHasUI() |
54 | 93 | throws Exception { |
|
0 commit comments