|
32 | 32 | import org.junit.jupiter.api.Test;
|
33 | 33 | import org.junit.jupiter.api.extension.ExtendWith;
|
34 | 34 | import org.junit.jupiter.api.io.TempDir;
|
| 35 | +import org.junit.jupiter.params.ParameterizedTest; |
| 36 | +import org.junit.jupiter.params.provider.CsvSource; |
35 | 37 | import org.mockito.ArgumentCaptor;
|
36 | 38 | import org.mockito.Captor;
|
37 | 39 | import org.mockito.Mock;
|
@@ -120,9 +122,9 @@ public void testFileAddedAfterListeners() throws IOException {
|
120 | 122 | List<Collection<FirstTypeDTO>> firstTypeCaptorValues = firstTypeCaptor.getAllValues();
|
121 | 123 | assertThat(firstTypeCaptorValues, hasSize(2));
|
122 | 124 | List<Collection<SecondTypeDTO>> secondTypeCaptor1Values = secondTypeCaptor1.getAllValues();
|
123 |
| - assertThat(firstTypeCaptorValues, hasSize(2)); |
| 125 | + assertThat(secondTypeCaptor1Values, hasSize(2)); |
124 | 126 | List<Collection<SecondTypeDTO>> secondTypeCaptor2Values = secondTypeCaptor2.getAllValues();
|
125 |
| - assertThat(firstTypeCaptorValues, hasSize(2)); |
| 127 | + assertThat(secondTypeCaptor2Values, hasSize(2)); |
126 | 128 |
|
127 | 129 | Collection<FirstTypeDTO> firstTypeElements = firstTypeCaptorValues.getFirst();
|
128 | 130 | Collection<SecondTypeDTO> secondTypeElements1 = secondTypeCaptor1Values.getFirst();
|
@@ -179,9 +181,9 @@ public void testFileAddedBeforeListeners() throws IOException {
|
179 | 181 | List<Collection<FirstTypeDTO>> firstTypeCaptorValues = firstTypeCaptor.getAllValues();
|
180 | 182 | assertThat(firstTypeCaptorValues, hasSize(2));
|
181 | 183 | List<Collection<SecondTypeDTO>> secondTypeCaptor1Values = secondTypeCaptor1.getAllValues();
|
182 |
| - assertThat(firstTypeCaptorValues, hasSize(2)); |
| 184 | + assertThat(secondTypeCaptor1Values, hasSize(2)); |
183 | 185 | List<Collection<SecondTypeDTO>> secondTypeCaptor2Values = secondTypeCaptor2.getAllValues();
|
184 |
| - assertThat(firstTypeCaptorValues, hasSize(2)); |
| 186 | + assertThat(secondTypeCaptor2Values, hasSize(2)); |
185 | 187 |
|
186 | 188 | Collection<FirstTypeDTO> firstTypeElements = firstTypeCaptorValues.getFirst();
|
187 | 189 | Collection<SecondTypeDTO> secondTypeElements1 = secondTypeCaptor1Values.getFirst();
|
@@ -268,6 +270,50 @@ public void testFileUpdated() throws IOException {
|
268 | 270 | assertThat(firstTypeCaptorValues.get(7), contains(new FirstTypeDTO("Third", "Third original")));
|
269 | 271 | }
|
270 | 272 |
|
| 273 | + @ParameterizedTest |
| 274 | + @CsvSource({ // |
| 275 | + "modelFileUpdateRemovedElements.yaml,modelV2FileUpdateRemovedElements.yaml", |
| 276 | + "modelFileUpdateRenamedElements.yaml,modelV2FileUpdateRenamedElements.yaml", |
| 277 | + "modelFileUpdateRemovedVersion.yaml,modelV2FileUpdateRemovedVersion.yaml" // |
| 278 | + }) |
| 279 | + public void testFileRemovedElements(String v1File, String v2File) throws IOException { |
| 280 | + YamlModelRepositoryImpl modelRepository = new YamlModelRepositoryImpl(watchServiceMock); |
| 281 | + modelRepository.addYamlModelListener(firstTypeListener); |
| 282 | + |
| 283 | + // File in v1 format |
| 284 | + Files.copy(SOURCE_PATH.resolve("modelFileUpdatePost.yaml"), fullModelPath); |
| 285 | + modelRepository.processWatchEvent(WatchService.Kind.CREATE, MODEL_PATH); |
| 286 | + verify(firstTypeListener).addedModel(eq(MODEL_NAME), any()); |
| 287 | + |
| 288 | + Files.copy(SOURCE_PATH.resolve(v1File), fullModelPath, StandardCopyOption.REPLACE_EXISTING); |
| 289 | + modelRepository.processWatchEvent(WatchService.Kind.MODIFY, MODEL_PATH); |
| 290 | + verify(firstTypeListener).removedModel(eq(MODEL_NAME), firstTypeCaptor.capture()); |
| 291 | + |
| 292 | + Collection<FirstTypeDTO> firstTypeElements = firstTypeCaptor.getAllValues().getFirst(); |
| 293 | + |
| 294 | + // Check that the elements were removed |
| 295 | + assertThat(firstTypeElements, hasSize(3)); |
| 296 | + assertThat(firstTypeElements, containsInAnyOrder(new FirstTypeDTO("First", "First original"), |
| 297 | + new FirstTypeDTO("Second", "Second original"), new FirstTypeDTO("Third", "Third original"))); |
| 298 | + |
| 299 | + // File in v2 format |
| 300 | + Files.copy(SOURCE_PATH.resolve("modelV2FileUpdatePost.yaml"), fullModel2Path); |
| 301 | + modelRepository.processWatchEvent(WatchService.Kind.CREATE, MODEL2_PATH); |
| 302 | + verify(firstTypeListener).addedModel(eq(MODEL2_NAME), any()); |
| 303 | + |
| 304 | + Files.copy(SOURCE_PATH.resolve(v2File), fullModel2Path, StandardCopyOption.REPLACE_EXISTING); |
| 305 | + modelRepository.processWatchEvent(WatchService.Kind.MODIFY, MODEL2_PATH); |
| 306 | + verify(firstTypeListener).removedModel(eq(MODEL2_NAME), firstTypeCaptor.capture()); |
| 307 | + |
| 308 | + assertThat(firstTypeCaptor.getAllValues(), hasSize(2)); |
| 309 | + firstTypeElements = firstTypeCaptor.getAllValues().getLast(); |
| 310 | + |
| 311 | + // Check that the elements were removed |
| 312 | + assertThat(firstTypeElements, hasSize(3)); |
| 313 | + assertThat(firstTypeElements, containsInAnyOrder(new FirstTypeDTO("First", "First original"), |
| 314 | + new FirstTypeDTO("Second", "Second original"), new FirstTypeDTO("Third", "Third original"))); |
| 315 | + } |
| 316 | + |
271 | 317 | @Test
|
272 | 318 | public void testFileRemoved() throws IOException {
|
273 | 319 | YamlModelRepositoryImpl modelRepository = new YamlModelRepositoryImpl(watchServiceMock);
|
|
0 commit comments