60faa760ba49355dd5da292542a1e07332690a21
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / openstack / utils / MsoHeatEnvironmentEntryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.mso.openstack.utils;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import org.junit.Test;
26
27 public class MsoHeatEnvironmentEntryTest {
28
29     private static final String PARAMETER_NAME = "keyTest";
30     private static final String VALUE_NAME = "valueTest";
31     private static final String NOT_EXISTING_PARAM = "notExistingParam";
32     private static final String RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY = "parameters: {"
33             + PARAMETER_NAME + ": " + VALUE_NAME + "}";
34     private static final String RAW_ENTRY_WITH_RESOURCE_REGISTRY = "resource_registry: resourceTest";
35     private static final String RAW_ENTRY_INVALID = "invalidRawEntry";
36     private static final String WHITESPACE = " ";
37
38     @Test
39     public void createObjectWithNullStringBuilder() {
40         MsoHeatEnvironmentEntry testedObject = MsoHeatEnvironmentEntry.create(null);
41         assertThat(testedObject.getRawEntry()).isNull();
42         assertThat(testedObject.containsParameter(PARAMETER_NAME)).isFalse();
43         assertThat(testedObject.isValid()).isTrue();
44     }
45
46     @Test
47     public void toFullString_ResourceRegistryNotPresentInRawEntry() {
48         MsoHeatEnvironmentEntry testedObject = MsoHeatEnvironmentEntry.create(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY);
49         assertThat(testedObject.getRawEntry()).isEqualTo(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY);
50         assertThat(testedObject.isValid()).isTrue();
51         assertThat(testedObject.containsParameter(PARAMETER_NAME)).isTrue();
52         assertThat(testedObject.toString()).contains(PARAMETER_NAME).contains(VALUE_NAME);
53     }
54
55     @Test
56     public void toFullString_ResourceRegistryPresentInRawEntry() {
57         MsoHeatEnvironmentEntry testedObject = MsoHeatEnvironmentEntry.create(RAW_ENTRY_WITH_RESOURCE_REGISTRY);
58         assertThat(testedObject.getRawEntry()).isEqualTo(RAW_ENTRY_WITH_RESOURCE_REGISTRY);
59         assertThat(testedObject.containsParameter(PARAMETER_NAME)).isFalse();
60         assertThat(testedObject.isValid()).isTrue();
61         assertThat(testedObject.toString()).contains(RAW_ENTRY_WITH_RESOURCE_REGISTRY);
62     }
63
64     @Test
65     public void toFullString_ExceptionOccurred() {
66         MsoHeatEnvironmentEntry testedObject = MsoHeatEnvironmentEntry.create(RAW_ENTRY_INVALID);
67         assertThat(testedObject.getRawEntry()).isEqualTo(RAW_ENTRY_INVALID);
68         assertThat(testedObject.isValid()).isFalse();
69         assertThat(testedObject.getErrorString()).isNotNull().isNotEmpty();
70     }
71
72     @Test
73     public void checkIfContainsTheParameter() {
74         MsoHeatEnvironmentEntry testedObject = MsoHeatEnvironmentEntry.create(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY);
75         assertThat(testedObject.containsParameter(PARAMETER_NAME)).isTrue();
76         assertThat(testedObject.containsParameter(NOT_EXISTING_PARAM)).isFalse();
77     }
78
79 }