How to use test method of io.kotest.matchers.url.matchers class

Best Kotest code snippet using io.kotest.matchers.url.matchers.test

BasicEventTest.kt

Source:BasicEventTest.kt Github

copy

Full Screen

1package dev.akkinoc.spring.boot.logback.access2import dev.akkinoc.spring.boot.logback.access.test.assertion.Assertions.assertLogbackAccessEventsEventually3import dev.akkinoc.spring.boot.logback.access.test.extension.EventsCapture4import dev.akkinoc.spring.boot.logback.access.test.extension.EventsCaptureExtension5import dev.akkinoc.spring.boot.logback.access.test.type.JettyReactiveWebTest6import dev.akkinoc.spring.boot.logback.access.test.type.JettyServletWebTest7import dev.akkinoc.spring.boot.logback.access.test.type.TomcatReactiveWebTest8import dev.akkinoc.spring.boot.logback.access.test.type.TomcatServletWebTest9import dev.akkinoc.spring.boot.logback.access.test.type.UndertowReactiveWebTest10import dev.akkinoc.spring.boot.logback.access.test.type.UndertowServletWebTest11import io.kotest.assertions.throwables.shouldThrowUnit12import io.kotest.matchers.booleans.shouldBeFalse13import io.kotest.matchers.booleans.shouldBeTrue14import io.kotest.matchers.collections.shouldBeSingleton15import io.kotest.matchers.collections.shouldContainAll16import io.kotest.matchers.collections.shouldContainExactly17import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder18import io.kotest.matchers.collections.shouldNotContainAnyOf19import io.kotest.matchers.longs.shouldBeBetween20import io.kotest.matchers.longs.shouldBeGreaterThanOrEqual21import io.kotest.matchers.longs.shouldBePositive22import io.kotest.matchers.longs.shouldBeZero23import io.kotest.matchers.maps.shouldBeEmpty24import io.kotest.matchers.nulls.shouldBeNull25import io.kotest.matchers.nulls.shouldNotBeNull26import io.kotest.matchers.shouldBe27import io.kotest.matchers.shouldNotBe28import io.kotest.matchers.string.shouldBeEmpty29import io.kotest.matchers.string.shouldNotBeEmpty30import io.kotest.matchers.string.shouldStartWith31import org.junit.jupiter.api.Test32import org.junit.jupiter.api.extension.ExtendWith33import org.springframework.beans.factory.annotation.Autowired34import org.springframework.boot.test.web.client.TestRestTemplate35import org.springframework.boot.test.web.client.exchange36import org.springframework.boot.web.server.LocalServerPort37import org.springframework.http.RequestEntity38import org.springframework.test.context.TestPropertySource39import java.lang.System.currentTimeMillis40import java.util.concurrent.TimeUnit.MILLISECONDS41/**42 * Tests the appended Logback-access event in the case where the configuration is the default.43 *44 * @property supportsRequestParametersByFormData Whether to support request parameters by form data.45 * @property supportsRequestAttributes Whether to support request attributes.46 * @property supportsSessionIDs Whether to support session IDs.47 * @property canForwardRequests Whether the web server can forward requests.48 */49@ExtendWith(EventsCaptureExtension::class)50@TestPropertySource(properties = ["logback.access.config=classpath:logback-access-test.capture.xml"])51sealed class BasicEventTest(52 private val supportsRequestParametersByFormData: Boolean,53 private val supportsRequestAttributes: Boolean,54 private val supportsSessionIDs: Boolean,55 private val canForwardRequests: Boolean,56) {57 @Test58 fun `Appends a Logback-access event`(59 @Autowired rest: TestRestTemplate,60 @LocalServerPort port: Int,61 capture: EventsCapture,62 ) {63 val request = RequestEntity.get("/mock-controller/text").build()64 val started = currentTimeMillis()...

Full Screen

Full Screen

WebhookClientTest.kt

Source:WebhookClientTest.kt Github

copy

Full Screen

...14 * limitations under the License.15 */16package org.jitsi.jibri.webhooks.v117import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper18import io.kotest.core.spec.IsolationMode19import io.kotest.core.spec.style.ShouldSpec20import io.kotest.matchers.collections.shouldHaveSize21import io.kotest.matchers.should22import io.kotest.matchers.shouldBe23import io.kotest.matchers.shouldNotBe24import io.kotest.matchers.string.shouldContain25import io.kotest.matchers.types.beInstanceOf26import io.ktor.client.HttpClient27import io.ktor.client.engine.mock.MockEngine28import io.ktor.client.engine.mock.MockEngineConfig29import io.ktor.client.engine.mock.MockRequestHandler30import io.ktor.client.engine.mock.respondError31import io.ktor.client.engine.mock.respondOk32import io.ktor.client.request.HttpRequestData33import io.ktor.content.TextContent34import io.ktor.http.ContentType35import io.ktor.http.HttpMethod36import io.ktor.http.HttpStatusCode37import io.mockk.every38import io.mockk.slot39import io.mockk.spyk40import kotlinx.coroutines.delay41import org.jitsi.jibri.status.ComponentBusyStatus42import org.jitsi.jibri.status.ComponentHealthStatus43import org.jitsi.jibri.status.JibriStatus44import org.jitsi.jibri.status.OverallHealth45import org.jitsi.jibri.util.TaskPools46import org.jitsi.test.concurrent.FakeExecutorService47class WebhookClientTest : ShouldSpec({48 isolationMode = IsolationMode.InstancePerLeaf49 val requests = mutableListOf<HttpRequestData>()50 val goodStatus = JibriStatus(51 ComponentBusyStatus.IDLE,52 OverallHealth(53 ComponentHealthStatus.HEALTHY,54 mapOf()55 )56 )57 val badStatus = JibriStatus(58 ComponentBusyStatus.IDLE,59 OverallHealth(60 ComponentHealthStatus.UNHEALTHY,61 mapOf()62 )63 )64 val client = WebhookClient(65 "test",66 client = HttpClient(MockEngine) {67 engine {68 addHandler { request ->69 requests += request70 with(request.url.toString()) {71 when {72 contains("success") -> {73 respondOk()74 }75 contains("delay") -> {76 delay(1000)77 respondOk()78 }79 contains("error") -> {80 respondError(HttpStatusCode.BadRequest)81 }82 else -> error("Unsupported URL")83 }84 }85 }86 }87 }88 )89 // Coroutines will sometimes try to execute a launch in the calling thread, so the normal FakeExecutorService90 // doesn't work as it relies on the calling code finishing and then the test code being able to call runOne91 // or runAll, etc. This overrides the execute method (which is what gets used by coroutine dispatchers) and92 // executes the Runnable immediately.93 val ioExecutor: FakeExecutorService = spyk {94 val runnable = slot<Runnable>()95 every { execute(capture(runnable)) } answers {96 runnable.captured.run()97 }98 }99 beforeSpec {100 TaskPools.ioPool = ioExecutor101 }102 afterSpec {103 TaskPools.Companion.ioPool = TaskPools.DefaultIoPool104 }105 context("when the client") {106 context("has a valid subscriber") {107 client.addSubscriber("success")108 context("calling updateStatus") {109 client.updateStatus(goodStatus)110 should("send a POST to the subscriber at the proper url") {111 requests shouldHaveSize 1112 with(requests[0]) {113 url.toString() shouldContain "/v1/status"114 method shouldBe HttpMethod.Post115 }116 }117 should("send the correct data") {118 requests[0].body.contentType shouldBe ContentType.Application.Json119 with(requests[0].body) {120 this should beInstanceOf<TextContent>()121 this as TextContent122 this.text shouldBe jacksonObjectMapper().writeValueAsString(123 JibriEvent.HealthEvent("test", goodStatus)124 )125 text shouldContain """126 "jibriId":"test"127 """.trimIndent()128 }129 }130 context("and calling updateStatus again") {131 client.updateStatus(badStatus)132 should("send another request with the new status") {133 requests shouldHaveSize 2134 with(requests[1].body) {135 this should beInstanceOf<TextContent>()136 this as TextContent137 this.text shouldContain jacksonObjectMapper().writeValueAsString(138 JibriEvent.HealthEvent("test", badStatus)139 )140 }141 }142 }143 }144 }145 context("has multiple subscribers") {146 client.addSubscriber("https://success")147 client.addSubscriber("https://delay")148 client.addSubscriber("https://error")149 context("calling updateStatus") {150 client.updateStatus(goodStatus)151 should("send a POST to the subscribers at the proper url") {152 requests shouldHaveSize 3...

Full Screen

Full Screen

AttachmentServiceTest.kt

Source:AttachmentServiceTest.kt Github

copy

Full Screen

...13import com.github.njuro.jard.embedData14import com.github.njuro.jard.metadata15import com.github.njuro.jard.multipartFile16import com.ninjasquad.springmockk.MockkBean17import io.kotest.matchers.booleans.shouldBeTrue18import io.kotest.matchers.file.shouldBeAFile19import io.kotest.matchers.file.shouldBeReadable20import io.kotest.matchers.file.shouldExist21import io.kotest.matchers.file.shouldHaveExtension22import io.kotest.matchers.file.shouldHaveNameWithoutExtension23import io.kotest.matchers.file.shouldNotBeEmpty24import io.kotest.matchers.file.shouldNotExist25import io.kotest.matchers.nulls.shouldBeNull26import io.kotest.matchers.nulls.shouldNotBeNull27import io.kotest.matchers.optional.shouldNotBePresent28import io.kotest.matchers.should29import io.kotest.matchers.shouldBe30import io.kotest.matchers.string.shouldNotBeBlank31import io.mockk.Runs32import io.mockk.every33import io.mockk.just34import org.junit.jupiter.api.AfterEach35import org.junit.jupiter.api.BeforeEach36import org.junit.jupiter.api.DisplayName37import org.junit.jupiter.api.Nested38import org.junit.jupiter.api.Test39import org.springframework.beans.factory.annotation.Autowired40import org.springframework.boot.test.context.SpringBootTest41import org.springframework.transaction.annotation.Transactional42import java.io.File43@SpringBootTest44@WithContainerDatabase45@Transactional46internal class AttachmentServiceTest {47 @Autowired48 private lateinit var attachmentService: AttachmentService49 @MockkBean50 private lateinit var remoteStorageService: RemoteStorageService51 @Autowired52 private lateinit var db: TestDataRepository53 @BeforeEach54 @AfterEach55 fun `delete test folder`() {56 val testFolder = attachmentPath(TEST_FOLDER_NAME).toFile()57 if (testFolder.exists()) {58 testFolder.deleteRecursively().shouldBeTrue()59 }60 }61 @Nested62 @DisplayName("save attachment")63 inner class SaveAttachment {64 private fun getRemoteUrl(folder: String, filename: String) = "https://remote-storage.com/$folder-$filename"65 @BeforeEach66 fun setUpMocks() {67 every {68 remoteStorageService.uploadFile(69 ofType(String::class),70 ofType(String::class),71 ofType(File::class)72 )...

Full Screen

Full Screen

ExtensionKtIT.kt

Source:ExtensionKtIT.kt Github

copy

Full Screen

1package ru.iopump.koproc2import io.kotest.assertions.asClue3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.nulls.shouldBeNull5import io.kotest.matchers.shouldBe6import io.kotest.matchers.string.shouldBeBlank7import io.kotest.matchers.string.shouldContain8import io.kotest.matchers.string.shouldNotBeBlank9import io.kotest.matchers.types.shouldBeInstanceOf10import kotlinx.coroutines.delay11import org.junit.jupiter.api.assertThrows12import org.slf4j.LoggerFactory13import java.net.ConnectException14import java.net.HttpURLConnection15import java.net.URL16import java.nio.file.Paths17@Suppress("BlockingMethodInNonBlockingContext")18class ExtensionKtIT : StringSpec() {19 private companion object {20 private val log = LoggerFactory.getLogger("koproc")21 }22 init {23 "Java process should started by 'startProcess', provide http access and stopped by 'close' method" {24 val jarPath = Paths.get(this::class.java.getResource("/koproc-sample.jar").toURI())25 val jarAccessUrl = URL("http://localhost:8000/test")26 val koproc = "java -jar $jarPath".startProcess { timeoutSec = 5 }27 koproc.use {28 delay(500)29 log.info("[TEST] Call: $it")30 with(jarAccessUrl.openConnection() as HttpURLConnection) {31 responseCode shouldBe 20032 inputStream.bufferedReader().readText() shouldBe "OK"33 }34 it.readAvailableOut.shouldNotBeBlank()35 log.info("[TEST] Out: ${it.readAvailableOut}")36 }37 assertThrows<ConnectException> {38 with(jarAccessUrl.openConnection() as HttpURLConnection) {39 responseCode shouldBe 404...

Full Screen

Full Screen

NetworkDrinkModelsTest.kt

Source:NetworkDrinkModelsTest.kt Github

copy

Full Screen

1package com.nrojiani.bartender.data.remote.dto2import com.nrojiani.bartender.data.domain.IbaCategory3import com.nrojiani.bartender.data.domain.IngredientMeasure4import com.nrojiani.bartender.di.NetworkModule5import com.nrojiani.bartender.test.utils.mocks.fromMockJson6import com.squareup.moshi.Moshi7import io.kotest.matchers.collections.shouldBeEmpty8import io.kotest.matchers.collections.shouldHaveSize9import io.kotest.matchers.nulls.shouldBeNull10import io.kotest.matchers.nulls.shouldNotBeNull11import io.kotest.matchers.shouldBe12import io.kotest.matchers.string.shouldBeEmpty13import net.lachlanmckee.timberjunit.TimberTestRule14import org.junit.Before15import org.junit.Rule16import org.junit.Test17class NetworkDrinkModelsTest {18 private lateinit var moshi: Moshi19 @get:Rule20 var logAllAlwaysRule: TimberTestRule = TimberTestRule.logAllAlways()21 @Before22 fun setUp() {23 moshi = NetworkModule.provideMoshi()24 }25 @Test26 fun test_NetworkDrink_deserialization() {27 val networkDrink = fromMockJson<NetworkDrink>(mocksRelativePath = "cocktail/gin-and-tonic.json")28 networkDrink.shouldNotBeNull()29 .apply {30 id.shouldBe("11403")31 drinkName.shouldBe("Gin And Tonic")32 category.shouldBe("Ordinary Drink")33 iba.shouldBeNull()34 alcoholic.shouldBe("Alcoholic")35 glass.shouldBe("Highball glass")36 instructions.shouldBe(37 "Pour the gin and the tonic water into a highball " +38 "glass almost filled with ice cubes. Stir well. Garnish with the lime wedge."39 )40 imageUrl.shouldBe("https://www.thecocktaildb.com/images/media/drink/z0omyp1582480573.jpg")41 videoUrl.shouldBeNull()42 ingredient1.shouldBe("Gin")43 ingredient2.shouldBe("Tonic water")44 ingredient3.shouldBe("Lime")45 measure1.shouldBe("2 oz ")46 measure2.shouldBe("5 oz ")47 measure3.shouldBe("1 ")48 }49 }50 @Test51 fun test_NetworkDrink_toDomainModel() {52 val networkDrinkResults = fromMockJson<NetworkDrinksContainer>(53 mocksRelativePath = "search/name/gin-and-tonic.json"54 )55 networkDrinkResults.shouldNotBeNull()56 networkDrinkResults.drinks?.shouldHaveSize(1)57 val networkGinAndTonic = networkDrinkResults.drinks?.first()58 val ginAndTonic = networkGinAndTonic?.toDomainModel()59 ginAndTonic.shouldNotBeNull()60 .apply {61 id.shouldBe("11403")62 drinkName.shouldBe("Gin And Tonic")63 ibaCategory.shouldBe(IbaCategory.NON_IBA)64 alcoholic.shouldBe("Alcoholic")65 glass.shouldBe("Highball glass")...

Full Screen

Full Screen

EventSerializationTest.kt

Source:EventSerializationTest.kt Github

copy

Full Screen

1package com.github.goodwillparking.robokash.slack.event2import com.github.goodwillparking.robokash.slack.UserId3import com.github.goodwillparking.robokash.util.DefaultSerializer4import com.github.goodwillparking.robokash.util.ResourceUtil.loadTextResource5import io.kotest.assertions.asClue6import io.kotest.core.datatest.forAll7import io.kotest.core.spec.style.FreeSpec8import io.kotest.matchers.collections.shouldContain9import io.kotest.matchers.should10import io.kotest.matchers.shouldBe11import io.kotest.matchers.types.beInstanceOf12import io.kotest.matchers.types.shouldBeInstanceOf13import kotlin.reflect.KClass14internal class EventSerializationTest : FreeSpec({15 "events should deserialize" - {16 forAll<EventSetup<*>>(17 "url-verification" to { EventSetup(it, UrlVerification::class) },18 "event-callback" to EventSetup("message", EventCallback::class),19 "unknown" to EventSetup("app-requested", UnknownEvent::class)20 ) { (fileName, eventType) -> deserializeFromFile(fileName, eventType) }21 }22 "inner events should deserialize" - {23 "message" {24 deserializeFromFile<EventCallback<*>>("message") { deserialized ->25 deserialized.event.apply {26 shouldBeInstanceOf<Message>()...

Full Screen

Full Screen

BootstrapControllerTests.kt

Source:BootstrapControllerTests.kt Github

copy

Full Screen

1package com.nnicolosi.theater.controllers2import com.nnicolosi.theater.services.BootstrapService3import io.kotest.matchers.should4import io.kotest.matchers.shouldBe5import io.kotest.matchers.types.beInstanceOf6import io.mockk.every7import io.mockk.mockk8import io.mockk.verify9import org.junit.jupiter.api.Nested10import org.junit.jupiter.api.Test11import org.springframework.web.servlet.view.RedirectView12class BootstrapControllerTests {13 private val bootstrapServiceMock: BootstrapService = mockk()14 val bootstrapController = BootstrapController(bootstrapServiceMock)15 @Nested16 inner class Initialize {17 @Test18 fun `initialize endpoint should call initialize method of bootstrap service`() {19 every { bootstrapServiceMock.initialize() } returns Unit...

Full Screen

Full Screen

RecordedRequestMatchers.kt

Source:RecordedRequestMatchers.kt Github

copy

Full Screen

1package com.nrojiani.bartender.data.test.utils2import io.kotest.matchers.collections.shouldBeIn3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.collections.shouldHaveSize5import io.kotest.matchers.nulls.shouldNotBeNull6import io.kotest.matchers.shouldBe7import okhttp3.mockwebserver.RecordedRequest8internal fun RecordedRequest.shouldHaveQueryParam(key: String, expectedValue: String) {9 requestUrl?.queryParameterValues(key)10 .shouldNotBeNull()11 .shouldHaveSize(1)12 .shouldContain(expectedValue)13}14internal fun RecordedRequest.shouldContainHeaders(headers: Map<String, String>) {15 headers.forEach { (name, expectedValue) ->16 this.getHeader(name).shouldBe(expectedValue)17 }18}19enum class HttpRequestMethod {20 GET, HEAD, PUT, POST, PATCH, DELETE, CONNECT, OPTIONS, TRACE...

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.url.matchers.shouldHavePath2 import io.kotest.matchers.url.matchers.shouldHaveQuery3 import io.kotest.matchers.url.matchers.shouldHaveScheme4 import io.kotest.matchers.url.matchers.shouldHaveUserInfo5 import io.kotest.matchers.url.matchers.shouldHaveHost6 import io.kotest.matchers.url.matchers.shouldHavePort7 import io.kotest.matchers.url.matchers.shouldHaveFragment8 import io.kotest.matchers.url.matchers.shouldHaveParameter9 import io.kotest.matchers.url.matchers.shouldHaveParameters10 import io.kotest.matchers.url.matchers.shouldHaveParameterCount11 import io.kotest.matchers.url.matchers.shouldHaveParameterValues12 import io.kotest.matchers.url.matchers.shouldHaveParameterValuesCount13 import io.kotest.matchers.url.matchers.shouldHaveEmptyParameterValues14 import io.kotest.matchers.url.matchers.shouldNotHaveEmptyParameterValues15 import io.kotest.matchers.url.matchers.shouldHaveEmptyParameters16 import io.kotest.matchers.url.matchers.shouldNotHaveEmptyParameters17 import io.kotest.matchers.url.matchers.shouldHaveParameterKey18 import io.kotest.matchers.url.matchers.shouldHaveParameterKeys19 import io.kotest.matchers.url.matchers.shouldHaveParameterKeyCount20 import io.kotest.matchers.url.matchers.shouldHaveParameterKeyValues21 import io.kotest.matchers.url.matchers.shouldHaveParameterKeyValueCount22 import io.kotest.matchers.url.matchers.shouldHaveParameterKeyValueValues23 import io.kotest.matchers.url.matchers.shouldHaveParameterKeyValueValueCount24 import io.kotest.matchers.url.matchers.shouldHaveEmptyParameterKeyValues25 import io.kotest.matchers.url.matchers.shouldNotHaveEmptyParameterKeyValues26 import io.kotest.matchers.url.matchers.shouldHaveEmptyParameterKeyValueValues27 import io.kotest.matchers.url.matchers.shouldNotHaveEmptyParameterKeyValueValues28 import io.kotest.matchers.url.matchers.shouldHaveEmptyParameterKey29 import io.kotest.matchers.url.matchers.shouldNotHaveEmptyParameterKey30 import io.kotest.matchers.url.matchers.shouldHaveEmptyParameterKeys31 import

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful