use of com.vaadin.flow.server.StreamResource in project flow by vaadin.
the class StreamResourceRegistryTest method unregisterResource_resourceIsRemoved.
@Test
public void unregisterResource_resourceIsRemoved() {
StreamResourceRegistry registry = session.getResourceRegistry();
StreamResource resource = new StreamResource("name", () -> makeEmptyStream());
StreamRegistration registration = registry.registerResource(resource);
Assert.assertNotNull(registration);
URI uri = registration.getResourceUri();
registration.unregister();
Optional<StreamResource> stored = registry.getResource(StreamResource.class, uri);
Assert.assertFalse("Unexpected stored resource is found after unregister()", stored.isPresent());
Assert.assertFalse("Unexpected resource is returned by the registration instance", registration.getResource() != null);
}
use of com.vaadin.flow.server.StreamResource in project flow by vaadin.
the class StreamResourceRegistryTest method registerResource_registrationResultCanBeFound.
@Test
public void registerResource_registrationResultCanBeFound() {
StreamResourceRegistry registry = session.getResourceRegistry();
StreamResource resource = new StreamResource("name", () -> makeEmptyStream());
StreamRegistration registration = registry.registerResource(resource);
Assert.assertNotNull(registration);
URI uri = registration.getResourceUri();
Optional<StreamResource> stored = registry.getResource(StreamResource.class, uri);
Assert.assertSame("Unexpected stored resource is returned for registered URI", resource, stored.get());
Assert.assertSame("Unexpected resource is returned by the registration instance", resource, registration.getResource());
}
use of com.vaadin.flow.server.StreamResource in project flow by vaadin.
the class StreamResourceTest method setContentTypeResolver.
@Test
public void setContentTypeResolver() {
StreamResource resource = new StreamResource("foo", () -> makeEmptyStream());
resource.setContentTypeResolver((res, context) -> "bar");
Assert.assertNotNull(resource.getContentTypeResolver());
assertContentType(resource, resource.getContentTypeResolver());
}
use of com.vaadin.flow.server.StreamResource in project flow by vaadin.
the class StreamResourceTest method getDefaultContentTypeResolver.
@Test
public void getDefaultContentTypeResolver() {
StreamResource resource = new StreamResource("foo", () -> makeEmptyStream());
ContentTypeResolver resolver = resource.getContentTypeResolver();
Assert.assertNotNull(resolver);
assertContentType(resource, resolver);
}
use of com.vaadin.flow.server.StreamResource in project flow by vaadin.
the class ElementTest method setResourceAttribute_elementIsNotAttached_elementHasAttribute.
@Test
public void setResourceAttribute_elementIsNotAttached_elementHasAttribute() {
UI.setCurrent(createUI());
Element element = ElementFactory.createDiv();
String resName = "resource";
StreamResource resource = createEmptyResource(resName);
element.setAttribute("foo", resource);
Assert.assertTrue(element.hasAttribute("foo"));
Assert.assertTrue(element.getAttribute("foo").endsWith(resName));
}
Aggregations