generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PI-2673 - move test data creation back to data loader. Use entityMana…
…ger.merge to resolve issue with detached entities.
- Loading branch information
1 parent
cf5d89d
commit 97e02ee
Showing
8 changed files
with
81 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...es-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/EntityManagerDataLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package uk.gov.justice.digital.hmpps.data | ||
|
||
import jakarta.persistence.EntityManager | ||
import jakarta.persistence.PersistenceContext | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
import uk.gov.justice.digital.hmpps.data.generator.AddressGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.ReferralGenerator | ||
|
||
@Component | ||
class EntityManagerDataLoader { | ||
|
||
@PersistenceContext | ||
private lateinit var entityManager: EntityManager | ||
|
||
@Transactional | ||
fun loadData() { | ||
AddressGenerator.PERSON_ADDRESS_ID = entityManager.merge(AddressGenerator.PERSON_ADDRESS).id | ||
AddressGenerator.INACTIVE_PERSON_ADDRESS_ID = entityManager.merge(AddressGenerator.INACTIVE_PERSON_ADDRESS).id | ||
entityManager.merge(ReferralGenerator.EXISTING_REFERRAL) | ||
entityManager.merge(ReferralGenerator.BOOKING_WITHOUT_ARRIVAL) | ||
ReferralGenerator.BOOKING_ARRIVED_DB_RECORD = entityManager.merge(ReferralGenerator.BOOKING_ARRIVED) | ||
ReferralGenerator.BOOKING_DEPARTED_DB_RECORD = entityManager.merge(ReferralGenerator.BOOKING_DEPARTED) | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/ReferralBookingDataLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package uk.gov.justice.digital.hmpps.data | ||
|
||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.ReferralGenerator | ||
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.ResidenceRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.PersonRepository | ||
|
||
@Component | ||
class ReferralBookingDataLoader( | ||
private val personRepository: PersonRepository, | ||
private val residenceRepository: ResidenceRepository | ||
) { | ||
fun loadData() { | ||
personRepository.save(PersonGenerator.PERSON_WITH_BOOKING) | ||
ReferralGenerator.ARRIVAL = residenceRepository.save( | ||
ReferralGenerator.generateResidence( | ||
PersonGenerator.PERSON_WITH_BOOKING, | ||
ReferralGenerator.BOOKING_ARRIVED_DB_RECORD!!, | ||
arrivalDateTime = ReferralGenerator.ARRIVAL.arrivalDate, | ||
) | ||
) | ||
ReferralGenerator.DEPARTURE = residenceRepository.save( | ||
ReferralGenerator.generateResidence( | ||
PersonGenerator.PERSON_WITH_BOOKING, | ||
ReferralGenerator.BOOKING_DEPARTED_DB_RECORD!!, | ||
arrivalDateTime = ReferralGenerator.DEPARTURE.arrivalDate, | ||
departureDateTime = ReferralGenerator.DEPARTURE.departureDate | ||
) | ||
) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters