Fix sonar issues
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / test / java / org / onap / blueprintgenerator / test / ExternalCertificateParametersFactoryServiceTest.java
1 /*============LICENSE_START=======================================================
2 org.onap.dcae
3 ================================================================================
4 Copyright (c) 2020-2021 Nokia Intellectual Property. All rights reserved.
5 Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
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
21 package org.onap.blueprintgenerator.test;
22
23 import org.onap.blueprintgenerator.constants.Constants;
24 import org.onap.blueprintgenerator.model.common.ExternalCertificateParameters;
25 import org.onap.blueprintgenerator.service.common.ExternalCertificateParametersFactoryService;
26 import org.junit.Test;
27 import org.springframework.beans.factory.annotation.Autowired;
28
29 import java.util.Map;
30
31 import static org.junit.Assert.assertEquals;
32 import static org.onap.blueprintgenerator.constants.Constants.COMMON_NAME_FIELD;
33 import static org.onap.blueprintgenerator.constants.Constants.SANS_FIELD;
34
35 /**
36  * Test for External Certificate Parameters Factory Service
37  */
38 public class ExternalCertificateParametersFactoryServiceTest extends BlueprintGeneratorTests {
39
40     private static final String PREFIXED_COMMON_NAME_FIELD =
41         Constants.INPUT_PREFIX + COMMON_NAME_FIELD;
42     private static final String PREFIXED_SANS_FIELD = Constants.INPUT_PREFIX + SANS_FIELD;
43     private static final String DEFAULT = "default";
44
45     @Autowired
46     private ExternalCertificateParametersFactoryService externalCertificateParametersFactoryService;
47
48     /**
49      * Test case to create  External Certificate Properties
50      *
51      */
52     @Test
53     public void shouldCreateExternalCertificatePropertiesObject() {
54
55         ExternalCertificateParameters result = externalCertificateParametersFactoryService.create();
56         assertEquals(result.getCommonName().getBpInputName(), PREFIXED_COMMON_NAME_FIELD);
57         assertEquals(result.getSans().getBpInputName(), PREFIXED_SANS_FIELD);
58     }
59
60     /**
61      * Test case to create Correct Input List with Default Values from Component Spec
62      *
63      */
64     @Test
65     public void shouldCreateCorrectInputListWithDefaultValuesTakenFromComponentSpec() {
66
67         Map<String, Map<String, Object>> result =
68             externalCertificateParametersFactoryService.createInputList();
69         assertEquals(
70             Constants.DEFAULT_COMMON_NAME, result.get(PREFIXED_COMMON_NAME_FIELD).get(DEFAULT));
71         assertEquals(Constants.DEFAULT_SANS, result.get(PREFIXED_SANS_FIELD).get(DEFAULT));
72     }
73 }