Use CBS by means of SDK in place of Consul
[dcaegen2/collectors/hv-ves.git] / sources / hv-collector-ssl / src / test / kotlin / org / onap / dcae / collectors / veshv / ssl / boundary / SecurityUtilsTest.kt
1 /*
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.ssl.boundary
21
22 import com.nhaarman.mockitokotlin2.doReturn
23 import com.nhaarman.mockitokotlin2.mock
24 import com.nhaarman.mockitokotlin2.verify
25 import com.nhaarman.mockitokotlin2.whenever
26 import org.apache.commons.cli.CommandLine
27 import org.assertj.core.api.Assertions.assertThat
28 import org.jetbrains.spek.api.Spek
29 import org.jetbrains.spek.api.dsl.describe
30 import org.jetbrains.spek.api.dsl.it
31 import org.jetbrains.spek.api.dsl.on
32 import org.onap.dcae.collectors.veshv.commandline.CommandLineOption
33 import org.onap.dcae.collectors.veshv.commandline.hasOption
34
35
36 internal object SecurityUtilsTest : Spek({
37
38     describe("creating securty configuration provider") {
39
40         on("command line without ssl disable") {
41             val commandLine: CommandLine = mock()
42             whenever(commandLine.hasOption(CommandLineOption.SSL_DISABLE)).doReturn(false)
43
44             it("should create configuration with some keys") {
45                 val configuration = createSecurityConfiguration(commandLine)
46
47                 verify(commandLine).hasOption(CommandLineOption.SSL_DISABLE)
48                 assertThat(configuration.isSuccess()).isTrue()
49                 configuration.map { assertThat(it.keys.isDefined()).isTrue() }
50             }
51         }
52         on("command line with ssl disabled") {
53             val commandLine: CommandLine = mock()
54             whenever(commandLine.hasOption(CommandLineOption.SSL_DISABLE)).doReturn(true)
55
56             it("should create configuration without keys") {
57                 val configuration = createSecurityConfiguration(commandLine)
58
59                 verify(commandLine).hasOption(CommandLineOption.SSL_DISABLE)
60                 assertThat(configuration.isSuccess()).isTrue()
61                 configuration.map { assertThat(it.keys.isEmpty()).isTrue() }
62             }
63         }
64     }
65 })