How to use Formatting class of com.github.kittinunf.fuel.core.extensions package

Best Fuel code snippet using com.github.kittinunf.fuel.core.extensions.Formatting

ADocTagAspect.kt

Source:ADocTagAspect.kt Github

copy

Full Screen

1package hal.spel.aspect2import com.fasterxml.jackson.databind.ObjectMapper3import com.github.kittinunf.fuel.core.Headers4import com.github.kittinunf.fuel.core.Method5import com.github.kittinunf.fuel.core.extensions.cUrlString6import com.github.kittinunf.fuel.core.requests.RepeatableBody7import hal.spel.Answer8import hal.spel.Link9import io.micronaut.http.HttpStatus10import java.io.PrintWriter11import kotlin.math.min12private val jackson = ObjectMapper()13private var counters = mutableMapOf<String, Int>()14private var relation: String? = null15/**16 * Reports the parts of the request and response as AsciiDoctor tags.17 *18 * Using this class the client application can produce the AsciiDoctor document containing19 * tags for all requests/responses application communicates with the server. Then that tags can be included20 * in a separate AsciiDoctor document built by AsciiDoctor plugin into final documentation including21 * "life" data.22 * Different instances of this class can report on different set of parts related to communication23 * with server. For example24 *25 * @param reporter -- the PrintWriter to print the text of the tag into. Could be File, Console or other Writer26 * @param parts -- the vararg of parts to include as tags27 * @param followed -- the AspectFormatter to link in the chain.28 * The Aspect generated by this Formatter will pass control to the aspect generated by this parameter29 */30class ADocTagFormatter(31 private val reporter: PrintWriter,32 vararg val parts: ReportPart,33 followed: AspectFormatter? = null34) : AspectFormatter(followed) {35 private val aDocTagFormatter = mutableMapOf<ReportPart, Pair<LinkFun?, AnswerFun?>>().also {36 ReportPart.values().forEach { part ->37 it[part] = Pair<LinkFun?, AnswerFun?>({38 preADocTagFormatter[part]?.invoke(this, reporter::println)39 this40 }, {41 postADocTagFormatter[part]?.invoke(it, reporter::println)42 })43 }44 }45 override fun makeAspect(aspect: Aspect?): Aspect {46 return makeReporterAspect(aDocTagFormatter, *parts, aspect = super.makeAspect(aspect))47 }48}49private fun <T> formatTag(tagName: String, obj: T?, reporter: (String) -> Unit) {50 reporter("""51 |#tag::$relation-$tagName-${counters[relation]}[]52 |${53 when (obj) {54 is Map<*, *> -> obj.filterValues {55 it != null56 }.map { (key, value) ->57 "$key:\t$value"58 }.joinToString("\n|\t", "\t")59 is Collection<*> -> obj.joinToString("\n|\t", "\t")60 else -> obj ?: ""61 }62 }63 |#end::$relation-$tagName-${counters[relation]}[]64 """.trimMargin()65 )66}67/**68 * AsciiDoc preRequest aspect definitions69 *70 * This Map defines the aspect making functions for different parts of [Link] object.71 *72 * The maker for [PRE_PARTS.REL] keeps track of similar requests and assigns unique number to make an AsciiDoc tag unique.73 * If this aspect won't be included in an aspect chain the [null] will be used instead of numbers and all segments74 * of AsciiDoc will have identical tags. It is recommended to always include [PRE_PARTS.REL] aspect even if the75 * corresponding segment won't be used in the final documentation.76 *77 *78 */79private val preADocTagFormatter = mapOf<ReportPart, (Link, (String) -> Unit) -> Link>(80 ReportPart.REL to { link, reporter ->81 // Assign next available number to make a unique AsciiDoc tag82 relation = link.rel?.apply {83 counters[this] = counters[this]?.let {84 it + 185 } ?: 186 }87 formatTag("ref", link.rel, reporter)88 link89 },90 ReportPart.LINK to { link, reporter ->91 formatTag("link", link.toMap(), reporter)92 link93 },94 ReportPart.URI to { link, reporter ->95 formatTag("URI", link.href, reporter)96 link97 },98 ReportPart.NAME to { link, reporter ->99 formatTag("name", link.name, reporter)100 link101 },102 ReportPart.TITLE to { link, reporter ->103 formatTag("title", link.title, reporter)104 link105 },106 ReportPart.TYPE to { link, reporter ->107 formatTag("type", link.type, reporter)108 link109 }110)111/**112 * AsciiDoc postRequest aspect definitions113 *114 * This Map defines the aspect making functions for different parts of [Answer] object.115 *116 */117private val postADocTagFormatter = mapOf<ReportPart, (Answer, (String) -> Unit) -> Unit>(118 ReportPart.URL to { answer, reporter ->119 formatTag("URL", answer.response.url.toString(), reporter)120 },121 ReportPart.CURL to { answer, reporter ->122 formatTag(123 "curl", answer.request.cUrlString()124 .replace(" -H", "\\\n -H")125 .replace(Regex(" (https?://.*)"), "\\\\\n \"$1\""), reporter126 )127 },128 ReportPart.HEADERS_OUT to { answer, reporter ->129 formatTag("headerOut", answer.request.headers, reporter)130 },131 ReportPart.COOKIES_OUT to { answer, reporter ->132 formatTag("cookieOut", answer.request["Set-Cookies"], reporter)133 },134 ReportPart.BODY_OUT to { answer, reporter ->135 if (answer.request.method in setOf(136 Method.POST,137 Method.PUT,138 Method.PATCH139 ) && !answer.request.body.isConsumed()140 ) {141 formatTag(142 "bodyOut",143 if (answer.request.body.isConsumed()) {144 "Length of the sent Body: ${answer.request.body.length}"145 } else {146 if (answer.request.header(Headers.CONTENT_TYPE).any { it.contains("json") }) {147 jackson.writerWithDefaultPrettyPrinter().writeValueAsString(answer.body?.invoke())148 } else {149 answer.request.body.asString(null)150 }151 }, reporter152 )153 } else {154 formatTag("bodyOut", "*** Cannot report body sent out ***", reporter)155 }156 },157 ReportPart.STATUS to { answer, reporter ->158 formatTag("status", "${answer.status.code} (${answer.status})", reporter)159 },160 ReportPart.HEADERS_IN to { answer, reporter ->161 formatTag("headersIn", answer.response.headers, reporter)162 },163 ReportPart.COOKIES_IN to { answer, reporter ->164 formatTag("cookiesIn", answer.response["Cookies"], reporter)165 },166 ReportPart.BODY_IN to { answer, reporter ->167 formatTag(168 "bodyIn",169 when (answer.status.code) {170 HttpStatus.FOUND.code -> "Redirection to: ${answer.response.header("Location").first()}"171 else ->172 if (answer.response.header(Headers.CONTENT_TYPE).any { it.contains("json") }) {173 jackson.writerWithDefaultPrettyPrinter().writeValueAsString(answer.body?.invoke())174 } else {175 val head = min(answer.response.contentLength, UNSTRUCTURED_HEAD_LENGTH)176 """ (length: ${answer.response.contentLength})177 |${String(answer.response.data).substring(0, head.toInt())}178 """.trimMargin()179 }180 }, reporter181 )182 }183)184/**185 * Factory function to create an aspect function to be called before sending HTTP request.186 *187 * The aspect created by this factory will call @reporter function for the string generated by the function in the map.188 * The function in the map formatting the corresponding part of the Link as an AsciiDocument tag and @reporter189 * will write that text into the stream, which may be associated with file or console.190 *191 * @param reporter -- function to record the formatted tag String192 * @param parts -- a vararg array of the parts to report on193 * @param aspect -- another aspect to chain to after executing this194 */195fun makePreADocTagAspect(reporter: (String) -> Unit, vararg parts: ReportPart, aspect: Aspect? = null): Aspect {196 return makePreReporterAspect(reporter, preADocTagFormatter, *parts, aspect = aspect)197}198/**199 * Factory function to create an aspect function to be called after sending HTTP request.200 *201 * The aspect created by this factory will call @reporter function for the string generated by the function in the map.202 * The function in the map formatting the corresponding part of the Answer as an AsciiDocument tag and @reporter203 * will write that text into the stream, which may be associated with file or console.204 *205 * @param reporter -- function to record the formatted tag String206 * @param parts -- a vararg array of the parts to report on207 * @param aspect -- another aspect to chain to after executing this208 */209fun makePostADocTagAspect(reporter: (String) -> Unit, vararg parts: ReportPart, aspect: Aspect? = null): Aspect {210 return makePostReporterAspect(reporter, postADocTagFormatter, *parts, aspect = aspect)211}...

Full Screen

Full Screen

LoggerAspect.kt

Source:LoggerAspect.kt Github

copy

Full Screen

1package hal.spel.aspect2import com.fasterxml.jackson.databind.ObjectMapper3import com.github.kittinunf.fuel.core.Headers4import com.github.kittinunf.fuel.core.Method5import com.github.kittinunf.fuel.core.extensions.cUrlString6import hal.spel.Answer7import hal.spel.Link8import io.micronaut.http.HttpStatus9import kotlin.math.min10const val UNSTRUCTURED_HEAD_LENGTH = 100L11private val jackson = ObjectMapper()12/**13 * Reports the parts of the request and response in the log.14 *15 * Using this class the client application can log all HTTP requests/responses.16 *17 * Different instances of this class can log at different level their own set of HTTP requests/responses parts.18 *19 * For example:20 * <code>21 * LoggerFormatter(logger::info, ReportPart.REL, ReportPart.status22 * , followed = LoggerFormatter(logger::debug, ReportPart.URL, ReportPart.HEADERS_OUT)23 * )24 * </code>25 *26 * @param reporter -- the simple function to log the logging message.27 * @param parts -- the vararg of parts to include as tags28 * @param followed -- the AspectFormatter to link in the chain.29 * The Aspect generated by this Formatter will pass control to the aspect generated by this parameter30 */31class LoggerFormatter(32 private val reporter: (String) -> Unit,33 vararg val parts: ReportPart,34 followed: AspectFormatter? = null35) : AspectFormatter(followed) {36 private val loggerFormatter: Map<ReportPart, Pair<LinkFun?, AnswerFun?>> =37 mutableMapOf<ReportPart, Pair<LinkFun?, AnswerFun?>>().also {38 ReportPart.values().forEach { part ->39 it[part] = Pair<LinkFun?, AnswerFun?>({40 preLoggerFormatter[part]?.invoke(this, reporter)41 this42 }, {43 postLoggerFormatter[part]?.invoke(it, reporter)44 })45 }46 }47 override fun makeAspect(aspect: Aspect?): Aspect {48 return makeReporterAspect(loggerFormatter, *parts, aspect = super.makeAspect(aspect))49 }50}51private val preLoggerFormatter = mapOf<ReportPart, (Link, (String) -> Unit) -> Link>(52 ReportPart.REL to { link, reporter ->53 reporter(">>> ${link.rel} <<<")54 link55 },56 ReportPart.LINK to { link, reporter ->57 reporter(58 if (link.name.isNullOrBlank()) {59 "Link href: ${link.href}"60 } else {61 "Link name: ${link.name} (${link.href})"62 }63 )64 link65 },66 ReportPart.URI to { link, reporter -> reporter("URL: ${link.href}"); link },67 ReportPart.NAME to { link, reporter -> reporter("Named: ${link.name}"); link },68 ReportPart.TITLE to { link, reporter -> reporter("Titled: ${link.title}"); link },69 ReportPart.TYPE to { link, reporter -> reporter("Accept: ${link.type}"); link }70)71private val postLoggerFormatter = mapOf<ReportPart, (Answer, (String) -> Unit) -> Unit>(72 ReportPart.URL to { answer, reporter -> reporter("Resource Location: ${answer.response.url}") },73 ReportPart.CURL to { answer, reporter ->74 if (!(answer.request.method in setOf(75 Method.POST,76 Method.PUT,77 Method.PATCH78 ) && answer.request.body.isConsumed())79 ) {80 reporter("$> ${answer.request.cUrlString()}")81 } else {82 reporter("*** Cannot report curl ***")83 }84 },85 ReportPart.HEADERS_OUT to { answer, reporter ->86 reporter(87 "Header sent: ${88 answer.request.headers.map { (key, value) ->89 "\t$key:\t${value.joinToString("\n\t\t")}"90 }.joinToString("\n", "\n")91 }"92 )93 },94 ReportPart.COOKIES_OUT to { answer, reporter ->95 reporter("Cookies sent: ${answer.request["Set-Cookies"].joinToString("\n\t", "\n\t")}")96 },97 ReportPart.BODY_OUT to { answer, reporter ->98 if (answer.request.method in setOf(99 Method.POST,100 Method.PUT,101 Method.PATCH102 ) && !answer.request.body.isConsumed()103 ) {104 reporter(105 if (answer.request.body.isConsumed()) {106 "Length of the sent Body: ${answer.request.body.length}"107 } else {108 "Body sent:\n${109 if (answer.request.header(Headers.CONTENT_TYPE).any { it.contains("json") }) {110 jackson.writerWithDefaultPrettyPrinter().writeValueAsString(answer.body?.invoke())111 } else {112 answer.request.body.asString(null)113 }114 }"115 }116 )117 } else {118 reporter("*** Cannot report body sent ***")119 }120 },121 ReportPart.STATUS to { answer, reporter -> reporter("Status: ${answer.status.code} (${answer.status})") },122 ReportPart.HEADERS_IN to { answer, reporter ->123 reporter(124 "Headers received: ${125 answer.response.headers.map { (key, value) ->126 "\t$key:\t${value.joinToString("\n\t\t")}"127 }.joinToString("\n", "\n")128 }"129 )130 },131 ReportPart.COOKIES_IN to { answer, reporter ->132 reporter("Cookies received: ${answer.response["Cookies"].joinToString("\n\t", "\n\t")}")133 },134 ReportPart.BODY_IN to { answer, reporter ->135 reporter(136 "Body received:${137 when (answer.status.code) {138 HttpStatus.FOUND.code -> "Redirection to: ${answer.response.header("Location").first()}"139 else ->140 if (answer.response.header(Headers.CONTENT_TYPE).any { it.contains("json") }) {141 "\n${jackson.writerWithDefaultPrettyPrinter().writeValueAsString(answer.body?.invoke())}"142 } else {143 val head = min(answer.response.contentLength, UNSTRUCTURED_HEAD_LENGTH)144 " (length: ${answer.response.contentLength})\n${145 String(answer.response.data).substring(146 0,147 head.toInt()148 )149 }"150 }151 }152 }"153 )154 }155)156/**157 * Factory function to create an aspect function to be called before sending HTTP request.158 *159 * The aspect created by this factory will call @reporter function for the string generated by the function in the map.160 * The function in the map formatting the corresponding part of the Link as an message for logger and @reporter161 * will call logger method with some level to log that message.162 *163 * @param reporter -- function to record the formatted tag String164 * @param parts -- a vararg array of the parts to report on165 * @param aspect -- another aspect to chain to after executing this166 */167fun makePreLoggerAspect(reporter: (String) -> Unit, vararg parts: ReportPart, aspect: Aspect? = null): Aspect {168 return makePreReporterAspect(reporter, preLoggerFormatter, *parts, aspect = aspect)169}170/**171 * Factory function to create an aspect function to be called after sending HTTP request.172 *173 * The aspect created by this factory will call @reporter function for the string generated by the function in the map.174 * The function in the map formatting the corresponding part of the Answer as an message for logger and @reporter175 * will call logger method with some level to log that message.176 *177 * @param reporter -- function to record the formatted tag String178 * @param parts -- a vararg array of the parts to report on179 * @param aspect -- another aspect to chain to after executing this180 */181fun makePostLoggerAspect(reporter: (String) -> Unit, vararg parts: ReportPart, aspect: Aspect? = null): Aspect {182 return makePostReporterAspect(reporter, postLoggerFormatter, *parts, aspect = aspect)183}...

Full Screen

Full Screen

build.gradle.kts

Source:build.gradle.kts Github

copy

Full Screen

1import org.jetbrains.dokka.gradle.DokkaTask2import org.jetbrains.kotlin.gradle.tasks.KotlinCompile3import org.jlleitschuh.gradle.ktlint.reporter.ReporterType4plugins {5 kotlin("jvm") version "1.4.10"6 kotlin("plugin.serialization") version "1.4.10"7 id("io.qameta.allure") version "2.8.1"8 id("org.jetbrains.dokka") version "0.10.1"9 id("com.adarshr.test-logger") version "2.1.1"10 id("io.gitlab.arturbosch.detekt") version "1.14.2"11 id("org.jlleitschuh.gradle.ktlint") version "9.4.1"12 id("com.github.ben-manes.versions") version "0.36.0"13 id("se.patrikerdes.use-latest-versions") version "0.2.15"14}15allprojects {16 apply(plugin = "io.qameta.allure")17 apply(plugin = "org.jetbrains.dokka")18 apply(plugin = "com.adarshr.test-logger")19 apply(plugin = "org.jetbrains.kotlin.jvm")20 apply(plugin = "io.gitlab.arturbosch.detekt")21 apply(plugin = "org.jlleitschuh.gradle.ktlint")22 apply(plugin = "com.github.ben-manes.versions")23 apply(plugin = "se.patrikerdes.use-latest-versions")24 apply(plugin = "org.jetbrains.kotlin.plugin.serialization")25 group = "ee.found"26 version = "1.0-SNAPSHOT"27 val fuelVersion = "2.3.0"28 val kotestVersion = "4.3.1"29 val allureVersion = "2.13.6"30 val aspectJVersion = "1.9.6"31 val exposedVersion = "0.28.1"32 val selenideVercion = "5.20.4"33 //region Settings34 val compileKotlin: KotlinCompile by tasks35 compileKotlin.kotlinOptions {36 jvmTarget = "11"37 }38 val compileTestKotlin: KotlinCompile by tasks39 compileTestKotlin.kotlinOptions {40 jvmTarget = "11"41 }42 //region Dokka43 // https://github.com/Kotlin/dokka44 // https://kotlinlang.org/docs/reference/kotlin-doc.html45 tasks.withType<DokkaTask> {46 outputFormat = "html"47 outputDirectory = "$buildDir/dokka"48 subProjects = subprojects.map { it.name }49 configuration {50 reportUndocumented = true51 }52 }53 //endregion54 //region Detekt55 detekt {56 input = files("src/main/kotlin", "src/test/kotlin")57 }58 //endregion59 //region Ktlint60 ktlint {61 verbose.set(true)62 outputToConsole.set(true)63 outputColorName.set("RED")64 reporters {65 reporter(ReporterType.PLAIN)66 }67 }68 //endregion69 //region Allure70 allure {71 version = allureVersion72 aspectjweaver = true73 aspectjVersion = aspectJVersion74 useJUnit5 {75 version = allureVersion76 }77 }78 //endregion79 //region Tests80 tasks.withType<Test> {81 testlogger {82 setTheme("mocha-parallel")83 }84 useJUnitPlatform()85 systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_class")86 systemProperty("junit.jupiter.execution.parallel.enabled", "true")87 systemProperty("junit.jupiter.execution.parallel.mode.default", "same_thread")88 systemProperty("junit.jupiter.extensions.autodetection.enabled", "true")89 systemProperty("junit.jupiter.execution.parallel.config.strategy", "dynamic")90 systemProperty("junit.jupiter.execution.parallel.mode.classes.default", "same_thread")91 }92 //endregion93 //endregion94 repositories {95 jcenter()96 mavenCentral()97 maven(url = "https://kotlin.bintray.com/kotlinx/") // soon will be just jcenter()98 }99 dependencies {100 implementation(kotlin("stdlib"))101 implementation(group = "io.qameta.allure", name = "allure-junit5", version = "2.13.5")102 detektPlugins(group = "io.gitlab.arturbosch.detekt", name = "detekt-formatting", version = "1.14.2")103 implementation(group = "org.litote.kmongo", name = "kmongo", version = "4.2.0")104 implementation(group = "com.google.code.gson", name = "gson", version = "2.8.6")105 implementation(group = "com.charleskorn.kaml", name = "kaml", version = "0.26.0")106 implementation(group = "org.postgresql", name = "postgresql", version = "42.2.18")107 implementation(group = "com.ecwid.consul", name = "consul-api", version = "1.4.5")108 implementation(group = "org.awaitility", name = "awaitility-kotlin", version = "4.0.3")109 implementation(group = "io.github.microutils", name = "kotlin-logging", version = "2.0.3")110 implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version = "0.1.0")111 implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-runtime", version = "+")112 implementation(group = "com.github.mifmif", name = "generex", version = "1.0.2")113 implementation(group = "com.fasterxml.jackson.module", name = "jackson-module-kotlin", version = "2.11.+")114 implementation(group = "com.github.vertical-blank", name = "sql-formatter", version = "1.0.3")115 // Kotest116 implementation(group = "io.kotest", name = "kotest-assertions-core", version = kotestVersion)117 // AspectJ118 implementation(group = "org.aspectj", name = "aspectjrt", version = aspectJVersion)119 implementation(group = "org.aspectj", name = "aspectjweaver", version = aspectJVersion)120 // JUnit121 implementation(platform("org.junit:junit-bom:5.7.0"))122 implementation(group = "org.junit.jupiter", name = "junit-jupiter")123 // Fuel124 implementation(group = "com.github.kittinunf.fuel", name = "fuel", version = fuelVersion)125 implementation(group = "com.github.kittinunf.fuel", name = "fuel-jackson", version = fuelVersion)126 implementation(group = "com.github.kittinunf.fuel", name = "fuel-kotlinx-serialization", version = fuelVersion)127 // Exposed128 implementation(group = "org.jetbrains.exposed", name = "exposed-dao", version = exposedVersion)129 implementation(group = "org.jetbrains.exposed", name = "exposed-core", version = exposedVersion)130 implementation(group = "org.jetbrains.exposed", name = "exposed-jdbc", version = exposedVersion)131 implementation(group = "org.jetbrains.exposed", name = "exposed-jodatime", version = exposedVersion)132 // Selenide133 implementation(group = "com.codeborne", name = "selenide", version = selenideVercion)134 }135}136tasks.test {137 onlyIf { false }138}139tasks.register("uitest", org.gradle.api.tasks.testing.Test::class) {140 description =141 "Runs browser tests. Pass -Dconfiguration=local to select target test stand. Possible values: local"142 include("ee/found/uitests/*Test.class")143 bypassSystemPropertiesToTest()144 outputs.upToDateWhen { false }145}146fun Test.bypassSystemPropertiesToTest() {147 systemProperties(System.getProperties().mapKeys { it.key as String })148}...

Full Screen

Full Screen

common-library.gradle.kts

Source:common-library.gradle.kts Github

copy

Full Screen

1import io.gitlab.arturbosch.detekt.detekt2import org.jetbrains.kotlin.gradle.tasks.KotlinCompile3plugins {4 kotlin("jvm")5 kotlin("kapt")6 id("io.gitlab.arturbosch.detekt")7 id("org.jetbrains.dokka")8 jacoco9}10repositories {11 mavenCentral()12 jcenter()13}14apply {15 from("${rootProject.rootDir}/properties.gradle.kts")16}17val ktlint: Configuration = configurations.create("ktlint")18val kotlinVersion: String by extra19val mockkVersion: String by extra20val kotlinTestVersion: String by extra21val arrowVersion: String by extra22val ktlintVersion: String by extra23val fuelVersion: String by extra24val arrowCoreExtVersion: String by extra25val jacksonVersion: String by extra26val commonsLangVersion: String by extra27dependencies {28 api(kotlin("stdlib-jdk8", kotlinVersion))29 api(kotlin("stdlib-jdk7", kotlinVersion))30 api(kotlin("stdlib", kotlinVersion))31 api(kotlin("reflect", kotlinVersion))32 implementation("com.github.kittinunf.fuel:fuel:$fuelVersion")33 implementation("com.github.kittinunf.fuel:fuel-jackson:$fuelVersion")34 api("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")35 api("io.arrow-kt:arrow-core:$arrowVersion")36 api("io.arrow-kt:arrow-core-extensions:$arrowCoreExtVersion")37 testImplementation("io.mockk:mockk:$mockkVersion")38 testImplementation("io.kotlintest:kotlintest-runner-junit5:$kotlinTestVersion")39 testImplementation("io.kotlintest:kotlintest-assertions:$kotlinTestVersion")40 testImplementation("io.kotlintest:kotlintest-assertions-arrow:$kotlinTestVersion")41 testImplementation("org.apache.commons:commons-lang3:$commonsLangVersion")42 testImplementation(gradleTestKit())43 ktlint("com.github.shyiko:ktlint:$ktlintVersion")44}45tasks {46 withType<KotlinCompile> {47 kotlinOptions {48 jvmTarget = JavaVersion.VERSION_1_8.toString()49 freeCompilerArgs = freeCompilerArgs + listOf(50 "-java-parameters",51 "-Xjsr305=strict",52 "-progressive")53 }54 }55 val ktlint by creating(JavaExec::class) {56 group = "verification"57 description = "Check Kotlin code style."58 classpath = configurations["ktlint"]59 main = "com.github.shyiko.ktlint.Main"60 args = listOf("src/**/*.kt")61 }62 "check" {63 dependsOn(ktlint)64 }65 create("ktlintFormat", JavaExec::class) {66 group = "formatting"67 description = "Fix Kotlin code style deviations."68 classpath = configurations["ktlint"]69 main = "com.github.shyiko.ktlint.Main"70 args = listOf("-F", "src/**/*.kt")71 }72 withType<Test> {73 useJUnitPlatform()74 }75}76val detektVersion: String by project77detekt {78 toolVersion = detektVersion79 input = files("$rootDir/src/main/kotlin")80 config = files("$rootDir/detekt-config.yml")81 filters = ".*/resources/.*,.*/build/.*"82}...

Full Screen

Full Screen

FormattingTest.kt

Source:FormattingTest.kt Github

copy

Full Screen

...5import org.hamcrest.CoreMatchers6import org.hamcrest.MatcherAssert7import org.junit.Test8import java.net.URL9class FormattingTest {10 @Test11 fun httpGetCurlString() {12 val request = DefaultRequest(13 method = Method.GET,14 url = URL("http://httpbin.org/get"),15 headers = Headers.from("Authentication" to "Bearer xxx"),16 parameters = listOf("foo" to "xxx")17 )18 MatcherAssert.assertThat(request.cUrlString(), CoreMatchers.equalTo("curl -i -H \"Authentication:Bearer xxx\" http://httpbin.org/get"))19 }20 @Test21 fun httpPostCurlString() {22 val request = DefaultRequest(23 method = Method.POST,...

Full Screen

Full Screen

Formatting

Using AI Code Generation

copy

Full Screen

1FuelManager.instance.baseHeaders = mapOf("Content-Type" to "application/json")2val (request, response, result) = Fuel.get("/users/kittinunf/repos").responseObject<List<Repository>>()3FuelManager.instance.baseHeaders = mapOf("Content-Type" to "application/json")4val (request, response, result) = Fuel.get("/users/kittinunf/repos").responseObject<List<Repository>>(gsonDeserializerOf())5FuelManager.instance.baseHeaders = mapOf("Content-Type" to "application/json")6val (request, response, result) = Fuel.get("/users/kittinunf/repos").responseObject<List<Repository>>(jacksonDeserializerOf())7FuelManager.instance.baseHeaders = mapOf("Content-Type" to "application/json")8val (request, response, result) = Fuel.get("/users/kittinunf/repos").responseObject<List<Repository>>(moshiDeserializerOf())9FuelManager.instance.baseHeaders = mapOf("Content-Type" to "application/xml")10val (request, response, result) = Fuel.get("/users/kittinunf/repos").responseObject<List<Repository>>(simpleXmlDeserializerOf())11FuelManager.instance.baseHeaders = mapOf("Content-Type" to "application/xml")12val (request, response, result) = Fuel.get("/users/kittinunf/repos").responseObject<List<Repository>>(xmlDeserializerOf())13FuelManager.instance.baseHeaders = mapOf("Content-Type" to "application/xml")14val (request, response, result) = Fuel.get("/users/kittinunf/repos").responseObject<List<Repository>>(xmlDeserializerOf())

Full Screen

Full Screen

Formatting

Using AI Code Generation

copy

Full Screen

1val (data, error) = result2data?.let { println(it) }3error?.let { println(it) }4val (data, error) = result5data?.let { println(it) }6error?.let { println(it) }7val (data, error) = result8data?.let { println(it) }9error?.let { println(it) }10val (data, error) = result11data?.let { println(it) }12error?.let { println(it) }13val (data, error) = result14data?.let { println(it) }15error?.let { println(it) }16val (data, error) = result17data?.let { println(it) }18error?.let { println(it) }19val (data, error) = result20data?.let { println(it) }21error?.let { println(it) }22val (data, error) =

Full Screen

Full Screen

Formatting

Using AI Code Generation

copy

Full Screen

1 .responseString()2 println(request)3 println(response)4 println(result.get())5 println("Hello, World!")6 }7}8{9 "args": {}, 10 "headers": {11 },

Full Screen

Full Screen

Formatting

Using AI Code Generation

copy

Full Screen

1val (data, error) = result2if (data != null) {3 println(Formatting.prettyPrint(data))4}5dependencies {6}

Full Screen

Full Screen

Formatting

Using AI Code Generation

copy

Full Screen

1var stringResponse = result.get()2var stringResponse = result.component1()3var stringResponse = result.component2()4var stringResponse = result.component3()5var stringResponse = result.get()6var stringResponse = result.component1()7var stringResponse = result.component2()8var stringResponse = result.component3()9var stringResponse = result.get()10var stringResponse = result.component1()11var stringResponse = result.component2()12var stringResponse = result.component3()13var stringResponse = result.get()14var stringResponse = result.component1()15var stringResponse = result.component2()16var stringResponse = result.component3()17var stringResponse = result.get()18var stringResponse = result.component1()19var stringResponse = result.component2()20var stringResponse = result.component3()21var stringResponse = result.get()22var stringResponse = result.component1()23var stringResponse = result.component2()24var stringResponse = result.component3()25var stringResponse = result.get()26var stringResponse = result.component1()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Fuel automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Formatting

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful