2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2019 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.config.impl.gsonadapters
22 import com.google.gson.JsonDeserializationContext
23 import com.google.gson.JsonParser
24 import com.google.gson.reflect.TypeToken
25 import com.nhaarman.mockitokotlin2.mock
26 import org.assertj.core.api.Assertions
27 import org.jetbrains.spek.api.Spek
28 import org.jetbrains.spek.api.dsl.describe
29 import org.jetbrains.spek.api.dsl.given
30 import org.jetbrains.spek.api.dsl.it
32 internal object SecurityAdapterTest : Spek({
34 describe("deserialization") {
35 val gson = JsonParser()
36 val context = mock<JsonDeserializationContext>()
37 val someType = TypeToken.get(SecurityAdapter::class.java).type
39 val cut = SecurityAdapter()
41 given("empty security object") {
42 val json = gson.parse("{}")
44 it("should parse json to security configuration without keys") {
45 val deserialized = cut.deserialize(json, someType, context)
47 Assertions.assertThat(deserialized.keys.isEmpty()).isTrue()
51 given("valid security object with ssl disabled") {
53 given("security keys missing") {
54 val json = gson.parse(SECURITY_WITH_SSL_DISABLED_AND_KEYS_MISSING)
56 it("should parse json to security configuration without keys") {
57 val deserialized = cut.deserialize(json, someType, context)
59 Assertions.assertThat(deserialized.keys.isEmpty()).isTrue()
63 given("security keys provided") {
64 val json = gson.parse(SECURITY_WITH_SSL_DISABLED_AND_KEYS_PROVIDED)
66 it("should parse json to security configuration without keys") {
67 val deserialized = cut.deserialize(json, someType, context)
69 Assertions.assertThat(deserialized.keys.isEmpty()).isTrue()
74 given("valid security object with missing sslDisable key") {
75 val json = gson.parse(MISSING_SSL_DISABLE_ENTRY)
77 it("should return parse json to security configuration") {
78 val deserialized = cut.deserialize(json, someType, context)
80 Assertions.assertThat(deserialized.keys.isDefined()).isTrue()
84 given("valid security object with ssl enabled") {
85 val json = gson.parse(VALID_SECURITY_WITH_SSL_ENABLED)
87 it("should return parse json to security configuration") {
88 val deserialized = cut.deserialize(json, someType, context)
90 Assertions.assertThat(deserialized.keys.isDefined()).isTrue()
96 val SECURITY_WITH_SSL_DISABLED_AND_KEYS_MISSING = """
102 val SECURITY_WITH_SSL_DISABLED_AND_KEYS_PROVIDED = """
106 "keyStoreFile": "test.ks.pkcs12",
107 "keyStorePassword": "changeMe",
108 "trustStoreFile": "trust.ks.pkcs12",
109 "trustStorePassword": "changeMeToo"
114 val MISSING_SSL_DISABLE_ENTRY = """
117 "keyStoreFile": "test.ks.pkcs12",
118 "keyStorePassword": "changeMe",
119 "trustStoreFile": "trust.ks.pkcs12",
120 "trustStorePassword": "changeMeToo"
125 val VALID_SECURITY_WITH_SSL_ENABLED = """
129 "keyStoreFile": "test.ks.pkcs12",
130 "keyStorePassword": "changeMe",
131 "trustStoreFile": "trust.ks.pkcs12",
132 "trustStorePassword": "changeMeToo"