diff options
Diffstat (limited to 'adapters/mso-adapter-utils/src/test/java/org')
2 files changed, 98 insertions, 23 deletions
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java index 6bd78153b6..250211845f 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java @@ -22,18 +22,15 @@ package org.openecomp.mso.adapter_utils.tests; import static org.junit.Assert.assertTrue;
-import com.woorea.openstack.heat.model.Stack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.openecomp.mso.entity.MsoRequest;
-import org.openecomp.mso.openstack.beans.HeatStatus;
import org.openecomp.mso.openstack.beans.MsoTenant;
import org.openecomp.mso.openstack.beans.NetworkRollback;
import org.openecomp.mso.openstack.beans.Pool;
-import org.openecomp.mso.openstack.beans.StackInfo;
import org.openecomp.mso.openstack.beans.Subnet;
import org.openecomp.mso.openstack.beans.VnfRollback;
@@ -99,26 +96,6 @@ public class AdapterBeansTest { }
@Test
- public final void stackInfoTest() {
- StackInfo stackInfo = new StackInfo();
- new StackInfo(new Stack());
- new StackInfo("name", HeatStatus.CREATED, "statusmessage", new HashMap<>());
- new StackInfo("name", HeatStatus.CREATED);
- stackInfo.setCanonicalName("Canonicalname");
- stackInfo.getCanonicalName();
- stackInfo.setName("name");
- stackInfo.getName();
- stackInfo.setOutputs(new HashMap<>());
- stackInfo.getOutputs();
- stackInfo.setParameters(new HashMap<>());
- stackInfo.getParameters();
- stackInfo.setStatus(HeatStatus.CREATED);
- stackInfo.getStatus();
- stackInfo.setStatusMessage("statusMessage");
- stackInfo.getStatusMessage();
- }
-
- @Test
public final void subnetTest() {
Subnet subnet = new Subnet();
subnet.setAllocationPools(new ArrayList<>());
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/StackInfoTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/StackInfoTest.java new file mode 100644 index 0000000000..9c7911ef89 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/StackInfoTest.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.openstack.beans; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.woorea.openstack.heat.model.Stack; +import java.io.IOException; +import org.codehaus.jackson.JsonNode; +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.Test; + +public class StackInfoTest { + + private static final String STACK_NAME = "stackNameTest"; + private static final String STACK_STATUS = "CREATE_COMPLETE"; + private static final String STACK_OUTPUT_KEY = "outputKeyTest"; + private static final String STACK_OUTPUT_VALUE = "outputValueTest"; + private static final String STACK_PARAM_KEY = "paramKeyTest"; + private static final String STACK_PARAM_VALUE = "paramValueTest"; + + @Test + public void setStatusNotFoundWhenStackIsNull() { + StackInfo stackInfo = new StackInfo(null); + assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.NOTFOUND); + assertThat(stackInfo.getOutputs()).isEmpty(); + assertThat(stackInfo.getParameters()).isEmpty(); + } + + @Test + public void createObjectWhenStackStatusIsNull() { + StackInfo stackInfo = new StackInfo(createStackWithStatus(null)); + assertThat(stackInfo.getName()).isEqualTo(STACK_NAME); + assertThat(stackInfo.getOutputs()).isEmpty(); + assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.INIT); + assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE); + } + + @Test + public void createObjectWhenStackStatusIsFound() { + StackInfo stackInfo = new StackInfo(createStackWithStatus(STACK_STATUS)); + assertThat(stackInfo.getName()).isEqualTo(STACK_NAME); + assertThat(stackInfo.getOutputs()).isEmpty(); + assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.CREATED); + assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE); + } + + @Test + public void createObjectWhenStackStatusIsUnknown() { + StackInfo stackInfo = new StackInfo(createStackWithStatus("unknownStatus")); + assertThat(stackInfo.getName()).isEqualTo(STACK_NAME); + assertThat(stackInfo.getOutputs()).isEmpty(); + assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.UNKNOWN); + assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE); + } + + @Test + public void createStackWhenOutputsListIsNotNull() throws IOException { + StackInfo stackInfo = new StackInfo(createStackWithOutputs()); + assertThat(stackInfo.getOutputs()).isNotEmpty().hasSize(1); + assertThat(stackInfo.getOutputs()).hasSize(1).containsEntry(STACK_OUTPUT_KEY, STACK_OUTPUT_VALUE); + } + + private Stack createStackWithStatus(String stackStatus) { + Stack stack = new Stack(); + stack.setStackName(STACK_NAME); + stack.setStackStatus(stackStatus); + stack.getParameters().put(STACK_PARAM_KEY, STACK_PARAM_VALUE); + return stack; + } + + private Stack createStackWithOutputs() throws IOException { + String json = "{\"outputs\":[{\"output_key\" : \"" + STACK_OUTPUT_KEY + "\", \"output_value\" : \"" + + STACK_OUTPUT_VALUE + "\" }]}"; + JsonNode node = new ObjectMapper().readTree(json); + Stack stack = new ObjectMapper().readValue(node, Stack.class); + return stack; + } + +} |