How to use beBlank method of io.kotest.matchers.string.matchers class

Best Kotest code snippet using io.kotest.matchers.string.matchers.beBlank

StringMatchersTest.kt

Source:StringMatchersTest.kt Github

copy

Full Screen

...5import io.kotest.data.row6import io.kotest.matchers.should7import io.kotest.matchers.shouldBe8import io.kotest.matchers.shouldNot9import io.kotest.matchers.string.beBlank10import io.kotest.matchers.string.beEmpty11import io.kotest.matchers.string.contain12import io.kotest.matchers.string.containADigit13import io.kotest.matchers.string.containIgnoringCase14import io.kotest.matchers.string.containOnlyDigits15import io.kotest.matchers.string.containOnlyOnce16import io.kotest.matchers.string.containOnlyWhitespace17import io.kotest.matchers.string.endWith18import io.kotest.matchers.string.haveSameLengthAs19import io.kotest.matchers.string.match20import io.kotest.matchers.string.shouldBeBlank21import io.kotest.matchers.string.shouldBeEmpty22import io.kotest.matchers.string.shouldBeEqualIgnoringCase23import io.kotest.matchers.string.shouldBeInteger24import io.kotest.matchers.string.shouldBeSingleLine25import io.kotest.matchers.string.shouldContain26import io.kotest.matchers.string.shouldContainADigit27import io.kotest.matchers.string.shouldContainIgnoringCase28import io.kotest.matchers.string.shouldContainOnlyDigits29import io.kotest.matchers.string.shouldContainOnlyOnce30import io.kotest.matchers.string.shouldEndWith31import io.kotest.matchers.string.shouldHaveLengthBetween32import io.kotest.matchers.string.shouldHaveLengthIn33import io.kotest.matchers.string.shouldHaveSameLengthAs34import io.kotest.matchers.string.shouldMatch35import io.kotest.matchers.string.shouldNotBeBlank36import io.kotest.matchers.string.shouldNotBeEmpty37import io.kotest.matchers.string.shouldNotBeEqualIgnoringCase38import io.kotest.matchers.string.shouldNotBeSingleLine39import io.kotest.matchers.string.shouldNotContain40import io.kotest.matchers.string.shouldNotContainADigit41import io.kotest.matchers.string.shouldNotContainIgnoringCase42import io.kotest.matchers.string.shouldNotContainOnlyDigits43import io.kotest.matchers.string.shouldNotContainOnlyOnce44import io.kotest.matchers.string.shouldNotEndWith45import io.kotest.matchers.string.shouldNotHaveLengthBetween46import io.kotest.matchers.string.shouldNotHaveLengthIn47import io.kotest.matchers.string.shouldNotHaveSameLengthAs48import io.kotest.matchers.string.shouldNotMatch49class StringMatchersTest : FreeSpec() {50 init {51 "string shouldBe other" - {52 "should support null arguments" {53 val a: String? = "a"54 val b: String? = "a"55 a shouldBe b56 }57 "should report when only line endings differ" {58 forAll(59 row("a\nb", "a\r\nb"),60 row("a\nb\nc", "a\nb\r\nc"),61 row("a\r\nb", "a\nb"),62 row("a\nb", "a\rb"),63 row("a\rb", "a\r\nb")64 ) { expected, actual ->65 shouldThrow<AssertionError> {66 actual shouldBe expected67 }.let {68 it.message shouldContain "contents match, but line-breaks differ"69 }70 }71 }72 "should show diff when newline count differs" {73 shouldThrow<AssertionError> {74 "a\nb" shouldBe "a\n\nb"75 }.message shouldBe """76 |(contents match, but line-breaks differ; output has been escaped to show line-breaks)77 |expected:<a\n\nb> but was:<a\nb>78 """.trimMargin()79 }80 }81 "contain only once" {82 "la tour" should containOnlyOnce("tour")83 "la tour tour" shouldNot containOnlyOnce("tour")84 "la tour tour" shouldNotContainOnlyOnce "tour"85 shouldThrow<AssertionError> {86 "la" should containOnlyOnce("tour")87 }.message shouldBe """"la" should contain the substring "tour" exactly once"""88 shouldThrow<AssertionError> {89 null shouldNot containOnlyOnce("tour")90 }.message shouldBe "Expecting actual not to be null"91 shouldThrow<AssertionError> {92 null shouldNotContainOnlyOnce "tour"93 }.message shouldBe "Expecting actual not to be null"94 shouldThrow<AssertionError> {95 null should containOnlyOnce("tour")96 }.message shouldBe "Expecting actual not to be null"97 shouldThrow<AssertionError> {98 null shouldContainOnlyOnce "tour"99 }.message shouldBe "Expecting actual not to be null"100 }101 "contain(regex)" {102 "la tour" should contain("^.*?tour$".toRegex())103 "la tour" shouldNot contain(".*?abc.*?".toRegex())104 "la tour" shouldContain "^.*?tour$".toRegex()105 "la tour" shouldNotContain ".*?abc.*?".toRegex()106 shouldThrow<AssertionError> {107 "la tour" shouldContain ".*?abc.*?".toRegex()108 }.message shouldBe "\"la tour\" should contain regex .*?abc.*?"109 shouldThrow<AssertionError> {110 "la tour" shouldNotContain "^.*?tour$".toRegex()111 }.message shouldBe "\"la tour\" should not contain regex ^.*?tour\$"112 shouldThrow<AssertionError> {113 null shouldNot contain("^.*?tour$".toRegex())114 }.message shouldBe "Expecting actual not to be null"115 shouldThrow<AssertionError> {116 null shouldNotContain "^.*?tour$".toRegex()117 }.message shouldBe "Expecting actual not to be null"118 shouldThrow<AssertionError> {119 null should contain("^.*?tour$".toRegex())120 }.message shouldBe "Expecting actual not to be null"121 shouldThrow<AssertionError> {122 null shouldContain "^.*?tour$".toRegex()123 }.message shouldBe "Expecting actual not to be null"124 }125 "string should beEmpty()" - {126 "should test that a string has length 0" {127 "" should beEmpty()128 "hello" shouldNot beEmpty()129 "hello".shouldNotBeEmpty()130 "".shouldBeEmpty()131 shouldThrow<AssertionError> {132 "hello".shouldBeEmpty()133 }.message shouldBe "\"hello\" should be empty"134 shouldThrow<AssertionError> {135 "".shouldNotBeEmpty()136 }.message shouldBe "<empty string> should not be empty"137 }138 "should fail if value is null" {139 shouldThrow<AssertionError> {140 null shouldNot beEmpty()141 }.message shouldBe "Expecting actual not to be null"142 shouldThrow<AssertionError> {143 null.shouldNotBeEmpty()144 }.message shouldBe "Expecting actual not to be null"145 shouldThrow<AssertionError> {146 null should beEmpty()147 }.message shouldBe "Expecting actual not to be null"148 shouldThrow<AssertionError> {149 null.shouldBeEmpty()150 }.message shouldBe "Expecting actual not to be null"151 }152 }153 "string should containADigit()" - {154 "should test that a string has at least one number" {155 "" shouldNot containADigit()156 "1" should containADigit()157 "a1".shouldContainADigit()158 "a1b" should containADigit()159 "hello" shouldNot containADigit()160 "hello".shouldNotContainADigit()161 shouldThrow<AssertionError> {162 "hello" should containADigit()163 }.message shouldBe "\"hello\" should contain at least one digit"164 }165 "should fail if value is null" {166 shouldThrow<AssertionError> {167 null shouldNot containADigit()168 }.message shouldBe "Expecting actual not to be null"169 shouldThrow<AssertionError> {170 null.shouldNotContainADigit()171 }.message shouldBe "Expecting actual not to be null"172 shouldThrow<AssertionError> {173 null should containADigit()174 }.message shouldBe "Expecting actual not to be null"175 shouldThrow<AssertionError> {176 null.shouldContainADigit()177 }.message shouldBe "Expecting actual not to be null"178 }179 }180 "string should beBlank()" - {181 "should test that a string has only whitespace" {182 "" should beBlank()183 "" should containOnlyWhitespace()184 " \t " should beBlank()185 "hello" shouldNot beBlank()186 "hello".shouldNotBeBlank()187 " ".shouldBeBlank()188 }189 "should fail if value is null" {190 shouldThrow<AssertionError> {191 null shouldNot beBlank()192 }.message shouldBe "Expecting actual not to be null"193 shouldThrow<AssertionError> {194 null.shouldNotBeBlank()195 }.message shouldBe "Expecting actual not to be null"196 shouldThrow<AssertionError> {197 null should beBlank()198 }.message shouldBe "Expecting actual not to be null"199 shouldThrow<AssertionError> {200 null.shouldBeBlank()201 }.message shouldBe "Expecting actual not to be null"202 }203 }204 "string should haveSameLengthAs(other)" - {205 "should test that a string has the same length as another string" {206 "hello" should haveSameLengthAs("world")207 "hello" shouldNot haveSameLengthAs("o")208 "" should haveSameLengthAs("")209 "" shouldNot haveSameLengthAs("o")210 "5" shouldNot haveSameLengthAs("")211 "" shouldHaveSameLengthAs ""...

Full Screen

Full Screen

BestellungRestTest.kt

Source:BestellungRestTest.kt Github

copy

Full Screen

...30import io.kotest.matchers.collections.shouldHaveSize31import io.kotest.matchers.shouldBe32import io.kotest.matchers.shouldNot33import io.kotest.matchers.shouldNotBe34import io.kotest.matchers.string.beBlank35import io.kotest.matchers.string.shouldMatch36import kotlinx.coroutines.ExperimentalCoroutinesApi37import kotlinx.coroutines.test.runTest38import org.junit.jupiter.api.DisplayName39import org.junit.jupiter.api.Nested40import org.junit.jupiter.api.Tag41import org.junit.jupiter.api.Test42import org.junit.jupiter.api.condition.EnabledForJreRange43import org.junit.jupiter.api.condition.JRE.JAVA_1744import org.junit.jupiter.api.condition.JRE.JAVA_1845import org.junit.jupiter.params.ParameterizedTest46import org.junit.jupiter.params.provider.CsvSource47import org.junit.jupiter.params.provider.ValueSource48import org.springframework.beans.factory.getBean49import org.springframework.boot.test.context.SpringBootTest50import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT51import org.springframework.boot.web.server.LocalServerPort52import org.springframework.context.ApplicationContext53import org.springframework.hateoas.MediaTypes.HAL_JSON54import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer55import org.springframework.http.HttpStatus.CREATED56import org.springframework.http.HttpStatus.NOT_FOUND57import org.springframework.http.HttpStatus.OK58import org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY59import org.springframework.test.context.ActiveProfiles60import org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication61import org.springframework.web.reactive.function.client.WebClient62import org.springframework.web.reactive.function.client.awaitBodilessEntity63import org.springframework.web.reactive.function.client.awaitBody64import org.springframework.web.reactive.function.client.awaitEntity65import org.springframework.web.reactive.function.client.awaitExchange66import java.math.BigDecimal67import java.math.BigDecimal.TEN68@Tag("rest")69@DisplayName("REST-Schnittstelle fuer Bestellungen testen")70@SpringBootTest(webEnvironment = RANDOM_PORT)71@ActiveProfiles(DEV)72@EnabledForJreRange(min = JAVA_17, max = JAVA_18)73@Suppress("ClassName", "UseDataClass")74@ExperimentalCoroutinesApi75class BestellungRestTest(@LocalServerPort private val port: Int, ctx: ApplicationContext) {76 private val baseUrl = "$SCHEMA://$HOST:$port$API_PATH"77 private val client = WebClient.builder()78 .filter(basicAuthentication(USER_ADMIN, PASSWORD))79 .baseUrl(baseUrl)80 .build()81 init {82 ctx.getBean<BestellungGetController>() shouldNotBe null83 }84 // -------------------------------------------------------------------------85 // L E S E N86 // -------------------------------------------------------------------------87 @ExperimentalCoroutinesApi88 @Nested89 inner class Lesen {90 @ParameterizedTest91 @ValueSource(strings = [ID_VORHANDEN])92 fun `Suche mit vorhandener ID`(id: String) = runTest {93 // when94 val response = client.get()95 .uri(ID_PATH, id)96 .accept(HAL_JSON)97 .awaitExchange { response -> response.awaitEntity<String>() }98 // then99 assertSoftly(response) {100 statusCode shouldBe OK101 body shouldNotBe null102 val kundeNachname: String = JsonPath.read(body, "$.kundeNachname")103 kundeNachname shouldNot beBlank()104 kundeNachname shouldNotBe "Fallback"105 val linkDiscoverer = HalLinkDiscoverer()106 val selfLink = linkDiscoverer.findLinkWithRel("self", body ?: "").get().href107 selfLink shouldBe "$baseUrl/$id"108 }109 }110 @ParameterizedTest111 @ValueSource(strings = [ID_INVALID, ID_NICHT_VORHANDEN])112 fun `Suche mit syntaktisch ungueltiger oder nicht-vorhandener ID`() = runTest {113 // given114 val id = ID_INVALID115 // when116 val statusCode = client.get()117 .uri(ID_PATH, id)...

Full Screen

Full Screen

OlmAccountTest.kt

Source:OlmAccountTest.kt Github

copy

Full Screen

...5import io.kotest.matchers.maps.shouldHaveSize6import io.kotest.matchers.shouldBe7import io.kotest.matchers.shouldNot8import io.kotest.matchers.shouldNotBe9import io.kotest.matchers.string.beBlank10import kotlinx.coroutines.ExperimentalCoroutinesApi11import kotlinx.coroutines.flow.flow12import kotlinx.coroutines.flow.take13import kotlinx.coroutines.flow.toList14import kotlinx.coroutines.test.runTest15import kotlin.test.Test16@OptIn(ExperimentalCoroutinesApi::class)17class OlmAccountTest {18 @Test19 fun create_shouldCreateAndVerify() = runTest {20 val account = OlmAccount.create()21 account.free()22 }23 @Test24 fun create_shouldHaveUniqueIdentityKeys() = runTest {25 // This test validates random series are provide enough random values.26 val size = 2027 val accounts = flow { while (true) emit(OlmAccount.create()) }.take(size).toList()28 accounts.map { it.identityKeys.curve25519 }.toSet() shouldHaveSize size29 accounts.forEach { it.free() }30 }31 @Test32 fun identityKeys_shouldContainKeys() = runTest {33 freeAfter(OlmAccount.create()) { account ->34 val identityKeys = account.identityKeys35 identityKeys.ed25519 shouldNot beBlank()36 identityKeys.curve25519 shouldNot beBlank()37 }38 }39 @Test40 fun maxNumberOfOneTimeKeys_shouldBeGreaterThanZero() = runTest {41 freeAfter(OlmAccount.create()) { account ->42 account.maxNumberOfOneTimeKeys shouldBeGreaterThan 043 }44 }45 @Test46 fun generateOneTimeKeys_shouldRun() = runTest {47 freeAfter(OlmAccount.create()) { account ->48 account.generateOneTimeKeys(2)49 }50 }51 @Test52 fun generateOneTimeKeys_shouldFailWithZero() = runTest {53 freeAfter(OlmAccount.create()) { account ->54 shouldThrow<IllegalArgumentException> {55 account.generateOneTimeKeys(0)56 }57 account.oneTimeKeys.curve25519 shouldHaveSize 058 }59 }60 @Test61 fun generateOneTimeKeys_shouldFailWithNegative() = runTest {62 freeAfter(OlmAccount.create()) { account ->63 shouldThrow<IllegalArgumentException> {64 account.generateOneTimeKeys(-50)65 }66 account.oneTimeKeys.curve25519 shouldHaveSize 067 }68 }69 @Test70 fun oneTimeKeys_shouldBeEmptyBeforeGeneration() = runTest {71 freeAfter(OlmAccount.create()) { account ->72 account.oneTimeKeys.curve25519 shouldHaveSize 073 }74 }75 @Test76 fun oneTimeKeys_shouldContainKeysAfterGeneration() = runTest {77 freeAfter(OlmAccount.create()) { account ->78 account.generateOneTimeKeys(5)79 val oneTimeKeys = account.oneTimeKeys.curve2551980 oneTimeKeys shouldHaveSize 581 oneTimeKeys.forEach {82 it.key shouldNot beBlank()83 it.value shouldNot beBlank()84 }85 }86 }87 @Test88 fun removeOneTimeKeys_shouldRemoveOneTimeKey() = runTest {89 freeAfter(OlmAccount.create(), OlmAccount.create()) { myAccount, theirAccount ->90 theirAccount.generateOneTimeKeys(1)91 val myIdentityKey = myAccount.identityKeys.curve2551992 val theirIdentityKey = theirAccount.identityKeys.curve2551993 val theirOneTimeKey = theirAccount.oneTimeKeys.curve25519.values.first()94 freeAfter(OlmSession.createOutbound(myAccount, theirIdentityKey, theirOneTimeKey)) { mySession ->95 val message = mySession.encrypt("hello").cipherText96 freeAfter(OlmSession.createInboundFrom(theirAccount, myIdentityKey, message)) {97 theirAccount.removeOneTimeKeys(mySession)98 }99 theirAccount.oneTimeKeys.curve25519.values shouldHaveSize 0100 shouldThrow<OlmLibraryException> {101 OlmSession.createInboundFrom(theirAccount, theirIdentityKey, message)102 }.message shouldBe "BAD_MESSAGE_KEY_ID"103 }104 }105 }106 @Test107 fun markOneTimeKeysAsPublished_shouldPreventOneTimeKeysToBePresentAgain() = runTest {108 freeAfter(OlmAccount.create()) { account ->109 account.generateOneTimeKeys(2)110 account.oneTimeKeys.curve25519 shouldHaveSize 2111 account.markKeysAsPublished()112 account.oneTimeKeys.curve25519 shouldHaveSize 0113 }114 }115 @Test116 fun sign_shouldSign() = runTest {117 freeAfter(OlmAccount.create()) { account ->118 account.sign("String to be signed by olm") shouldNot beBlank()119 }120 }121 @Test122 fun generateFallbackKey_shouldRun() = runTest {123 freeAfter(OlmAccount.create()) { account ->124 account.generateFallbackKey()125 }126 }127 @Test128 fun unpublishedFallbackKey_shouldHaveSize1AfterGeneration() = runTest {129 freeAfter(OlmAccount.create()) { account ->130 account.generateFallbackKey()131 val key1 = account.unpublishedFallbackKey.curve25519132 account.generateFallbackKey()133 val key2 = account.unpublishedFallbackKey.curve25519134 key1 shouldHaveSize 1135 key2 shouldHaveSize 1136 key1 shouldNotBe key2137 }138 }139 @Test140 fun unpublishedFallbackKey_shouldBeEmptyBeforeGeneration() = runTest {141 freeAfter(OlmAccount.create()) { account ->142 account.unpublishedFallbackKey.curve25519 shouldHaveSize 0143 }144 }145 @Test146 fun forgetOldFallbackKey_shouldRunAndRemoveFallbackKey() = runTest {147 freeAfter(OlmAccount.create()) { account ->148 account.generateFallbackKey()149 account.unpublishedFallbackKey.curve25519 shouldHaveSize 1150 account.forgetOldFallbackKey()151 account.unpublishedFallbackKey.curve25519 shouldHaveSize 1152 account.generateFallbackKey()153 account.unpublishedFallbackKey.curve25519 shouldHaveSize 1154 }155 }156 @Test157 fun pickle() = runTest {158 freeAfter(OlmAccount.create()) { account ->159 account.pickle("someKey") shouldNot beBlank()160 }161 }162 @Test163 fun unpickleAccount() = runTest {164 var keys: OlmIdentityKeys? = null165 val pickle = freeAfter(OlmAccount.create()) { account ->166 keys = account.identityKeys167 account.pickle("someKey")168 }169 pickle shouldNot beBlank()170 freeAfter(OlmAccount.unpickle("someKey", pickle)) { account ->171 account.identityKeys shouldBe keys172 }173 }174}...

Full Screen

Full Screen

AddNewMovieCopySpec.kt

Source:AddNewMovieCopySpec.kt Github

copy

Full Screen

...4import io.kotest.core.spec.style.StringSpec5import io.kotest.matchers.collections.shouldHaveSingleElement6import io.kotest.matchers.shouldBe7import io.kotest.matchers.shouldNot8import io.kotest.matchers.string.beBlank9import pl.michalperlak.videorental.inventory.domain.MovieCopyStatus10import pl.michalperlak.videorental.inventory.domain.MovieId11import pl.michalperlak.videorental.inventory.dto.NewMovieCopy12import pl.michalperlak.videorental.inventory.error.ErrorAddingMovieCopy13import pl.michalperlak.videorental.inventory.error.InvalidMovieId14import pl.michalperlak.videorental.inventory.error.MovieIdNotFound15import java.io.IOException16import java.time.Clock17import java.time.Instant18import java.time.LocalDate19import java.time.Month20import java.time.ZoneOffset21class AddNewMovieCopySpec : StringSpec({22 "should add movie copy and return its data" {23 // given24 val currentTime = Instant.ofEpochSecond(12345678)25 val inventory = createInventory(clock = Clock.fixed(currentTime, ZoneOffset.UTC))26 val movieId = inventory.addMovie(title = "Test", releaseDate = LocalDate.of(2020, Month.JUNE, 25))27 val newMovieCopy = NewMovieCopy(movieId)28 // when29 val result = inventory.addNewCopy(newMovieCopy)30 // then31 result shouldBeRight {32 it.copyId shouldNot beBlank()33 it.movieId shouldNot beBlank()34 it.status shouldBe MovieCopyStatus.AVAILABLE.name35 it.added shouldBe currentTime36 }37 }38 "should save copy in the repository" {39 // given40 val currentTime = Instant.ofEpochSecond(12345678)41 val movieCopiesRepository = InMemoryMovieCopiesRepository()42 val inventory = createInventory(43 movieCopiesRepository = movieCopiesRepository,44 clock = Clock.fixed(currentTime, ZoneOffset.UTC)45 )46 val movieId = inventory.addMovie(title = "Test movie", releaseDate = LocalDate.of(2020, Month.JUNE, 25))47 val newMovieCopy = NewMovieCopy(movieId)...

Full Screen

Full Screen

KlikkPåNotifikasjonGraphQLTests.kt

Source:KlikkPåNotifikasjonGraphQLTests.kt Github

copy

Full Screen

...3import io.kotest.matchers.collections.beEmpty4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNot7import io.kotest.matchers.string.beBlank8import io.kotest.matchers.types.beOfType9import io.ktor.http.*10import io.mockk.MockKAssertScope11import io.mockk.coEvery12import io.mockk.coVerify13import io.mockk.mockk14import io.mockk.unmockkAll15import no.nav.arbeidsgiver.notifikasjon.hendelse.HendelseModel.BrukerKlikket16import no.nav.arbeidsgiver.notifikasjon.hendelse.HendelseProdusent17import no.nav.arbeidsgiver.notifikasjon.infrastruktur.graphql.GraphQLRequest18import no.nav.arbeidsgiver.notifikasjon.util.BRUKER_HOST19import no.nav.arbeidsgiver.notifikasjon.util.SELVBETJENING_TOKEN20import no.nav.arbeidsgiver.notifikasjon.util.getGraphqlErrors21import no.nav.arbeidsgiver.notifikasjon.util.getTypedContent22import no.nav.arbeidsgiver.notifikasjon.util.ktorBrukerTestServer23import no.nav.arbeidsgiver.notifikasjon.util.post24import java.util.*25class KlikkPåNotifikasjonGraphQLTests: DescribeSpec({26 val queryModel = mockk<BrukerRepositoryImpl>(relaxed = true)27 val kafkaProducer = mockk<HendelseProdusent>()28 val engine = ktorBrukerTestServer(29 brukerRepository = queryModel,30 kafkaProducer = kafkaProducer,31 )32 coEvery { kafkaProducer.send(any<BrukerKlikket>()) } returns Unit33 afterSpec {34 unmockkAll()35 }36 describe("bruker-api: rapporterer om at notifikasjon er klikket på") {37 context("uklikket-notifikasjon eksisterer for bruker") {38 val id = UUID.fromString("09d5a598-b31a-11eb-8529-0242ac130003")39 coEvery { queryModel.virksomhetsnummerForNotifikasjon(id) } returns "1234"40 val httpResponse = engine.post(41 "/api/graphql",42 host = BRUKER_HOST,43 jsonBody = GraphQLRequest(44 """45 mutation {46 notifikasjonKlikketPaa(id: "$id") {47 __typename48 ... on BrukerKlikk {49 id50 klikketPaa51 }52 }53 }54 """.trimIndent()55 ),56 accept = "application/json",57 authorization = "Bearer $SELVBETJENING_TOKEN"58 )59 it("ingen http/graphql-feil") {60 httpResponse.status() shouldBe HttpStatusCode.OK61 httpResponse.getGraphqlErrors() should beEmpty()62 }63 val graphqlSvar = httpResponse.getTypedContent<BrukerAPI.NotifikasjonKlikketPaaResultat>("notifikasjonKlikketPaa")64 it("ingen domene-feil") {65 graphqlSvar should beOfType<BrukerAPI.BrukerKlikk>()66 }67 it("response inneholder klikketPaa og id") {68 val brukerKlikk = graphqlSvar as BrukerAPI.BrukerKlikk69 brukerKlikk.klikketPaa shouldBe true70 brukerKlikk.id shouldNot beBlank()71 }72 val brukerKlikketMatcher: MockKAssertScope.(BrukerKlikket) -> Unit = { brukerKlikket ->73 brukerKlikket.fnr shouldNot beBlank()74 brukerKlikket.notifikasjonId shouldBe id75 /* For øyeblikket feiler denne, siden virksomhetsnummer ikke hentes ut. */76 brukerKlikket.virksomhetsnummer shouldNot beBlank()77 }78 it("Event produseres på kafka") {79 coVerify {80 kafkaProducer.send(withArg(brukerKlikketMatcher))81 }82 }83 it("Database oppdaters") {84 coVerify {85 queryModel.oppdaterModellEtterHendelse(86 withArg(brukerKlikketMatcher)87 )88 }89 }90 }...

Full Screen

Full Screen

StatusPageTests.kt

Source:StatusPageTests.kt Github

copy

Full Screen

...4import com.fasterxml.jackson.core.io.ContentReference5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.matchers.shouldBe7import io.kotest.matchers.shouldNot8import io.kotest.matchers.string.beBlank9import io.kotest.matchers.string.shouldNotContain10import io.ktor.http.*11import io.ktor.routing.*12import io.ktor.server.testing.*13import io.mockk.spyk14import io.mockk.verify15import no.nav.arbeidsgiver.notifikasjon.util.ktorBrukerTestServer16import org.slf4j.LoggerFactory17class StatusPageTests : DescribeSpec({18 val spiedOnLogger = spyk(LoggerFactory.getLogger("KtorTestApplicationLogger"))19 val engine = ktorBrukerTestServer(20 environment = {21 log = spiedOnLogger22 }23 )24 fun whenExceptionThrown(path: String, ex: Exception): TestApplicationResponse {25 engine.environment.application.routing {26 get(path) {27 throw ex28 }29 }30 return engine.handleRequest(HttpMethod.Get, path).response31 }32 describe("status page handling") {33 context("when an unexpected error occurs") {34 val ex = RuntimeException("uwotm8?")35 val response = whenExceptionThrown("/some/runtime/exception", ex)36 it("it returns InternalServerError") {37 response.status() shouldBe HttpStatusCode.InternalServerError38 }39 it("and response has no content") {40 response.content shouldNotContain ex.message!!41 }42 it("and response header contains correlation id") {43 response.headers[HttpHeaders.XCorrelationId] shouldNot beBlank()44 }45 }46 context("when an JsonProcessingException occurs") {47 val ex = object : JsonProcessingException(48 "Error", JsonLocation(ContentReference.unknown(), 42,42,42)49 ) {}50 val response = whenExceptionThrown("/some/json/exception", ex)51 it("it returns InternalServerError") {52 response.status() shouldBe HttpStatusCode.InternalServerError53 }54 it("and excludes JsonLocation from log") {55 verify { spiedOnLogger.warn(56 any() as String,57 ex::class.qualifiedName,58 withArg { jpex:JsonProcessingException ->59 jpex.location shouldBe null60 }61 )}62 }63 it("and response does not include exception message") {64 response.content shouldNotContain ex.message!!65 }66 it("and response header contains correlation id") {67 response.headers[HttpHeaders.XCorrelationId] shouldNot beBlank()68 }69 }70 }71})

Full Screen

Full Screen

OlmOutboundGroupSessionTest.kt

Source:OlmOutboundGroupSessionTest.kt Github

copy

Full Screen

2import io.kotest.assertions.assertSoftly3import io.kotest.matchers.collections.shouldHaveSize4import io.kotest.matchers.shouldBe5import io.kotest.matchers.shouldNot6import io.kotest.matchers.string.beBlank7import kotlinx.coroutines.ExperimentalCoroutinesApi8import kotlinx.coroutines.flow.flow9import kotlinx.coroutines.flow.take10import kotlinx.coroutines.flow.toList11import kotlinx.coroutines.test.runTest12import kotlin.test.Test13@OptIn(ExperimentalCoroutinesApi::class)14class OlmOutboundGroupSessionTest {15 @Test16 fun createOutboundSession() = runTest {17 freeAfter(OlmOutboundGroupSession.create()) { outboundSession ->18 outboundSession.sessionId shouldNot beBlank()19 outboundSession.sessionKey shouldNot beBlank()20 outboundSession.messageIndex shouldBe 021 }22 }23 @Test24 fun encryptMessage() = runTest {25 freeAfter(OlmOutboundGroupSession.create()) { outboundSession ->26 outboundSession.encrypt("I'm clear!") shouldNot beBlank()27 outboundSession.messageIndex shouldBe 128 }29 }30 @Test31 fun create_shouldHaveUniqueIdAndKey() = runTest {32 // This test validates random series are provide enough random values.33 val size = 1034 val sessions = flow { while (true) emit(OlmOutboundGroupSession.create()) }.take(size).toList()35 assertSoftly {36 sessions.map { it.sessionId }.toSet() shouldHaveSize size37 sessions.map { it.sessionKey }.toSet() shouldHaveSize size38 }39 sessions.forEach { it.free() }40 }41 @Test42 fun pickle() = runTest {43 freeAfter(OlmOutboundGroupSession.create()) { session ->44 session.pickle("someKey") shouldNot beBlank()45 }46 }47 @Test48 fun unpickle() = runTest {49 val pickle = freeAfter(OlmOutboundGroupSession.create()) { session ->50 session.pickle("someKey") to session.sessionId51 }52 freeAfter(OlmOutboundGroupSession.unpickle("someKey", pickle.first)) { session ->53 session.sessionId shouldBe pickle.second54 }55 }56}...

Full Screen

Full Screen

CorrelationIdTests.kt

Source:CorrelationIdTests.kt Github

copy

Full Screen

2import io.kotest.core.datatest.forAll3import io.kotest.core.spec.style.DescribeSpec4import io.kotest.matchers.shouldBe5import io.kotest.matchers.shouldNot6import io.kotest.matchers.string.beBlank7import io.ktor.http.*8import no.nav.arbeidsgiver.notifikasjon.util.get9import no.nav.arbeidsgiver.notifikasjon.util.ktorBrukerTestServer10class CorrelationIdTests : DescribeSpec({11 val engine = ktorBrukerTestServer()12 describe("correlation id handling") {13 context("when no callid given") {14 val response = engine.get("/internal/alive")15 it("generates callid for us") {16 response.headers[HttpHeaders.XCorrelationId] shouldNot beBlank()17 }18 }19 context("with callid") {20 val callid = "1234"21 context("with header name:") {22 forAll("callid", "CALLID", "call-id") { headerName ->23 val response = engine.get( "/internal/alive") {24 addHeader(headerName, callid)25 }26 it("it replies with callid: $callid from $headerName") {27 response.headers[HttpHeaders.XCorrelationId] shouldBe callid28 }29 }30 }...

Full Screen

Full Screen

beBlank

Using AI Code Generation

copy

Full Screen

1str.shouldBeBlank()2str.shouldBeEmpty()3str.shouldBeEmpty()4str.shouldBeEmpty()5str.shouldBeEmpty()6str.shouldBeEmpty()7str.shouldBeEmpty()8str.shouldBeEmpty()9str.shouldBeEmpty()10str.shouldBeEmpty()11str.shouldBeEmpty()12str.shouldBeEmpty()13str.shouldBeEmpty()14str.shouldBeEmpty()15str.shouldBeEmpty()16str.shouldBeEmpty()17str.shouldBeEmpty()

Full Screen

Full Screen

beBlank

Using AI Code Generation

copy

Full Screen

1class StringMatchersTest {2fun `should use beBlank method of io.kotest.matchers.string.matchers class`(){3.shouldBeBlank()4}5}6class CollectionMatchersTest {7fun `should use beEmpty method of io.kotest.matchers.collections.matchers class`(){8listOf<String>()9.shouldBeEmpty()10}11}12class MapMatchersTest {13fun `should use beEmpty method of io.kotest.matchers.maps.matchers class`(){14mapOf<String, String>()15.shouldBeEmpty()16}17}18class SequenceMatchersTest {19fun `should use beEmpty method of io.kotest.matchers.sequences.matchers class`(){20sequenceOf<String>()21.shouldBeEmpty()22}23}24class IterableMatchersTest {25fun `should use beEmpty method of io.kotest.matchers.iterables.matchers class`(){26listOf<String>()27.shouldBeEmpty()28}29}30class IntMatchersTest {31fun `should use beEmpty method of io.kotest.matchers.ints.matchers class`(){32.shouldBeEmpty()33}34}35class LongMatchersTest {36fun `should use beEmpty method of io.kotest.matchers.longs.matchers class`(){37.shouldBeEmpty()38}39}40class FloatMatchersTest {41fun `should use beEmpty method of io.kotest.matchers.floats.matchers class`(){42.shouldBeEmpty()43}44}45class DoubleMatchersTest {46fun `should use beEmpty method of io.kotest.matchers.doubles.matchers class`(){47.shouldBeEmpty()48}49}

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