|
16 | 16 |
|
17 | 17 | package org.springframework.cloud.config.monitor; |
18 | 18 |
|
| 19 | +import java.nio.file.Files; |
19 | 20 | import java.nio.file.Path; |
| 21 | +import java.nio.file.Paths; |
20 | 22 | import java.util.ArrayList; |
21 | 23 | import java.util.Arrays; |
22 | 24 | import java.util.List; |
|
26 | 28 | import org.junit.jupiter.api.AfterEach; |
27 | 29 | import org.junit.jupiter.api.BeforeEach; |
28 | 30 | import org.junit.jupiter.api.Test; |
| 31 | +import org.junit.jupiter.api.io.TempDir; |
29 | 32 |
|
30 | 33 | import org.springframework.cloud.config.server.environment.AbstractScmEnvironmentRepository; |
31 | 34 | import org.springframework.cloud.config.server.environment.JGitEnvironmentProperties; |
@@ -54,6 +57,9 @@ public class FileMonitorConfigurationTest { |
54 | 57 |
|
55 | 58 | private List<AbstractScmEnvironmentRepository> repositories = new ArrayList<>(); |
56 | 59 |
|
| 60 | + @TempDir |
| 61 | + private Path tempDir; |
| 62 | + |
57 | 63 | @BeforeEach |
58 | 64 | public void setup() { |
59 | 65 | fileMonitorConfiguration.setResourceLoader(new FileSystemResourceLoader()); |
@@ -89,6 +95,22 @@ public void testStart_withNativeEnvironmentRepository() { |
89 | 95 | assertOnDirectory(1); |
90 | 96 | } |
91 | 97 |
|
| 98 | + @Test |
| 99 | + public void testStart_withNativeEnvironmentRepositoryAndRelativeFileUri() throws Exception { |
| 100 | + // given |
| 101 | + Path relativeLocation = Paths.get("target", "file-monitor", tempDir.getFileName().toString(), "config.d"); |
| 102 | + Files.createDirectories(relativeLocation); |
| 103 | + NativeEnvironmentRepository repository = createNativeEnvironmentRepository("file:" + relativeLocation); |
| 104 | + ReflectionTestUtils.setField(fileMonitorConfiguration, "nativeEnvironmentRepository", repository); |
| 105 | + |
| 106 | + // when |
| 107 | + fileMonitorConfiguration.start(); |
| 108 | + |
| 109 | + // then |
| 110 | + Set<Path> directory = getDirectory(); |
| 111 | + assertThat(directory).containsExactly(relativeLocation.toAbsolutePath()); |
| 112 | + } |
| 113 | + |
92 | 114 | @Test |
93 | 115 | public void testStart_withOneScmRepository() { |
94 | 116 | // given |
@@ -203,9 +225,13 @@ private void addScmRepository(AbstractScmEnvironmentRepository... repository) { |
203 | 225 | } |
204 | 226 |
|
205 | 227 | private NativeEnvironmentRepository createNativeEnvironmentRepository() { |
| 228 | + return createNativeEnvironmentRepository("classpath:pathsamples"); |
| 229 | + } |
| 230 | + |
| 231 | + private NativeEnvironmentRepository createNativeEnvironmentRepository(String... searchLocations) { |
206 | 232 | ConfigurableEnvironment environment = createConfigurableEnvironment(); |
207 | 233 | NativeEnvironmentProperties properties = new NativeEnvironmentProperties(); |
208 | | - properties.setSearchLocations(new String[] { "classpath:pathsamples" }); |
| 234 | + properties.setSearchLocations(searchLocations); |
209 | 235 | return new NativeEnvironmentRepository(environment, properties, ObservationRegistry.NOOP); |
210 | 236 | } |
211 | 237 |
|
|
0 commit comments