Package uk.gov.nationalarchives.droid.core.interfaces

Examples of uk.gov.nationalarchives.droid.core.interfaces.ResourceId


        ProgressMonitor progressMonitor = mock(ProgressMonitor.class);
        walker.setProgressMonitor(progressMonitor);
        FileEventHandler fileEventHandler = mock(FileEventHandler.class);
        DirectoryEventHandler dirEventhandler = mock(DirectoryEventHandler.class);
        when(dirEventhandler.onEvent(locations[0],
                null, 0, false)).thenReturn(new ResourceId(1L, ""));
        when(dirEventhandler.onEvent(locations[1],
                null, 0, false)).thenReturn(new ResourceId(2L, ""));
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir1/subdir1"),
                new ResourceId(1L, ""), 1, false)).thenReturn(new ResourceId(11L, ""));
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir1/subdir2"),
                new ResourceId(1L, ""), 1, false)).thenReturn(new ResourceId(12L, ""));
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir2/subdir1"),
                new ResourceId(2L, ""), 1, false)).thenReturn(new ResourceId(21L, ""));
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir2/subdir2"),
                new ResourceId(2L, ""), 1, false)).thenReturn(new ResourceId(22L, ""));
       
        walker.setDirectoryEventHandler(dirEventhandler);
        walker.setFileEventHandler(fileEventHandler);

        walker.walk(profileSpec, new ProfileWalkState());

        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir1/file11.ext"), new ResourceId(1L, ""), null);
        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir1/file12.ext"), new ResourceId(1L, ""), null);
        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir1/file13.ext"), new ResourceId(1L, ""), null);
        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir1/file14.ext"), new ResourceId(1L, ""), null);
        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir1/file15.ext"), new ResourceId(1L, ""), null);

        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);
        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);
        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);
        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);
        verify(fileEventHandler).onEvent(
                canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);

        verify(fileEventHandler, times(10)).onEvent(any(File.class), (ResourceId) any(),
                (ResourceId) isNull());

        verify(fileEventHandler, never()).onEvent(
View Full Code Here


        FileEventHandler fileEventHandler = mock(FileEventHandler.class);
        walker.setFileEventHandler(fileEventHandler);

        DirectoryEventHandler dirEventhandler = mock(DirectoryEventHandler.class);
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir1"),
                null, 0, false)).thenReturn(new ResourceId(1L, ""));
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir2"),
                null, 0, false)).thenReturn(new ResourceId(2L, ""));
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir1/subdir1"),
                new ResourceId(1L, ""), 1, false)).thenReturn(new ResourceId(11L, ""));
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir1/subdir2"),
                new ResourceId(1L, ""), 1, false)).thenReturn(new ResourceId(12L, ""));
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir2/subdir1"),
                new ResourceId(2L, ""), 1, false)).thenReturn(new ResourceId(21L, ""));
        when(dirEventhandler.onEvent(canonicalFile(TEST_ROOT, "dir2/subdir2"),
                new ResourceId(2L, ""), 1, false)).thenReturn(new ResourceId(22L, ""));
        walker.setDirectoryEventHandler(dirEventhandler);

        walker.walk(profileSpec, new ProfileWalkState());

        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/file11.ext"), new ResourceId(1L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/file12.ext"), new ResourceId(1L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/file13.ext"), new ResourceId(1L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/file14.ext"), new ResourceId(1L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/file15.ext"), new ResourceId(1L, ""), null);

        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir1/file111.ext"),
                new ResourceId(11L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir1/file112.ext"),
                new ResourceId(11L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir1/file113.ext"),
                new ResourceId(11L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir1/file114.ext"),
                new ResourceId(11L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir1/file115.ext"),
                new ResourceId(11L, ""), null);

        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir2/file121.ext"),
                new ResourceId(12L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir2/file122.ext"),
                new ResourceId(12L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir2/file123.ext"),
                new ResourceId(12L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir2/file124.ext"),
                new ResourceId(12L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir1/subdir2/file125.ext"),
                new ResourceId(12L, ""), null);

        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/file21.ext"), new ResourceId(2L, ""), null);

        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir1/file211.ext"),
                new ResourceId(21L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir1/file212.ext"),
                new ResourceId(21L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir1/file213.ext"),
                new ResourceId(21L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir1/file214.ext"),
                new ResourceId(21L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir1/file215.ext"),
                new ResourceId(21L, ""), null);

        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir2/file221.ext"),
                new ResourceId(22L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir2/file222.ext"),
                new ResourceId(22L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir2/file223.ext"),
                new ResourceId(22L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir2/file224.ext"),
                new ResourceId(22L, ""), null);
        verify(fileEventHandler).onEvent(canonicalFile(TEST_ROOT, "dir2/subdir2/file225.ext"),
                new ResourceId(22L, ""), null);

        verify(fileEventHandler, times(30)).onEvent(any(File.class), (ResourceId) any(),
                (ResourceId) isNull());
    }
View Full Code Here

        fileEventHandler.setResultHandler(resultHandler);
       
        SubmissionThrottle throttle = mock(SubmissionThrottle.class);
        fileEventHandler.setSubmissionThrottle(throttle);

        fileEventHandler.onEvent(file, new ResourceId(1L, ""), null);
       
        ArgumentCaptor<IdentificationException> exCaptor = ArgumentCaptor.forClass(IdentificationException.class);
        verify(resultHandler).handleError(exCaptor.capture());
       
        final IdentificationException thrown = exCaptor.getValue();
View Full Code Here

            }
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });

      when(directoryHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {

         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });

      try {
         fileWalker.walk();
         fail("Expected file walker to throw exception");
      } catch (DirectoryWalker.CancelException e) {
         assertEquals(files[FILES_TO_WALK], e.getFile());
      }

      FileWalkerHandler resumeHandler = mock(FileWalkerHandler.class);
     
      when(resumeHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {
        
         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            File thisFile = (File) invocation.getArguments()[0];
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });  
     
      fileWalker.setFileHandler(resumeHandler);
      fileWalker.walk();
View Full Code Here

            }
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });
      when(directoryHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {

         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });

      try {
         fileWalker.walk();
         fail("Expected file walker to throw exception");
      } catch (DirectoryWalker.CancelException e) {
         assertEquals(files[FILES_TO_WALK], e.getFile());
      }
     
      if(files[FILES_TO_WALK].delete()) {
         if(fileSet.contains(files[FILES_TO_WALK]))
            fileSet.remove(files[FILES_TO_WALK]);
         else
            fail("File not found within set.");
      }
      else
         fail("Error deleting test file: " + files[FILES_TO_WALK].toURI());
     
      FileWalkerHandler resumeHandler = mock(FileWalkerHandler.class);
      when(resumeHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {
        
         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            File thisFile = (File) invocation.getArguments()[0];
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });  
     
      fileWalker.setFileHandler(resumeHandler);
      fileWalker.walk();
View Full Code Here

            }
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });
     
      when(directoryHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {

         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });

      try {
         fileWalker.walk();
         fail("Expected file walker to throw exception");
      } catch (DirectoryWalker.CancelException e) {
         assertEquals(files[FILES_TO_WALK], e.getFile());
      }

      File parentDir = files[FILES_TO_WALK].getParentFile();
           
      // List files in directory that still exist to remove from the set
      // Simulating deletion of the files via the next deleteDirectory() call
      List<File> dirList = new ArrayList(FileUtils.listFiles(parentDir, null, true));
           
      Iterator dirListIterator = dirList.iterator();

      while(dirListIterator.hasNext())
      {
         // remove any files we haven't scanned yet from hashset
         File tmpFile = (File) dirListIterator.next();
         if(fileSet.contains(tmpFile))
            fileSet.remove(tmpFile);
      }
     
      FileUtils.deleteDirectory(parentDir);
     
      FileWalkerHandler resumeHandler = mock(FileWalkerHandler.class);
      when(resumeHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {
        
         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            File thisFile = (File) invocation.getArguments()[0];
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      })
     
      fileWalker.setFileHandler(resumeHandler);
      fileWalker.walk();
View Full Code Here

            }
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });
      when(directoryHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {

         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });

      try {
         fileWalker.walk();
         fail("Expected file walker to throw exception");
      } catch (DirectoryWalker.CancelException e) {
         assertEquals(files[FILES_TO_WALK], e.getFile());
      }

      final File directoryToEmpty = files[FILES_TO_WALK].getParentFile();

      for (File f : directoryToEmpty.listFiles()) {
         if (fileSet.contains(f))
            fileSet.remove(f);
         f.delete();
      }
      assertEquals(0, directoryToEmpty.listFiles().length);

      FileWalkerHandler resumeHandler = mock(FileWalkerHandler.class);
      when(resumeHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {
        
         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            File thisFile = (File) invocation.getArguments()[0];
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });
     
      fileWalker.setFileHandler(resumeHandler);
      fileWalker.walk();
