Package uk.gov.nationalarchives.droid.core

Examples of uk.gov.nationalarchives.droid.core.BinarySignatureIdentifier


public class SubmissionGatewayTest {

    @Test
    public void testDroid4IndentificationWithAZipFile() throws Exception {

        BinarySignatureIdentifier droid = new BinarySignatureIdentifier();
        SubmissionGateway submissionGateway = new SubmissionGateway();
        submissionGateway.setDroidCore(droid);
       
        droid.setSignatureFile("test_sig_files/DROID_SignatureFile_V26.xml");
        ResultHandler resultHandler = mock(ResultHandler.class);
        submissionGateway.setResultHandler(resultHandler);
        submissionGateway.setProcessArchives(true);
        submissionGateway.setExecutorService(Executors.newFixedThreadPool(2));
       
        SubmissionQueue submissionQueue = mock(SubmissionQueue.class);
        submissionGateway.setSubmissionQueue(submissionQueue);

        ArchiveFormatResolver archiveFormatResolver = mock(ArchiveFormatResolver.class);
        ArchiveHandlerFactory archiveHandlerFactory = mock(ArchiveHandlerFactory.class);
        when(archiveFormatResolver.forPuid("x-fmt/412")).thenReturn("ZIP");

        TrueZipArchiveHandler zipHandler = new TrueZipArchiveHandler();
        zipHandler.setDroidCore(submissionGateway);
        zipHandler.setFactory(new ZipEntryRequestFactory());
        zipHandler.setResultHandler(resultHandler);

        when(archiveHandlerFactory.getHandler("ZIP")).thenReturn(zipHandler);

        ArchiveFormatResolver containerFormatResolver = mock(ArchiveFormatResolver.class);
       
        submissionGateway.setArchiveFormatResolver(archiveFormatResolver);
        submissionGateway.setArchiveHandlerFactory(archiveHandlerFactory);
        submissionGateway.setContainerFormatResolver(containerFormatResolver);
        try {
            droid.init();
        } catch (SignatureParseException x) {
            assertEquals("Can't parse signature file", x.getMessage());
        }

        File file = new File("test_sig_files/persistence.zip");
View Full Code Here


    }

    @Test
    public void testResultAvailableWhenIdentificationFailed() throws InterruptedException {

        BinarySignatureIdentifier droid = new BinarySignatureIdentifier();
       
        SubmissionGateway submissionGateway = new SubmissionGateway();
        SubmissionQueue submissionQueue = mock(SubmissionQueue.class);
        submissionGateway.setSubmissionQueue(submissionQueue);
        submissionGateway.setDroidCore(droid);
       
        droid.setSignatureFile("test_sig_files/DROID_SignatureFile_V26.xml");
        ResultHandler resultHandler = mock(ResultHandler.class);
        submissionGateway.setResultHandler(resultHandler);
        submissionGateway.setExecutorService(Executors.newFixedThreadPool(2));
        try {
            droid.init();
        } catch (SignatureParseException e) {
            assertEquals("Can't parse signature file", e.getCause().getMessage());
        }

        File file = new File("test_sig_files/sample.pdf");
View Full Code Here

    private String gZipFile =
            "src/test/resources/testfiles/test.gz";
   
    @Before
    public void setUp() throws CommandExecutionException {
        binarySignatureIdentifier = new BinarySignatureIdentifier();
        binarySignatureIdentifier.setSignatureFile(standardSignatures);
        try {
            binarySignatureIdentifier.init();
        } catch (SignatureParseException e) {
            throw new CommandExecutionException("Can't parse signature file");
View Full Code Here

    private String tarFile =
            "src/test/resources/testfiles/test.tar";
   
    @Before
    public void setUp() throws CommandExecutionException {
        binarySignatureIdentifier = new BinarySignatureIdentifier();
        binarySignatureIdentifier.setSignatureFile(standardSignatures);
        try {
            binarySignatureIdentifier.init();
        } catch (SignatureParseException e) {
            throw new CommandExecutionException("Can't parse signature file");
View Full Code Here

    private String zipFile =
            "src/test/resources/testfiles/test.zip";
   
    @Before
    public void setUp() throws CommandExecutionException {
        binarySignatureIdentifier = new BinarySignatureIdentifier();
        binarySignatureIdentifier.setSignatureFile(standardSignatures);
        try {
            binarySignatureIdentifier.init();
        } catch (SignatureParseException e) {
            throw new CommandExecutionException("Can't parse signature file");
View Full Code Here

          matchedFiles.add(singleFileToProcess);
        } else {
            throw new CommandExecutionException(String.format("The specified input %s was not found", targetDirectoryOrFile));        
        }

        BinarySignatureIdentifier binarySignatureIdentifier = new BinarySignatureIdentifier();
        File fileSignaturesFile = new File(fileSignaturesFileName);
        if (!fileSignaturesFile.exists()) {
            throw new CommandExecutionException("Signature file not found");
        }

        binarySignatureIdentifier.setSignatureFile(fileSignaturesFileName);
        try {
            binarySignatureIdentifier.init();
        } catch (SignatureParseException e) {
            throw new CommandExecutionException("Can't parse signature file");
        }
        binarySignatureIdentifier.setMaxBytesToScan(maxBytesToScan);
        String path = fileSignaturesFile.getAbsolutePath();
        String slash = path.contains(FORWARD_SLASH) ? FORWARD_SLASH : BACKWARD_SLASH;
        String slash1 = slash;
     
        ContainerSignatureDefinitions containerSignatureDefinitions = null;
        if (containerSignaturesFileName != null) {
            File containerSignaturesFile = new File(containerSignaturesFileName);
            InputStream in = null;
            if (!containerSignaturesFile.exists()) {
                throw new CommandExecutionException("Container signature file not found");
            }
            try {
                in = new FileInputStream(containerSignaturesFileName);
                final ContainerSignatureSaxParser parser = new ContainerSignatureSaxParser();
                containerSignatureDefinitions = parser.parse(in);
            } catch (SignatureParseException e) {
                throw new CommandExecutionException("Can't parse container signature file");
            } catch (IOException ioe) {
                throw new CommandExecutionException(ioe);
            } catch (JAXBException jaxbe) {
                throw new CommandExecutionException(jaxbe);
            }finally{
              if(in!=null){
                try {
            in.close();
          } catch (IOException e) {
            throw new CommandExecutionException("Error closing InputStream on signature file");
          }
               
              }
            }
        }
       
        path = "";
        ResultPrinter resultPrinter =
            new ResultPrinter(binarySignatureIdentifier, containerSignatureDefinitions,
                path, slash, slash1, archives);

        String fileName = null;
        for (File file : matchedFiles) {
            try {
                fileName = file.getCanonicalPath();
            } catch (IOException e) {
                throw new CommandExecutionException(e);
            }
            URI uri = file.toURI();
            RequestMetaData metaData =
                new RequestMetaData(file.length(), file.lastModified(), fileName);
            RequestIdentifier identifier = new RequestIdentifier(uri);
            identifier.setParentId(1L);
           
            InputStream in = null;
            IdentificationRequest request = new FileSystemIdentificationRequest(metaData, identifier);
            try {
                in = new FileInputStream(file);
                request.open(in);
                IdentificationResultCollection results =
                    binarySignatureIdentifier.matchBinarySignatures(request);
               
                resultPrinter.print(results, request);
            } catch (FileNotFoundException fnfe) {
              log.error("error processing files", fnfe);
              throw new CommandExecutionException(fnfe);
View Full Code Here

TOP

Related Classes of uk.gov.nationalarchives.droid.core.BinarySignatureIdentifier

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.