ContentPackImport { public void startup() { final List<Path> contentPacksDirs = getContentPackBaseDirs(); startup(contentPacksDirs); } @SuppressWarnings("unused") @Inject  ContentPackImport(final ImportExportService importExportService,
                      final ContentPackImportConfig config,
                      final TempDirProvider tempDirProvider,
                      final SecurityContext securityContext); void startup();  }
@Test void testStartup_disabled() throws IOException { Mockito.reset(contentPackImportConfig); Mockito.when(contentPackImportConfig.isEnabled()).thenReturn(false); ContentPackImport contentPackImport = getContentPackImport(); FileUtil.touch(testPack1); contentPackImport.startup(Collections.singletonList(contentPackDir)); Mockito.verifyZeroInteractions(importExportService); assertThat(Files.exists(testPack1)).isTrue(); }
@Test void testStartup_enabledNoFiles() { setStandardMockAnswers(); Mockito.when(contentPackImportConfig.isEnabled()).thenReturn(true); ContentPackImport contentPackImport = getContentPackImport(); contentPackImport.startup(Collections.singletonList(contentPackDir)); Mockito.verifyZeroInteractions(importExportService); }
@Test void testStartup_enabledThreeFiles() throws IOException { setStandardMockAnswers(); Mockito.when(contentPackImportConfig.isEnabled()).thenReturn(true); ContentPackImport contentPackImport = getContentPackImport(); FileUtil.touch(testPack1); FileUtil.touch(testPack2); FileUtil.touch(testPack3); contentPackImport.startup(Collections.singletonList(contentPackDir)); Mockito.verify(importExportService, Mockito.times(1)) .performImportWithoutConfirmation(testPack1); Mockito.verify(importExportService, Mockito.times(1)) .performImportWithoutConfirmation(testPack2); Mockito.verify(importExportService, Mockito.times(0)) .performImportWithoutConfirmation(testPack3); assertThat(Files.exists(testPack1)) .isFalse(); assertThat(Files.exists(testPack1)).isFalse(); assertThat(Files.exists(contentPackDir.resolve(ContentPackImport.IMPORTED_DIR).resolve(testPack1.getFileName()))) .isTrue(); }
@Disabled @Test void testStartup_customLocation(@TempDir final Path tempDir) throws IOException { setStandardMockAnswers(); Mockito.when(contentPackImportConfig.isEnabled()).thenReturn(true); Mockito.when(contentPackImportConfig.getImportDirectory()) .thenReturn(tempDir.toAbsolutePath().toString()); ContentPackImport contentPackImport = getContentPackImport(); Path packFile = tempDir.resolve("testFile1.zip"); FileUtil.touch(packFile); contentPackImport.startup(Collections.singletonList(contentPackDir)); Mockito.verify(importExportService, Mockito.times(1)) .performImportWithoutConfirmation(packFile); assertThat(Files.exists(packFile)).isFalse(); assertThat(Files.exists(packFile)).isFalse(); assertThat(Files.exists(tempDir.resolve(ContentPackImport.IMPORTED_DIR).resolve(packFile.getFileName()))) .isTrue(); }
@Test void testStartup_failedImport() throws IOException { setStandardMockAnswers(); Mockito.when(contentPackImportConfig.isEnabled()).thenReturn(true); ContentPackImport contentPackImport = getContentPackImport(); Mockito.doThrow(new RuntimeException("Error thrown by mock import service for test")) .when(importExportService) .performImportWithoutConfirmation(ArgumentMatchers.any()); FileUtil.touch(testPack1); contentPackImport.startup(Collections.singletonList(contentPackDir)); assertThat(Files.exists(testPack1)).isFalse(); assertThat(Files.exists(contentPackDir.resolve(ContentPackImport.FAILED_DIR).resolve(testPack1.getFileName()))) .isTrue(); }