How to use Base64 class of org.spekframework.spek2.runtime.util package

Best Spek code snippet using org.spekframework.spek2.runtime.util.Base64

SdpKanalITSpek.kt

Source:SdpKanalITSpek.kt Github

copy

Full Screen

...48import java.io.StringReader49import java.net.ServerSocket50import java.nio.file.Files51import java.nio.file.Paths52import java.util.Base6453import java.util.UUID54import java.util.concurrent.TimeUnit55import java.util.concurrent.locks.ReentrantReadWriteLock56import javax.jms.BytesMessage57import javax.jms.ConnectionFactory58import javax.jms.TextMessage59import javax.naming.InitialContext60import javax.xml.bind.JAXBContext61import kotlin.concurrent.write62fun randomPort() = ServerSocket(0).use {63 it.localPort64}65val sdpMockPort: Int = randomPort()66val legalArchiveMockPort = randomPort()67open class QueuedReceiptHandler : SbdHandler {68 val receipts: MutableMap<String, EbmsResponse> = mutableMapOf()69 val userMessageHandlers = mutableListOf<()->EbmsResponse>()70 private val reentrantReadWriteLock: ReentrantReadWriteLock = ReentrantReadWriteLock()71 override fun handleUserMessage(sbdIn: StandardBusinessDocument, attachments: List<EbmsAttachment>, senderOrgNumber: String, userMessage: UserMessage): EbmsResponse {72 // Assume its a request to send SDP73 if (userMessageHandlers.isEmpty())74 return EbmsResponse(null, null, true, listOf())75 return reentrantReadWriteLock.write {76 userMessageHandlers.removeAt(0)()77 }78 }79 override fun handleSignalMessage(attachments: List<EbmsAttachment>, senderOrgNumber: String, signalMessage: SignalMessage): EbmsResponse = reentrantReadWriteLock.write {80 if (signalMessage.pullRequest != null && receipts.containsKey(signalMessage.pullRequest.mpc)) {81 return receipts.remove(signalMessage.pullRequest.mpc)!!82 }83 DefaultSbdHandler.noNewMessages()84 }85}86object SdpKanalITSpek : Spek({87 System.setProperty("javax.xml.soap.SAAJMetaFactory", "com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl")88 val activeMQServer = ActiveMQServers.newActiveMQServer(ConfigurationImpl()89 .setPersistenceEnabled(false)90 .setJournalDirectory("target/data/journal")91 .setSecurityEnabled(false)92 .addAcceptorConfiguration("invm", "vm://0"))93 activeMQServer.start()94 val keyStore = generateKeyStore().apply {95 Files.newOutputStream(Paths.get("build/keystore.p12")).use {96 store(it, "changeit".toCharArray())97 }98 Base64.getEncoder().wrap(Files.newOutputStream(Paths.get("build/keystore.p12.b64"))).use {99 store(it, "changeit".toCharArray())100 }101 }102 val requestHandler = spy(QueuedReceiptHandler())103 fun initSdpServer() = createSDPMockServer(sbdHandler = requestHandler, port = sdpMockPort, keyStore = keyStore)104 var sdpServer = initSdpServer()105 val vaultCredentials: VaultCredentials = objectMapper.readValue(VaultCredentials::class.java.getResourceAsStream("/vault.json"))106 val virksomhetssertifikatCredentials: VirksomhetssertifikatCredentials = objectMapper.readValue(VaultCredentials::class.java.getResourceAsStream("/virksomhet.json"))107 val config = SdpConfiguration(108 knownHostsFile = "TODO",109 ebmsEndpointUrl = "http://localhost:$sdpMockPort/sdpmock",110 mqHostname = "UNUSED",111 mqPort = -1,112 mqQueueManager = "UNUSED",113 mqChannel = "UNUSED",114 inputQueueNormal = "sdp_input_normal",115 inputQueuePriority = "sdp_input_priority",116 inputQueueNormalBackout = "sdp_input_normal_boq",117 inputQueuePriorityBackout = "sdp_input_priority_boq",118 receiptQueueNormal = "sdp_receipt_normal",119 receiptQueuePriority = "sdp_receipt_priority",120 keystorePath = "build/keystore.p12.b64",121 keystoreCredentialsPath = "UNUSED",122 truststorePath = "build/keystore.p12.b64",123 mqConcurrentConsumers = 4,124 receiptPollIntervalNormal = 1000,125 legalArchiveUrl = "http://localhost:$legalArchiveMockPort/upload",126 sdpCheckRevocation = false,127 sftpUrl = "UNUSED"128 )129 val requestMock = mock<() -> Any>()130 // TODO: Use mock engine whenever it supports JSON131 val legalArchiveMock = embeddedServer(CIO, port = legalArchiveMockPort) {132 install(ContentNegotiation) {133 jackson { }134 }135 routing {136 post("/upload") {137 call.respond(requestMock())138 }139 }140 }.start()141 val legalArchiveLogger = LegalArchiveLogger(config.legalArchiveUrl, "user", "pass")142 val sdpKeys = SdpKeys(config.keystorePath, config.truststorePath, virksomhetssertifikatCredentials, vaultCredentials, config.sdpCheckRevocation)143 val certBytes = sdpKeys.truststore.getCertificate("posten").encoded144 // Certificates are double base64 encoded145 val certB64 = Base64.getEncoder().encode(certBytes)146 val appCert = Base64.getEncoder().encodeToString(certB64)147 val connectionFactory = InitialContext().lookup("ConnectionFactory") as ConnectionFactory148 val queueConnection = connectionFactory.createConnection()149 queueConnection.start()150 val connectionPool = ConnectionPool({ mock(ChannelSftp::class) }, {})151 val camelContext = createCamelContext(config, sdpKeys, connectionFactory, connectionPool, legalArchiveLogger)152 camelContext.start()153 val session = queueConnection.createSession()154 val normalQueueSender = session.createProducer(session.createQueue(config.inputQueueNormal))155 val normalQueueConsumer = session.createConsumer(session.createQueue(config.inputQueueNormal))156 val priorityQueueSender = session.createProducer(session.createQueue(config.inputQueuePriority))157 val normalReceiptConsumer = session.createConsumer(session.createQueue(config.receiptQueueNormal))158 val priorityReceiptConsumer = session.createConsumer(session.createQueue(config.receiptQueuePriority))159 val normalBackoutConsumer = session.createConsumer(session.createQueue(config.inputQueueNormalBackout))160 val priorityBackoutConsumer = session.createConsumer(session.createQueue(config.inputQueuePriorityBackout))...

Full Screen

Full Screen

Path.kt

Source:Path.kt Github

copy

Full Screen

1package org.spekframework.spek2.runtime.scope2import org.spekframework.spek2.runtime.util.Base643import org.spekframework.spek2.runtime.util.ClassUtil4import kotlin.reflect.KClass5val Path.isRoot: Boolean6 get() {7 return name.isEmpty() && parent == null8 }9// handles two cases10// classToPath -> discoveryRequest.path11// 1: my.package/MyClass -> my.package/MyClass/description12// 2: my.package/MyClass/description -> my.package/MyClass13fun Path.intersects(path: Path) = this.isParentOf(path) || path.isParentOf(this)14data class Path(val name: String, val parent: Path?) {15 private val serialized by lazy {16 serialize(this)17 }18 private val humanReadable by lazy {19 serialize(this, false)20 }21 private val encoded by lazy {22 encode(name)23 }24 fun resolve(name: String) = Path(name, this)25 fun isParentOf(path: Path): Boolean {26 var current: Path? = path27 while (current != null) {28 if (current == this) {29 return true30 }31 current = current.parent32 }33 return false34 }35 fun serialize(): String = serialized36 override fun toString(): String {37 return humanReadable38 }39 companion object {40 const val PATH_SEPARATOR = '/'41 private fun serialize(path: Path, encoded: Boolean = true): String {42 return if (path.parent == null) {43 // this will be an empty string44 path.name45 } else {46 val name = if (encoded) {47 path.encoded48 } else {49 path.name50 }51 "${serialize(path.parent, encoded)}$PATH_SEPARATOR$name".trimStart(PATH_SEPARATOR)52 }53 }54 fun encode(name: String): String {55 return Base64.encodeToString(name)56 }57 fun decode(name: String): String {58 return Base64.decodeToString(name)59 }60 }61}62class PathBuilder(private var parent: Path) {63 constructor() : this(ROOT)64 fun appendPackage(packageName: String): PathBuilder {65 packageName.split('.')66 .forEach { part -> append(part) }67 return this68 }69 fun append(name: String): PathBuilder {70 parent = Path(name, parent)71 return this72 }...

Full Screen

Full Screen

Base64Test.kt

Source:Base64Test.kt Github

copy

Full Screen

1package org.spekframework.spek2.runtime.util2import kotlin.test.*3// Based on https://kotlinlang.org/docs/tutorials/multiplatform-library.html4class Base64Test {5 @Test6 fun testEncodeString() {7 checkEncodeToString("Kotlin is awesome", "S290bGluIGlzIGF3ZXNvbWU=")8 }9 @Test10 fun testEncodePaddedStrings() {11 checkEncodeToString("", "")12 checkEncodeToString("1", "MQ==")13 checkEncodeToString("22", "MjI=")14 checkEncodeToString("333", "MzMz")15 checkEncodeToString("4444", "NDQ0NA==")16 }17 @Test18 fun testDecodeString() {19 checkDecodeFromString("S290bGluIGlzIGF3ZXNvbWU=", "Kotlin is awesome")20 }21 @Test22 fun testDecodePaddedStrings() {23 checkDecodeFromString("", "")24 checkDecodeFromString("MQ==", "1")25 checkDecodeFromString("MjI=", "22")26 checkDecodeFromString("MzMz", "333")27 checkDecodeFromString("NDQ0NA==", "4444")28 }29 @Test30 fun testDecodeInvalidStrings() {31 assertFailsWith<IllegalArgumentException>("Invalid Base64 encoded data.") { Base64.decodeToString("a") }32 assertFailsWith<IllegalArgumentException>("Invalid Base64 encoded data.") { Base64.decodeToString("aa") }33 assertFailsWith<IllegalArgumentException>("Invalid Base64 encoded data.") { Base64.decodeToString("aaa") }34 assertFailsWith<IllegalArgumentException>("Invalid Base64 encoded data.") { Base64.decodeToString("a===") }35 assertFailsWith<IllegalArgumentException>("Invalid Base64 encoded data.") { Base64.decodeToString("aa&a") }36 }37 private fun checkEncodeToString(input: String, expectedOutput: String) {38 assertEquals(expectedOutput, Base64.encodeToString(input))39 }40 private fun checkDecodeFromString(input: String, expectedOutput: String) {41 assertEquals(expectedOutput, Base64.decodeToString(input))42 }43}...

Full Screen

Full Screen

Base64.kt

Source:Base64.kt Github

copy

Full Screen

1package org.spekframework.spek2.runtime.util2actual object Base64 {3 actual fun encodeToString(text: String): String {4 return java.util.Base64.getEncoder().encodeToString(text.toByteArray())5 }6 actual fun decodeToString(encodedText: String): String {7 return String(8 java.util.Base64.getDecoder().decode(encodedText.toByteArray())9 )10 }11}...

Full Screen

Full Screen

Base64

Using AI Code Generation

copy

Full Screen

1val base64 = Base64()2val encoded = base64.encodeToString("hello world".toByteArray())3println(encoded)4val decoded = base64.decodeToString(encoded)5println(decoded)6val base64 = Base64()7val encoded = base64.encodeToString("hello world".toByteArray())8println(encoded)9val decoded = base64.decodeToString(encoded)10println(decoded)11class Base64Test : Spek({12 val base64 = Base64()13 describe("Base64") {14 it("should encode and decode") {15 val encoded = base64.encodeToString("hello world".toByteArray())16 val decoded = base64.decodeToString(encoded)17 assertEquals("hello world", decoded)18 }19 }20})21class Base64Test : Spek({22 val base64 = Base64()23 describe("Base64") {24 it("should encode and decode") {25 val encoded = base64.encodeToString("hello world".toByteArray())26 val decoded = base64.decodeToString(encoded)27 assertEquals("hello world", decoded)28 }29 }30})31class Base64Test : Spek({32 val base64 = Base64()33 describe("Base64") {34 it("should encode and decode") {35 val encoded = base64.encodeToString("hello world".toByteArray())36 val decoded = base64.decodeToString(encoded)37 assertEquals("hello world", decoded)38 }39 }40})41class Base64Test : Spek({42 val base64 = Base64()43 describe("Base64") {44 it("should encode and decode") {45 val encoded = base64.encodeToString("hello world".toByteArray())46 val decoded = base64.decodeToString(encoded)47 assertEquals("hello world", decoded)48 }49 }50})51class Base64Test : Spek({52 val base64 = Base64()53 describe("Base64") {54 it("should encode and decode") {55 val encoded = base64.encodeToString("hello world".toByteArray())56 val decoded = base64.decodeToString(encoded)57 assertEquals("hello world", decoded)58 }59 }60})61class Base64Test : Spek({62 val base64 = Base64()63 describe("Base64") {64 it("should encode and decode") {

Full Screen

Full Screen

Base64

Using AI Code Generation

copy

Full Screen

1val encoded = Base64.encodeToString("Hello".toByteArray())2assertThat(encoded).isEqualTo("SGVsbG8=")3}4}5}6describe("A calculator") {7it("sums two numbers") {8assertThat(result).isEqualTo(3)9}10}11fun main(args: Array<String>) {12SpekRuntime().run(SimpleCalculatorTest::class)13}14class SimpleCalculatorJUnitTest : SpekJUnitPlatform(SimpleCalculatorTest::class)15test {16useJUnitPlatform()17}

Full Screen

Full Screen

Base64

Using AI Code Generation

copy

Full Screen

1val encodedString = Base64.encodeToString(stringToEncode.toByteArray(), Base64.NO_WRAP)2println(encodedString)3val decodedString = Base64.decode(encodedString, Base64.NO_WRAP)4println(String(decodedString))5val decodedString = Base64.decodeToString(encodedString, Base64.NO_WRAP)6println(decodedString)7val decodedString = Base64.decode(encodedString, Base64.NO_WRAP)8println(String(decodedString))9val decodedString = Base64.decode(encodedString, Base64.NO_WRAP)10println(String(decodedString))11val decodedString = Base64.decode(encodedString, Base64.NO_WRAP)12println(String(decodedString))13val decodedString = Base64.decode(encodedString, Base64.NO_WRAP)14println(String(decodedString))15val decodedString = Base64.decode(encodedString, Base64.NO_WRAP)16println(String(decodedString))17val decodedString = Base64.decode(encodedString, Base64.NO_WRAP)18println(String(decodedString))19val decodedString = Base64.decode(encodedString, Base64.NO_WRAP)20println(String(decodedString))

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 Spek automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful