Skip to content

testcontainers#37

Open
Ingvord wants to merge 5 commits intomainfrom
testcontainers
Open

testcontainers#37
Ingvord wants to merge 5 commits intomainfrom
testcontainers

Conversation

@Ingvord
Copy link
Copy Markdown
Member

@Ingvord Ingvord commented Feb 20, 2026

Integrate testcontainers for unit testing

Ingvord and others added 2 commits February 20, 2026 22:20
- Migrate TestBase, Proposal3ServiceBeanTest, Shipping3ServiceBeanTest,
  Container3ServiceBeanTest and BLSample3ServiceBeanTest from JUnit 4
  annotations to JUnit 5 (Jupiter); BLSample3VOTest kept as JUnit 4
  via vintage-engine
- Add JUnit Jupiter 5.11.4, junit-vintage-engine and Surefire 3.2.5 to pom.xml
- Enable Proposal3, Shipping3, Container3 and BLSample3 service tests;
  12 tests now active (81 total, 0 failures)
- Refactor BLSample3ServiceBean.getDiffractionPlan: move Ejb3ServiceLocator
  lookup inside the null-check and collapse duplicate if/else-if branches
  into a single ternary + one if, so the locator is never called when no
  diffractionPlanId is present

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests no longer need a manually-started database. Running `mvn test`
pulls a mariadb:11 image, starts it, and tears it down automatically.

TestBase starts a single MariaDBContainer as a JVM-scoped static
singleton and creates the EJBContainer only once for the whole test run,
keeping the startup overhead minimal.

The container is initialised from files in ispyb-database/schema/:
  01-schema.sql    ← pydb_empty.sql (canonical empty-schema dump)
  02-proposals.sql ← test-data-proposals.sql  (Person/Proposal data)
  03-shipping.sql  ← test-data-shipping.sql   (Shipping/Dewar/Container)
  04-blsample.sql  ← test-data-blsample.sql   (Protein/Crystal/BLSample)

Keeping one SQL file per test class makes it straightforward to diagnose
which fixture data is needed when a test fails.

Files are bound from the host filesystem via withFileSystemBind so the
canonical data scripts live alongside the schema in ispyb-database/,
not buried in test resources. The project root is resolved through the
maven.multiModuleProjectDirectory system property (falls back to ".."
for IDE runs from the ispyb-ejb directory).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Ingvord Ingvord requested a review from HelgaMond February 20, 2026 19:57
Ingvord and others added 3 commits February 20, 2026 23:56
Tier 2 — fix hardcoded production IDs, migrate from JUnit 4 @ignore to JUnit 5:
  - Protein3ServiceBeanTest: use fixture Protein id=1 (with crystal) / id=2 (no crystal)
  - Crystal3ServiceBeanTest: use fixture proteinId=1
  - DewarRestWsServiceBeanTest: use session id=1 / proposal 8425; assert non-empty results

Tier 3 — add session/beamline fixtures, enable two more tests:
  - test-data-sessions.sql: BeamLineSetup(1), BLSession(1, P11), ShippingHasSession, EnergyScan(1, Se)
  - BeamLineSetup3ServiceBeanTest: findByPk(1) and findByScreeningInputId(missing=null)
  - EnergyScanRestWsServiceTest: assert real rows via v_energyScan view

Tier 4 — new test classes for core MX services:
  - Person3ServiceBeanTest: findByPk, findByLogin, findByFamilyAndGivenName
  - Session3ServiceBeanTest: findByPk, findByShippingId, hasDataCollectionGroups, getNbOfCollects
  - Dewar3ServiceBeanTest: findByPk (plain/with-containers), findByShippingId, countDewarSamples
  - DewarTransportHistory3ServiceBeanTest: findAll, findByDewarId

Fixture data is now split into one SQL file per concern, stored in ispyb-database/schema/:
  test-data-proposals.sql, test-data-shipping.sql, test-data-proteins.sql (new),
  test-data-blsample.sql (Protein row moved to proteins file), test-data-sessions.sql (new)

Result: 37 active tests (up from 12), 0 failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add test-data-collections.sql: DataCollectionGroup(1) + DataCollection(1, 100 images)
- Mount 07-collections.sql in TestBase
- New DataCollectionGroup3ServiceBeanTest: findByPk, findByPkWithDataCollections,
  findAll, findFiltered, findBySampleId
- New DataCollection3ServiceBeanTest: findByPk, findByProposalId, getNbOfCollects,
  getNbOfTests (native-query quirks treated same as countDewarSamples: assert >= 0)
- Skip DataCollection3ServiceBean.findAll() — pre-existing invalid JPQL ("from VO")

103 tests, 0 failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
OpenJPA 4.0.0 strictly enforces the JPQL spec: queries must start with
SELECT, UPDATE, or DELETE. Three service beans used Hibernate's shorthand
"from Entity vo" which omits the SELECT clause and is not valid JPQL.

- DataCollection3ServiceBean.findAll(): "from DataCollection3VO vo"
- Proposal3ServiceBean.findAll(): "from Proposal3VO vo"
- Person3ServiceBean.findBySiteId(): "from Person3VO vo where ..."

All three rewritten to standard "SELECT vo FROM Entity vo [WHERE ...]".
DataCollection3ServiceBeanTest.findAll() re-enabled now that the bug is fixed.

104 tests, 0 failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant