@Test
  public void shouldSkipNotObjectIssuerCertificateObjects() {
    X509ResourceCertificate certificate = createManifestEECertificate();
    X509Crl crl = getCrl();

    subject.addToWorkQueueIfObjectIssuer(taContext, URI.create("rsync://host/cert"), certificate);
    assertTrue(workQueue.isEmpty());

    subject.addToWorkQueueIfObjectIssuer(taContext, URI.create("rsync://host/crl"), crl);
    assertTrue(workQueue.isEmpty());
  }
  @Test
  public void shouldProcessManifestFromObjectIssuingCertificate() {
    final ManifestCms manifestCms = getRootManifestCms();
    final MutableBoolean fetchManifestCalled = new MutableBoolean(false);
    final MutableBoolean processedManifestFilesCalled = new MutableBoolean(false);

    subject =
        new TopDownWalker(workQueue, certificateRepositoryObjectFetcher, validitionResult) {
          @Override
          ManifestCms fetchManifest(
              URI manifestURI, CertificateRepositoryObjectValidationContext context) {
            fetchManifestCalled.setValue(true);
            assertEquals(ta.getManifestUri(), manifestURI);
            return manifestCms;
          }

          @Override
          void processManifestFiles(
              CertificateRepositoryObjectValidationContext context, ManifestCms actualManifestCms) {
            processedManifestFilesCalled.setValue(true);
            assertEquals(ta, context.getCertificate());
            assertEquals(manifestCms, actualManifestCms);
          }
        };

    subject.processManifest(taContext);

    assertTrue(fetchManifestCalled.booleanValue());
    assertTrue(processedManifestFilesCalled.booleanValue());
  }
  @Test
  public void shouldPrefetchRepository() {
    subject.prefetch(taContext);

    verify(certificateRepositoryObjectFetcher)
        .prefetch(eq(ROOT_SIA_REPO_RSYNC_LOCATION), isA(ValidationResult.class));
  }
  @Test
  public void shouldAddObjectIssuerCertificatesToWorkQueue() {
    subject.addToWorkQueueIfObjectIssuer(taContext, taContext.getLocation(), ta);

    assertTrue(workQueue.size() == 1);
    CertificateRepositoryObjectValidationContext context = workQueue.remove();
    assertEquals(ta, context.getCertificate());
  }
  @Test
  public void shouldFetchManifest() {
    ManifestCms manifestCms = getRootManifestCms();
    when(certificateRepositoryObjectFetcher.getManifest(
            eq(ROOT_SIA_MANIFEST_RSYNC_LOCATION), eq(taContext), isA(ValidationResult.class)))
        .thenReturn(manifestCms);

    assertEquals(manifestCms, subject.fetchManifest(ROOT_SIA_MANIFEST_RSYNC_LOCATION, taContext));
  }
  @Test
  public void shouldNotProcessFilesWhenManifestIsNull() {
    when(certificateRepositoryObjectFetcher.getManifest(
            eq(ROOT_SIA_MANIFEST_RSYNC_LOCATION), eq(taContext), isA(ValidationResult.class)))
        .thenReturn(null);

    subject.processManifest(taContext);

    verify(certificateRepositoryObjectFetcher)
        .getManifest(
            eq(ROOT_SIA_MANIFEST_RSYNC_LOCATION), eq(taContext), isA(ValidationResult.class));
    verifyNoMoreInteractions(certificateRepositoryObjectFetcher);
  }
  @Test
  public void shouldSkipInvalidObjects() {
    ManifestCms manifestCms = getRootManifestCms();

    when(certificateRepositoryObjectFetcher.getObject(
            eq(ROOT_SIA_REPO_RSYNC_LOCATION.resolve("foo1")),
            eq(taContext),
            eq(manifestCms.getFileContentSpecification("foo1")),
            isA(ValidationResult.class)))
        .thenReturn(null);
    when(certificateRepositoryObjectFetcher.getObject(
            eq(ROOT_SIA_REPO_RSYNC_LOCATION.resolve("BaR")),
            eq(taContext),
            eq(manifestCms.getFileContentSpecification("BaR")),
            isA(ValidationResult.class)))
        .thenReturn(null);

    subject.processManifestFiles(taContext, manifestCms);

    assertTrue(workQueue.isEmpty());
  }
  @Test
  public void shouldAddFetchedObjectIssuerToWorkQueue() {
    ManifestCms manifestCms = getRootManifestCms();
    X509Crl crl = getCrl();

    when(certificateRepositoryObjectFetcher.getObject(
            eq(ROOT_SIA_REPO_RSYNC_LOCATION.resolve("foo1")),
            eq(taContext),
            eq(manifestCms.getFileContentSpecification("foo1")),
            isA(ValidationResult.class)))
        .thenReturn(ta);
    when(certificateRepositoryObjectFetcher.getObject(
            eq(ROOT_SIA_REPO_RSYNC_LOCATION.resolve("BaR")),
            eq(taContext),
            eq(manifestCms.getFileContentSpecification("BaR")),
            isA(ValidationResult.class)))
        .thenReturn(crl);

    subject.processManifestFiles(taContext, manifestCms);

    assertEquals(1, workQueue.size());
    assertEquals(ta, workQueue.remove().getCertificate());
  }