Merge "Refactor, fix code formatting and add unittests"
[dcaegen2/platform.git] / mod / bpgenerator / src / test / java / org / onap / blueprintgenerator / models / blueprint / tls / ExternalCertificateParametersFactoryTest.java
1 /*============LICENSE_START=======================================================
2  org.onap.dcae
3  ================================================================================
4  Copyright (c) 2020 Nokia Intellectual Property. All rights reserved.
5  ================================================================================
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9
10  http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.blueprintgenerator.models.blueprint.tls;
21
22 import org.junit.Test;
23 import org.onap.blueprintgenerator.models.blueprint.tls.impl.ExternalCertificateParameters;
24
25 import java.util.LinkedHashMap;
26 import java.util.Map;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.COMMON_NAME_FIELD;
30 import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.DEFAULT_COMMON_NAME;
31 import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.DEFAULT_SANS;
32 import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.INPUT_PREFIX;
33 import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.SANS_FIELD;
34
35 public class ExternalCertificateParametersFactoryTest {
36
37     private static final String PREFIXED_COMMON_NAME_FIELD = INPUT_PREFIX + COMMON_NAME_FIELD;
38     private static final String PREFIXED_SANS_FIELD = INPUT_PREFIX + SANS_FIELD;
39     private static final String DEFAULT = "default";
40
41     @Test
42     public void shouldCreateExternalCertificatePropertiesObject() {
43         // given
44         ExternalCertificateParametersFactory cut = new ExternalCertificateParametersFactory();
45         // when
46         ExternalCertificateParameters result = cut.create();
47         // then
48         assertEquals(result.getCommonName().getBpInputName(), PREFIXED_COMMON_NAME_FIELD);
49         assertEquals(result.getSans().getBpInputName(), PREFIXED_SANS_FIELD);
50     }
51
52     @Test
53     public void shouldCreateCorrectInputListWithDefaultValuesTakenFromComponentSpec() {
54         // given
55         ExternalCertificateParametersFactory cut = new ExternalCertificateParametersFactory();
56         // when
57         Map<String, LinkedHashMap<String, Object>> result = cut.createInputList();
58         // then
59         assertEquals(DEFAULT_COMMON_NAME, result.get(PREFIXED_COMMON_NAME_FIELD).get(DEFAULT));
60         assertEquals(DEFAULT_SANS, result.get(PREFIXED_SANS_FIELD).get(DEFAULT));
61     }
62 }