This file contains hidden or 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
| testUserActive() | |
| Starting process: IsUserActive | |
| Found user: User(id='6dbcb954-ac34-4945-abdc-ff239c662069', banned=false) | |
| Check user: User(id='6dbcb954-ac34-4945-abdc-ff239c662069', banned=false) is active and returning: true | |
| Unregistering mocks | |
| testUserInactive() | |
| Starting process: IsUserActive | |
| Found user: User(id='dcf81663-abfb-48c3-a181-d19b81c1d323', banned=false) | |
| Check user: User(id='dcf81663-abfb-48c3-a181-d19b81c1d323', banned=false) is active and returning: false |
This file contains hidden or 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
| class IsUserActiveProcessTest: BaseProcessTest() { | |
| protected fun prepareEnvAndStartProcess(userExists: Boolean = true, userIsActive: Boolean = true): ProcessAssertions { | |
| val mockUserService = mock(UserService::class.java) | |
| val mockUser = User() | |
| if (userExists) { | |
| `when`(mockUserService.findUser(mockUser.id)).thenReturn(mockUser) | |
| `when`(mockUserService.isBanned(mockUser)).thenReturn(!userIsActive) |
This file contains hidden or 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
| @RunWith(SpringRunner::class) | |
| @SpringBootTest | |
| abstract class BaseProcessTest { | |
| @Autowired protected lateinit var runtimeService: RuntimeService | |
| abstract fun processName(): String | |
| fun startProcess(variables: Map<String, Any> = mapOf()) { | |
| logger.debug("Starting process: ${processName()}") |
This file contains hidden or 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
| @Configuration | |
| class TestConfiguration { | |
| @Bean | |
| fun flowableTestSpringProcessEngineConfig() = EngineConfigurationConfigurer<SpringProcessEngineConfiguration> { | |
| it.expressionManager = MockExpressionManager() | |
| } | |
| } |
This file contains hidden or 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
| val userService = mock(UserService::class.java) | |
| val serviceTask = BanUserServiceTask(userService) |
This file contains hidden or 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
| @Component | |
| class BanUserServiceTask @Autowired constructor( | |
| val userService: UserService | |
| ) |
This file contains hidden or 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
| @Component | |
| class IsUserActiveServiceTask @Autowired constructor( | |
| val userService: UserService | |
| ) { | |
| fun checkUserExists(userId: String) { | |
| userService.findUser(userId).let { | |
| if (it == null) { | |
| logger.error("User with id: $userId is not found") | |
| throw BpmnError(ERR_USER_NOT_EXIST) |
This file contains hidden or 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
| @Component | |
| class BanUserServiceTask @Autowired constructor( | |
| val userService: UserService | |
| ) { | |
| fun ban(userId: String) { | |
| userService.findUser(userId)?.let { | |
| logger.debug("Banning user: $it") | |
| userService.ban(it) | |
| return | |
| } |
This file contains hidden or 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
| class User(val id: String): Serializable { | |
| var banned = false | |
| } |
This file contains hidden or 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
| @Service | |
| class UserService { | |
| fun findUser(id: String): User? { | |
| throw NotImplementedError() | |
| } | |
| fun isBanned(user: User): Boolean { | |
| throw NotImplementedError() | |
| } |