Skip to content

Commit

Permalink
2024.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Adven27 committed Jan 21, 2024
1 parent 272b124 commit ba64166
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 114 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@ jobs:
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Update live specs
run: sh .utility/update-gh-pages.sh
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
ext.exposed_version = '0.41.1'
ext.klogging_version = '3.0.4'
ext.jacksonKt_version = '2.14.1'
ext.libVersion = '2024.0.0'
ext.libVersion = '2024.0.1'
repositories {
mavenCentral()
maven {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import mu.KLogging
import org.asciidoctor.Asciidoctor
import org.asciidoctor.Attributes
import org.asciidoctor.Attributes.FONT_ICONS
import org.asciidoctor.AttributesBuilder
import org.asciidoctor.Options
import org.asciidoctor.Placement.LEFT
import org.asciidoctor.SafeMode.UNSAFE
Expand All @@ -19,17 +18,17 @@ import org.concordion.internal.ConcordionBuilder.getBaseOutputDir
import java.io.ByteArrayInputStream
import java.io.File
import java.io.InputStreamReader
import java.nio.file.Files
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
import kotlin.time.measureTimedValue

open class AdocExtension : ConcordionExtension {
companion object : KLogging() {
const val BASE = "ext/ascii"
const val BASE_BS = "ext/bootstrap"
private const val SPECS_ADOC_RESOURCES_DIR = "SPECS_ADOC_RESOURCES_DIR"
private const val SPECS_ADOC_BASE_DIR = "SPECS_ADOC_BASE_DIR"
private const val SPECS_ADOC_VERSION = "SPECS_ADOC_VERSION"
val ADOC_BASE_DIR = File(System.getProperty(SPECS_ADOC_BASE_DIR, "./src/test/resources/specs"))
val RESOURCES_DIR: String = System.getProperty(SPECS_ADOC_RESOURCES_DIR, "./src/test/resources")
val BASE_DIR: String = System.getProperty(SPECS_ADOC_BASE_DIR, "/specs")
val ADOC_VERSION: String = System.getProperty(SPECS_ADOC_VERSION, "<Set system property $SPECS_ADOC_VERSION>")
val ADOC: Asciidoctor = Asciidoctor.Factory.create().apply {
System.setProperty("jruby.compat.version", "RUBY1_9")
Expand All @@ -41,33 +40,39 @@ open class AdocExtension : ConcordionExtension {
.postprocessor(ConcordionPostprocessor::class.java)
.treeprocessor(ExamTreeProcessor())
}
val CACHE: MutableMap<String, ByteArrayInputStream> = mutableMapOf()

fun copyGeneratedDiagramImagesToReports(baseDir: File) {
File(baseDir.path + File.separator + "img").takeIf { it.exists() }?.let { img ->
val output = File(getBaseOutputDir().path + File.separator + "specs/img")
output.takeUnless { it.exists() }?.let { Files.createDirectories(it.toPath()) }
img.listFiles()?.forEach {
Files.move(
it.toPath(),
File(output.path + File.separator + it.name).toPath(),
REPLACE_EXISTING
val ADOC_OPTS: Options = Options.builder()
.standalone(true)
.baseDir(File("$RESOURCES_DIR$BASE_DIR"))
.safe(UNSAFE)
.backend("xhtml5")
.attributes(
Attributes.builder()
.noFooter(true)
.sourceHighlighter("highlight.js")
.showTitle(true)
.tableOfContents(true)
.tableOfContents(LEFT)
.icons(FONT_ICONS)
.attributes(
mapOf(
"toclevels" to "4",
"diagram-cachedir" to getBaseOutputDir().path,
"imagesoutdir" to getBaseOutputDir().path + BASE_DIR,
"version" to ADOC_VERSION
)
)
}
Files.deleteIfExists(img.toPath())
}
}
.build()
)
.build()
val CACHE: MutableMap<String, ByteArrayInputStream> = mutableMapOf()
}

protected open fun configureAttributesBuilder(b: AttributesBuilder): AttributesBuilder = b

override fun addTo(ex: ConcordionExtender) {
addStyles(ex)
ex.withSpecificationType("adoc") { i, n ->
measureTimedValue {
CACHE.getOrPut(n) {
ByteArrayInputStream(ADOC.convert(InputStreamReader(i).readText(), options()).toByteArray())
.also { copyGeneratedDiagramImagesToReports(ADOC_BASE_DIR) }
ByteArrayInputStream(ADOC.convert(InputStreamReader(i).readText(), ADOC_OPTS).toByteArray())
}
}.let {
logger.info { "$n converted in " + it.duration }
Expand Down Expand Up @@ -117,32 +122,6 @@ open class AdocExtension : ConcordionExtension {
)
}

private fun options(): Options? = Options.builder()
.standalone(true)
.baseDir(ADOC_BASE_DIR)
.safe(UNSAFE)
.backend("xhtml5")
.attributes(
Attributes.builder()
.noFooter(true)
.imagesDir("img")
.sourceHighlighter("highlight.js")
.showTitle(true)
.tableOfContents(true)
.tableOfContents(LEFT)
.icons(FONT_ICONS)
.attributes(
mapOf(
"toclevels" to "4",
"diagram-cachedir" to getBaseOutputDir().path,
"version" to ADOC_VERSION
)
)
.apply { configureAttributesBuilder(this) }
.build()
)
.build()

protected open fun attrs(): Map<String, String> = mapOf()

class HighlightJs : SyntaxHighlighterAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ open class ConcordionPostprocessor : Postprocessor() {
"eq-json",
"eq-xml",
"verifier",
"ds",
AWAIT_AT_MOST_SEC_SPINAL,
AWAIT_AT_MOST_SEC_CAMEL,
AWAIT_POLL_DELAY_MILLIS_SPINAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class ExamExtension(private vararg var plugins: ExamPlugin) : ConcordionExtensio
}

@Suppress("unused")
fun withVerifiers(overrideVerifiers: Map<String, ContentVerifier>): ExamExtension {
CONTENT_VERIFIERS += overrideVerifiers
fun withVerifiers(vararg overrideVerifiers: Pair<String, ContentVerifier>): ExamExtension {
CONTENT_VERIFIERS += overrideVerifiers.toMap()
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ enum class DateHelpers(
override val options: Map<String, String> = emptyMap()
) : ExamHelper {
at(
example = "{{at '-2d'}}",
expected = LocalDateTime.now().minusDays(2).toDate()
example = "{{at '-2d' '-1m'}}",
expected = LocalDateTime.now().minusDays(2).minusMinutes(1).toDate()
) {
override fun invoke(context: Any?, options: Options) =
(if (context is String) AT.plus(detectAndParse(context)) else AT).toDate()
override fun invoke(context: Any?, options: Options) = (
context.takeIf { it is String }?.let {
(setOf(context) + options.params).map { detectAndParse(it as String) }.fold(AT) { r, d -> r.plus(d) }
} ?: AT
).toDate()
},
now(
example = """{{now "yyyy-MM-dd'T'HH:mm:ss" tz="GMT+3" minus="1 y, 2 months, d 3" plus="4 h, 5 min, 6 s"}}""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class DbCheckParser : DbCheckCommand.Parser {

private fun toColumns(cols: List<String>) = cols.map { Column(it, DataType.UNKNOWN) }.toTypedArray()

private fun cols(it: Html) =
it.el.getFirstChildElement("thead").getFirstChildElement("tr").childElements.map { it.text.trim() }
private fun cols(html: Html) =
html.el.getFirstChildElement("thead")?.getFirstChildElement("tr")?.childElements?.map { it.text.trim() }
?: listOf()

private fun values(it: Html) = it.el().getFirstChildElement("tbody").childElements.map { tr ->
tr.childElements.map { it.text.trim() }
}
private fun values(html: Html) =
html.el.getFirstChildElement("tbody")?.childElements?.map { tr -> tr.childElements.map { it.text.trim() } }
?: listOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class MqPlugin(
private val testers: Map<String, MqTester>,
private val override: Map<String, Command> = mapOf()
) : ExamPlugin {

constructor(vararg testers: Pair<String, MqTester>) : this(testers.toMap())

override fun commands(): Map<String, Command> = mapOf(
"mq-set" to MqSetCommand(testers),
"mq-check" to MqCheckCommand(testers),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.adven27.concordion.extensions.exam.mq.commands

import com.github.jknack.handlebars.internal.text.StringEscapeUtils.escapeJava
import io.github.adven27.concordion.extensions.exam.core.Content
import io.github.adven27.concordion.extensions.exam.core.ContentVerifier.Fail
import io.github.adven27.concordion.extensions.exam.core.commands.Verifier
Expand Down Expand Up @@ -160,6 +161,6 @@ interface MqCheckRenderer {

// language=html
private fun toRows(headers: Map<String, String?>) = headers.entries.joinToString("\n") { (k, v) ->
"""<tr><td class="success">$k</td><td class="success"><pre>$v</pre></td></tr>"""
"""<tr><td class="success">$k</td><td class="success"><pre><![CDATA[${escapeJava(v)}]]></pre></td></tr>"""
}
}
4 changes: 2 additions & 2 deletions example/src/test/kotlin/specs/Specs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class Specs : AbstractSpecs() {

override fun init(): ExamExtension = ExamExtension(
WsPlugin(PORT.also { System.setProperty("server.port", it.toString()) }),
MqPlugin(mapOf("myQueue" to DummyMq(), "myAnotherQueue" to DummyMq())),
MqPlugin("myQueue" to DummyMq(), "myAnotherQueue" to DummyMq()),
DbPlugin(dbTester)
).withHandlebar { hb ->
hb.registerHelper(
Expand All @@ -42,7 +42,7 @@ open class Specs : AbstractSpecs() {
}
)
}.withVerifiers(
mapOf("jsonIgnoreExtraFields" to JsonVerifier { it.withOptions(IGNORING_EXTRA_FIELDS) })
"jsonIgnoreExtraFields" to JsonVerifier { it.withOptions(IGNORING_EXTRA_FIELDS) }
)

override fun startSut() {
Expand Down
2 changes: 1 addition & 1 deletion example/src/test/resources/specs/code/VerifierConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Specs : AbstractSpecs() {
override fun init() = ExamExtension(
//...
).withVerifiers(
mapOf("jsonIgnoreExtraFields" to JsonVerifier { it.withOptions(IGNORING_EXTRA_FIELDS) })
"jsonIgnoreExtraFields" to JsonVerifier { it.withOptions(IGNORING_EXTRA_FIELDS) }
)
}
4 changes: 4 additions & 0 deletions example/src/test/resources/specs/core-set.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Set `mapObject` = [e-set=mapObject]`{{map a='1' b='2'}}`
include::core-set.adoc[tags=fl]
--

.Given file `/data/core/file.txt`
[source]
include::../data/core/file.txt[]

====
//tag::fl[]
[.when]
Expand Down
2 changes: 1 addition & 1 deletion example/src/test/resources/specs/diagram/mq-plugin.puml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ component MqPlugin #AFF {
interface MqTester {
fun start()
fun stop()
fun send(message: Message, params: Map<String, String>)
fun send(message: Message)
fun receive(): List<Message>
fun purge()
fun accumulateOnRetries(): Boolean = true
Expand Down
46 changes: 31 additions & 15 deletions example/src/test/resources/specs/plugin-db.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,17 @@ DbUnit --> DB :interacts with
testImplementation "io.github.adven27:exam-db:{version}"

.Configuration
[source,java]
--
public class Specs extends AbstractSpecs {
@Override
protected ExamExtension init() {
return new ExamExtension(
new DbPlugin(
"org.postgresql.Driver", // driver class
"jdbc:postgresql://localhost:5432/postgres", // jdbc url
"postgres", // user
"postgres" // password
)
);
}
}
[source,kotlin]
--
class Specs : AbstractSpecs() {
override fun init() = ExamExtension(
DbPlugin(
driver = "org.postgresql.Driver",
url = "jdbc:postgresql://localhost:5432/postgres",
user = "postgres",
password = "postgres"
)
)
--

.Commands
Expand Down Expand Up @@ -110,6 +106,26 @@ id, name, height, manufactured
//end::db-check[]
====

.Check emptiness
[source,asciidoc]
--
include::plugin-db.adoc[tags=db-check-empty]
--

====
.Set empty table
[e-db-set=ANDROIDS_TABLE]
|===
|===
//tag::db-check-empty[]
.Check table
[e-db-check=ANDROIDS_TABLE]
|===
|===
//end::db-check-empty[]
====

=== e-db-clean [[e-db-clean]]

Cleans specified tables in a database.
Expand Down
Loading

0 comments on commit ba64166

Please sign in to comment.