-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* m6l1 - Prepare * m6l1 - Chain of Responsibility * M6l2 biz (#26) * m6l1 - Chain of Responsibility (cherry picked from commit 80c19ed85f4415940a9c475344925c421cf17992) * m6l2 remove unknown failing test --------- Co-authored-by: Sergey Okatov <[email protected]> Co-authored-by: Sergey Okatov <[email protected]>
- Loading branch information
1 parent
b2e81fb
commit 9be9ab5
Showing
31 changed files
with
1,066 additions
and
116 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
98 changes: 0 additions & 98 deletions
98
ok-marketplace-be/ok-marketplace-app-spring/src/test/kotlin/mock/AdControllerV1StubTest.kt
This file was deleted.
Oops, something went wrong.
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
72 changes: 72 additions & 0 deletions
72
ok-marketplace-be/ok-marketplace-biz/src/commonMain/kotlin/MkplAdProcessor.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,72 @@ | ||
package ru.otus.otuskotlin.marketplace.biz | ||
|
||
import ru.otus.otuskotlin.marketplace.biz.general.initStatus | ||
import ru.otus.otuskotlin.marketplace.biz.general.operation | ||
import ru.otus.otuskotlin.marketplace.biz.general.stubs | ||
import ru.otus.otuskotlin.marketplace.biz.stubs.* | ||
import ru.otus.otuskotlin.marketplace.common.MkplContext | ||
import ru.otus.otuskotlin.marketplace.common.MkplCorSettings | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplCommand | ||
import ru.otus.otuskotlin.marketplace.cor.rootChain | ||
|
||
class MkplAdProcessor( | ||
private val corSettings: MkplCorSettings = MkplCorSettings.NONE | ||
) { | ||
suspend fun exec(ctx: MkplContext) = businessChain.exec(ctx.also { it.corSettings = corSettings }) | ||
|
||
private val businessChain = rootChain<MkplContext> { | ||
initStatus("Инициализация статуса") | ||
|
||
operation("Создание объявления", MkplCommand.CREATE) { | ||
stubs("Обработка стабов") { | ||
stubCreateSuccess("Имитация успешной обработки", corSettings) | ||
stubValidationBadTitle("Имитация ошибки валидации заголовка") | ||
stubValidationBadDescription("Имитация ошибки валидации описания") | ||
stubDbError("Имитация ошибки работы с БД") | ||
stubNoCase("Ошибка: запрошенный стаб недопустим") | ||
} | ||
} | ||
operation("Получить объявление", MkplCommand.READ) { | ||
stubs("Обработка стабов") { | ||
stubReadSuccess("Имитация успешной обработки", corSettings) | ||
stubValidationBadId("Имитация ошибки валидации id") | ||
stubDbError("Имитация ошибки работы с БД") | ||
stubNoCase("Ошибка: запрошенный стаб недопустим") | ||
} | ||
} | ||
operation("Изменить объявление", MkplCommand.UPDATE) { | ||
stubs("Обработка стабов") { | ||
stubUpdateSuccess("Имитация успешной обработки", corSettings) | ||
stubValidationBadId("Имитация ошибки валидации id") | ||
stubValidationBadTitle("Имитация ошибки валидации заголовка") | ||
stubValidationBadDescription("Имитация ошибки валидации описания") | ||
stubDbError("Имитация ошибки работы с БД") | ||
stubNoCase("Ошибка: запрошенный стаб недопустим") | ||
} | ||
} | ||
operation("Удалить объявление", MkplCommand.DELETE) { | ||
stubs("Обработка стабов") { | ||
stubDeleteSuccess("Имитация успешной обработки", corSettings) | ||
stubValidationBadId("Имитация ошибки валидации id") | ||
stubDbError("Имитация ошибки работы с БД") | ||
stubNoCase("Ошибка: запрошенный стаб недопустим") | ||
} | ||
} | ||
operation("Поиск объявлений", MkplCommand.SEARCH) { | ||
stubs("Обработка стабов") { | ||
stubSearchSuccess("Имитация успешной обработки", corSettings) | ||
stubValidationBadId("Имитация ошибки валидации id") | ||
stubDbError("Имитация ошибки работы с БД") | ||
stubNoCase("Ошибка: запрошенный стаб недопустим") | ||
} | ||
} | ||
operation("Поиск подходящих предложений для объявления", MkplCommand.OFFERS) { | ||
stubs("Обработка стабов") { | ||
stubOffersSuccess("Имитация успешной обработки", corSettings) | ||
stubValidationBadId("Имитация ошибки валидации id") | ||
stubDbError("Имитация ошибки работы с БД") | ||
stubNoCase("Ошибка: запрошенный стаб недопустим") | ||
} | ||
} | ||
}.build() | ||
} |
15 changes: 15 additions & 0 deletions
15
ok-marketplace-be/ok-marketplace-biz/src/commonMain/kotlin/general/InitStatus.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,15 @@ | ||
package ru.otus.otuskotlin.marketplace.biz.general | ||
|
||
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl | ||
import ru.otus.otuskotlin.marketplace.cor.worker | ||
import ru.otus.otuskotlin.marketplace.common.MkplContext | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplState | ||
|
||
fun ICorChainDsl<MkplContext>.initStatus(title: String) = worker() { | ||
this.title = title | ||
this.description = """ | ||
Этот обработчик устанавливает стартовый статус обработки. Запускается только в случае не заданного статуса. | ||
""".trimIndent() | ||
on { state == MkplState.NONE } | ||
handle { state = MkplState.RUNNING } | ||
} |
17 changes: 17 additions & 0 deletions
17
ok-marketplace-be/ok-marketplace-biz/src/commonMain/kotlin/general/Operation.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,17 @@ | ||
package ru.otus.otuskotlin.marketplace.biz.general | ||
|
||
import ru.otus.otuskotlin.marketplace.common.MkplContext | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplCommand | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplState | ||
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl | ||
import ru.otus.otuskotlin.marketplace.cor.chain | ||
|
||
fun ICorChainDsl<MkplContext>.operation( | ||
title: String, | ||
command: MkplCommand, | ||
block: ICorChainDsl<MkplContext>.() -> Unit | ||
) = chain { | ||
block() | ||
this.title = title | ||
on { this.command == command && state == MkplState.RUNNING } | ||
} |
13 changes: 13 additions & 0 deletions
13
ok-marketplace-be/ok-marketplace-biz/src/commonMain/kotlin/general/Stubs.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,13 @@ | ||
package ru.otus.otuskotlin.marketplace.biz.general | ||
|
||
import ru.otus.otuskotlin.marketplace.common.MkplContext | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplState | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplWorkMode | ||
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl | ||
import ru.otus.otuskotlin.marketplace.cor.chain | ||
|
||
fun ICorChainDsl<MkplContext>.stubs(title: String, block: ICorChainDsl<MkplContext>.() -> Unit) = chain { | ||
block() | ||
this.title = title | ||
on { workMode == MkplWorkMode.STUB && state == MkplState.RUNNING } | ||
} |
16 changes: 0 additions & 16 deletions
16
...rketplace-biz/src/commonMain/kotlin/ru/otus/otuskotlin/marketplace/biz/MkplAdProcessor.kt
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
ok-marketplace-be/ok-marketplace-biz/src/commonMain/kotlin/stubs/StubCreateSuccess.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,33 @@ | ||
package ru.otus.otuskotlin.marketplace.biz.stubs | ||
|
||
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl | ||
import ru.otus.otuskotlin.marketplace.cor.worker | ||
import ru.otus.otuskotlin.marketplace.common.MkplContext | ||
import ru.otus.otuskotlin.marketplace.common.MkplCorSettings | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplDealSide | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplState | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplVisibility | ||
import ru.otus.otuskotlin.marketplace.common.stubs.MkplStubs | ||
import ru.otus.otuskotlin.marketplace.logging.common.LogLevel | ||
import ru.otus.otuskotlin.marketplace.stubs.MkplAdStub | ||
|
||
fun ICorChainDsl<MkplContext>.stubCreateSuccess(title: String, corSettings: MkplCorSettings) = worker { | ||
this.title = title | ||
this.description = """ | ||
Кейс успеха для создания объявления | ||
""".trimIndent() | ||
on { stubCase == MkplStubs.SUCCESS && state == MkplState.RUNNING } | ||
val logger = corSettings.loggerProvider.logger("stubOffersSuccess") | ||
handle { | ||
logger.doWithLogging(id = this.requestId.asString(), LogLevel.DEBUG) { | ||
state = MkplState.FINISHING | ||
val stub = MkplAdStub.prepareResult { | ||
adRequest.title.takeIf { it.isNotBlank() }?.also { this.title = it } | ||
adRequest.description.takeIf { it.isNotBlank() }?.also { this.description = it } | ||
adRequest.adType.takeIf { it != MkplDealSide.NONE }?.also { this.adType = it } | ||
adRequest.visibility.takeIf { it != MkplVisibility.NONE }?.also { this.visibility = it } | ||
} | ||
adResponse = stub | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
ok-marketplace-be/ok-marketplace-biz/src/commonMain/kotlin/stubs/StubDeleteSuccess.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,28 @@ | ||
package ru.otus.otuskotlin.marketplace.biz.stubs | ||
|
||
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl | ||
import ru.otus.otuskotlin.marketplace.cor.worker | ||
import ru.otus.otuskotlin.marketplace.common.MkplContext | ||
import ru.otus.otuskotlin.marketplace.common.MkplCorSettings | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplState | ||
import ru.otus.otuskotlin.marketplace.common.stubs.MkplStubs | ||
import ru.otus.otuskotlin.marketplace.logging.common.LogLevel | ||
import ru.otus.otuskotlin.marketplace.stubs.MkplAdStub | ||
|
||
fun ICorChainDsl<MkplContext>.stubDeleteSuccess(title: String, corSettings: MkplCorSettings) = worker { | ||
this.title = title | ||
this.description = """ | ||
Кейс успеха для удаления объявления | ||
""".trimIndent() | ||
on { stubCase == MkplStubs.SUCCESS && state == MkplState.RUNNING } | ||
val logger = corSettings.loggerProvider.logger("stubOffersSuccess") | ||
handle { | ||
logger.doWithLogging(id = this.requestId.asString(), LogLevel.DEBUG) { | ||
state = MkplState.FINISHING | ||
val stub = MkplAdStub.prepareResult { | ||
adRequest.title.takeIf { it.isNotBlank() }?.also { this.title = it } | ||
} | ||
adResponse = stub | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
ok-marketplace-be/ok-marketplace-biz/src/commonMain/kotlin/stubs/StubNoCase.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,26 @@ | ||
package ru.otus.otuskotlin.marketplace.biz.stubs | ||
|
||
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl | ||
import ru.otus.otuskotlin.marketplace.cor.worker | ||
import ru.otus.otuskotlin.marketplace.common.MkplContext | ||
import ru.otus.otuskotlin.marketplace.common.helpers.fail | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplError | ||
import ru.otus.otuskotlin.marketplace.common.models.MkplState | ||
|
||
fun ICorChainDsl<MkplContext>.stubNoCase(title: String) = worker { | ||
this.title = title | ||
this.description = """ | ||
Валидируем ситуацию, когда запрошен кейс, который не поддерживается в стабах | ||
""".trimIndent() | ||
on { state == MkplState.RUNNING } | ||
handle { | ||
fail( | ||
MkplError( | ||
code = "validation", | ||
field = "stub", | ||
group = "validation", | ||
message = "Wrong stub case is requested: ${stubCase.name}" | ||
) | ||
) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
ok-marketplace-be/ok-marketplace-biz/src/commonMain/kotlin/stubs/StubOffersSuccess.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,28 @@ | ||
package ru.otus.otuskotlin.marketplace.biz.stubs | ||
|
||
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl | ||
import ru.otus.otuskotlin.marketplace.cor.worker | ||
import ru.otus.otuskotlin.marketplace.common.MkplContext | ||
import ru.otus.otuskotlin.marketplace.common.MkplCorSettings | ||
import ru.otus.otuskotlin.marketplace.common.models.* | ||
import ru.otus.otuskotlin.marketplace.common.stubs.MkplStubs | ||
import ru.otus.otuskotlin.marketplace.logging.common.LogLevel | ||
import ru.otus.otuskotlin.marketplace.stubs.MkplAdStub | ||
|
||
fun ICorChainDsl<MkplContext>.stubOffersSuccess(title: String, corSettings: MkplCorSettings) = worker { | ||
this.title = title | ||
this.description = """ | ||
Кейс успеха для получения предложений для объявления | ||
""".trimIndent() | ||
on { stubCase == MkplStubs.SUCCESS && state == MkplState.RUNNING } | ||
val logger = corSettings.loggerProvider.logger("stubOffersSuccess") | ||
handle { | ||
logger.doWithLogging(id = this.requestId.asString(), LogLevel.DEBUG) { | ||
state = MkplState.FINISHING | ||
adResponse = MkplAdStub.prepareResult { | ||
adRequest.id.takeIf { it != MkplAdId.NONE }?.also { this.id = it } | ||
} | ||
adsResponse.addAll(MkplAdStub.prepareOffersList(adResponse.title, MkplDealSide.SUPPLY)) | ||
} | ||
} | ||
} |
Oops, something went wrong.