-
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.
feat: prevent new ReportCalculation if one is still pending (#32)
- Loading branch information
1 parent
2d5311a
commit ba797bb
Showing
11 changed files
with
224 additions
and
33 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
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
103 changes: 103 additions & 0 deletions
103
...l/aambackendservice/reporting/report/core/DefaultReportDocumentChangeEventConsumerTest.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,103 @@ | ||
package com.aamdigital.aambackendservice.reporting.report.core | ||
|
||
import com.aamdigital.aambackendservice.error.InternalServerException | ||
import com.aamdigital.aambackendservice.queue.core.QueueMessageParser | ||
import com.aamdigital.aambackendservice.reporting.reportcalculation.core.CreateReportCalculationUseCase | ||
import com.aamdigital.aambackendservice.reporting.reportcalculation.core.ReportCalculationChangeUseCase | ||
import com.rabbitmq.client.Channel | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.reset | ||
import org.mockito.kotlin.whenever | ||
import org.springframework.amqp.AmqpRejectAndDontRequeueException | ||
import org.springframework.amqp.core.Message | ||
import reactor.test.StepVerifier | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class DefaultReportDocumentChangeEventConsumerTest { | ||
|
||
private lateinit var service: ReportDocumentChangeEventConsumer | ||
|
||
@Mock | ||
lateinit var messageParser: QueueMessageParser | ||
|
||
@Mock | ||
lateinit var mockMessage: Message | ||
|
||
@Mock | ||
lateinit var mockChannel: Channel | ||
|
||
@Mock | ||
lateinit var createReportCalculationUseCase: CreateReportCalculationUseCase | ||
|
||
@Mock | ||
lateinit var reportCalculationChangeUseCase: ReportCalculationChangeUseCase | ||
|
||
@Mock | ||
lateinit var identifyAffectedReportsUseCase: IdentifyAffectedReportsUseCase | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
reset( | ||
messageParser, | ||
createReportCalculationUseCase, | ||
reportCalculationChangeUseCase, | ||
identifyAffectedReportsUseCase | ||
) | ||
|
||
service = DefaultReportDocumentChangeEventConsumer( | ||
messageParser = messageParser, | ||
createReportCalculationUseCase = createReportCalculationUseCase, | ||
reportCalculationChangeUseCase = reportCalculationChangeUseCase, | ||
identifyAffectedReportsUseCase = identifyAffectedReportsUseCase | ||
) | ||
} | ||
|
||
@Test | ||
fun `should return MonoError with AmqpRejectAndDontRequeueException when MessageParser throws exception`() { | ||
// given | ||
val rawMessage = "foo" | ||
|
||
whenever(messageParser.getTypeKClass(any())) | ||
.thenAnswer { | ||
throw InternalServerException() | ||
} | ||
|
||
StepVerifier | ||
// when | ||
.create(service.consume(rawMessage, mockMessage, mockChannel)) | ||
// then | ||
.expectErrorSatisfies { | ||
assertThat(it).isInstanceOf(AmqpRejectAndDontRequeueException::class.java) | ||
Assertions.assertTrue(it.localizedMessage.startsWith("[INTERNAL_SERVER_ERROR]")) | ||
} | ||
.verify() | ||
} | ||
|
||
@Test | ||
fun `should return MonoError with AmqpRejectAndDontRequeueException when EventType is unknown`() { | ||
// given | ||
val rawMessage = "foo" | ||
|
||
whenever(messageParser.getTypeKClass(any())) | ||
.thenAnswer { | ||
String::class | ||
} | ||
|
||
StepVerifier | ||
// when | ||
.create(service.consume(rawMessage, mockMessage, mockChannel)) | ||
// then | ||
.expectErrorSatisfies { | ||
assertThat(it).isInstanceOf(AmqpRejectAndDontRequeueException::class.java) | ||
Assertions.assertTrue(it.localizedMessage.startsWith("[NO_USECASE_CONFIGURED]")) | ||
} | ||
.verify() | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...kendservice/reporting/reportcalculation/core/DefaultCreateReportCalculationUseCaseTest.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,63 @@ | ||
package com.aamdigital.aambackendservice.reporting.reportcalculation.core | ||
|
||
import com.aamdigital.aambackendservice.domain.DomainReference | ||
import com.aamdigital.aambackendservice.error.InternalServerException | ||
import com.aamdigital.aambackendservice.reporting.report.core.ReportingStorage | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.reset | ||
import org.mockito.kotlin.whenever | ||
import reactor.core.publisher.Mono | ||
import reactor.test.StepVerifier | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class DefaultCreateReportCalculationUseCaseTest { | ||
|
||
private lateinit var service: CreateReportCalculationUseCase | ||
|
||
@Mock | ||
lateinit var reportingStorage: ReportingStorage | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
reset(reportingStorage) | ||
service = DefaultCreateReportCalculationUseCase(reportingStorage) | ||
} | ||
|
||
@Test | ||
fun `should return Failure when ReportingStorage throws error`() { | ||
// given | ||
whenever(reportingStorage.fetchCalculations(any())) | ||
.thenAnswer { | ||
Mono.error<List<*>> { | ||
InternalServerException() | ||
} | ||
} | ||
|
||
StepVerifier | ||
// when | ||
.create( | ||
service.createReportCalculation( | ||
CreateReportCalculationRequest( | ||
report = DomainReference("Report:1"), | ||
args = mutableMapOf() | ||
) | ||
) | ||
) | ||
// then | ||
.assertNext { | ||
assertThat(it).isInstanceOf(CreateReportCalculationResult.Failure::class.java) | ||
Assertions.assertEquals( | ||
CreateReportCalculationResult.ErrorCode.INTERNAL_SERVER_ERROR, | ||
(it as CreateReportCalculationResult.Failure).errorCode | ||
) | ||
} | ||
.verifyComplete() | ||
} | ||
} |