use of com.vaadin.flow.server.StreamResource in project flow by vaadin.
the class ElementTest method setResourceAttribute_elementIsAttached_removeAttribute.
@Test
public void setResourceAttribute_elementIsAttached_removeAttribute() throws URISyntaxException, InterruptedException {
UI ui = createUI();
UI.setCurrent(ui);
StreamResource resource = createEmptyResource("resource");
ui.getElement().setAttribute("foo", resource);
String uri = ui.getElement().getAttribute("foo");
Optional<StreamResource> res = ui.getSession().getResourceRegistry().getResource(StreamResource.class, new URI(uri));
Assert.assertTrue(res.isPresent());
res = null;
WeakReference<StreamResource> ref = new WeakReference<>(resource);
resource = null;
ui.getElement().removeAttribute("foo");
TestUtil.isGarbageCollected(ref);
res = ui.getSession().getResourceRegistry().getResource(StreamResource.class, new URI(uri));
Assert.assertFalse(res.isPresent());
Assert.assertFalse(ui.getElement().hasAttribute("foo"));
Assert.assertNull(ui.getElement().getAttribute("foo"));
}
Aggregations