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.
- Loading branch information
1 parent
895afb9
commit 79fd947
Showing
8 changed files
with
101 additions
and
14 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
31 changes: 31 additions & 0 deletions
31
...nd-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/DocumentGenerator.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,31 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.Event | ||
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.DocEvent | ||
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.DocumentType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.EventDocument | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.Person | ||
import java.time.ZonedDateTime | ||
|
||
object DocumentGenerator { | ||
val EVENT_DOC = generateEventDoc() | ||
|
||
fun generateEventDoc( | ||
event: Event = PersonGenerator.ANOTHER_EVENT, | ||
id: Long = IdGenerator.getAndIncrement() | ||
): EventDocument { | ||
val doc = EventDocument(event.toDocEvent()) | ||
doc.id = id | ||
doc.person = PersonGenerator.DEFAULT | ||
doc.name = "test.doc" | ||
doc.primaryKeyId = doc.event?.id!! | ||
doc.alfrescoId = "uuid1" | ||
doc.lastSaved = ZonedDateTime.now().minusDays(7) | ||
doc.dateProduced = null | ||
doc.type = DocumentType.DOCUMENT | ||
return doc | ||
} | ||
|
||
private fun Event.toDocEvent() = | ||
DocEvent(id, Person(personId, "", false ), true, number, null, null) | ||
} |
58 changes: 58 additions & 0 deletions
58
...-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/DocIntegrationTest.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,58 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import org.hamcrest.Matchers | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.header | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import org.springframework.util.ResourceUtils | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.security.withOAuth2Token | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
internal class DocIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Autowired | ||
lateinit var wireMockserver: WireMockServer | ||
|
||
@Test | ||
fun `document is downloaded`() { | ||
mockMvc.perform( | ||
get("/document/A000001/uuid1").accept("application/octet-stream").withOAuth2Token(wireMockserver) | ||
) | ||
.andExpect(status().is2xxSuccessful) | ||
.andExpect(header().string("Content-Type", "application/octet-stream")) | ||
.andExpect( | ||
header().string( | ||
"Content-Disposition", | ||
"attachment; filename=\"=?UTF-8?Q?test.doc?=\"; filename*=UTF-8''test.doc" | ||
) | ||
) | ||
.andExpect(header().doesNotExist("Custom-Alfresco-Header")) | ||
.andExpect(content().bytes(ResourceUtils.getFile("classpath:simulations/__files/document.pdf").readBytes())) | ||
} | ||
|
||
@Test | ||
fun `list documents`() { | ||
mockMvc.perform(get("/document/${PersonGenerator.DEFAULT.crn}/all").withOAuth2Token(wireMockserver)) | ||
.andExpect(status().isOk) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].id",Matchers.equalTo("uuid1"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].level",Matchers.equalTo("Conviction"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].eventNumber",Matchers.equalTo("8"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].filename",Matchers.equalTo("test.doc"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].typeCode",Matchers.equalTo("EVENT"))) | ||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].typeDescription",Matchers.equalTo("Event"))) | ||
|
||
|
||
} | ||
} |
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