This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
forked from iguissouma/chutney-kotlin-dsl
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add component to kotlin feature #22
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
kotlin.code.style=official | ||
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
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/com/chutneytesting/kotlin/synchronize/ScenarioSynchronizeService.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,65 @@ | ||
package com.chutneytesting.kotlin.synchronize | ||
|
||
import com.chutneytesting.kotlin.util.ChutneyServerInfo | ||
import com.chutneytesting.kotlin.dsl.ChutneyScenario | ||
import com.chutneytesting.kotlin.transformation.ChutneyServerServiceImpl | ||
import java.io.File | ||
|
||
/** | ||
* Synchronise scenario locally and/or remotely and returns elapsed time in milliseconds. | ||
*/ | ||
fun ChutneyScenario.synchronise(serverInfo: ChutneyServerInfo? = null, updateRemote: Boolean = false, path: String = "src/main/resources/chutney/") { | ||
val json = this.toString() | ||
val fileName = (this.id?.let { this.id.toString() + "-" } ?: "") + title + ".chutney.json" | ||
File(path).walkTopDown().filter { it.isFile }.firstOrNull { | ||
val chutneyScenarioIdFromFileName = getChutneyScenarioIdFromFileName(it.name) | ||
it.name.equals(fileName, ignoreCase = true) || (this.id != null && chutneyScenarioIdFromFileName != null && this.id == chutneyScenarioIdFromFileName) | ||
}?.apply { | ||
this.writeText(json) | ||
}?.also { | ||
println("| AT json synchronized:: ${it.absolutePath}") | ||
} ?: File("src/main/resources/chutney/in_progress/$fileName").apply { writeText(json) } | ||
.also { println("| AT json created:: ${it.absolutePath}") } | ||
|
||
if (updateRemote && this.id != null && serverInfo != null) { | ||
updateJsonRemoteScenario(serverInfo, this.id, json) | ||
} | ||
} | ||
|
||
/** | ||
* Cosmetic to create a list of scenarios | ||
*/ | ||
class SynchronizeScenariosBuilder { | ||
var scenarios: List<ChutneyScenario> = mutableListOf() | ||
|
||
operator fun ChutneyScenario.unaryPlus() { | ||
scenarios = scenarios + this | ||
} | ||
|
||
operator fun List<ChutneyScenario>.unaryPlus() { | ||
scenarios = scenarios + this | ||
} | ||
|
||
operator fun ChutneyScenario.unaryMinus() { | ||
// scenarios = scenarios - this | ||
// cosmetic to ignore scenario | ||
} | ||
} | ||
|
||
private fun updateJsonRemoteScenario(serverInfo: ChutneyServerInfo, id: Int, content: String) { | ||
try { | ||
ChutneyServerServiceImpl.updateJsonScenario(serverInfo, content, id.toString()) | ||
println("| remote AT json synchronized:: ${serverInfo.remoteServerUrl}/#/scenario/$id/execution/last") | ||
} catch (e: Exception) { | ||
println("| remote AT json cannot be synchronized:: $id") | ||
} | ||
} | ||
|
||
private fun getChutneyScenarioIdFromFileName(fileName: String): Int? { | ||
val dashIndex = fileName.indexOf("-") | ||
return try { | ||
if (dashIndex > 0) Integer.valueOf(fileName.substring(0, dashIndex)) else null | ||
} catch (e: Exception) { | ||
null | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/com/chutneytesting/kotlin/transformation/ChutneyServerServiceImpl.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,42 @@ | ||
package com.chutneytesting.kotlin.transformation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe put this in synchornize package ? |
||
|
||
import com.chutneytesting.kotlin.transformation.from_component_to_kotlin.ComposableStepDto | ||
import com.chutneytesting.kotlin.transformation.from_component_to_kotlin.ComposableTestCaseDto | ||
import com.chutneytesting.kotlin.util.ChutneyServerInfo | ||
import com.chutneytesting.kotlin.util.HttpClient | ||
import org.apache.commons.lang3.StringUtils | ||
|
||
|
||
interface ChutneyServerService { | ||
fun getAllComponent(serverInfo: ChutneyServerInfo): List<ComposableStepDto> | ||
fun getAllScenarios(serverInfo: ChutneyServerInfo): List<LinkedHashMap<String, Any>> | ||
fun getComposedScenario(serverInfo: ChutneyServerInfo, scenarioId: String): ComposableTestCaseDto | ||
fun updateJsonScenario(serverInfo: ChutneyServerInfo, scenarioContent: String, scenarioId: String) | ||
} | ||
|
||
object ChutneyServerServiceImpl : ChutneyServerService { | ||
|
||
override fun getAllComponent(serverInfo: ChutneyServerInfo): List<ComposableStepDto> { | ||
return HttpClient.get(serverInfo, "/api/steps/v1/all") | ||
} | ||
|
||
override fun getAllScenarios(serverInfo: ChutneyServerInfo): List<LinkedHashMap<String, Any>> { | ||
return HttpClient.get(serverInfo, "/api/scenario/v2") | ||
} | ||
|
||
override fun getComposedScenario(serverInfo: ChutneyServerInfo, scenarioId: String): ComposableTestCaseDto { | ||
return HttpClient.get(serverInfo, "/api/scenario/component-edition/$scenarioId") | ||
} | ||
|
||
override fun updateJsonScenario(serverInfo: ChutneyServerInfo, scenarioContent: String, scenarioId: String) { | ||
val generatedTag = "GENERATED" | ||
val escapeSql = escapeSql(scenarioContent) | ||
val body = "update scenario set content='$escapeSql', version=version+1, tags=CASE WHEN tags like '%$generatedTag%' THEN tags ELSE CONCAT_WS(',',tags,'$generatedTag') end where id = '$scenarioId'" | ||
|
||
HttpClient.post<Any>(serverInfo, "/api/v1/admin/database/execute/jdbc", body) | ||
} | ||
|
||
private fun escapeSql(str: String?): String? = if (str == null) null else StringUtils.replace(str, "'", "''") | ||
|
||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't a required input.
Maybe something like this :
("nbLoggedRow" to nbLoggedRow).takeIf { nbLoggedRow.isNotBlank() }