use of com.vaadin.flow.server.StreamResourceRegistry in project flow by vaadin.
the class StreamResourceRegistryTest method registerTwoResourcesWithSameName_resourcesHasDifferentURI.
@Test
public void registerTwoResourcesWithSameName_resourcesHasDifferentURI() {
StreamResourceRegistry registry = session.getResourceRegistry();
StreamResource resource1 = new StreamResource("name", () -> makeEmptyStream());
StreamRegistration registration1 = registry.registerResource(resource1);
StreamResource resource2 = new StreamResource("name", () -> makeEmptyStream());
StreamRegistration registration2 = registry.registerResource(resource2);
Assert.assertNotEquals("Two different resource are registered to the same URI", registration1.getResourceUri(), registration2.getResourceUri());
registration1.unregister();
Assert.assertTrue("Second resource is not found after first resource has been unregistered", registry.getResource(registration2.getResourceUri()).isPresent());
}
use of com.vaadin.flow.server.StreamResourceRegistry in project flow by vaadin.
the class StreamResourceRegistryTest method getResourceUrlIsEncoded.
@Test
public void getResourceUrlIsEncoded() throws UnsupportedEncodingException {
StreamResourceRegistry registry = session.getResourceRegistry();
StreamResource resource = new StreamResource("a?b=c d&e", () -> makeEmptyStream());
StreamRegistration registration = registry.registerResource(resource);
URI url = registration.getResourceUri();
String suffix = URLEncoder.encode(resource.getName(), StandardCharsets.UTF_8.name());
Assert.assertTrue("Resource url is not encoded", url.toString().endsWith(suffix));
}
use of com.vaadin.flow.server.StreamResourceRegistry 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.StreamResourceRegistry 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());
}
Aggregations