Class TaxonFactory

java.lang.Object
ubic.gemma.core.util.test.fixture.TaxonFactory

@Component public class TaxonFactory extends Object
Typed factory for persistent Taxon test fixtures.

This is the Phase 3 replacement for PersistentDummyObjectHelper.getTestPersistentTaxon() and the private getTestNonPersistentTaxon() helper. It exists primarily to make HB6-safe "resolve existing seed, don't fabricate transient" the easy default — the old pattern of Taxon.Factory.newInstance() + setCommonName("mouse") and hoping the persister deduplicates worked under HB5 but broke under HB6.

Usage:

  Taxon mouse = taxonFactory.mouse();            // seeded taxon (NCBI 10090)
  Taxon human = taxonFactory.human();            // seeded taxon (NCBI 9606)
  Taxon rat   = taxonFactory.byCommonName("rat").build();
  Taxon adhoc = taxonFactory.adHoc().build();    // freshly-created (admin-only)
  Taxon adhoc = taxonFactory.adHoc()
                   .withNcbiId(99999)
                   .withScientificName("Testus testus")
                   .withCommonName("testbeast")
                   .build();

Design notes:

  • The seeded-taxon shortcuts (mouse(), human(), rat(), zebrafish(), fly(), worm(), yeast()) resolve straight to the seeded row from init-data.sql. They throw if the seed isn't there.
  • byCommonName(String) / byNcbiId(Integer) / byScientificName(String) are the same idea, parameterized.
  • adHoc() is the only path that ever creates a new Taxon row. It is intended for tests that need to verify behaviour on a taxon distinct from the seeded set (e.g. yeast-second-NCBI cases, taxon admin tests). Generates a randomized NCBI id (50000+ to stay clear of any real assignment) and a random scientific + common name. The factory persists through TaxonService#findOrCreate(Taxon) so the path mirrors the production admin flow.
  • Default isGenesUsable=true for ad-hoc taxa — this is what almost every test wants. Use TaxonFactory.AdHocBuilder.withGenesUsable(boolean) to override.
Author:
Phase 3 (Vision section 3 - test-fixture rewrite)
  • Constructor Details

    • TaxonFactory

      public TaxonFactory()
  • Method Details

    • mouse

      public Taxon mouse()
      Resolve the seeded mouse taxon (NCBI 10090).
    • human

      public Taxon human()
      Resolve the seeded human taxon (NCBI 9606).
    • rat

      public Taxon rat()
      Resolve the seeded rat taxon (NCBI 10116).
    • zebrafish

      public Taxon zebrafish()
      Resolve the seeded zebrafish taxon (NCBI 7955).
    • fly

      public Taxon fly()
      Resolve the seeded fly taxon (NCBI 7227).
    • worm

      public Taxon worm()
      Resolve the seeded worm taxon (NCBI 6239).
    • yeast

      public Taxon yeast()
      Resolve the seeded yeast taxon (NCBI 4932, secondary 559292).
    • byCommonName

      public TaxonFactory.ResolveBuilder byCommonName(String commonName)
      Resolve a seeded taxon by its common name. Throws if not present.
    • byScientificName

      public TaxonFactory.ResolveBuilder byScientificName(String scientificName)
      Resolve a seeded taxon by its scientific name. Throws if not present.
    • byNcbiId

      public TaxonFactory.ResolveBuilder byNcbiId(Integer ncbiId)
      Resolve a seeded taxon by its NCBI id. Throws if not present.
    • adHoc

      public TaxonFactory.AdHocBuilder adHoc()
      Start building a freshly-created (non-seeded) taxon. Defaults to a randomized scientific name, common name, and NCBI id; isGenesUsable=true. Caller is responsible for cleaning up unless the test extends a context that does it for them.