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.
Browse files
Browse the repository at this point in the history
Co-authored-by: Marcus Aspin <[email protected]>
- Loading branch information
1 parent
1d27890
commit 4003bec
Showing
31 changed files
with
589 additions
and
108 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
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
18 changes: 16 additions & 2 deletions
18
projects/cas3-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.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 |
---|---|---|
@@ -1,25 +1,39 @@ | ||
package uk.gov.justice.digital.hmpps.data | ||
|
||
import jakarta.annotation.PostConstruct | ||
import jakarta.persistence.EntityManager | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.boot.context.event.ApplicationReadyEvent | ||
import org.springframework.context.ApplicationListener | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
import uk.gov.justice.digital.hmpps.data.generator.BusinessInteractionGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.ContactTypeGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator | ||
import uk.gov.justice.digital.hmpps.user.AuditUserRepository | ||
|
||
@Component | ||
@ConditionalOnProperty("seed.database") | ||
class DataLoader( | ||
private val auditUserRepository: AuditUserRepository | ||
private val auditUserRepository: AuditUserRepository, | ||
private val em: EntityManager | ||
) : ApplicationListener<ApplicationReadyEvent> { | ||
|
||
@PostConstruct | ||
fun saveAuditUser() { | ||
auditUserRepository.save(UserGenerator.AUDIT_USER) | ||
} | ||
|
||
@Transactional | ||
override fun onApplicationEvent(are: ApplicationReadyEvent) { | ||
// Perform dev/test database setup here, using JPA repositories and generator classes... | ||
em.saveAll( | ||
BusinessInteractionGenerator.UPDATE_CONTACT, | ||
ContactTypeGenerator.CONTACT_TYPE, | ||
PersonGenerator.PERSON_CRN, | ||
PersonGenerator.generatePersonManager(PersonGenerator.PERSON_CRN) | ||
) | ||
} | ||
|
||
fun EntityManager.saveAll(vararg any: Any) = any.forEach { persist(it) } | ||
} |
13 changes: 13 additions & 0 deletions
13
...rc/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/BusinessInteractionGenerator.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,13 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.audit.BusinessInteraction | ||
import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode | ||
import java.time.ZonedDateTime | ||
|
||
object BusinessInteractionGenerator { | ||
val UPDATE_CONTACT = BusinessInteraction( | ||
IdGenerator.getAndIncrement(), | ||
BusinessInteractionCode.UPDATE_CONTACT.code, | ||
ZonedDateTime.now().minusMonths(6) | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
...delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactTypeGenerator.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,11 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ContactType | ||
|
||
object ContactTypeGenerator { | ||
val CONTACT_TYPE = ContactType( | ||
IdGenerator.getAndIncrement(), | ||
"EARS", | ||
false | ||
) | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.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,14 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.Person | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.PersonManager | ||
|
||
object PersonGenerator { | ||
val PERSON_CRN = generate("A000001", null) | ||
|
||
fun generate(crn: String, noms: String?, softDeleted: Boolean = false, id: Long = IdGenerator.getAndIncrement()) = | ||
Person(crn, noms, softDeleted, id) | ||
|
||
fun generatePersonManager(person: Person) = | ||
PersonManager(IdGenerator.getAndIncrement(), person.id, 1, 1, 1, 1) | ||
} |
6 changes: 6 additions & 0 deletions
6
projects/cas3-and-delius/src/dev/resources/local-public-key.pub
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,6 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCc2Dlk/NOvXrjSs83W+Nj4bMfz | ||
6svg2ulfcqTcEoA/Vy6FWK3pOX50VZph3V0Sbh8OTRyHgTw3BRQKrxE/TdsUWw8A | ||
QxgbjBWypmm6I/gUGeiSgYwATZpdVbqmuNI0BRg5l/vgJki6K5cg+4fRazZXaHvN | ||
ldzA6bUDdyt73u7qSwIDAQAB | ||
-----END PUBLIC KEY----- |
17 changes: 0 additions & 17 deletions
17
projects/cas3-and-delius/src/dev/resources/messages/example-message.json
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
projects/cas3-and-delius/src/dev/resources/messages/referral-submitted.json
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,18 @@ | ||
{ | ||
"eventType": "accommodation.cas3.referral.submitted", | ||
"version": 1, | ||
"description": "A cas3 referral has been submitted", | ||
"detailUrl": "http://localhost:{wiremock.port}/cas3-api/events/referral-submitted/1234", | ||
"occurredAt": "2022-12-04T10:42:43+00:00", | ||
"additionalInformation": { | ||
"applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080" | ||
}, | ||
"personReference": { | ||
"identifiers": [ | ||
{ | ||
"type": "CRN", | ||
"value": "A000001" | ||
} | ||
] | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-referral-submitted.json
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,13 @@ | ||
{ | ||
"id": "364145f9-0af8-488e-9901-b4c46cd9ba37", | ||
"timestamp": "2022-11-30T14:53:44", | ||
"eventType": "accommodation.cas3.referral.submitted", | ||
"eventDetails": { | ||
"applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080", | ||
"applicationUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/application/68df9f6c-3fcb-4ec6-8fcf-96551cd9b080", | ||
"personReference": { | ||
"crn": "A000001", | ||
"noms": "A0001AA" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
projects/cas3-and-delius/src/dev/resources/simulations/__files/hmpps-auth-token-body.json
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,10 @@ | ||
{ | ||
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJwcm9iYXRpb24taW50ZWdyYXRpb24tZGV2IiwiZ3JhbnRfdHlwZSI6ImNsaWVudF9jcmVkZW50aWFscyIsInVzZXJfbmFtZSI6InByb2JhdGlvbi1pbnRlZ3JhdGlvbi1kZXYiLCJzY29wZSI6WyJyZWFkIiwid3JpdGUiXSwiYXV0aF9zb3VyY2UiOiJub25lIiwiaXNzIjoiaHR0cHM6Ly9zaWduLWluLWRldi5obXBwcy5zZXJ2aWNlLmp1c3RpY2UuZ292LnVrL2F1dGgvaXNzdWVyIiwiZXhwIjo5OTk5OTk5OTk5LCJhdXRob3JpdGllcyI6WyJST0xFX0FQUFJPVkVEX1BSRU1JU0VTX1NUQUZGIl0sImp0aSI6IjI1RHVSbjEtaHlIWmV3TGNkSkp4d1ZMMDNLVSIsImNsaWVudF9pZCI6InByb2JhdGlvbi1pbnRlZ3JhdGlvbi1kZXYiLCJpYXQiOjE2NjM3NTczMTF9.HmAw0LBKPSHHyDh1egCb1i2ubjzDQ9x43XKDt-Qg09GsS7RuroBUm2BmRoCXPIapSve-BaUBWGa_pPopsaX6VBlzHBOWZPu68HaCkzBa82fwvyVPI3s88eJBUemEOZWQ0RmCx8KiPjK53-rZEhx_aEMJSQoHJIrFK86TjLwphk4", | ||
"token_type": "bearer", | ||
"expires_in": 9999999999, | ||
"scope": "read write", | ||
"sub": "probation-integration-dev", | ||
"auth_source": "none", | ||
"jti": "fN29JHJy1N7gcYvqe-8B_k5T0mA", | ||
"iss": "https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer" | ||
} |
17 changes: 17 additions & 0 deletions
17
projects/cas3-and-delius/src/dev/resources/simulations/mappings/cas3-api.json
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,17 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"urlPath": "/cas3-api/events/referral-submitted/1234" | ||
}, | ||
"response": { | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"status": 200, | ||
"bodyFileName": "cas3-referral-submitted.json" | ||
} | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
projects/cas3-and-delius/src/dev/resources/simulations/mappings/hmpps-auth.json
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,13 @@ | ||
{ | ||
"request": { | ||
"method": "POST", | ||
"urlPath": "/auth/oauth/token" | ||
}, | ||
"response": { | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"status": 200, | ||
"bodyFileName": "hmpps-auth-token-body.json" | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CASIntegrationTest.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,56 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import org.hamcrest.MatcherAssert | ||
import org.hamcrest.Matchers | ||
import org.junit.jupiter.api.MethodOrderer | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestMethodOrder | ||
import org.mockito.Mockito | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ContactRepository | ||
import uk.gov.justice.digital.hmpps.messaging.HmppsChannelManager | ||
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService | ||
import uk.gov.justice.digital.hmpps.telemetry.notificationReceived | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation::class) | ||
internal class CASIntegrationTest { | ||
@Value("\${messaging.consumer.queue}") | ||
lateinit var queueName: String | ||
|
||
@Autowired | ||
lateinit var channelManager: HmppsChannelManager | ||
|
||
@Autowired | ||
lateinit var wireMockServer: WireMockServer | ||
|
||
@Autowired | ||
lateinit var contactRepository: ContactRepository | ||
|
||
@MockBean | ||
lateinit var telemetryService: TelemetryService | ||
|
||
@Test | ||
fun `message is processed correctly`() { | ||
// Given an application-submitted event | ||
val event = prepEvent("referral-submitted", wireMockServer.port()) | ||
|
||
// When it is received | ||
channelManager.getChannel(queueName).publishAndWait(event) | ||
|
||
// Then it is logged to telemetry | ||
Mockito.verify(telemetryService).notificationReceived(event) | ||
|
||
val contact = | ||
contactRepository.getByExternalReference(event.message.additionalInformation["applicationId"] as String) | ||
|
||
MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EARS")) | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
...as3-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
.../cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/FeignOAuth2Config.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,15 @@ | ||
package uk.gov.justice.digital.hmpps.config | ||
|
||
import org.springframework.cloud.openfeign.EnableFeignClients | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager | ||
import uk.gov.justice.digital.hmpps.config.feign.FeignConfig | ||
import uk.gov.justice.digital.hmpps.integrations.approvedpremesis.Cas3ApiClient | ||
|
||
@Configuration | ||
@EnableFeignClients(clients = [Cas3ApiClient::class]) | ||
class FeignOAuth2Config( | ||
authorizedClientManager: OAuth2AuthorizedClientManager | ||
) : FeignConfig(authorizedClientManager) { | ||
override fun registrationId() = "cas3-and-delius" | ||
} |
Oops, something went wrong.