-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
229 changed files
with
3,947 additions
and
5,338 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
55 changes: 55 additions & 0 deletions
55
...nMain/kotlin/dk/cachet/carp/common/test/infrastructure/ApplicationServiceDecoratorTest.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,55 @@ | ||
package dk.cachet.carp.common.test.infrastructure | ||
|
||
import dk.cachet.carp.common.application.services.ApplicationService | ||
import dk.cachet.carp.common.application.services.IntegrationEvent | ||
import dk.cachet.carp.common.infrastructure.services.* | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
|
||
/** | ||
* Base class to test whether an application service decorator correctly invokes the decorated service. | ||
*/ | ||
@ExperimentalCoroutinesApi | ||
@Suppress( | ||
"FunctionName", | ||
"UnnecessaryAbstractClass" // Prevent test being picked up by test runner. | ||
) | ||
abstract class ApplicationServiceDecoratorTest< | ||
TService : ApplicationService<TService, TEvent>, | ||
TEvent : IntegrationEvent<TService>, | ||
TRequest : ApplicationServiceRequest<TService, *> | ||
>( | ||
private val requestsTest: ApplicationServiceRequestsTest<TService, TRequest>, | ||
private val serviceInvoker: ApplicationServiceInvoker<TService, TRequest> | ||
) | ||
{ | ||
@Test | ||
fun request_invoker_calls_service() = runTest { | ||
// Create logged service. | ||
val service = requestsTest.createService() | ||
val logger = ApplicationServiceLogger<TService, TEvent>() | ||
val eventBusLog = EventBusLog( SingleThreadedEventBus() ) // Ignore events. | ||
val ignoreServiceInvocation = | ||
object : Command<TRequest> | ||
{ | ||
// The returned result goes unused in this test, so just return null. | ||
override suspend fun invoke( request: TRequest ): Any? = null | ||
} | ||
val loggedService = requestsTest.decoratedServiceConstructor( service ) | ||
{ ApplicationServiceRequestLogger( eventBusLog, logger::addLog, ignoreServiceInvocation ) } | ||
|
||
// Test whether each invoked method on the decorated service is converted back into the same request object. | ||
// `requestTest` guarantees a request for each call is available. | ||
requestsTest.requests.forEach { | ||
serviceInvoker.invokeOnService( it, loggedService ) | ||
assertTrue( | ||
logger.wasCalled( it ), | ||
"Service wasn't called or parameters of called request don't match: $it" | ||
) | ||
logger.clear() | ||
} | ||
} | ||
} |
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
Oops, something went wrong.