Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flow-push/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<description>${project.name}</description>

<properties>
<pushDirectory>${project.build.outputDirectory}/META-INF/resources/VAADIN/static/push</pushDirectory>
<pushDirectory>${project.build.outputDirectory}/META-INF/VAADIN/webapp/VAADIN/static/push</pushDirectory>
<vaadinPush.js>${pushDirectory}/vaadinPush.js</vaadinPush.js>
<vaadinPush-min.js>${pushDirectory}/vaadinPush-min.js</vaadinPush-min.js>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@

setupRequestURI("", "", "/frontend/.");
Mockito.when(servletService.getStaticResource("/frontend/."))
.thenReturn(new URL("jar:" + warFile.toURI().toURL() + "!/"

Check warning on line 426 in flow-server/src/test/java/com/vaadin/flow/server/StaticFileServerTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "URL"; it is deprecated.

See more on https://sonarcloud.io/project/issues?id=vaadin_flow&issues=AZq24uU3cVVFjZ8tpTc4&open=AZq24uU3cVVFjZ8tpTc4&pullRequest=22830
+ archiveFile.getName() + "!/frontend"));
Assert.assertTrue(
"Request should return as static request as we can not determine non file resources in jar files.",
Expand Down Expand Up @@ -1252,6 +1252,51 @@
Assert.assertFalse(fileServer.serveStaticResource(request, response));
}

@Test
public void serveStaticResource_vaadinPushScript_servedFromMetaInfVaadinWebapp()
throws IOException {
String pathInfo = "/VAADIN/static/push/vaadinPush.js";
setupRequestURI("", "", pathInfo);
String fileData = "window.vaadinPush = {};";
ClassLoader mockLoader = Mockito.mock(ClassLoader.class);
Mockito.when(servletService.getClassLoader()).thenReturn(mockLoader);

// The push script should be loaded from META-INF/VAADIN/webapp/
// (not from META-INF/resources/VAADIN/static/push/)
Mockito.when(mockLoader.getResource(
"META-INF/VAADIN/webapp/VAADIN/static/push/vaadinPush.js"))
.thenReturn(createFileURLWithDataAndLength(
"/push/vaadinPush.js", fileData));

mockStatsBundles(mockLoader);
mockConfigurationPolyfills();

Assert.assertTrue(fileServer.serveStaticResource(request, response));
Assert.assertEquals(fileData, out.getOutputString());
}

@Test
public void serveStaticResource_vaadinPushMinScript_servedFromMetaInfVaadinWebapp()
throws IOException {
String pathInfo = "/VAADIN/static/push/vaadinPush-min.js";
setupRequestURI("", "", pathInfo);
String fileData = "window.vaadinPush={};";
ClassLoader mockLoader = Mockito.mock(ClassLoader.class);
Mockito.when(servletService.getClassLoader()).thenReturn(mockLoader);

// The push script should be loaded from META-INF/VAADIN/webapp/
Mockito.when(mockLoader.getResource(
"META-INF/VAADIN/webapp/VAADIN/static/push/vaadinPush-min.js"))
.thenReturn(createFileURLWithDataAndLength(
"/push/vaadinPush-min.js", fileData));

mockStatsBundles(mockLoader);
mockConfigurationPolyfills();

Assert.assertTrue(fileServer.serveStaticResource(request, response));
Assert.assertEquals(fileData, out.getOutputString());
}

private static class CapturingServletOutputStream
extends ServletOutputStream {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand Down
Loading