2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.openecomp.mso.openstack.utils;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import org.junit.Test;
27 public class MsoHeatEnvironmentEntryTest {
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";
38 public void createObjectWithNullStringBuilder() {
39 MsoHeatEnvironmentEntry testedObject = new MsoHeatEnvironmentEntry(null);
40 assertThat(testedObject.isValid()).isTrue();
41 assertThat(testedObject.getRawEntry()).isNull();
42 assertThat(testedObject.containsParameter(PARAMETER_NAME)).isFalse();
46 public void toFullString_ResourceRegistryNotPresentInRawEntry() {
47 StringBuilder sb = new StringBuilder(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY);
48 MsoHeatEnvironmentEntry testedObject = new MsoHeatEnvironmentEntry(sb);
49 assertThat(testedObject.getRawEntry()).isEqualTo(sb);
50 assertThat(testedObject.isValid()).isTrue();
51 assertThat(testedObject.containsParameter(PARAMETER_NAME)).isTrue();
52 assertThat(testedObject.toString()).doesNotContain(RAW_ENTRY_WITH_RESOURCE_REGISTRY);
56 public void toFullString_ExceptionOccurred() {
57 StringBuilder sb = new StringBuilder(RAW_ENTRY_INVALID);
58 MsoHeatEnvironmentEntry testedObject = new MsoHeatEnvironmentEntry(sb);
59 assertThat(testedObject.getRawEntry()).isEqualTo(sb);
60 assertThat(testedObject.isValid()).isFalse();
61 assertThat(testedObject.getErrorString()).isNotNull().isNotEmpty();
65 public void checkIfContainsTheParameter() {
66 StringBuilder sb = new StringBuilder(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY);
67 MsoHeatEnvironmentEntry testedObject = new MsoHeatEnvironmentEntry(sb);
68 assertThat(testedObject.getRawEntry()).isEqualTo(sb);
69 assertThat(testedObject.isValid()).isTrue();
70 assertThat(testedObject.containsParameter(PARAMETER_NAME)).isTrue();
71 assertThat(testedObject.containsParameter(NOT_EXISTING_PARAM)).isFalse();