@Test
  public void identifyGZipArchiveTest() throws CommandExecutionException {

    String fileName;
    File file = new File(tarFile);
    if (!file.exists()) {
      fail("TAR test file not found");
    }
    URI uri = file.toURI();
    RequestIdentifier identifier = new RequestIdentifier(uri);
    identifier.setParentId(1L);
    try {
      fileName = file.getCanonicalPath();
      RequestMetaData metaData = new RequestMetaData(file.length(), file.lastModified(), fileName);
      FileSystemIdentificationRequest request =
          new FileSystemIdentificationRequest(metaData, identifier);

      InputStream tarStream = new FileInputStream(file);
      request.open(tarStream);
      tarArchiveContentIdentifier.identify(uri, request);

    } catch (IOException e) {
      throw new CommandExecutionException(e);
    }
  }
  @Test
  public void identifyZipFileTest() throws CommandExecutionException {

    zipIdentifierEngine.setRequestFactory(requestFactory);
    zipContainerContentIdentifier.setIdentifierEngine(zipIdentifierEngine);
    Object object = zipContainerContentIdentifier.getIdentifierEngine();
    assertEquals(object.getClass(), zipIdentifierEngine.getClass());

    try {
      InputStream in = new FileInputStream(containerSignatures);
      ContainerSignatureSaxParser parser = new ContainerSignatureSaxParser();
      containerSignatureDefinitions = parser.parse(in);
    } catch (SignatureParseException e) {
      throw new CommandExecutionException("Can't parse container signature file");
    } catch (Exception e) {
      throw new CommandExecutionException(e);
    }

    zipContainerContentIdentifier.init(containerSignatureDefinitions, "ZIP");
    object = zipContainerContentIdentifier.getContainerIdentifierInit();
    assertEquals(object.getClass(), containerIdentifierInit.getClass());

    object = zipContainerContentIdentifier.getFormats();
    assertEquals(object.getClass(), formats.getClass());

    String fileName;
    File file = new File(zipFile);
    if (!file.exists()) {
      fail("ZIP test file not found");
    }
    URI uri = file.toURI();
    RequestIdentifier identifier = new RequestIdentifier(uri);
    identifier.setParentId(1L);
    try {
      fileName = file.getCanonicalPath();
      RequestMetaData metaData = new RequestMetaData(file.length(), file.lastModified(), fileName);
      FileSystemIdentificationRequest request =
          new FileSystemIdentificationRequest(metaData, identifier);
      IdentificationResultCollection results = new IdentificationResultCollection(request);
      request.open(file);
      results = zipContainerContentIdentifier.process(request.getSourceInputStream(), results);
      if (results.getResults().isEmpty()) {
        fail("ZIP file not identified");
      }
      String fmtExpected = "";
      for (IdentificationResult identResult : results.getResults()) {
        if (identResult.getPuid().equals("fmt/189")) {
          fmtExpected = identResult.getPuid();
        }
      }
      assertEquals(fmtExpected, "fmt/189");
    } catch (IOException e) {
      throw new CommandExecutionException(e);
    }
  }
  /**
   * @param request The archive request to handle.
   * @param results The previous identification results for the archive format.
   * @return
   */
  private boolean handleArchive(
      IdentificationRequest request, IdentificationResultCollection results) {

    boolean jobCountDecremented = false;

    String archiveFormat = getArchiveFormat(results);
    if (archiveFormat != null) {
      results.setArchive(true);
      ResourceId id = resultHandler.handle(results);
      jobCounter.incrementPostProcess();
      RequestIdentifier identifier = request.getIdentifier();
      identifier.setResourceId(id);
      if (identifier.getAncestorId() == null) {
        identifier.setAncestorId(id.getId());
      }
      submissionQueue.add(request.getIdentifier());
      jobCounter.decrement();
      jobCountDecremented = true;
      try {
        // BNO: Does this always return the same archive handler for any given container format?
        // And will it end up using the same submission gateway, or a new one with a different
        // thread pool?
        ArchiveHandler handler = archiveHandlerFactory.getHandler(archiveFormat);
        handler.handle(request);
        // CHECKSTYLE:OFF
      } catch (Exception e) {
        // CHECKSTYLE:ON
        String causeMessage = "";
        if (e.getCause() != null) {
          causeMessage = e.getCause().getMessage();
        }
        final String message =
            String.format(
                ARCHIVE_ERROR,
                archiveFormat,
                request.getIdentifier().getUri().toString(),
                e.getMessage(),
                causeMessage);
        log.warn(message);
        resultHandler.handleError(
            new IdentificationException(request, IdentificationErrorType.OTHER, e));
      } finally {
        submissionQueue.remove(request.getIdentifier());
        jobCounter.decrementPostProcess();
      }
    } else {
      ResourceId id = resultHandler.handle(results);
      request.getIdentifier().setNodeId(id.getId());
    }
    return jobCountDecremented;
  }
  /*
   ** Similar to above - except that there is no second occurrence of the final left fragment - and
   ** the sole occurrence of this fragment is beyond the maximum offset for the sequence as a whole
   ** from BOF. N.B. This test passes in the previous version DROID 6.2.1
   */
  @Test
  public void testFinalLeftFragmentBeyondSeqMaxOffset() throws Exception {

    final String sigFile = "left-frag-1200.xml";
    final String fileToScan = "left1200a.ext";
    final String expectedPuid = "dev/1200";

    BinarySignatureIdentifier droid = new BinarySignatureIdentifier();
    droid.setSignatureFile(TESTAREA + sigFile);
    try {
      droid.init();
    } catch (SignatureParseException x) {
      assertEquals("Can't parse signature file", x.getMessage());
    }
    File file = new File(TESTAREA + fileToScan);
    assertTrue(file.exists());
    URI resourceUri = file.toURI();

    RequestMetaData metaData = new RequestMetaData(file.length(), file.lastModified(), fileToScan);
    RequestIdentifier identifier = new RequestIdentifier(resourceUri);
    identifier.setParentId(1L);

    IdentificationRequest<File> request = new FileSystemIdentificationRequest(metaData, identifier);
    request.open(file);

    IdentificationResultCollection resultsCollection = droid.matchBinarySignatures(request);
    List<IdentificationResult> results = resultsCollection.getResults();

    assertEquals(0, results.size());

    Iterator<IdentificationResult> iter = results.iterator();
    while (iter.hasNext()) {
      IdentificationResult result = iter.next();
      assertEquals(expectedPuid, result.getPuid());
    }
  }