View Full Code Here

            }
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });
      when(directoryHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {

         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });

      try {
         fileWalker.walk();
         fail("Expected file walker to throw exception");
      } catch (DirectoryWalker.CancelException e) {
         assertEquals(files[FILES_TO_WALK], e.getFile());
      }

      final File newFile = new File(files[POSITION_FOR_NEW_FILE].getPath() + "a");
      assertTrue(newFile.createNewFile());
      fileSet.add(newFile);   // represent the new file in the HashSet

      FileWalkerHandler resumeHandler = mock(FileWalkerHandler.class);
      when(resumeHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {
        
         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            File thisFile = (File) invocation.getArguments()[0];
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });
     
      fileWalker.setFileHandler(resumeHandler);
      fileWalker.walk();
View Full Code Here

            }
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");           
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });
      when(directoryHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {

         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });


      try {
         fileWalker.walk();
         fail("Expected file walker to throw exception");
      } catch (DirectoryWalker.CancelException e) {
         assertEquals(files[FILES_TO_WALK], e.getFile());
      }

      /* Note: simply adds a new directory with nothing in it. We don't need
       * to add to the fileSet, DROID should simply look in the directory and
       * do nothing. It will then continue to scan the other files as normal.
       */
      final File newFile = new File(files[POSITION_FOR_NEW_FILE].getPath() + "a");
      assertTrue(newFile.mkdir());

      FileWalkerHandler resumeHandler = mock(FileWalkerHandler.class);
      when(resumeHandler.handle(any(File.class), anyInt(), any(ProgressEntry.class))).thenAnswer(new Answer<ResourceId>() {
        
         @Override
         public ResourceId answer(InvocationOnMock invocation) throws Throwable {
            File thisFile = (File) invocation.getArguments()[0];
            if(fileSet.contains(thisFile))
               fileSet.remove(thisFile);
            else
               fail("File not found within set.");
            return new ResourceId(nextId.incrementAndGet(), "");
         }
      });
     
      fileWalker.setFileHandler(resumeHandler);
      fileWalker.walk();
View Full Code Here

    public void testDirectoryEventHandlerSavesANewNodeButDoesNotSubmitToDroid() {
       
        File file = new File("my/directory");
        URI uri = file.toURI();
       
        ResourceId id = new ResourceId(1L, "");
       
        directoryEventHandler.onEvent(file, id, 1, false);
       
        ArgumentCaptor<IdentificationResult> captor = ArgumentCaptor.forClass(IdentificationResult.class);
        verify(resultHandler).handleDirectory(captor.capture(), eq(id), eq(false));
View Full Code Here

TOP

Related Classes of uk.gov.nationalarchives.droid.core.interfaces.ResourceId

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.