8000 Feature/aarti by 4arti · Pull Request #653 · specmatic/specmatic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature/aarti #653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package `in`.specmatic.contract.utilities

import `in`.specmatic.core.utilities.URIUtils.parsePathParams
import `in`.specmatic.core.utilities.URIUtils.parseQuery
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import java.net.URI
import java.net.URISyntaxException


internal class URIUtilsTest {
@Test
@Throws(URISyntaxException::class)
Expand All @@ -23,4 +25,17 @@ internal class URIUtilsTest {
Assertions.assertEquals(pathParameters["petid"], "(number)")
Assertions.assertEquals(pathParameters["owner"], "(string)")
}

@Test
fun testParseQuery() {
val query = "name=John&age=30&country=USA"
val result = parseQuery(query)
val expectedValidMap = mapOf(
"name" to "John",
"age" to "30",
"country" to "USA"
)
Assertions.assertEquals(expectedValidMap,result)

}
}
49 changes: 49 additions & 0 deletions core/src/test/kotlin/utilities/UtilitiesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ import `in`.specmatic.core.utilities.*
import `in`.specmatic.core.value.JSONObjectValue
import `in`.specmatic.core.value.toXMLNode
import java.io.File
import org.junit.Assert.*
import javax.xml.transform.TransformerFactory
import javax.xml.transform.dom.DOMSource
import javax.xml.transform.stream.StreamResult
import io.mockk.*
import org.w3c.dom.Document
import java.io.StringWriter
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.transform.Transformer
import javax.xml.transform.OutputKeys

internal class UtilitiesTest {
@Test
Expand Down Expand Up @@ -154,4 +164,43 @@ internal class UtilitiesTest {
assertThat(sources == expectedSources).isTrue
}

@Test
fun testXmlToString() {
val mockTransformerFactory = mockk<TransformerFactory>()
val mockTransformer = mockk<Transformer>()
val mockConfigureTransformer = mockk<(Transformer) -> Unit>()

every { mockTransformerFactory.newTransformer() } returns mockTransformer

val document = createMockDocument()
val rootElement = document.createElement("root")
document.appendChild(rootElement)

val domSource = DOMSource(rootElement)

every { mockTransformer.setOutputProperty(any(), any()) } just Runs
every { mockTransformer.transform(domSource, any()) } just Runs
every { mockConfigureTransformer.invoke(any()) } just Runs

val output = xmlToString(domSource, mockConfigureTransformer)

assertEquals("<root/>", output)
}

private fun createMockDocument(): Document {
val documentBuilderFactory = DocumentBuilderFactory.newInstance()
val documentBuilder = documentBuilderFactory.newDocumentBuilder()
return documentBuilder.newDocument()
}
private fun xmlToString(domSource: DOMSource, configureTransformer: (Transformer) -> Unit = {}): String {
val writer = StringWriter()
val result = StreamResult(writer)
val tf = TransformerFactory.newInstance()
val transformer = tf.newTransformer()
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes")
configureTransformer(transformer)
transformer.transform(domSource, result)
return writer.toString()
}

}
0