Skip to content

Commit

Permalink
feat(sharing state): #163 add testcases for optional filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-exxcellent committed May 24, 2023
1 parent cc51219 commit 9c031ee
Showing 1 changed file with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@ class SharingStateControllerIT @Autowired constructor(

val stateAddress = insertSharingStateSuccess(LsaType.Address, externalId = "exIdAddress")
val stateSite = insertSharingStateSuccess(LsaType.Site, externalId = "exIdSite")
insertSharingStateSuccess(LsaType.LegalEntity, externalId = "exIdEntity1")
val stateLegalEntity1 = insertSharingStateSuccess(LsaType.LegalEntity, externalId = "exIdEntity1")
val stateLegalEntity2 = insertSharingStateSuccess(LsaType.LegalEntity, externalId = "exIdEntity2")
insertSharingStateSuccess(LsaType.Address, externalId = "exIdMultiple")
insertSharingStateSuccess(LsaType.Site, externalId = "exIdMultiple")
insertSharingStateSuccess(LsaType.LegalEntity, externalId = "exIdMultiple")

val searchAddress = readSharingStates(LsaType.Address, "exIdAddress")
assertThat(searchAddress).hasSize(1)
assertThat(searchAddress.first()).isEqualTo(stateAddress)
val searchAddressById = readSharingStates(LsaType.Address, "exIdAddress")
assertThat(searchAddressById).hasSize(1)
assertThat(searchAddressById.first()).isEqualTo(stateAddress)

val searchSites = readSharingStates(LsaType.Site, "exIdSite")
assertThat(searchSites).hasSize(1)
assertThat(searchSites.first()).isEqualTo(stateSite)
val searchSitesById = readSharingStates(LsaType.Site, "exIdSite")
assertThat(searchSitesById).hasSize(1)
assertThat(searchSitesById.first()).isEqualTo(stateSite)

val searchWrongId = readSharingStates(LsaType.Address, "exIdEntity")
assertThat(searchWrongId).hasSize(0)
val searchAddressWrongId = readSharingStates(LsaType.Address, "exIdEntity")
assertThat(searchAddressWrongId).hasSize(0)

val searchEntityMultiple = readSharingStates(LsaType.LegalEntity, "exIdEntity1", "exIdEntity2")
assertThat(searchEntityMultiple).hasSize(2)
Expand All @@ -77,6 +80,19 @@ class SharingStateControllerIT @Autowired constructor(
assertThat(searchEntitySingle).hasSize(1)
assertThat(searchEntitySingle.first()).isEqualTo(stateLegalEntity2)

val searchAll = readSharingStates(null)
assertThat(searchAll).hasSize(7)

val searchEntityAllLegalEntities = readSharingStates(LsaType.LegalEntity)
assertThat(searchEntityAllLegalEntities).hasSize(3)
assertThat(searchEntityAllLegalEntities).extracting(SharingStateDto::externalId.name)
.contains(stateLegalEntity1.externalId, stateLegalEntity2.externalId, "exIdMultiple")

val searchAllWithSameId = readSharingStates(null, "exIdMultiple")
assertThat(searchAllWithSameId).hasSize(3)
assertThat(searchAllWithSameId).extracting(SharingStateDto::externalId.name)
.containsOnly("exIdMultiple")

}

@Test
Expand All @@ -89,7 +105,6 @@ class SharingStateControllerIT @Autowired constructor(
val searchAddress = readSharingStates(LsaType.Address, "exIdAddress1")
assertThat(searchAddress).hasSize(1)
assertThat(searchAddress.first()).isEqualTo(stateAddress1)

}

@Test
Expand Down Expand Up @@ -118,18 +133,43 @@ class SharingStateControllerIT @Autowired constructor(
assertThat(readUpdatedAddress.first()).isEqualTo(updatedAddress1)
}

@Test
fun `insert and update states with sharingProcessStarted`() {

val startTime = LocalDateTime.now().withNano(0)
val stateAddress1 = insertSharingStateSuccess(
lsaType = LsaType.Address, externalId = "exIdAddress1",
sharingProcessStarted = startTime
)

val readInsertedAddress = readSharingStates(LsaType.Address, "exIdAddress1")
assertThat(readInsertedAddress.first().sharingProcessStarted).isEqualTo(startTime)

val updatedWithEmpyStarted = stateAddress1.copy(
sharingStateType = SharingStateType.Error,
sharingProcessStarted = null,
sharingErrorMessage = "Changed",
)
gateClient.sharingState().upsertSharingState(updatedWithEmpyStarted)

val readUpdatedAddress = readSharingStates(LsaType.Address, "exIdAddress1")
assertThat(readUpdatedAddress.first().sharingStateType).isEqualTo(SharingStateType.Error)
assertThat(readUpdatedAddress.first().sharingProcessStarted).isEqualTo(startTime).describedAs("Update with null - sharingProcessStarted not changed ")
assertThat(readUpdatedAddress.first().sharingErrorMessage).isEqualTo("Changed")

}

/**
* Insert Sharing State only with required fields filled
*/
fun insertSharingStateSuccess(lsaType: LsaType, externalId: String): SharingStateDto {
fun insertSharingStateSuccess(lsaType: LsaType, externalId: String, sharingProcessStarted: LocalDateTime? = null): SharingStateDto {

val newState = SharingStateDto(
lsaType = lsaType,
externalId = externalId,
sharingStateType = SharingStateType.Success,
sharingErrorCode = null,
sharingProcessStarted = null,
sharingProcessStarted = sharingProcessStarted,
sharingErrorMessage = null,
bpn = null
)
Expand All @@ -155,7 +195,7 @@ class SharingStateControllerIT @Autowired constructor(
return newState
}

fun readSharingStates(lsaType: LsaType, vararg externalIds: String): Collection<SharingStateDto> {
fun readSharingStates(lsaType: LsaType?, vararg externalIds: String): Collection<SharingStateDto> {

return gateClient.sharingState().getSharingStates(PaginationRequest(), lsaType, externalIds.asList()).content
}
Expand Down

0 comments on commit 9c031ee

Please sign in to comment.