Class ExperimentFactory

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

@Component public class ExperimentFactory extends Object
Typed factory for persistent ExpressionExperiment test fixtures.

This is the Phase 3 replacement for the bulkier PersistentDummyObjectHelper.getTestPersistentBasicExpressionExperiment(...) family. It exists to make test fixtures Hibernate-6-safe by construction and to keep test setup boilerplate down to one line:

  var ee = experimentFactory.bulkRna().build();
  var ee = experimentFactory.bulkRna().withSamples(50).withArrayDesign(ad).build();
  var ee = experimentFactory.singleCell().build();

Design notes (HB6-relevant):

  • build() persists the experiment via SecurableBaseImmutableService.create(ExpressionExperiment) so the ACL-creation listener fires through the production code path (mirrors how real EEs are created).
  • The transient EE is constructed with all associations attached BEFORE persist. Collections on the entity are mutated via getXxx().add(...) rather than replaced via setXxx(new HashSet<>(...)); the latter pattern is the classic HB6 PersistentSet replacement pitfall on managed entities and the habit is enforced here so that future "withXxx().withYyy().postPersistMutation()" extensions remain safe.
  • Taxa are resolved from init-data.sql-seeded rows via TaxonService.findByCommonName(String); the factory never fabricates a transient Taxon (that pattern relied on HB5's loose findOrCreate in the persister and broke in HB6).
  • External databases (GEO, PubMed) are resolved from ExternalDatabaseService.findByName(String) for the same reason; only the DatabaseEntry that links to them is transient.
  • If no ArrayDesign is supplied, one is created and persisted up-front through SecurableBaseImmutableService.create(ArrayDesign) so that bioassays attach to a managed AD.
Author:
Phase 3 (Vision §3 — test-fixture rewrite)
  • Constructor Details

    • ExperimentFactory

      public ExperimentFactory()
  • Method Details

    • bulkRna

      public ExperimentFactory.Builder bulkRna()
      Start building a bulk-RNA expression experiment. Defaults: mouse taxon, 8 samples, freshly-minted single-platform AD with zero composite sequences, one preferred raw QuantitationType.
    • singleCell

      public ExperimentFactory.Builder singleCell()
      Start building a single-cell expression experiment. Same defaults as bulkRna() except that the EE is flagged single-cell and no raw bulk QT is added by default. Single-cell vector population is the caller's responsibility (use SingleCellExpressionExperimentService after ExperimentFactory.Builder.build() returns).