Add Rest client that do not add any default headers
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / rest-lib / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / rest / service / BluePrintRestLibPropertyServiceTest.kt
index 0d187fb..64f3f10 100644 (file)
@@ -39,6 +39,7 @@ import org.springframework.test.context.junit4.SpringRunner
 import kotlin.test.assertEquals
 import kotlin.test.assertFailsWith
 import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
 
 @RunWith(SpringRunner::class)
 @ContextConfiguration(
@@ -197,6 +198,40 @@ class BluePrintRestLibPropertyServiceTest {
         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
@@ -215,6 +250,22 @@ class BluePrintRestLibPropertyServiceTest {
         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)
@@ -480,6 +531,17 @@ class BluePrintRestLibPropertyServiceTest {
         }
         """.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 =
             """{
@@ -490,6 +552,13 @@ class BluePrintRestLibPropertyServiceTest {
             }
             """.trimIndent()
 
+        private fun noDefaultHeadersField(): String =
+            """{
+              "type": "no-def-headers",
+              "url": "http://127.0.0.1:8000"
+            }
+            """.trimIndent()
+
         private val emptyAdditionalHeaders = """,
           "additionalHeaders" : {
           }