/**
   * Creates a scenario where the fetcher always throws a bridge failure exception. Shows that the
   * query does not repeat infinitely.
   *
   * @throws psidev.psi.mi.jami.enricher.exception.EnricherException
   */
  @Test(expected = EnricherException.class)
  public void test_bridgeFailure_throws_exception_when_persistent() throws EnricherException {

    persistentBioactiveEntity = new DefaultBioactiveEntity(TEST_SHORTNAME, TEST_FULLNAME);
    persistentBioactiveEntity.setChebi(CHEBI_ID);

    int timesToTry = -1;

    FailingBioactiveEntityFetcher fetcher = new FailingBioactiveEntityFetcher(timesToTry);
    fetcher.addEntry(CHEBI_ID, Collections.singleton(persistentBioactiveEntity));
    enricher = new FullBioactiveEntityUpdater(fetcher);

    enricher.enrich(persistentBioactiveEntity);

    fail("Exception should be thrown before this point");
  }
  /**
   * Creates a scenario where the fetcher does not retrieve an entry on its first attempt. If the
   * enricher re-queries the fetcher, it will eventually receive the entry.
   *
   * @throws EnricherException
   */
  @Test
  public void test_bridgeFailure_does_not_throw_exception_when_not_persistent()
      throws EnricherException {

    persistentBioactiveEntity = new DefaultBioactiveEntity(TEST_SHORTNAME, TEST_FULLNAME);
    persistentBioactiveEntity.setChebi(CHEBI_ID);

    int timesToTry = 3;
    assertTrue(
        "The test can not be applied as the conditions do not invoke the required response. "
            + "Change the timesToTry.",
        timesToTry < 5);

    FailingBioactiveEntityFetcher fetcher = new FailingBioactiveEntityFetcher(timesToTry);
    fetcher.addEntry(CHEBI_ID, Collections.singleton(persistentBioactiveEntity));
    enricher = new FullBioactiveEntityUpdater(fetcher);

    enricher.enrich(persistentBioactiveEntity);

    assertEquals(TEST_FULLNAME, persistentBioactiveEntity.getFullName());
  }
  @Test
  public void test_enrichment_completes_as_failed_when_no_entry_fetched() throws EnricherException {

    persistentBioactiveEntity = new DefaultBioactiveEntity(TEST_SHORTNAME, TEST_FULLNAME);
    fetcher.clearEntries();

    enricher.setListener(
        new BioactiveEntityEnricherListenerManager(
            new BioactiveEntityEnricherLogger(),
            new BioactiveEntityEnricherListener() {
              public void onEnrichmentComplete(
                  BioactiveEntity object, EnrichmentStatus status, String message) {
                assertTrue(object == persistentBioactiveEntity);
                assertEquals(EnrichmentStatus.FAILED, status);
                persistentInt++;
              }

              public void onChebiUpdate(BioactiveEntity bioactiveEntity, String oldId) {
                fail("failed");
              }

              public void onSmileUpdate(BioactiveEntity bioactiveEntity, String oldSmile) {
                fail("failed");
              }

              public void onStandardInchiKeyUpdate(BioactiveEntity bioactiveEntity, String oldKey) {
                fail("failed");
              }

              public void onStandardInchiUpdate(BioactiveEntity bioactiveEntity, String oldInchi) {
                fail("failed");
              }

              public void onShortNameUpdate(BioactiveEntity interactor, String oldShortName) {
                fail("failed");
              }

              public void onFullNameUpdate(BioactiveEntity interactor, String oldFullName) {
                fail("failed");
              }

              public void onOrganismUpdate(BioactiveEntity interactor, Organism oldOrganism) {
                fail("failed");
              }

              public void onInteractorTypeUpdate(BioactiveEntity interactor, CvTerm oldType) {
                fail("failed");
              }

              public void onAddedIdentifier(BioactiveEntity interactor, Xref added) {
                fail("failed");
              }

              public void onRemovedIdentifier(BioactiveEntity interactor, Xref removed) {
                fail("failed");
              }

              public void onAddedXref(BioactiveEntity interactor, Xref added) {
                fail("failed");
              }

              public void onRemovedXref(BioactiveEntity interactor, Xref removed) {
                fail("failed");
              }

              public void onAddedAlias(BioactiveEntity interactor, Alias added) {
                fail("failed");
              }

              public void onRemovedAlias(BioactiveEntity interactor, Alias removed) {
                fail("failed");
              }

              public void onAddedChecksum(BioactiveEntity interactor, Checksum added) {
                fail("failed");
              }

              public void onRemovedChecksum(BioactiveEntity interactor, Checksum removed) {
                fail("failed");
              }

              public void onAddedAnnotation(BioactiveEntity o, Annotation added) {
                Assert.fail();
              }

              public void onRemovedAnnotation(BioactiveEntity o, Annotation removed) {
                Assert.fail();
              }

              public void onEnrichmentError(BioactiveEntity object, String message, Exception e) {
                Assert.fail();
              }
            }));

    enricher.enrich(persistentBioactiveEntity);

    assertEquals(1, persistentInt);
  }
 /**
  * Attempts to enrich a null CvTerm. This should always cause an illegal argument exception
  *
  * @throws EnricherException
  */
 @Test(expected = IllegalArgumentException.class)
 public void test_enriching_with_null_CvTerm() throws EnricherException {
   BioactiveEntity nullBioactiveEntity = null;
   enricher.enrich(nullBioactiveEntity);
   fail("Exception should be thrown before this point");
 }