import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
@RunWith(SpringRunner::class)
@ContextConfiguration(
assertEquals("https://localhost:8443", p.url)
}
+ @Test
+ fun testSSLNoDefHeadersPropertiesAsJson() {
+ val actualObj: JsonNode = defaultMapper.readTree(sslNoDefHeadersField())
+ val properties = bluePrintRestLibPropertyService.restClientProperties(
+ actualObj
+ )
+ assertNotNull(properties, "failed to create property bean")
+
+ val p: SSLRestClientProperties =
+ properties as SSLRestClientProperties
+
+ assertEquals("src/test/resources/keystore.p12", p.sslTrust)
+ assertEquals("changeit", p.sslTrustPassword)
+ assertEquals("PKCS12", p.keyStoreInstance)
+ assertEquals("src/test/resources/keystore.p12", p.sslKey)
+ assertEquals("changeit", p.sslKeyPassword)
+ assertEquals("ssl-no-def-headers", p.type)
+ assertEquals("https://localhost:8443", p.url)
+ assertTrue(p.values.containsKey("type"))
+ }
+
+ @Test
+ fun testNoDefHeadersPropertiesAsJson() {
+ val actualObj: JsonNode = defaultMapper.readTree(noDefaultHeadersField())
+ val p = bluePrintRestLibPropertyService.restClientProperties(
+ actualObj
+ )
+ assertNotNull(p, "failed to create property bean")
+
+ assertEquals("no-def-headers", p.type)
+ assertEquals("http://127.0.0.1:8000", p.url)
+ assertTrue(p.values.containsKey("type"))
+ }
+
@Test
fun testBlueprintWebClientService() {
val blueprintWebClientService = bluePrintRestLibPropertyService
assertNotNull(blueprintWebClientService, "failed to create blueprintWebClientService")
}
+ @Test
+ fun testNoHeadersForNoDefaultHeaderService() {
+ val actualObj: JsonNode = defaultMapper.readTree(noDefaultHeadersField())
+ val blueprintWebClientService = bluePrintRestLibPropertyService
+ .blueprintWebClientService(actualObj)
+ assertEquals(0, blueprintWebClientService.defaultHeaders().size)
+ }
+
+ @Test
+ fun testNoHeadersForSSLNoDefaultHeaderService() {
+ val actualObj: JsonNode = defaultMapper.readTree(sslNoDefHeadersField())
+ val blueprintWebClientService = bluePrintRestLibPropertyService
+ .blueprintWebClientService(actualObj)
+ assertEquals(0, blueprintWebClientService.defaultHeaders().size)
+ }
+
// pass the result of $typeEndpointWithHeadersField() output with and without headers to compare.
private fun validateHeadersDidNotChangeWithEmptyAdditionalHeaders(noHeaders: String, withHeaders: String) {
val parsedObj: JsonNode = defaultMapper.readTree(noHeaders)
}
""".trimIndent()
+ private fun sslNoDefHeadersField(): String = """{
+ "type" : "ssl-no-def-headers",
+ "url" : "https://localhost:8443",
+ "keyStoreInstance" : "PKCS12",
+ "sslTrust" : "src/test/resources/keystore.p12",
+ "sslTrustPassword" : "changeit",
+ "sslKey" : "src/test/resources/keystore.p12",
+ "sslKeyPassword" : "changeit"
+ }
+ """.trimIndent()
+
// Don't forget to supply "," as the first char to make valid JSON
private fun basicAuthEndpointWithHeadersField(headers: String = ""): String =
"""{
}
""".trimIndent()
+ private fun noDefaultHeadersField(): String =
+ """{
+ "type": "no-def-headers",
+ "url": "http://127.0.0.1:8000"
+ }
+ """.trimIndent()
+
private val emptyAdditionalHeaders = """,
"additionalHeaders" : {
}