|
19 | 19 | import jakarta.servlet.ServletContextEvent; |
20 | 20 | import jakarta.servlet.ServletContextListener; |
21 | 21 |
|
| 22 | +import java.io.IOException; |
| 23 | +import java.net.URL; |
| 24 | +import java.net.URLClassLoader; |
| 25 | +import java.nio.file.Files; |
| 26 | +import java.nio.file.Path; |
| 27 | +import java.util.Arrays; |
22 | 28 | import java.util.Collections; |
23 | 29 | import java.util.HashMap; |
24 | 30 | import java.util.Map; |
|
29 | 35 | import org.junit.After; |
30 | 36 | import org.junit.Assert; |
31 | 37 | import org.junit.Before; |
| 38 | +import org.junit.Rule; |
32 | 39 | import org.junit.Test; |
| 40 | +import org.junit.rules.TemporaryFolder; |
33 | 41 | import org.mockito.Mock; |
34 | 42 | import org.mockito.MockedStatic; |
35 | 43 | import org.mockito.Mockito; |
36 | 44 | import org.mockito.MockitoAnnotations; |
37 | 45 | import org.springframework.boot.autoconfigure.AutoConfigurationPackages; |
38 | 46 | import org.springframework.context.ApplicationContext; |
39 | 47 | import org.springframework.core.env.Environment; |
| 48 | +import org.springframework.core.io.DefaultResourceLoader; |
| 49 | +import org.springframework.core.io.Resource; |
40 | 50 |
|
41 | 51 | import com.vaadin.flow.component.Component; |
42 | 52 | import com.vaadin.flow.di.Lookup; |
|
54 | 64 | import com.vaadin.flow.server.startup.ApplicationRouteRegistry; |
55 | 65 | import com.vaadin.flow.server.startup.ServletDeployer; |
56 | 66 |
|
| 67 | +import static org.assertj.core.api.Assertions.assertThat; |
| 68 | + |
57 | 69 | public class VaadinServletContextInitializerTest { |
58 | 70 |
|
| 71 | + @Rule |
| 72 | + public TemporaryFolder temporaryFolder = new TemporaryFolder(); |
| 73 | + |
59 | 74 | @Mock |
60 | 75 | private ApplicationContext applicationContext; |
61 | 76 |
|
@@ -216,6 +231,37 @@ public int setErrorParameter(BeforeEnterEvent event, |
216 | 231 | Assert.assertEquals(TestErrorView.class, navigationTarget); |
217 | 232 | } |
218 | 233 |
|
| 234 | + @Test |
| 235 | + public void customResourceLoader_classpathRootContainsUnicodeCombiningCharacter_resourcesAreMatched() |
| 236 | + throws Exception { |
| 237 | + Path tempDir = temporaryFolder.getRoot().toPath(); |
| 238 | + Path classesRoot = tempDir.resolve("François") |
| 239 | + .resolve("vaadin-c\u0327-repro").resolve("target/classes"); |
| 240 | + Path applicationClass = classesRoot |
| 241 | + .resolve("com/example/application/Application.class"); |
| 242 | + Files.createDirectories(applicationClass.getParent()); |
| 243 | + Files.write(applicationClass, new byte[] { 0 }); |
| 244 | + |
| 245 | + try (URLClassLoader classLoader = new URLClassLoader( |
| 246 | + new URL[] { classesRoot.toUri().toURL() }, null)) { |
| 247 | + Resource[] resources = new VaadinServletContextInitializer.CustomResourceLoader( |
| 248 | + new DefaultResourceLoader(classLoader)).getResources( |
| 249 | + "classpath*:com/example/application/**/*.class"); |
| 250 | + |
| 251 | + assertThat(resources).as(Arrays.toString(resources)).anySatisfy( |
| 252 | + resource -> assertThat(getResourcePath(resource)).endsWith( |
| 253 | + "/com/example/application/Application.class")); |
| 254 | + } |
| 255 | + } |
| 256 | + |
| 257 | + private static String getResourcePath(Resource resource) { |
| 258 | + try { |
| 259 | + return resource.getURI().getPath(); |
| 260 | + } catch (IOException exception) { |
| 261 | + throw new IllegalStateException(exception); |
| 262 | + } |
| 263 | + } |
| 264 | + |
219 | 265 | private Runnable initRouteNotFoundMocksAndGetContextInitializedMockCall( |
220 | 266 | VaadinServletContextInitializer vaadinServletContextInitializer) |
221 | 267 | throws Exception { |
|
0 commit comments