Skip to content

Commit

Permalink
PI-2515: CVL Text has a 4000 byte limit - truncate bytes (#4223)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 authored Sep 11, 2024
1 parent dbff1ae commit c5843af
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LicenceCondition(
@Column(name = "lic_condition_notes")
val notes: String?,

@Column
@Column(columnDefinition = "varchar2(4000)")
val cvlText: String?,

@Column(columnDefinition = "number")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LicenceConditionService(
category,
subCategory,
notes,
cvlText.let { it?.take(4000) }
cvlText?.let { String(it.toByteArray().take(4000).toByteArray()) }
)
)
licenceConditionManagerRepository.save(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ internal class LicenceConditionServiceTest {

@Test
fun `cvlText is truncated to 4000 chars when greater than 4000`() {
val cvlText = 'A'.repeat(4212)
val cvlText = 'A'.repeat(2000) + '|'.repeat(1000) + '£'.repeat(1120)
val expected = String(cvlText.toByteArray().take(4000).toByteArray())
licenceConditionService.createLicenceCondition(
disposal,
LocalDate.now(),
Expand All @@ -97,7 +98,9 @@ internal class LicenceConditionServiceTest {
)
val lcCaptor = ArgumentCaptor.forClass(LicenceCondition::class.java)
Mockito.verify(licenceConditionRepository, Mockito.times(1)).save(lcCaptor.capture())
assertThat(lcCaptor.value.cvlText?.length, equalTo(4000))
val lc = lcCaptor.value.cvlText!!
assertThat(lc.toByteArray().size, equalTo(4000))
assertThat(lc, equalTo(expected))
}

@Test
Expand Down

0 comments on commit c5843af

Please sign in to comment.