diff options
author | Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> | 2022-10-11 09:59:57 +0200 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> | 2022-10-25 07:01:33 +0000 |
commit | 1c887f8ea35f836ec57a9ba6ea5d6d04093ed051 (patch) | |
tree | 4fd708549629041483b6b85642e2df16efa33a8e /ms/blueprintsprocessor/modules/commons/rest-lib/src/test | |
parent | fe6da442cfdf37a4f47d9e7be65c797ae261e91f (diff) |
Add Rest client that do not add any default headers
In consequence we can specify client without default
headers. Still, we can specify additional headers in
the client properties. We can use data disctionary
definition to add extra headers. Sice Kohn we can also
template the headers section in the data dictionary so
ssuch headers can be created dynamically.
Issue-ID: CCSDK-3787
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: I14c219251e11733c7cdfe059c87717f6b0fded0d
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/rest-lib/src/test')
-rw-r--r-- | ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt index 0d187fbc2..64f3f10ac 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt @@ -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( @@ -198,6 +199,40 @@ class BluePrintRestLibPropertyServiceTest { } @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 .blueprintWebClientService("sample") @@ -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" : { } |