Exemplo n.º 1
0
 @Test
 public void testWillContinueToLoadOnException() throws Exception {
   final IPlatformImporter importer = mock(IPlatformImporter.class);
   final FileInputStream inputStream = mock(FileInputStream.class);
   final ArchiveLoader loader = createArchiveLoader(importer, inputStream);
   final File directory = mock(File.class);
   final File jobs = mock(File.class);
   String jobsName = "jobs.zip";
   when(jobs.getName()).thenReturn(jobsName);
   final File reports = mock(File.class);
   when(jobs.getPath()).thenReturn("/root/path/" + jobsName);
   String reportsName = "reports.zip";
   when(reports.getName()).thenReturn(reportsName);
   when(reports.getPath()).thenReturn("/root/path/" + reportsName);
   when(directory.listFiles(ZIPS_FILTER)).thenReturn(new File[] {jobs, reports});
   Exception exception =
       new RuntimeException("exception thrown on purpose from testWillContinueToLoadOnException");
   doThrow(exception).when(importer).importFile(argThat(bundleMatcher(jobsName, inputStream)));
   IRepositoryImportLogger logger = mock(IRepositoryImportLogger.class);
   when(importer.getRepositoryImportLogger()).thenReturn(logger);
   loader.loadAll(directory, ZIPS_FILTER);
   verify(importer).importFile(argThat(bundleMatcher(jobsName, inputStream)));
   verify(importer).importFile(argThat(bundleMatcher(reportsName, inputStream)));
   verify(jobs).renameTo(argThat(fileMatcher(jobs)));
   verify(reports).renameTo(argThat(fileMatcher(reports)));
 }
Exemplo n.º 2
0
 @Test
 public void testDoesNotBombWhenZeroFilesFound() throws Exception {
   final IPlatformImporter importer = mock(IPlatformImporter.class);
   final ArchiveLoader loader = new ArchiveLoader(importer);
   final File directory = mock(File.class);
   when(directory.listFiles(ZIPS_FILTER)).thenReturn(new File[] {});
   loader.loadAll(directory, ZIPS_FILTER);
 }
Exemplo n.º 3
0
 @Test
 public void testDoesNotBombWhenDirectoryDoesNotExist() throws Exception {
   IPlatformImporter importer = mock(IPlatformImporter.class);
   ArchiveLoader loader = new ArchiveLoader(importer);
   try {
     loader.loadAll(new File("/fake/path/that/does/not/exist"), ArchiveLoader.ZIPS_FILTER);
   } catch (Exception e) {
     Assert.fail("Expected no exception but got " + e.getMessage());
   }
 }