Skip to content

Commit

Permalink
PI-2673 - move test data creation back to data loader
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Jan 6, 2025
1 parent 6276745 commit cacb78f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class DataLoader(
private val disabilityRepository: DisabilityRepository,
private val offenceRepository: OffenceRepository,
private val mainOffenceRepository: MainOffenceRepository,
private val teamOfficeLinkRepository: TeamOfficeLinkRepository
private val teamOfficeLinkRepository: TeamOfficeLinkRepository,
private val entityManagerDataLoader: EntityManagerDataLoader
) : ApplicationListener<ApplicationReadyEvent> {

@PostConstruct
Expand Down Expand Up @@ -279,6 +280,8 @@ class DataLoader(
)

personRepository.save(PersonGenerator.FUZZY_SEARCH)
entityManagerDataLoader.loadData()
nsiManagerRepository.save(NsiGenerator.generateManager(entityManagerDataLoader.NSI_FUZZY_SEARCH!!))

auditUserRepository.save(UserGenerator.LIMITED_ACCESS_USER)
personRepository.saveAll(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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.NsiGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.referral.entity.Nsi

@Component
class EntityManagerDataLoader {

@PersistenceContext
private lateinit var entityManager: EntityManager

var NSI_FUZZY_SEARCH : Nsi? = null

@Transactional
fun loadData() {
NSI_FUZZY_SEARCH = entityManager.merge(NsiGenerator.FUZZY_SEARCH)
entityManager.merge(NsiGenerator.TERMINATED)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.Contact
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactOutcome
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType
import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.EventRepository
import uk.gov.justice.digital.hmpps.integrations.delius.referral.NsiManagerRepository
import uk.gov.justice.digital.hmpps.integrations.delius.referral.NsiRepository
import uk.gov.justice.digital.hmpps.integrations.delius.referral.NsiStatusHistoryRepository
import uk.gov.justice.digital.hmpps.integrations.delius.referral.entity.NsiStatus
Expand Down Expand Up @@ -66,9 +65,6 @@ internal class ReferAndMonitorIntegrationTest {
@Autowired
lateinit var eventRepository: EventRepository

@Autowired
lateinit var nsiManagerRepository: NsiManagerRepository

@Test
@Order(1)
fun `session appointment feedback submitted failed to comply`() {
Expand Down Expand Up @@ -368,11 +364,6 @@ internal class ReferAndMonitorIntegrationTest {

@Test
fun `failure to find appointment is rejected with reason`() {
NsiGenerator.FUZZY_SEARCH = nsiRepository.save(NsiGenerator.FUZZY_SEARCH)
nsiManagerRepository.save(NsiGenerator.generateManager(NsiGenerator.FUZZY_SEARCH))

NsiGenerator.TERMINATED = nsiRepository.save(NsiGenerator.TERMINATED)

val notification = prepNotification(
notification("session-appointment-feedback-submitted-not-found"),
wireMockServer.port()
Expand Down

0 comments on commit cacb78f

Please sign in to comment.