summaryrefslogtreecommitdiffstats
path: root/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test')
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/TestStackResource.java52
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/CommonUtility.java72
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/RequestFailedExceptionTest.java145
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestIdentityUrl.java100
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderAdapterImpl.java497
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderCache.java118
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderOperation.java141
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestRequestContext.java162
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalog.java96
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogFactory.java120
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogV2.java293
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogV3.java279
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestTenantCache.java246
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestVMURL.java135
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/api/ProviderOperationFactoryTest.java179
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/AttachVolumeServerTest.java72
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/DettachVolumeServerTest.java101
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/MockGenerator.java167
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestCreateSnapshot.java68
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestEvacuateServer.java114
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestLookupServer.java57
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestMigrateServer.java82
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRebootServer.java92
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRebuildServer.java158
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRestartServer.java90
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRestoreStack.java93
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestSnapshotStack.java71
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestStartServer.java66
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestStopServer.java66
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestTerminateServer.java68
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestTerminateStack.java71
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestVmStatuschecker.java124
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderOperation.java338
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderServerOperation.java592
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderStackOperation.java199
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestCreateSnapshotParams.java49
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestData.java129
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestEnvironment.java62
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestMetadata.java43
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestParameters.java43
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestProperties.java49
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResourceData.java48
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResourceRegistry.java46
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources.java42
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources_.java49
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources__.java52
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshot.java86
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshotDetails.java53
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshotRestoreResponse.java63
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestTemplate.java58
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestVolume.java60
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestVolume_.java94
-rw-r--r--adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/resources/default.properties112
53 files changed, 6462 insertions, 0 deletions
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/TestStackResource.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/TestStackResource.java
new file mode 100644
index 000000000..36d71c1e7
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/TestStackResource.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas;
+
+import com.woorea.openstack.base.client.OpenStackClient;
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.openstack.heat.StackResource;
+import org.powermock.reflect.internal.WhiteboxImpl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class TestStackResource {
+
+ private StackResource stackResource;
+ private OpenStackClient client;
+
+ @Test
+ public void testShow() {
+ stackResource = new StackResource(client);
+ assertNotNull(stackResource.show("stackName", "123"));
+ }
+
+ @Test
+ public void testShowStack() throws Exception {
+ stackResource = new StackResource(client);
+ StackResource.ShowStack showStack = stackResource.new ShowStack("stackName", "111");
+ StringBuilder path = WhiteboxImpl.getInternalState(showStack, "path");
+ assertEquals("/stacks/stackName/111", path.toString());
+ assertNotNull(stackResource.new ShowStack("stackName", "111"));
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/CommonUtility.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/CommonUtility.java
new file mode 100644
index 000000000..825c65ce6
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/CommonUtility.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import java.lang.reflect.Field;
+import java.util.Map;
+
+/**
+ * This class is used as a utility class to support the test cases.
+ */
+public class CommonUtility {
+
+ /**
+ * Use reflection to locate fields and methods so that they can be manipulated during the test
+ * to change the internal state accordingly.
+ *
+ * @param privateFields
+ * @param object
+ *
+ */
+ public static void injectMockObjects(Map<String, Object> privateFields, Object object) {
+ privateFields.forEach((fieldName, fieldInstance) -> {
+ try {
+ Field privateField = object.getClass().getDeclaredField(fieldName);
+ privateField.setAccessible(true);
+ privateField.set(object, fieldInstance);
+ } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
+ // Exception occurred while accessing the private fields
+ }
+ });
+ }
+
+ /**
+ * Use reflection to locate fields and methods of the base class so that they can be manipulated
+ * during the test to change the internal state accordingly.
+ *
+ * @param privateFields
+ * @param catalogObject
+ *
+ */
+ public static void injectMockObjectsInBaseClass(Map<String, Object> privateFields, Object catalogObject) {
+ // For base class
+ privateFields.forEach((fieldName, fieldInstance) -> {
+ try {
+ Field privateField = catalogObject.getClass().getSuperclass().getDeclaredField(fieldName);
+ privateField.setAccessible(true);
+ privateField.set(catalogObject, fieldInstance);
+ } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
+ // Exception occurred while accessing the private fields
+ }
+ });
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/RequestFailedExceptionTest.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/RequestFailedExceptionTest.java
new file mode 100644
index 000000000..e02afeb1c
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/RequestFailedExceptionTest.java
@@ -0,0 +1,145 @@
+/*-
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright (C) 2018 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Stack;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * This class is used to test methods and functions of the Request Failed Exception class
+ */
+public class RequestFailedExceptionTest {
+
+ @Test
+ public void testRequestFailedException() {
+ RequestFailedException requestFailedException = new RequestFailedException();
+ Assert.assertNull(requestFailedException.getCause());
+ Assert.assertNull(requestFailedException.getLocalizedMessage());
+ Assert.assertNull(requestFailedException.getMessage());
+ }
+
+ @Test
+ public void testRequestFailedExceptionString() {
+ String message = "my test message";
+ RequestFailedException requestFailedException = new RequestFailedException(message);
+ Assert.assertNull(requestFailedException.getCause());
+ Assert.assertEquals(message, requestFailedException.getLocalizedMessage());
+ Assert.assertEquals(message, requestFailedException.getMessage());
+ }
+
+ @Test
+ public void testRequestFailedExceptionStringStringHttpStatusServer() {
+ Server server=new Server();
+ server.setId("svrId");
+ HttpStatus status=HttpStatus.OK_200;
+ String reason="Success";
+ String operation="POST";
+ RequestFailedException requestFailedException = new RequestFailedException(operation, reason, status, server);
+ requestFailedException.setOperation(operation);
+ requestFailedException.setReason(reason);
+ requestFailedException.setServerId("svrId");
+ requestFailedException.setStatus(status);
+ requestFailedException.setServer(server);
+ Assert.assertEquals("POST",requestFailedException.getOperation());
+ Assert.assertEquals("Success",requestFailedException.getReason());
+ Assert.assertEquals("svrId",requestFailedException.getServerId());
+ Assert.assertEquals( HttpStatus.OK_200,requestFailedException.getStatus());
+ Assert.assertEquals(server, requestFailedException.getServer());
+ }
+
+ @Test
+ public void testRequestFailedExceptionStringStringHttpStatusStack() {
+ String operation="POST";
+ String reason="Success";
+ HttpStatus status=HttpStatus.OK_200;
+ Stack stack = new Stack();
+ RequestFailedException requestFailedException = new RequestFailedException(operation, reason, status, stack);
+ requestFailedException.setOperation(operation);
+ requestFailedException.setReason(reason);
+ requestFailedException.setStatus(status);
+ Assert.assertEquals("POST",requestFailedException.getOperation());
+ Assert.assertEquals("Success",requestFailedException.getReason());
+ Assert.assertEquals( HttpStatus.OK_200,requestFailedException.getStatus());
+ }
+
+ @Test
+ public void testRequestFailedExceptionThrowableStringStringHttpStatusServer() {
+ String tMessage = "throwable message";
+ Server server=new Server();
+ HttpStatus status=HttpStatus.ACCEPTED_202;
+ String reason="Success";
+ String operation="POST";
+ Throwable throwable = new Throwable(tMessage);
+ RequestFailedException requestFailedException = new RequestFailedException(throwable,operation,reason, status, server);
+ Assert.assertEquals(throwable, requestFailedException.getCause());
+ }
+
+ @Test
+ public void testRequestFailedExceptionStringThrowable() {
+ String message = "my test message";
+ String tMessage = "throwable message";
+ Throwable throwable = new Throwable(tMessage);
+ RequestFailedException requestFailedException = new RequestFailedException(message, throwable);
+ Assert.assertEquals(throwable, requestFailedException.getCause());
+ Assert.assertTrue(requestFailedException.getLocalizedMessage().contains(message));
+ Assert.assertTrue(requestFailedException.getMessage().contains(message));
+ }
+
+ @Test
+ public void testRequestFailedExceptionStringThrowableBooleanBoolean() {
+ String message = "my test message";
+ String tMessage = "throwable message";
+ Throwable throwable = new Throwable(tMessage);
+ RequestFailedException requestFailedException = new RequestFailedException(message, throwable, true, true);
+ Assert.assertEquals(throwable, requestFailedException.getCause());
+ Assert.assertTrue(requestFailedException.getLocalizedMessage().contains(message));
+ Assert.assertTrue(requestFailedException.getMessage().contains(message));
+ }
+
+ @Test
+ public void testRequestFailedExceptionThrowable() {
+ String message = "my test message";
+ Throwable throwable = new Throwable(message);
+ RequestFailedException requestFailedException = new RequestFailedException(throwable);
+ Assert.assertEquals(throwable, requestFailedException.getCause());
+ Assert.assertTrue(requestFailedException.getLocalizedMessage().contains(message));
+ Assert.assertTrue(requestFailedException.getMessage().contains(message));
+ }
+
+ /**
+ * This test case is used to test the request failed exception class without server
+ *
+ */
+ @Test
+ public void testRequestFailedExceptionThrowableStringWithoutServer() {
+ String tMessage = "throwable message";
+ Server server = null;
+ HttpStatus status = HttpStatus.ACCEPTED_202;
+ String reason = "Success";
+ String operation = "POST";
+ Throwable throwable = new Throwable(tMessage);
+ RequestFailedException requestFailedException = new RequestFailedException(throwable, operation, reason, status, server);
+ Assert.assertEquals(throwable, requestFailedException.getCause());
+ Assert.assertNull(requestFailedException.getServer());
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestIdentityUrl.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestIdentityUrl.java
new file mode 100644
index 000000000..0240e4f96
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestIdentityUrl.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import java.util.Properties;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class TestIdentityUrl {
+
+ private static String URL;
+
+ @BeforeClass
+ public static void before() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ URL = props.getProperty("");
+ }
+
+ /**
+ * Test that we can parse and interpret valid URLs
+ */
+ @Test
+ public void testValidURL1() {
+ URL = "http://192.168.1.1:5000/v2.0/";
+ IdentityURL idurl = IdentityURL.parseURL(URL);
+ assertNotNull(idurl);
+ assertTrue(idurl.getScheme().equals("http"));
+ assertTrue(idurl.getHost().equals("192.168.1.1"));
+ assertTrue(idurl.getPort().equals("5000"));
+ assertNull(idurl.getPath());
+ assertTrue(idurl.getVersion().equals("v2.0"));
+ assertTrue(idurl.toString().equals("http://192.168.1.1:5000/v2.0"));
+ }
+
+ @Test
+ public void testValidURL2() {
+ URL = "https://192.168.1.1:5000/v3/";
+ IdentityURL idurl = IdentityURL.parseURL(URL);
+ assertNotNull(idurl);
+ assertTrue(idurl.getScheme().equals("https"));
+ assertTrue(idurl.getHost().equals("192.168.1.1"));
+ assertTrue(idurl.getPort().equals("5000"));
+ assertNull(idurl.getPath());
+ assertTrue(idurl.getVersion().equals("v3"));
+ assertTrue(idurl.toString().equals("https://192.168.1.1:5000/v3"));
+ }
+
+ @Test
+ public void testValidURL3() {
+ URL = "http://192.168.1.1/v2.0/";
+ IdentityURL idurl = IdentityURL.parseURL(URL);
+ assertNotNull(idurl);
+ assertTrue(idurl.getScheme().equals("http"));
+ assertTrue(idurl.getHost().equals("192.168.1.1"));
+ assertNull(idurl.getPort());
+ assertNull(idurl.getPath());
+ assertTrue(idurl.getVersion().equals("v2.0"));
+ System.out.println(idurl.toString());
+ assertTrue(idurl.toString().equals("http://192.168.1.1/v2.0"));
+ }
+
+ @Test
+ public void testValidURL4() {
+ URL = "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3";
+ IdentityURL idurl = IdentityURL.parseURL(URL);
+ assertNotNull(idurl);
+ assertTrue(idurl.getScheme().equals("http"));
+ assertTrue(idurl.getHost().equals("msb.onap.org"));
+ assertTrue(idurl.getPort().equals("80"));
+ assertTrue(idurl.getPath().equals("/api/multicloud/v0/cloudowner_region/identity"));
+ assertTrue(idurl.getVersion().equals("v3"));
+ assertTrue(idurl.toString().equals("http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3"));
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderAdapterImpl.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderAdapterImpl.java
new file mode 100644
index 000000000..49e5a3812
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderAdapterImpl.java
@@ -0,0 +1,497 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import com.att.cdp.zones.model.Image;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Stack;
+import com.google.common.collect.ImmutableMap;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.sli.adaptors.iaas.ProviderAdapter;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.api.IProviderOperation;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.api.ProviderOperationFactory;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.common.enums.Operation;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.EvacuateServer;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.when;
+
+/**
+ * This class is used to test methods and functions of the adapter implementation that do not
+ * require and do not set up connections to any providers.
+ */
+@Ignore
+@RunWith(MockitoJUnitRunner.class)
+@Category(TestProviderAdapterImpl.class)
+public class TestProviderAdapterImpl {
+
+ @SuppressWarnings("nls")
+ private static final String PROVIDER_NAME = "ILAB";
+
+ @SuppressWarnings("nls")
+ private static final String PROVIDER_TYPE = "OpenStackProvider";
+
+ private static String IDENTITY_URL;
+
+ private static String SERVER_URL;
+
+ private static String SERVER_ID;
+
+ private static Field configField;
+
+ private static ProviderAdapterImpl adapter;
+
+ /**
+ * The Factory.
+ */
+ @Mock
+ ProviderOperationFactory factory;
+
+ /**
+ * The Provider operation.
+ */
+ @Mock
+ IProviderOperation providerOperation;
+
+ /**
+ * The Evacuate server.
+ */
+ @Mock
+ EvacuateServer evacuateServer;
+
+ private SvcLogicContext svcContext;
+
+ private Map<String, String> params;
+
+ private Image image;
+
+ private Server server;
+
+ private Stack stack;
+
+ /**
+ * Use reflection to locate fields and methods so that they can be manipulated during the test
+ * to change the internal state accordingly.
+ *
+ * @throws NoSuchFieldException if the field(s) dont exist
+ * @throws SecurityException if reflective access is not allowed
+ */
+ @SuppressWarnings("nls")
+ @BeforeClass
+ public static void once() throws NoSuchFieldException, SecurityException {
+ Class<?> providerAdapterImplClass = ProviderAdapterImpl.class;
+ Class<?> configurationFactoryClass = ConfigurationFactory.class;
+
+ Field providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
+ providerCacheField.setAccessible(true);
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ IDENTITY_URL = props.getProperty("provider1.identity");
+ SERVER_URL = props.getProperty("test.url");
+ configField = configurationFactoryClass.getDeclaredField("config");
+ configField.setAccessible(true);
+ SERVER_ID = "server1";
+ }
+
+ /**
+ * Use reflection to locate fields and methods so that they can be manipulated during the test
+ * to change the internal state accordingly.
+ *
+ * @throws IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof), or if an unwrapping conversion fails.
+ * @throws IllegalAccessException if this Field object is enforcing Java language access control and the underlying field is either inaccessible or final.
+ */
+ @Before
+ public void setup() throws IllegalArgumentException, IllegalAccessException {
+ configField.set(null, null);
+ Properties properties = new Properties();
+ adapter = new ProviderAdapterImpl(properties);
+ svcContext = new SvcLogicContext();
+ params = new HashMap<>();
+ params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL);
+ params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME);
+ server = new Server();
+ server.setId(SERVER_ID);
+ image = new Image();
+ image.setStatus(Image.Status.ACTIVE);
+ stack = new Stack();
+ stack.setStatus(Stack.Status.ACTIVE);
+ Map<String, Object> privateFields = ImmutableMap.<String, Object>builder().put("factory", factory)
+ .put("providerCache", getProviderCache()).build();
+ CommonUtility.injectMockObjects(privateFields, adapter);
+ }
+
+ private Map<String, ProviderCache> getProviderCache() {
+ Map<String, ProviderCache> providerCache = new HashMap<>();
+ ProviderCache cache = new ProviderCache();
+ cache.setIdentityURL(IDENTITY_URL);
+ cache.setProviderName(PROVIDER_NAME);
+ cache.setProviderType(PROVIDER_TYPE);
+ providerCache.put(cache.getIdentityURL(), cache);
+ return providerCache;
+ }
+
+ /**
+ * This test case is used to invoke the default constructor
+ */
+ @Test
+ public void testDefaultConstructor() {
+ ProviderAdapter adapter = new ProviderAdapterImpl();
+ assertNotNull(adapter);
+ }
+
+ /**
+ * This test case is used to invoke the argument constructor
+ */
+ @Test
+ public void testArgumentedConstructor() {
+ ProviderAdapter adapter = new ProviderAdapterImpl(true);
+ assertNotNull(adapter);
+ }
+
+ /**
+ * Tests that we get the Adapter name
+ */
+ //@Test
+ public void testAdapterName() {
+ assertNotNull(adapter.getAdapterName());
+ }
+
+ /**
+ * This test case is used to restart the server
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the server cannot be restarted for some reason
+ */
+ @Test
+ public void testRestartServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.RESTART_SERVICE, Server.Status.RUNNING);
+ Server actualServer = adapter.restartServer(params, svcContext);
+ assertEquals(Server.Status.RUNNING, actualServer.getStatus());
+ }
+
+ /**
+ * This test case is used to start the server
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the server cannot be started for some reason
+ */
+ @Test
+ public void testStartServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.START_SERVICE, Server.Status.RUNNING);
+ Server actualServer = adapter.startServer(params, svcContext);
+ assertEquals(Server.Status.RUNNING, actualServer.getStatus());
+ }
+
+ /**
+ * This test case is used to stop the server
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the server cannot be stopped for some reason
+ */
+ @Test
+ public void testStopServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.STOP_SERVICE, Server.Status.READY);
+ Server actualServer = adapter.stopServer(params, svcContext);
+ assertEquals(Server.Status.READY, actualServer.getStatus());
+ }
+
+ /**
+ * Tests that the vmStatuschecker method works and returns the correct status of the VM
+ * requested
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the vm status can not be verified
+ */
+ @Test
+ public void testVmStatuschecker()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.VMSTATUSCHECK_SERVICE, Server.Status.READY);
+ Server actualServer = adapter.vmStatuschecker(params, svcContext);
+ assertEquals(Server.Status.READY, actualServer.getStatus());
+ }
+
+ /**
+ * Tests that the terminate stack method works
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the stack cannot be terminated for some reason
+ */
+ @Test
+ public void testTerminateStack()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.TERMINATE_STACK, null);
+ stack.setStatus(Stack.Status.DELETED);
+ Stack actualStack = adapter.terminateStack(params, svcContext);
+ assertEquals(Stack.Status.DELETED, actualStack.getStatus());
+ }
+
+ /**
+ * Tests that the snapshot method works and returns snapshot of the stack
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the stack snapshot can not be taken for some reason
+ */
+ @Test
+ public void testSnapshotStack()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.SNAPSHOT_STACK, null);
+ Stack actualStack = adapter.snapshotStack(params, svcContext);
+ assertEquals(Stack.Status.ACTIVE, actualStack.getStatus());
+ }
+
+ /**
+ * Tests that the restore method works and returns restored stack
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the stack cannot be restored for some reason
+ */
+ @Test
+ public void testRestoreStack()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.RESTORE_STACK, null);
+ Stack actualStack = adapter.restoreStack(params, svcContext);
+ assertEquals(Stack.Status.ACTIVE, actualStack.getStatus());
+ }
+
+ /**
+ * Tests that the lookup server will lookup for the server with server id
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the server cannot be found for some reason
+ */
+ @Test
+ public void testLookupServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.LOOKUP_SERVICE, Server.Status.READY);
+ Server actualServer = adapter.lookupServer(params, svcContext);
+ assertEquals(SERVER_ID, actualServer.getId());
+ }
+
+ /**
+ * Tests that the to create a snapshot and return a image
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the image snapshot can not be taken for some reason
+ */
+ @Test
+ public void testCreateSnapshot()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.SNAPSHOT_SERVICE, Server.Status.READY);
+ Image actualImage = adapter.createSnapshot(params, svcContext);
+ assertEquals(image.getStatus(), actualImage.getStatus());
+ }
+
+ /**
+ * Tests that the to calculate the server volume and attach it to the server
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the Server volume can not be calculated for some reason
+ */
+ @Test
+ public void testAttachVolume()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.ATTACHVOLUME_SERVICE, Server.Status.READY);
+ Server actualServer = adapter.attachVolume(params, svcContext);
+ assertEquals(SERVER_ID, actualServer.getId());
+ }
+
+ /**
+ * Tests that the to detach the calculated volume from the server
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid
+ * @throws SvcLogicException If the Server volume can not be detached for some reason
+ */
+ @Test
+ public void testDettachVolume()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.DETACHVOLUME_SERVICE, Server.Status.READY);
+ Server actualServer = adapter.dettachVolume(params, svcContext);
+ assertEquals(SERVER_ID, actualServer.getId());
+ }
+
+ /**
+ * Tests that we can restart a server that is already stopped
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid.
+ * @throws SvcLogicException If the server cannot be restarted for some reason
+ */
+ @Test
+ public void testRestartStoppedServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.RESTART_SERVICE, Server.Status.RUNNING);
+ Server actualServer = adapter.restartServer(params, svcContext);
+ assertEquals(Server.Status.RUNNING, actualServer.getStatus());
+
+ }
+
+ /**
+ * Tests that we can rebuild a server (not created from a bootable volume)
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid.
+ * @throws SvcLogicException If the provider cannot be found
+ */
+ @Test
+ public void testRebuildServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.REBUILD_SERVICE, Server.Status.READY);
+ Server actualServer = adapter.rebuildServer(params, svcContext);
+ assertEquals(Server.Status.READY, actualServer.getStatus());
+ }
+
+ /**
+ * Tests that we can terminate a running server
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid.
+ * @throws SvcLogicException If the provider cannot be found
+ */
+ @Test
+ public void testTerminateServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.TERMINATE_SERVICE, Server.Status.DELETED);
+ Server actualServer = adapter.terminateServer(params, svcContext);
+ assertEquals(Server.Status.DELETED, actualServer.getStatus());
+ }
+
+ /**
+ * Tests that we can evacuate a server to move it to non-pending state
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid.
+ * @throws SvcLogicException If the provider cannot be found
+ */
+ @Test
+ public void testEvacuateServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.EVACUATE_SERVICE, Server.Status.READY);
+ Server actualServer = adapter.evacuateServer(params, svcContext);
+ assertEquals(Server.Status.READY, actualServer.getStatus());
+ }
+
+ /**
+ * Tests that we can migrate a server. Migration can be done only on certain statuses like
+ * READY, RUNNING & SUSPENDED
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid.
+ * @throws SvcLogicException If the provider cannot be found
+ */
+ @Test
+ public void testMigrateServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.MIGRATE_SERVICE, Server.Status.READY);
+ Server actualServer = adapter.migrateServer(params, svcContext);
+ assertEquals(Server.Status.READY, actualServer.getStatus());
+ }
+
+ /**
+ * Tests that we can reboot a server
+ *
+ * @throws IllegalStateException If the identity service is not available or cannot be created
+ * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if the expected argument(s) are not defined or are invalid.
+ * @throws SvcLogicException If the provider cannot be found
+ */
+ @Test
+ public void testRebootServer()
+ throws IllegalStateException, IllegalArgumentException, SvcLogicException {
+ prepareMock(Operation.REBOOT_SERVICE, Server.Status.READY);
+ Server actualServer = adapter.rebootServer(params, svcContext);
+ assertEquals(Server.Status.READY, actualServer.getStatus());
+ }
+
+ private void prepareMock(Operation operation, Server.Status serverStatus) throws SvcLogicException {
+ IProviderOperation providerOperation = fetchOperation.apply(operation);
+ ModelObject modelObject = fetchModelObject.apply(operation, serverStatus);
+ when(factory.getOperationObject(operation)).thenReturn(providerOperation);
+ when(providerOperation.doOperation(anyObject(), anyObject())).thenReturn(modelObject);
+
+ }
+
+ /**
+ * The Fetch operation.
+ */
+ Function<Operation, IProviderOperation> fetchOperation = operation -> {
+ if (operation.equals(Operation.EVACUATE_SERVICE))
+ return evacuateServer;
+ else
+ return providerOperation;
+ };
+
+ /**
+ * The Fetch server.
+ */
+ Function<Server.Status, Server> fetchServer = status -> {
+ server.setStatus(status);
+ return server;
+ };
+
+ /**
+ * The Fetch model object.
+ */
+ BiFunction<Operation, Server.Status, ModelObject> fetchModelObject = (operation, status) -> {
+ if (operation.equals(Operation.SNAPSHOT_SERVICE))
+ return image;
+ else if (operation == Operation.RESTORE_STACK || operation == Operation.SNAPSHOT_STACK
+ || operation == Operation.TERMINATE_STACK)
+ return stack;
+ else
+ return fetchServer.apply(status);
+ };
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderCache.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderCache.java
new file mode 100644
index 000000000..4a27c1fd8
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderCache.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import com.att.cdp.zones.Context;
+import com.google.common.collect.ImmutableMap;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.sli.adaptors.iaas.Constants;
+import org.onap.ccsdk.sli.core.utils.configuration.Configuration;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+import org.onap.ccsdk.sli.core.utils.pool.Pool;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * This class is used to test methods and functions of the provider cache
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TestProviderCache {
+
+ private ProviderCache providerCache;
+
+ @Mock
+ private TenantCache tenantCache;
+
+ @Mock
+ private ServiceCatalog catalog;
+
+ @Mock
+ private Context context;
+
+ @Mock
+ Pool<Context> pool;
+
+ @SuppressWarnings("nls")
+ private static final String PROVIDER_NAME = "ILAB";
+
+ @SuppressWarnings("nls")
+ private static final String PROVIDER_TYPE = "OpenStackProvider";
+
+ private static String TENANT_ID;
+
+ protected Set<String> regions = new HashSet<>(Arrays.asList("RegionOne"));
+
+ private Map<String, TenantCache> tenants = new HashMap<String, TenantCache>();
+
+ @BeforeClass
+ public static void before() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ TENANT_ID = props.getProperty("provider1.tenant1.id",
+ props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
+ }
+
+ /**
+ * Use reflection to locate fields and methods so that they can be manipulated during the test
+ * to change the internal state accordingly.
+ *
+ */
+ @Before
+ public void setup() {
+ Configuration props = ConfigurationFactory.getConfiguration();
+ props.setProperty(Constants.PROPERTY_RETRY_LIMIT, "10");
+ providerCache = new ProviderCache();
+ providerCache.setIdentityURL("http://192.168.1.1:5000/v2.0/");
+ providerCache.setProviderName(PROVIDER_NAME);
+ providerCache.setProviderType(PROVIDER_TYPE);
+ tenantCache = new TenantCache(providerCache);
+ tenants.put(TENANT_ID, tenantCache);
+ Map<String, Object> privateFields = ImmutableMap.<String, Object>builder().put("tenants", tenants).build();
+ CommonUtility.injectMockObjects(privateFields, providerCache);
+ }
+
+ /**
+ * Ensure that we set up the Tenants property correctly
+ */
+ @Test
+ public void testTenantsProperty() {
+ assertNotNull(providerCache.getTenants());
+ }
+
+ /**
+ * Ensure that we set up the Tenant Id property correctly
+ */
+ @Test
+ public void testTenantIdProperty() {
+ assertNotNull(providerCache.getTenant(TENANT_ID));
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderOperation.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderOperation.java
new file mode 100644
index 000000000..794ea967f
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestProviderOperation.java
@@ -0,0 +1,141 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import com.att.cdp.zones.model.ModelObject;
+import java.lang.reflect.Field;
+import java.util.Map;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.base.ProviderOperation;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.slf4j.MDC;
+
+import static org.onap.ccsdk.sli.adaptors.iaas.Constants.MDC_SERVICE;
+
+/**
+ * This class is used to test methods and functions of the adapter implementation that do not
+ * require and do not set up connections to any providers.
+ *
+ * @since Jan 20, 2016
+ * @version $Id$
+ */
+
+public class TestProviderOperation extends ProviderOperation {
+
+ /**
+ * Use reflection to locate fields and methods so that they can be manipulated during the test
+ * to change the internal state accordingly.
+ *
+ * @throws NoSuchFieldException if the field(s) dont exist
+ * @throws SecurityException if reflective access is not allowed
+ * @throws NoSuchMethodException If the method(s) dont exist
+ */
+ @SuppressWarnings("nls")
+ @BeforeClass
+ public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
+ Class<?> providerAdapterImplClass = ProviderAdapterImpl.class;
+ Class<?> configurationFactoryClass = ConfigurationFactory.class;
+
+ Field providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache");
+ providerCacheField.setAccessible(true);
+
+ Field configField = configurationFactoryClass.getDeclaredField("config");
+ configField.setAccessible(true);
+ }
+
+ /**
+ * This test expects a failure because the value to be validated is a null URL
+ *
+ * @throws RequestFailedException Expected
+ */
+ @SuppressWarnings("nls")
+ @Test(expected = RequestFailedException.class)
+ public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException {
+ MDC.put(MDC_SERVICE, "junit");
+ String link = null;
+ validateVMURL(VMURL.parseURL(link));
+ }
+
+ /**
+ * This test expects a failure because the value to be validated is an empty URL
+ *
+ * @throws RequestFailedException Expected
+ */
+ @SuppressWarnings("nls")
+ @Test(expected = RequestFailedException.class)
+ public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException {
+ MDC.put(MDC_SERVICE, "junit");
+ String link = "";
+ validateVMURL(VMURL.parseURL(link));
+ }
+
+ /**
+ * This test expects a failure because the value to be validated is a blank URL
+ *
+ * @throws RequestFailedException Expected
+ */
+ @SuppressWarnings("nls")
+ @Test(expected = RequestFailedException.class)
+ public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException {
+ MDC.put(MDC_SERVICE, "junit");
+ String link = " ";
+ validateVMURL(VMURL.parseURL(link));
+ }
+
+ /**
+ * This test expects a failure because the value to be validated is a bad URL
+ *
+ * @throws RequestFailedException Expected
+ */
+ @SuppressWarnings("nls")
+ @Test(expected = RequestFailedException.class)
+ public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException {
+ MDC.put(MDC_SERVICE, "junit");
+ String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/";
+ validateVMURL(VMURL.parseURL(link));
+ }
+
+ /**
+ * This test expects to pass
+ *
+ * @throws RequestFailedException Un-Expected
+ */
+ @SuppressWarnings("nls")
+ @Test
+ public void testValidateParameterPatternValidURL() throws RequestFailedException {
+ MDC.put(MDC_SERVICE, "junit");
+ String link =
+ "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551";
+ validateVMURL(VMURL.parseURL(link));
+ }
+
+ @Override
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws SvcLogicException {
+ return null;
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestRequestContext.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestRequestContext.java
new file mode 100644
index 000000000..65eb2da12
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestRequestContext.java
@@ -0,0 +1,162 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.iaas.Constants;
+import org.onap.ccsdk.sli.core.utils.configuration.Configuration;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test the RequestContext object
+ * <p>
+ * The request context is used to track retries, recovery attempts, and time to live of the
+ * processing of a request.
+ * </p>
+ */
+
+public class TestRequestContext {
+
+ private RequestContext rc;
+ private Configuration config = ConfigurationFactory.getConfiguration();
+
+ /**
+ * Set up the test environment by forcing the retry delay and limit to small values for the test
+ * and setting up the request context object.
+ */
+ @Before
+ public void setup() {
+ config.setProperty(Constants.PROPERTY_RETRY_DELAY, "1");
+ config.setProperty(Constants.PROPERTY_RETRY_LIMIT, "3");
+ rc = new RequestContext(null);
+ rc.setTimeToLiveSeconds(2);
+ }
+
+ /**
+ * Ensure that we set up the property correctly
+ */
+ @Test
+ public void testRetryDelayProperty() {
+ assertEquals(1, rc.getRetryDelay());
+ }
+
+ /**
+ * Ensure that we set up the property correctly
+ */
+ @Test
+ public void testRetryLimitProperty() {
+ assertEquals(3, rc.getRetryLimit());
+ }
+
+ /**
+ * This test ensures that the retry attempt counter is zero on a new context
+ */
+ @Test
+ public void testRetryCountNoRetries() {
+ assertEquals(0, rc.getAttempts());
+ }
+
+ /**
+ * Test that the delay is accurate
+ */
+ @Test
+ public void testDelay() {
+ long future = System.currentTimeMillis() + (rc.getRetryDelay() * 1000L);
+
+ rc.delay();
+
+ assertTrue(System.currentTimeMillis() >= future);
+ }
+
+ /**
+ * The RequestContext tracks the number of retry attempts against the limit. This test verifies
+ * that tracking logic works correctly.
+ */
+ @Test
+ public void testCanRetry() {
+ assertEquals(0, rc.getAttempts());
+ assertTrue(rc.attempt());
+ assertEquals(1, rc.getAttempts());
+ assertTrue(rc.attempt());
+ assertEquals(2, rc.getAttempts());
+ assertTrue(rc.attempt());
+ assertEquals(3, rc.getAttempts());
+ assertFalse(rc.attempt());
+ assertEquals(3, rc.getAttempts());
+ assertFalse(rc.attempt());
+ assertEquals(3, rc.getAttempts());
+ assertFalse(rc.attempt());
+ assertEquals(3, rc.getAttempts());
+ }
+
+ /**
+ * The same RequestContext is used throughout the processing, and retries need to be reset once
+ * successfully connected so that any earlier (successful) recoveries are not considered when
+ * performing any new future recoveries. This test ensures that a reset clears the retry counter
+ * and that we can attempt retries again up to the limit.
+ */
+ @Test
+ public void testResetAndCanRetry() {
+ assertTrue(rc.attempt());
+ assertTrue(rc.attempt());
+ assertTrue(rc.attempt());
+ rc.reset();
+
+ assertTrue(rc.attempt());
+ assertTrue(rc.attempt());
+ assertTrue(rc.attempt());
+ assertFalse(rc.attempt());
+ assertFalse(rc.attempt());
+ assertFalse(rc.attempt());
+ }
+
+ /**
+ * This test is used to test tracking of time to live for the request context. Because time is
+ * inexact, the assertions can only be ranges of values, such as at least some value or greater.
+ * The total duration tracking in the request context is only updated on each call to
+ * {@link RequestContext#isAlive()}. Also, durations are NOT affected by calls to reset.
+ */
+ @Test
+ public void testTimeToLive() {
+ assertTrue(rc.getTotalDuration() == 0L);
+ assertTrue(rc.isAlive());
+ rc.reset();
+ rc.delay();
+ assertTrue(rc.isAlive());
+ assertTrue(rc.getTotalDuration() >= 1000L);
+ rc.reset();
+ rc.delay();
+ rc.isAlive();
+ assertTrue(rc.getTotalDuration() >= 2000L);
+ rc.reset();
+ rc.delay();
+ assertFalse(rc.isAlive());
+ assertTrue(rc.getTotalDuration() >= 3000L);
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalog.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalog.java
new file mode 100644
index 000000000..755b58dd1
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalog.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+/**
+ * This class tests the service catalog against a known provider.
+ */
+@Ignore
+@RunWith(MockitoJUnitRunner.class)
+public class TestServiceCatalog {
+
+ // Number
+ private static int EXPECTED_REGIONS = 2;
+
+ private ServiceCatalog catalog;
+
+
+ @BeforeClass
+ public static void before() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+
+ EXPECTED_REGIONS = Integer.parseInt(props.getProperty("test.expected-regions", "2"));
+ }
+
+ /**
+ * Setup the test environment by loading a new service catalog for each test
+ *
+ * @throws ZoneException
+ */
+ @Before
+ public void setup() throws ZoneException {
+ catalog = Mockito.mock(ServiceCatalog.class, CALLS_REAL_METHODS);
+ Mockito.doCallRealMethod().when(catalog).trackRequest();
+ catalog.rwLock = new ReentrantReadWriteLock();
+ Set<String> testdata = new HashSet<>();
+ testdata.add("RegionOne");
+ catalog.regions = testdata;
+ }
+
+ /**
+ * Ensure that we set up the Region property correctly
+ */
+ @Test
+ public void testKnownRegions() {
+ assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
+ }
+
+ /**
+ * Ensure that we invoke the track request method
+ */
+ @Test
+ public void testTrackRequest() {
+ catalog.trackRequest();
+ verify(catalog,times(1)).trackRequest();
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogFactory.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogFactory.java
new file mode 100644
index 000000000..4075a401c
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogFactory.java
@@ -0,0 +1,120 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import java.util.Properties;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * This class tests the service catalog factory against a known provider.
+ */
+public class TestServiceCatalogFactory {
+
+ @Test
+ public void testGetServiceCatalogV2() {
+ String tenantIdentifier = null;
+ String principal = null;
+ String credential = null;
+ String domain = null;
+ Properties properties = null;
+
+ String url = "http://192.168.1.1:5000/v2.0/";
+ ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential,
+ domain, properties);
+ Assert.assertNotNull(catalog);
+ Assert.assertEquals(catalog.getClass(), ServiceCatalogV2.class);
+
+ url = "http://192.168.1.1:5000/v2/";
+ catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, domain,
+ properties);
+ Assert.assertNotNull(catalog);
+ Assert.assertEquals(catalog.getClass(), ServiceCatalogV2.class);
+
+ url = "http://192.168.1.1:5000/v2.1/";
+ catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, domain,
+ properties);
+ Assert.assertNotNull(catalog);
+ Assert.assertEquals(catalog.getClass(), ServiceCatalogV2.class);
+
+ }
+
+ @Test
+ public void testGetServiceCatalogV3() {
+ String url = "http://192.168.1.1:5000/v3.0/";
+ String tenantIdentifier = null;
+ String principal = null;
+ String credential = null;
+ String domain = null;
+ Properties properties = null;
+ ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential,
+ domain, properties);
+
+ Assert.assertNotNull(catalog);
+ Assert.assertEquals(catalog.getClass(), ServiceCatalogV3.class);
+ }
+
+ @Test
+ public void testGetServiceCatalogOther() {
+ String url = "http://192.168.1.1:5000/v4.0/";
+ String tenantIdentifier = null;
+ String principal = null;
+ String credential = null;
+ String domain = null;
+ Properties properties = null;
+ ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential,
+ domain, properties);
+
+ Assert.assertNull(catalog);
+ }
+
+ @Test
+ public void testGetServiceCatalogEmptyURL() {
+ String url = null;
+ String tenantIdentifier = null;
+ String principal = null;
+ String credential = null;
+ String domain = null;
+ Properties properties = null;
+ ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential,
+ domain, properties);
+
+ Assert.assertNull(catalog);
+ }
+
+ @Test
+ public void testGetServiceCatalogWithoutVersion() {
+ String url = "http://192.168.1.1:5000/";
+ String tenantIdentifier = null;
+ String principal = null;
+ String credential = null;
+ String domain = null;
+ Properties properties = null;
+ ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential,
+ domain, properties);
+
+ Assert.assertNull(catalog);
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogV2.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogV2.java
new file mode 100644
index 000000000..844f81296
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogV2.java
@@ -0,0 +1,293 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.ContextFactory;
+import com.google.common.collect.ImmutableMap;
+import com.woorea.openstack.base.client.OpenStackClientConnector;
+import com.woorea.openstack.base.client.OpenStackConnectException;
+import com.woorea.openstack.base.client.OpenStackResponseException;
+import com.woorea.openstack.keystone.Keystone;
+import com.woorea.openstack.keystone.api.TokensResource;
+import com.woorea.openstack.keystone.model.Access;
+import com.woorea.openstack.keystone.model.Access.Service;
+import com.woorea.openstack.keystone.model.Access.Service.Endpoint;
+import com.woorea.openstack.keystone.model.Tenant;
+import com.woorea.openstack.keystone.model.Token;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+import org.powermock.reflect.Whitebox;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+/**
+ * This class tests the service catalog against a known provider.
+ */
+@Ignore
+@RunWith(MockitoJUnitRunner.class)
+public class TestServiceCatalogV2 {
+
+ // Number
+ private static int EXPECTED_REGIONS = 1;
+ private static int EXPECTED_ENDPOINTS = 1;
+
+ private static String PRINCIPAL;
+ private static String CREDENTIAL;
+ private static String TENANT_NAME;
+ private static String TENANT_ID;
+ private static String IDENTITY_URL;
+ private static String REGION_NAME;
+ private static String PUBLIC_URL;
+
+ private static String IP;
+ private static String PORT;
+ private static String TENANTID;
+ private static String VMID;
+ private static String URL;
+
+ private ServiceCatalogV2 catalog;
+
+ private Properties properties;
+
+ @Mock
+ private Tenant tenant;
+
+ private final Set<String> regions = new HashSet<>(Arrays.asList("RegionOne"));
+
+ private Map<String, Service> serviceTypes;
+
+ private Map<String, List<Service.Endpoint>> serviceEndpoints;
+
+ @BeforeClass
+ public static void before() {
+ final Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ IDENTITY_URL = props.getProperty("provider1.identity", "appc");
+ PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
+ CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
+ TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
+ TENANT_ID = props.getProperty("provider1.tenant1.id",
+ props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
+ REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
+
+ IP = props.getProperty("test.ip");
+ PORT = props.getProperty("test.port");
+ TENANTID = props.getProperty("test.tenantid");
+ VMID = props.getProperty("test.vmid");
+
+ EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0"));
+ EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0"));
+
+ PUBLIC_URL =
+ "http://192.168.1.2:5000/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345";
+ }
+
+ /**
+ * Setup the test environment by loading a new service catalog for each test Use reflection to
+ * locate fields and methods so that they can be manipulated during the test to change the
+ * internal state accordingly.
+ *
+ */
+ @Before
+ public void setup() {
+ URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);
+ properties = new Properties();
+ properties.setProperty(ContextFactory.PROPERTY_PROXY_HOST, "PROXY_HOST");
+ properties.setProperty(ContextFactory.PROPERTY_PROXY_PORT, "PROXY_PORT");
+ catalog = new ServiceCatalogV2(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties);
+ final Service service = new Service();
+ serviceTypes = ImmutableMap.<String, Service>builder().put(ServiceCatalog.COMPUTE_SERVICE, service)
+ .put(ServiceCatalog.IDENTITY_SERVICE, service).put(ServiceCatalog.IMAGE_SERVICE, service)
+ .put(ServiceCatalog.NETWORK_SERVICE, service).put(ServiceCatalog.VOLUME_SERVICE, service).build();
+ Map<String, Object> endpointPrivateFields =
+ ImmutableMap.<String, Object>builder().put("publicURL", PUBLIC_URL).put("region", REGION_NAME).build();
+ Service.Endpoint endpoint = new Service.Endpoint();
+ CommonUtility.injectMockObjects(endpointPrivateFields, endpoint);
+ final List<Service.Endpoint> endpoints = Arrays.asList(endpoint);
+ serviceEndpoints = ImmutableMap.<String, List<Service.Endpoint>>builder()
+ .put(ServiceCatalog.COMPUTE_SERVICE, endpoints).build();
+ Map<String, Object> privateFields =
+ ImmutableMap.<String, Object>builder().put("regions", regions).put("tenant", tenant)
+ .put("serviceTypes", serviceTypes).put("serviceEndpoints", serviceEndpoints).build();
+ CommonUtility.injectMockObjects(privateFields, catalog);
+ CommonUtility.injectMockObjectsInBaseClass(privateFields, catalog);
+
+ }
+
+ /**
+ * Ensure that we get the Tenant Name & Tenant Id property are returned correctly
+ */
+ @Test
+ public void testKnownTenant() {
+ when(tenant.getName()).thenReturn(TENANT_NAME);
+ when(tenant.getId()).thenReturn(TENANT_ID);
+ assertEquals(TENANT_NAME, catalog.getProjectName());
+ assertEquals(TENANT_ID, catalog.getProjectId());
+ }
+
+ /**
+ * Ensure that we set up the Region property correctly
+ */
+ @Test
+ public void testKnownRegions() {
+ assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
+ assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
+ }
+
+ /**
+ * Ensure that that we can check for published services correctly
+ */
+ @Test
+ public void testServiceTypesPublished() {
+ assertTrue(catalog.isServicePublished("compute"));
+ assertFalse(catalog.isServicePublished("bogus"));
+ }
+
+ /**
+ * Ensure that we can get the list of published services
+ */
+ @Test
+ public void testPublishedServicesList() {
+ final List<String> services = catalog.getServiceTypes();
+ assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
+ assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
+ assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
+ assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
+ assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
+ }
+
+ /**
+ * Ensure that we can get the endpoint(s) for a service
+ */
+ @Test
+ public void testEndpointList() {
+ List<Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
+ assertNotNull(endpoints);
+ assertFalse(endpoints.isEmpty());
+ assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
+ }
+
+ /**
+ * Ensure that we override the toString method
+ */
+ @Test
+ public void testToString() {
+ when(tenant.getId()).thenReturn(TENANT_ID);
+ when(tenant.getDescription()).thenReturn("Tenant one");
+ final String testString = catalog.toString();
+ assertNotNull(testString);
+ }
+
+ /**
+ * Ensure that we can get the VM Region
+ */
+ @Test
+ public void testGetVMRegion() {
+ VMURL url = VMURL.parseURL(URL);
+ String region = catalog.getVMRegion(url);
+ assertEquals(REGION_NAME, region);
+ }
+
+ /**
+ * Ensure that we can get the null region when no URL is passed
+ */
+ @Test
+ public void testGetVMRegionWithoutURL() {
+ String region = catalog.getVMRegion(null);
+ assertNull(region);
+ }
+
+ @Ignore
+ @Test
+ public void liveConnectionTest() {
+ // this test should only be used by developers when testing against a live Openstack
+ // instance, otherwise it should be ignored
+ properties = new Properties();
+ String identity = "http://192.168.0.1:5000/v2.0";
+ String tenantName = "Tenant";
+ String user = "user";
+ String pass = "pass";
+
+ ServiceCatalogV2 catalog = new ServiceCatalogV2(identity, tenantName, user, pass, properties);
+
+ try {
+ catalog.init();
+ } catch (ZoneException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ String out = catalog.toString();
+ System.out.println(out);
+ assertNotNull(catalog);
+ }
+
+ @Test
+ public void testInit() throws ZoneException, ClassNotFoundException, InstantiationException, IllegalAccessException, OpenStackConnectException, OpenStackResponseException {
+ ServiceCatalogV2 catalogSpy = Mockito.spy(catalog);
+ Class<?> connectorClass = Class.forName(ServiceCatalogV2.CLIENT_CONNECTOR_CLASS);
+ OpenStackClientConnector connector = (OpenStackClientConnector) connectorClass.newInstance();
+ Keystone keystone = Mockito.spy(new Keystone(IDENTITY_URL, connector));
+ TokensResource tokens = Mockito.mock(TokensResource.class);
+ TokensResource.Authenticate authenticate = Mockito.mock(TokensResource.Authenticate.class);
+ Mockito.when(keystone.tokens()).thenReturn(tokens);
+ Mockito.when(tokens.authenticate(Mockito.any())).thenReturn(authenticate);
+ Access access = Mockito.mock(Access.class);
+
+ Token token = new Token();
+ Mockito.when(access.getToken()).thenReturn(token);
+ Mockito.when(authenticate.execute()).thenReturn(access);
+ Mockito.when(authenticate.withTenantName(Mockito.anyString())).thenReturn(authenticate);
+ Mockito.when(catalogSpy.getKeystone(Mockito.anyString(), Mockito.any())).thenReturn(keystone);
+ Access.Service service = new Access.Service();
+ Endpoint endpoint = new Endpoint();
+ List<Endpoint> endpointList = new ArrayList<>();
+ endpointList.add(endpoint);
+ Whitebox.setInternalState(service, "endpoints", endpointList);
+ List<Service> serviceList = new ArrayList<>();
+ serviceList.add(service);
+ Mockito.when(access.getServiceCatalog()).thenReturn(serviceList);
+ catalogSpy.init();
+ Mockito.verify(access).getServiceCatalog();
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogV3.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogV3.java
new file mode 100644
index 000000000..c30febd3b
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestServiceCatalogV3.java
@@ -0,0 +1,279 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.ContextFactory;
+import com.google.common.collect.ImmutableMap;
+import com.woorea.openstack.base.client.OpenStackClientConnector;
+import com.woorea.openstack.base.client.OpenStackConnectException;
+import com.woorea.openstack.base.client.OpenStackResponseException;
+import com.woorea.openstack.keystone.v3.Keystone;
+import com.woorea.openstack.keystone.v3.api.TokensResource;
+import com.woorea.openstack.keystone.v3.model.Token;
+import com.woorea.openstack.keystone.v3.model.Token.Service;
+import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+import org.powermock.reflect.Whitebox;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+/**
+ * This class tests the service catalog against a known provider.
+ */
+@Ignore
+@RunWith(MockitoJUnitRunner.class)
+public class TestServiceCatalogV3 {
+
+ // Number
+ private static int EXPECTED_REGIONS = 1;
+ private static int EXPECTED_ENDPOINTS = 1;
+
+ private static String PRINCIPAL;
+ private static String CREDENTIAL;
+ private static String DOMAIN;
+ private static String TENANT_NAME;
+ private static String TENANT_ID;
+ private static String IDENTITY_URL;
+ private static String REGION_NAME;
+ private static String PUBLIC_URL;
+
+ private static String IP;
+ private static String PORT;
+ private static String TENANTID;
+ private static String VMID;
+ private static String URL;
+
+ private ServiceCatalogV3 catalog;
+
+ private ServiceCatalogV3 spyCatalog;
+
+ private Properties properties;
+
+ private Token.Project project = new Token.Project();
+
+ private final Set<String> regions = new HashSet<>(Arrays.asList("RegionOne"));
+
+ private Map<String, Service> serviceTypes;
+
+ private Map<String, List<Service.Endpoint>> serviceEndpoints;
+
+ @BeforeClass
+ public static void before() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ IDENTITY_URL = props.getProperty("provider1.identity");
+ PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc");
+ CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
+ DOMAIN = props.getProperty("provider1.tenant1.domain", "Default");
+ TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
+ TENANT_ID = props.getProperty("provider1.tenant1.id",
+ props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
+ REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
+
+ IP = props.getProperty("test.ip");
+ PORT = props.getProperty("test.port");
+ TENANTID = props.getProperty("test.tenantid");
+ VMID = props.getProperty("test.vmid");
+
+ EXPECTED_REGIONS = Integer.parseInt(props.getProperty("test.expected-regions", "0"));
+ EXPECTED_ENDPOINTS = Integer.parseInt(props.getProperty("test.expected-endpoints", "0"));
+ PUBLIC_URL =
+ "http://192.168.1.2:5000/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345";
+
+ }
+
+ /**
+ * Use reflection to locate fields and methods so that they can be manipulated during the test
+ * to change the internal state accordingly.
+ */
+ @Before
+ public void setup() {
+ URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);
+ properties = new Properties();
+ properties.setProperty(ContextFactory.PROPERTY_PROXY_HOST, "PROXY_HOST");
+ properties.setProperty(ContextFactory.PROPERTY_PROXY_PORT, "PROXY_PORT");
+ catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);
+ spyCatalog = Mockito.spy(catalog);
+ project.setId(TENANT_ID);
+ project.setName(TENANT_NAME);
+ final Service service = new Service();
+ serviceTypes = ImmutableMap.<String, Service>builder().put(ServiceCatalog.COMPUTE_SERVICE, service)
+ .put(ServiceCatalog.IDENTITY_SERVICE, service).put(ServiceCatalog.IMAGE_SERVICE, service)
+ .put(ServiceCatalog.NETWORK_SERVICE, service).put(ServiceCatalog.VOLUME_SERVICE, service).build();
+ final Service.Endpoint endpoint = new Service.Endpoint();
+ endpoint.setUrl(PUBLIC_URL);
+ endpoint.setRegion(REGION_NAME);
+ final List<Service.Endpoint> endpoints = Arrays.asList(endpoint);
+ serviceEndpoints = ImmutableMap.<String, List<Service.Endpoint>>builder()
+ .put(ServiceCatalog.COMPUTE_SERVICE, endpoints).build();
+ Map<String, Object> privateFields =
+ ImmutableMap.<String, Object>builder().put("project", project).put("regions", regions)
+ .put("serviceTypes", serviceTypes).put("serviceEndpoints", serviceEndpoints).build();
+ CommonUtility.injectMockObjects(privateFields, catalog);
+ CommonUtility.injectMockObjectsInBaseClass(privateFields, catalog);
+ }
+
+ /**
+ * Ensure that we get the Tenant Name & Tenant Id property are returned correctly
+ */
+ @Test
+ public void testKnownTenant() {
+ when(spyCatalog.getProject()).thenReturn(project);
+ assertEquals(TENANT_NAME, catalog.getProjectName());
+ assertEquals(TENANT_ID, catalog.getProjectId());
+ }
+
+ /**
+ * Ensure that we set up the Region property correctly
+ */
+ @Test
+ public void testKnownRegions() {
+ assertEquals(EXPECTED_REGIONS, catalog.getRegions().size());
+ assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]);
+ }
+
+ /**
+ * Ensure that that we can check for published services correctly
+ */
+ @Test
+ public void testServiceTypesPublished() {
+ assertTrue(catalog.isServicePublished("compute"));
+ assertFalse(catalog.isServicePublished("bogus"));
+ }
+
+ /**
+ * Ensure that we can get the list of published services
+ */
+ @Test
+ public void testPublishedServicesList() {
+ List<String> services = catalog.getServiceTypes();
+ assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE));
+ assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE));
+ assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE));
+ assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE));
+ assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE));
+ }
+
+ /**
+ * Ensure that we can get the endpoint(s) for a service
+ */
+ @Test
+ public void testEndpointList() {
+ List<Endpoint> endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE);
+ assertNotNull(endpoints);
+ assertFalse(endpoints.isEmpty());
+ assertEquals(EXPECTED_ENDPOINTS, endpoints.size());
+ }
+
+ /**
+ * Ensure that we override the toString method
+ */
+ @Test
+ public void testToString() {
+ String testString = catalog.toString();
+ assertNotNull(testString);
+ }
+
+ /**
+ * Ensure that we can get the VM Region
+ */
+ @Test
+ public void testGetVMRegion() {
+ VMURL url = VMURL.parseURL(URL);
+ String region = catalog.getVMRegion(url);
+ assertEquals(REGION_NAME, region);
+ }
+
+ /**
+ * Ensure that we can get the null region when no URL is passed
+ */
+ @Test
+ public void testGetVMRegionWithoutURL() {
+ String region = catalog.getVMRegion(null);
+ assertNull(region);
+ }
+
+ @Ignore
+ @Test
+ public void liveConnectionTest() {
+ // this test should only be used by developers when testing against a live Openstack
+ // instance, otherwise it should be ignored
+ properties = new Properties();
+ String identity = "";
+ String tenantName = "";
+ String user = "";
+ String pass = "";
+
+ catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);
+ assertNotNull(catalog);
+ }
+
+ @Test
+ public void testInit() throws ZoneException, ClassNotFoundException, InstantiationException, IllegalAccessException, OpenStackConnectException, OpenStackResponseException {
+ ServiceCatalogV3 catalogSpy = Mockito.spy(catalog);
+ Class<?> connectorClass = Class.forName(ServiceCatalogV2.CLIENT_CONNECTOR_CLASS);
+ OpenStackClientConnector connector = (OpenStackClientConnector) connectorClass.newInstance();
+ Keystone keystone = Mockito.spy(new Keystone(IDENTITY_URL, connector));
+ TokensResource tokens = Mockito.mock(TokensResource.class);
+ TokensResource.Authenticate authenticate = Mockito.mock(TokensResource.Authenticate.class);
+ Mockito.when(keystone.tokens()).thenReturn(tokens);
+ Mockito.when(tokens.authenticate(Mockito.any())).thenReturn(authenticate);
+ Token token = Mockito.mock(Token.class);
+
+ Mockito.when(authenticate.execute()).thenReturn(token);
+ //Mockito.when(authenticate.withTenantName(Mockito.anyString())).thenReturn(authenticate);
+ Mockito.when(catalogSpy.getKeystone(Mockito.anyString(), Mockito.any())).thenReturn(keystone);
+ Endpoint endpoint = new Endpoint();
+ List<Endpoint> endpointList = new ArrayList<>();
+ endpointList.add(endpoint);
+ List<Token.Service> serviceList = new ArrayList<>();
+ Token.Service service = new Token.Service();
+ Whitebox.setInternalState(service, "endpoints", endpointList);
+ serviceList.add(service);
+ Mockito.when(token.getCatalog()).thenReturn(serviceList);
+ catalogSpy.init();
+ Mockito.verify(token).getCatalog();
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestTenantCache.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestTenantCache.java
new file mode 100644
index 000000000..5ae9aa32d
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestTenantCache.java
@@ -0,0 +1,246 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (C) 2019 IBM.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import com.att.cdp.exceptions.ContextConnectionException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.Context;
+import com.google.common.collect.ImmutableMap;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.sli.adaptors.iaas.Constants;
+import org.onap.ccsdk.sli.core.utils.configuration.Configuration;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+import org.onap.ccsdk.sli.core.utils.pool.Pool;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.when;
+
+/**
+ * This class is used to test methods and functions of the Tenant cache
+ */
+@Ignore
+@RunWith(MockitoJUnitRunner.class)
+public class TestTenantCache {
+
+ private TenantCache tenantCache;
+
+ private VMURL url;
+
+ @Mock
+ private ServiceCatalog catalog;
+
+ @Mock
+ private Context context;
+
+ @Mock
+ Pool<Context> pool;
+
+ private ProviderCache provider;
+
+ private static String TENANT_NAME;
+ private static String TENANT_ID;
+ private static String IDENTITY_URL;
+ private static String REGION_NAME;
+ private static String CREDENTIAL;
+ private static String DOMAIN;
+
+ protected Set<String> regions = new HashSet<>(Arrays.asList("RegionOne"));
+
+ @BeforeClass
+ public static void before() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ IDENTITY_URL = props.getProperty("provider1.identity");
+ TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc");
+ TENANT_ID = props.getProperty("provider1.tenant1.id",
+ props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst"));
+ DOMAIN = props.getProperty("provider1.tenant1.domain", "Default");
+ CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc");
+ REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne");
+ }
+
+ @Before
+ public void setup() {
+ Configuration props = ConfigurationFactory.getConfiguration();
+ props.setProperty(Constants.PROPERTY_RETRY_LIMIT, "3");
+ provider = new ProviderCache();
+ provider.setIdentityURL(IDENTITY_URL);
+ tenantCache = new TenantCache(provider);
+ tenantCache.setDomain(DOMAIN);
+ tenantCache.setPassword(CREDENTIAL);
+ tenantCache.setTenantId(TENANT_ID);
+ tenantCache.setTenantName(TENANT_NAME);
+ tenantCache.setUserid(CREDENTIAL);
+ props.setProperty(Constants.PROPERTY_RETRY_DELAY, "1");
+ Map<String, Object> privateFields = ImmutableMap.<String, Object>builder().put("catalog", catalog).build();
+ CommonUtility.injectMockObjects(privateFields, tenantCache);
+ }
+
+ @Test
+ public void testDetermineRegion() {
+ when(catalog.getVMRegion(url)).thenReturn(REGION_NAME);
+ assertEquals(REGION_NAME, tenantCache.determineRegion(url));
+ }
+
+ @Test
+ public void testDestroy() {
+ TenantCache spy = Mockito.spy(tenantCache);
+ spy.destroy(context, pool);
+ assertNotNull(spy);
+ }
+
+ @Test
+ public void testDestroyWithException() throws IOException {
+ doThrow(new IOException("I/O Exception occured while closing context")).when(context).close();
+ TenantCache spy = Mockito.spy(tenantCache);
+ spy.destroy(context, pool);
+ assertNotNull(spy);
+ }
+
+ @Test
+ public void testInitialize() {
+ TenantCache spyTenant = Mockito.spy(tenantCache);
+ when(catalog.getRegions()).thenReturn(regions);
+ when(catalog.getProjectId()).thenReturn(TENANT_ID);
+ when(catalog.getProjectName()).thenReturn(TENANT_NAME);
+ spyTenant.initialize();
+ assertNotNull(spyTenant);
+ }
+
+ @Test
+ public void testInitializeWithOverLimit() {
+ Configuration props = ConfigurationFactory.getConfiguration();
+ props.setProperty(Constants.PROPERTY_RETRY_LIMIT, "1");
+ TenantCache spyTenant = Mockito.spy(tenantCache);
+ when(spyTenant.getServiceCatalogFactory(anyString(), anyString(), anyObject())).thenReturn(catalog);
+ when(spyTenant.getTenantName()).thenReturn(TENANT_NAME);
+ when(catalog.getRegions()).thenReturn(regions);
+ spyTenant.initialize();
+ assertNotNull(props);
+ }
+
+ @Test
+ public void testInitializeWithContextConnectionException() throws ZoneException {
+ Configuration props = ConfigurationFactory.getConfiguration();
+ props.setProperty(Constants.PROPERTY_RETRY_LIMIT, "2");
+ props.setProperty(Constants.PROPERTY_RETRY_DELAY, "1");
+ doThrow(new ContextConnectionException("Contex Connection Exception")).when(catalog).init();
+ TenantCache spyTenant = Mockito.spy(tenantCache);
+ spyTenant.initialize();
+ assertNotNull(props);
+ }
+
+ @Test
+ public void testInitializeWithZoneException() throws ZoneException {
+ Configuration props = ConfigurationFactory.getConfiguration();
+ props.setProperty(Constants.PROPERTY_RETRY_LIMIT, "2");
+ props.setProperty(Constants.PROPERTY_RETRY_DELAY, "1");
+ doThrow(new ZoneException("Zone Exception")).when(catalog).init();
+ TenantCache spyTenant = Mockito.spy(tenantCache);
+ when(spyTenant.getServiceCatalogFactory(anyString(), anyString(), anyObject())).thenReturn(catalog);
+ spyTenant.initialize();
+ assertNotNull(props);
+ }
+
+ /**
+ * Ensure that we set up the Domain property correctly
+ */
+ @Test
+ public void testDomainProperty() {
+ assertEquals(DOMAIN, tenantCache.getDomain());
+ }
+
+ /**
+ * Ensure that we set up the Provider property correctly
+ */
+ @Test
+ public void testProviderProperty() {
+ assertEquals(provider, tenantCache.getProvider());
+ }
+
+ /**
+ * Ensure that we set up the Password property correctly
+ */
+ @Test
+ public void testPasswordProperty() {
+ assertEquals(CREDENTIAL, tenantCache.getPassword());
+ }
+
+ /**
+ * Ensure that we set up the Tenant Id property correctly
+ */
+ @Test
+ public void testTenantIdProperty() {
+ assertEquals(TENANT_ID, tenantCache.getTenantId());
+ }
+
+ /**
+ * Ensure that we set up the Tenant Name property correctly
+ */
+ @Test
+ public void testTenantNameProperty() {
+ assertEquals(TENANT_NAME, tenantCache.getTenantName());
+ }
+
+ /**
+ * Ensure that we set up the User Id property correctly
+ */
+ @Test
+ public void testUserIdProperty() {
+ assertEquals(CREDENTIAL, tenantCache.getUserid());
+ }
+
+ /**
+ * Ensure that we set up the Pools property correctly
+ */
+ @Test
+ public void testPoolsProperty() {
+ assertNotNull(tenantCache.getPools());
+ }
+
+ @Test
+ public void testProvider() {
+ tenantCache.setProvider(provider);
+ assertEquals(provider, tenantCache.getProvider());
+ }
+
+ @Test
+ public void testServiceCatalog() {
+ assertTrue(tenantCache.getServiceCatalog() instanceof ServiceCatalog);
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestVMURL.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestVMURL.java
new file mode 100644
index 000000000..b638526cc
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/impl/TestVMURL.java
@@ -0,0 +1,135 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.impl;
+
+import java.util.Properties;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+/**
+ * This class is used to test methods and functions of the VMURL
+ */
+@Ignore
+public class TestVMURL {
+
+ private static String IP;
+ private static String PORT;
+ private static String TENANTID;
+ private static String VMID;
+ private static String URL;
+ private static String VERSION;
+
+ @BeforeClass
+ public static void before() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ IP = props.getProperty("test.ip");
+ PORT = props.getProperty("test.port");
+ TENANTID = props.getProperty("test.tenantid");
+ VMID = props.getProperty("test.vmid");
+ VERSION = props.getProperty("test.version");
+ }
+
+ /**
+ * Test that we can parse and interpret valid URLs
+ */
+ @Test
+ public void testValidURL1() {
+ URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);
+ VMURL url = VMURL.parseURL(URL);
+
+ assertEquals("http", url.getScheme());
+ assertEquals(IP, url.getHost());
+ assertEquals(PORT, url.getPort());
+ assertEquals(TENANTID, url.getTenantId());
+ assertEquals(VMID, url.getServerId());
+ assertEquals(VERSION, url.getVersion());
+ assertEquals(url.toString(), URL);
+ }
+
+ @Test
+ public void testValidURL2() {
+ URL = String.format("http://%s/v2/%s/servers/%s", IP, TENANTID, VMID);
+ VMURL url = VMURL.parseURL(URL);
+ assertEquals("http", url.getScheme());
+ assertEquals(IP, url.getHost());
+ assertNull(url.getPort());
+ assertNull(url.getPath());
+ assertEquals(TENANTID, url.getTenantId());
+ assertEquals(VMID, url.getServerId());
+ assertEquals(VERSION, url.getVersion());
+ assertEquals(url.toString(), URL);
+ }
+
+ @Test
+ public void testValidURL3() {
+ URL = "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345";
+ VMURL url = VMURL.parseURL(URL);
+ assertNotNull(url);
+ assertEquals("http", url.getScheme());
+ assertEquals("msb.onap.org", url.getHost());
+ assertEquals("80", url.getPort());
+ assertEquals("/api/multicloud/v0/cloudowner_region", url.getPath());
+ assertEquals(TENANTID, url.getTenantId());
+ assertEquals(VMID, url.getServerId());
+ assertEquals(url.toString(), URL);
+ }
+
+ /**
+ * Test that we ignore and return null for invalid URLs
+ */
+ @Test
+ public void testInvalidURLs() {
+ VMURL url = VMURL.parseURL(null);
+ assertNull(url);
+
+ url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
+ assertNull(url);
+
+ url = VMURL.parseURL(String.format("http:/%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
+ assertNull(url);
+
+ url = VMURL.parseURL(String.format("http:///%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID));
+ assertNull(url);
+
+ url = VMURL.parseURL(String.format("http://v2/%s/servers/%s", TENANTID, VMID));
+ assertNull(url);
+
+ url = VMURL.parseURL(String.format("%s:%s/%s/servers/%s", IP, PORT, TENANTID, VMID));
+ assertNull(url);
+
+ url = VMURL.parseURL(String.format("%s:%s/v2/servers/%s", IP, PORT, VMID));
+ assertNull(url);
+
+ url = VMURL.parseURL(String.format("%s:%s/v2/%s/%s", IP, PORT, TENANTID, VMID));
+ assertNull(url);
+
+ url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers", IP, PORT, TENANTID));
+ assertNull(url);
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/api/ProviderOperationFactoryTest.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/api/ProviderOperationFactoryTest.java
new file mode 100644
index 000000000..c051b24ab
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/api/ProviderOperationFactoryTest.java
@@ -0,0 +1,179 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Modifications Copyright (C) 2019 IBM.
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.api;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.common.enums.Operation;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.*;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.onap.ccsdk.sli.adaptors.iaas.provider.operation.common.enums.Operation.*;
+
+public class ProviderOperationFactoryTest {
+
+ @Test
+ public void should_return_evacuate_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(EVACUATE_SERVICE);
+
+ Assert.assertTrue(operation instanceof EvacuateServer);
+ }
+
+ @Test
+ public void should_return_migrate_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(MIGRATE_SERVICE);
+
+ Assert.assertTrue(operation instanceof MigrateServer);
+ }
+
+ @Test
+ public void should_return_rebuild_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(REBUILD_SERVICE);
+
+ Assert.assertTrue(operation instanceof RebuildServer);
+ }
+
+ @Test
+ public void should_return_restart_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(RESTART_SERVICE);
+
+ Assert.assertTrue(operation instanceof RestartServer);
+ }
+
+ @Test
+ public void should_return_vm_status_check_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(VMSTATUSCHECK_SERVICE);
+
+ Assert.assertTrue(operation instanceof VmStatuschecker);
+ }
+
+ @Test
+ public void should_return_snapshot_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(SNAPSHOT_SERVICE);
+
+ Assert.assertTrue(operation instanceof CreateSnapshot);
+ }
+
+ @Test
+ public void should_return_terminate_stack_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(TERMINATE_STACK);
+
+ Assert.assertTrue(operation instanceof TerminateStack);
+ }
+
+ @Test
+ public void should_return_snapshot_stack_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(SNAPSHOT_STACK);
+
+ Assert.assertTrue(operation instanceof SnapshotStack);
+ }
+
+ @Test
+ public void should_return_restore_stack_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(RESTORE_STACK);
+
+ Assert.assertTrue(operation instanceof RestoreStack);
+ }
+
+ @Test
+ public void should_return_start_service_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(START_SERVICE);
+
+ Assert.assertTrue(operation instanceof StartServer);
+ }
+
+ @Test
+ public void should_return_stop_service_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(STOP_SERVICE);
+
+ Assert.assertTrue(operation instanceof StopServer);
+ }
+
+ @Test
+ public void should_return_terminate_service_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(TERMINATE_SERVICE);
+
+ Assert.assertTrue(operation instanceof TerminateServer);
+ }
+
+ @Test
+ public void should_return_lookup_service_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(LOOKUP_SERVICE);
+
+ Assert.assertTrue(operation instanceof LookupServer);
+ }
+
+ @Test
+ public void should_return_attach_volume_service_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(ATTACHVOLUME_SERVICE);
+
+ Assert.assertTrue(operation instanceof AttachVolumeServer);
+ }
+
+ @Test
+ public void should_return_detach_volume_service_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(DETACHVOLUME_SERVICE);
+
+ Assert.assertTrue(operation instanceof DettachVolumeServer);
+ }
+
+ @Test
+ public void should_return_reboot_service_operation() throws SvcLogicException {
+ IProviderOperation operation = ProviderOperationFactory
+ .getInstance()
+ .getOperationObject(Operation.REBOOT_SERVICE);
+
+ Assert.assertTrue(operation instanceof RebootServer);
+ }
+
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/AttachVolumeServerTest.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/AttachVolumeServerTest.java
new file mode 100644
index 000000000..8a647a77a
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/AttachVolumeServerTest.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.VolumeService;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Volume;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AttachVolumeServerTest {
+
+ @Test
+ public void attachVolumeTest() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ VolumeService volumeService = mock(VolumeService.class);
+ List<Volume> volumeList = new ArrayList<>();
+ doReturn(volumeList).when(volumeService).getVolumes();
+ doReturn(mg.getContext()).when(server).getContext();
+ doReturn(volumeService).when(mg.getContext()).getVolumeService();
+ AttachVolumeServer rbs = new AttachVolumeServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ assertTrue(rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext()) instanceof ModelObject);
+ }
+
+ @Test
+ public void attachVolumeTestException() throws ZoneException, SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ VolumeService volumeService = mock(VolumeService.class);
+ when(volumeService.getVolumes()).thenThrow(new ZoneException("Zone Exception"));
+ doReturn(mg.getContext()).when(server).getContext();
+ doReturn(volumeService).when(mg.getContext()).getVolumeService();
+ AttachVolumeServer attachVolumeServer = new AttachVolumeServer();
+ attachVolumeServer.setProviderCache(mg.getProviderCacheMap());
+ attachVolumeServer.executeProviderOperation(mg.getParams(), context);
+ assertEquals("FAILURE", context.getAttribute("VOLUME_STATUS"));
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/DettachVolumeServerTest.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/DettachVolumeServerTest.java
new file mode 100644
index 000000000..23bc126e0
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/DettachVolumeServerTest.java
@@ -0,0 +1,101 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.TimeoutException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.ComputeService;
+import com.att.cdp.zones.VolumeService;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Volume;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestContext;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestFailedException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+
+
+public class DettachVolumeServerTest {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void detachVolumeTest() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ VolumeService volumeService = mock(VolumeService.class);
+ List<Volume> volumeList = new ArrayList<>();
+ doReturn(volumeList).when(volumeService).getVolumes();
+ doReturn(mg.getContext()).when(server).getContext();
+ doReturn(volumeService).when(mg.getContext()).getVolumeService();
+ DettachVolumeServer rbs = new DettachVolumeServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ assertTrue(rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext()) instanceof ModelObject);
+ }
+
+ @Test
+ public void validateDetachTest() throws RequestFailedException, ZoneException {
+ DettachVolumeServer rbs = Mockito.spy(new DettachVolumeServer());
+ RequestContext rc = Mockito.mock(RequestContext.class);
+ ComputeService ser = Mockito.mock(ComputeService.class);
+ Mockito.doReturn(true).doReturn(false).when(rc).attempt();
+ Map<String, String> attachments = new HashMap<>();
+ attachments.put("VOLUME_ID", "VOLUME_ID");
+ Mockito.doReturn(attachments).when(ser).getAttachments(Mockito.anyString());
+ assertTrue(rbs.validateDetach(rc, ser, "VM", "VOLUME_ID"));
+ }
+
+ @Test
+ public void validateDetachTestTimeoutException() throws RequestFailedException, ZoneException {
+ DettachVolumeServer rbs = Mockito.spy(new DettachVolumeServer());
+ RequestContext rc = Mockito.mock(RequestContext.class);
+ ComputeService ser = Mockito.mock(ComputeService.class);
+ Mockito.doReturn(true).doReturn(false).when(rc).attempt();
+ Mockito.doReturn(30).when(rc).getAttempts();
+ expectedEx.expect(TimeoutException.class);
+ rbs.validateDetach(rc, ser, "VM", "VOLUME_ID");
+ }
+
+ @Test
+ public void validateDetachTest3Arg() throws RequestFailedException, ZoneException {
+ DettachVolumeServer rbs = Mockito.spy(new DettachVolumeServer());
+ ComputeService ser = Mockito.mock(ComputeService.class);
+ Map<String, String> attachments = new HashMap<>();
+ attachments.put("VOLUME_ID", "VOLUME_ID");
+ Mockito.doReturn(attachments).when(ser).getAttachments(Mockito.anyString());
+ assertTrue(rbs.validateDetach(ser, "VM", "VOLUME_ID"));
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/MockGenerator.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/MockGenerator.java
new file mode 100644
index 000000000..b87dee439
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/MockGenerator.java
@@ -0,0 +1,167 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.openstack.OpenStackContext;
+import com.att.cdp.zones.ComputeService;
+import com.att.cdp.zones.ImageService;
+import com.att.cdp.zones.Provider;
+import com.att.cdp.zones.model.Hypervisor;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import java.util.HashMap;
+import java.util.Map;
+import org.onap.ccsdk.sli.adaptors.iaas.Constants;
+import org.onap.ccsdk.sli.core.utils.configuration.Configuration;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+import org.onap.ccsdk.sli.adaptors.iaas.ProviderAdapter;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.ProviderCache;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestContext;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.TenantCache;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.VMURL;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.utils.pool.Pool;
+import org.onap.ccsdk.sli.core.utils.pool.PoolDrainedException;
+import org.onap.ccsdk.sli.core.utils.pool.PoolExtensionException;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+public class MockGenerator {
+
+ private Map<String, ProviderCache> providerCacheMap;
+ private Map<String, String> params;
+ private SvcLogicContext ctx;
+ private Server server;
+ private ImageService imageService;
+ private OpenStackContext context;
+ private ComputeService computeService;
+
+ public static final String SERVER_ID = "12442";
+ public static final String SERVER_NAME = "Server1";
+ private final Configuration configuration = ConfigurationFactory.getConfiguration();
+
+ /**
+ * This method created a mocked up object representing the OpenStack objects which would be
+ * gathered from remote systems during runtime, but which are not available during a unit test.
+ *
+ * @param serverStatus Most of the classes in the package we are testing have different actions
+ * depending on the status of the server. This allows a different set of mock data to be
+ * created depending on which status is being tested.
+ */
+ public MockGenerator(Status serverStatus) {
+ configuration.setProperty(Constants.PROPERTY_STACK_STATE_CHANGE_TIMEOUT, "2");
+ configuration.setProperty(Constants.PROPERTY_RETRY_LIMIT, "10");
+ ctx = mock(SvcLogicContext.class);
+ RequestContext requestContext = mock(RequestContext.class);
+ server = mock(Server.class);
+ doReturn(SERVER_NAME).when(server).getName();
+ doReturn(SERVER_ID).when(server).getId();
+ Status status = serverStatus;
+ doReturn(status).when(server).getStatus();
+ // the example base image that our fake server was built off of
+ doReturn("linuxBase").when(server).getImage();
+ Hypervisor hypervisor = mock(Hypervisor.class);
+ com.att.cdp.zones.model.Hypervisor.Status hypervisorStatus =
+ com.att.cdp.zones.model.Hypervisor.Status.ENABLED;
+ doReturn(hypervisorStatus).when(hypervisor).getStatus();
+ com.att.cdp.zones.model.Hypervisor.State hypervisorState =
+ com.att.cdp.zones.model.Hypervisor.State.UP;
+ doReturn(hypervisorState).when(hypervisor).getState();
+ doReturn(hypervisor).when(server).getHypervisor();
+ context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ imageService = mock(ImageService.class);
+ computeService = mock(ComputeService.class);
+ try {
+ doReturn(server).when(computeService).getServer("abc12345-1234-5678-890a-abcdefb12345");
+ } catch (ZoneException e2) {
+ // TODO Auto-generated catch block
+ e2.printStackTrace();
+ }
+ doReturn(context).when(server).getContext();
+ doReturn(provider).when(context).getProvider();
+ doReturn(imageService).when(context).getImageService();
+ doReturn(computeService).when(context).getComputeService();
+ doReturn(false).when(requestContext).attempt();
+ doReturn(true).when(requestContext).isFailed();
+ params = new HashMap<String, String>();
+ params.put(ProviderAdapter.PROPERTY_INSTANCE_URL,
+ "http://10.1.1.2:5000/v2/abc12345-1234-5678-890a-abcdefb12345/servers/abc12345-1234-5678-890a-abcdefb12345");
+ params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, "provider1");
+ params.put(ProviderAdapter.PROPERTY_IDENTITY_URL,
+ "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3");
+ ProviderCache providerCache = mock(ProviderCache.class);
+ TenantCache tenantCache = mock(TenantCache.class);
+ doReturn("cloudowner_region").when(tenantCache).determineRegion(any(VMURL.class));
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantId();
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantName();
+ Pool pool = mock(Pool.class);
+ try {
+ doReturn(context).when(pool).reserve();
+ } catch (PoolExtensionException | PoolDrainedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ Map<String, Pool> tenantCachePools = new HashMap<String, Pool>();
+ tenantCachePools.put("cloudowner_region", pool);
+ doReturn(tenantCachePools).when(tenantCache).getPools();
+ doReturn(tenantCache).when(providerCache).getTenant("abc12345-1234-5678-890a-abcdefb12345");
+ providerCacheMap = new HashMap<String, ProviderCache>();
+ providerCacheMap.put(
+ "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3",
+ providerCache);
+ }
+
+ public Map<String, String> getParams() {
+ return params;
+ }
+
+ public Map<String, ProviderCache> getProviderCacheMap() {
+ return providerCacheMap;
+ }
+
+ public SvcLogicContext getSvcLogicContext() {
+ return ctx;
+ }
+
+ public Server getServer() {
+ return server;
+ }
+
+ public ImageService getImageService() {
+ return imageService;
+ }
+
+ public OpenStackContext getContext() {
+ return context;
+ }
+
+ public ComputeService getComputeService() {
+ return computeService;
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestCreateSnapshot.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestCreateSnapshot.java
new file mode 100644
index 000000000..7dae3d5be
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestCreateSnapshot.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Image;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class TestCreateSnapshot {
+
+ @Test
+ public void createSnapshotRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ Image image = mock(Image.class);
+ doReturn("1234567").when(image).getId();
+ doReturn(mg.getContext()).when(image).getContext();
+ doReturn("wrong image name").when(image).getName();
+ doReturn(com.att.cdp.zones.model.Image.Status.ACTIVE).when(image).getStatus();
+ doReturn(image).when(mg.getImageService()).getImageByName(any());
+ CreateSnapshot rbs = new CreateSnapshot();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during CreateSnapshot.executeProviderOperation");
+ }
+ ArgumentCaptor<String> createSnapshotCaptor = ArgumentCaptor.forClass(String.class);
+ verify(server).createSnapshot(createSnapshotCaptor.capture());
+ ArgumentCaptor<String> getImageNameCaptor = ArgumentCaptor.forClass(String.class);
+ verify(mg.getImageService(), atLeastOnce()).getImageByName(getImageNameCaptor.capture());
+ assertEquals("in:\"" + createSnapshotCaptor.getValue() + "\"", getImageNameCaptor.getValue());
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestEvacuateServer.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestEvacuateServer.java
new file mode 100644
index 000000000..e9ca878bd
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestEvacuateServer.java
@@ -0,0 +1,114 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Image;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.iaas.Constants;
+import org.onap.ccsdk.sli.adaptors.iaas.ProviderAdapter;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.ProviderAdapterImpl;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.powermock.reflect.Whitebox;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+
+public class TestEvacuateServer {
+
+ @Test
+ public void evacuateServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ EvacuateServer rbs = new EvacuateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ mg.getParams().put(ProviderAdapter.PROPERTY_TARGETHOST_ID, "newServer1");
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during EvacuateServer.executeProviderOperation");
+ }
+ verify(mg.getComputeService()).moveServer(server.getId(), "newServer1");
+ }
+
+ @Test
+ public void evacuateServerPaImpl() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ EvacuateServer rbs = new EvacuateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ mg.getParams().put(ProviderAdapter.PROPERTY_TARGETHOST_ID, "newServer1");
+ List<Image> images = new ArrayList<>();
+ images.add(Mockito.mock(Image.class));
+ Mockito.doReturn(images).when(mg.getServer()).getSnapshots();
+ ProviderAdapterImpl paImpl = Mockito.mock(ProviderAdapterImpl.class);
+ Whitebox.setInternalState(rbs, "paImpl", paImpl);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("error_code", "300");
+ rbs.executeProviderOperation(mg.getParams(), ctx);
+ verify(mg.getComputeService()).moveServer("12442", "newServer1");
+ }
+
+ @Test
+ public void evacuateServerSvcLogicException() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ EvacuateServer rbs = new EvacuateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ mg.getParams().put(ProviderAdapter.PROPERTY_TARGETHOST_ID, "newServer1");
+ List<Image> images = new ArrayList<>();
+ images.add(Mockito.mock(Image.class));
+ Mockito.doReturn(images).when(mg.getServer()).getSnapshots();
+ ProviderAdapterImpl paImpl = Mockito.mock(ProviderAdapterImpl.class);
+ Mockito.doThrow(new SvcLogicException()).when(paImpl).rebuildServer(Mockito.anyMap(),
+ Mockito.any(SvcLogicContext.class));
+ Whitebox.setInternalState(rbs, "paImpl", paImpl);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("error_code", "300");
+ rbs.executeProviderOperation(mg.getParams(), ctx);
+ assertEquals("Internal Server Error", ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
+ }
+
+ @Test
+ public void evacuateServerZoneException() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ EvacuateServer rbs = new EvacuateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ mg.getParams().put(ProviderAdapter.PROPERTY_TARGETHOST_ID, "newServer1");
+ List<Image> images = new ArrayList<>();
+ images.add(Mockito.mock(Image.class));
+ Mockito.doReturn(images).when(mg.getServer()).getSnapshots();
+ Mockito.doThrow(new ZoneException("TEST")).when(mg.getServer()).refreshAll();
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("error_code", "300");
+ rbs.executeProviderOperation(mg.getParams(), ctx);
+ assertEquals("TEST", ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestLookupServer.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestLookupServer.java
new file mode 100644
index 000000000..40ece56c6
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestLookupServer.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.junit.Assert.assertTrue;
+
+public class TestLookupServer {
+
+ @Test
+ public void lookupServer() {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ LookupServer rbs = new LookupServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = null;
+ try {
+ mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during LookupServer.executeProviderOperation");
+ }
+ boolean correctServerReturned = false;
+ try {
+ Server returnedServer = (Server) mo;
+ correctServerReturned = returnedServer == server;
+ } catch (Exception e) {
+ Assert.fail();
+ }
+ assertTrue(correctServerReturned);
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestMigrateServer.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestMigrateServer.java
new file mode 100644
index 000000000..61c3678da
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestMigrateServer.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.onap.ccsdk.sli.adaptors.iaas.ProviderAdapter;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class TestMigrateServer {
+
+ @Test
+ public void should_migrateSuspendedServer() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ MigrateServer rbs = new MigrateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during MigrateServer.executeProviderOperation");
+ }
+ verify(mg.getComputeService()).migrateServer(MockGenerator.SERVER_ID);
+ verify(server, atLeastOnce()).waitForStateChange(anyInt(), anyInt(), Matchers.anyVararg());
+ }
+
+ @Test
+ public void should_returnNullAsServer(){
+
+ // given
+ Map<String, String> params = mock(Map.class);
+ SvcLogicContext svcLogicContext = mock(SvcLogicContext.class);
+ MockGenerator mockGenerator = new MockGenerator(Status.READY);
+ MigrateServer migrateServer = new MigrateServer();
+ migrateServer.setProviderCache(mockGenerator.getProviderCacheMap());
+ ModelObject modelObject = new Server();
+
+ // when
+ when(params.get(ProviderAdapter.PROPERTY_INSTANCE_URL)).thenReturn(null);
+ try {
+ modelObject = migrateServer.executeProviderOperation(params,svcLogicContext);
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during MigrateServer.executeProviderOperation");
+ }
+
+ // then
+ Assert.assertNull(modelObject);
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRebootServer.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRebootServer.java
new file mode 100644
index 000000000..7a24eba88
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRebootServer.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.Context;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Tenant;
+import java.util.Properties;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+import org.onap.ccsdk.sli.adaptors.iaas.ProviderAdapter;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestContext;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestFailedException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestRebootServer {
+
+ @Test
+ public void should_returnNullAsServer() throws ZoneException,SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ RebootServer rbs = new RebootServer();
+ mg.getParams().put(ProviderAdapter.PROPERTY_INSTANCE_URL, "url1");
+ mg.getParams().put(ProviderAdapter.REBOOT_TYPE, "");
+ mg.getParams().put("REBOOT_STATUS", "SUCCESS");
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ assertEquals("SUCCESS", mg.getParams().get("REBOOT_STATUS"));
+ }
+
+ @Test
+ public void rebootServerTest() throws ZoneException,SvcLogicException, RequestFailedException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ SubclassRebootServer rbs = Mockito.spy(new SubclassRebootServer());
+ mg.getParams().put(ProviderAdapter.PROPERTY_INSTANCE_URL, getURL());
+ mg.getParams().put(ProviderAdapter.REBOOT_TYPE, "HARD");
+ mg.getParams().put("REBOOT_STATUS", "SUCCESS");
+ Tenant tenant = new Tenant();
+ tenant.setName("TENANT_NAME");
+ mg.getContext().setTenant(tenant);
+ Mockito.doReturn(mg.getContext()).when(rbs).getContext(Mockito.any(RequestContext.class), Mockito.anyString(),
+ Mockito.anyString());
+ Mockito.doReturn(mg.getServer()).when(rbs).lookupServer(Mockito.any(RequestContext.class), Mockito.any(Context.class),
+ Mockito.anyString());
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ assertEquals("SUCCESS", mg.getParams().get("REBOOT_STATUS"));
+ }
+
+ private String getURL() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ return String.format("http://%s:%s/v2/%s/servers/%s", props.getProperty("test.ip"), props.getProperty("test.port"),
+ "3b3d77e0-a79d-4c10-bfac-1b3914af1a14", "3b3d77e0-a79d-4c10-bfac-1b3914af1a14");
+ }
+
+ class SubclassRebootServer extends RebootServer {
+ @Override
+ public Context getContext(RequestContext rc, String selfLinkURL, String providerName) {
+ return super.getContext(rc, selfLinkURL, providerName);
+ }
+ @Override
+ public Server lookupServer(RequestContext rc, Context context, String id) throws ZoneException, RequestFailedException {
+ return super.lookupServer(rc, context, id);
+ }
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRebuildServer.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRebuildServer.java
new file mode 100644
index 000000000..d8c15b177
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRebuildServer.java
@@ -0,0 +1,158 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.onap.ccsdk.sli.adaptors.iaas.Constants;
+import org.onap.ccsdk.sli.core.utils.configuration.Configuration;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.verify;
+
+
+public class TestRebuildServer {
+ protected static final Configuration configuration = ConfigurationFactory.getConfiguration();
+
+ @Test
+ public void rebuildServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).rebuild("linuxBase");
+ inOrderTest.verify(server).start();
+
+ }
+
+ @Test
+ public void rebuildServerReady() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.READY);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).rebuild("linuxBase");
+ inOrderTest.verify(server).start();
+ }
+
+ @Test
+ public void rebuildServerPause() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.PAUSED);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).unpause();
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).rebuild("linuxBase");
+ inOrderTest.verify(server).start();
+ }
+
+ @Test
+ public void rebuildServerError() {
+ MockGenerator mg = new MockGenerator(Status.ERROR);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ verify(mg.getSvcLogicContext()).setAttribute(Constants.ATTRIBUTE_ERROR_CODE,
+ "405");
+ }
+
+ @Test
+ public void rebuildServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during RebuildServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).resume();
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).rebuild("linuxBase");
+ inOrderTest.verify(server).start();
+ }
+
+ @Test
+ public void rebuildServerException() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(null);
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ SvcLogicContext context = new SvcLogicContext();
+ rbs.executeProviderOperation(mg.getParams(), context);
+ assertEquals("ERROR", context.getAttribute("REBUILD_STATUS"));
+ }
+
+ @Test
+ public void rebuildServerDeleted() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.DELETED);
+ RebuildServer rbs = new RebuildServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.setRebuildSleepTime(0);
+ SvcLogicContext context = new SvcLogicContext();
+ rbs.executeProviderOperation(mg.getParams(), context);
+ assertEquals("ERROR", context.getAttribute("REBUILD_STATUS"));
+ }
+
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRestartServer.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRestartServer.java
new file mode 100644
index 000000000..ece66e7e3
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRestartServer.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Modifications Copyright (C) 2019 IBM
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.inOrder;
+
+public class TestRestartServer {
+
+ @Test
+ public void restartServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ RestartServer rbs = new RestartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during RestartServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).resume();
+ }
+
+ @Test
+ public void restartServerRunning() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ RestartServer rbs = new RestartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).start();
+ }
+
+ @Test
+ public void pauseServerRunning() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.READY);
+ Server server = mg.getServer();
+ RestartServer rbs = new RestartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).start();
+ }
+
+ @Test
+ public void pauseServerError() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.ERROR);
+ Server server = mg.getServer();
+ RestartServer rbs = new RestartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ assertNotNull(mg);
+
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRestoreStack.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRestoreStack.java
new file mode 100644
index 000000000..25be06a13
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestRestoreStack.java
@@ -0,0 +1,93 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.openstack.connectors.HeatConnector;
+import com.att.cdp.zones.Context;
+import com.att.cdp.zones.StackService;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Stack;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.iaas.ProviderAdapter;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+
+public class TestRestoreStack {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void restoreStackTest() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ HeatConnector heatConnector = Mockito.mock(HeatConnector.class);
+ StackService stackService = mock(StackService.class);
+ Stack stack1 = mock(Stack.class);
+ doReturn("stack1").when(stack1).getId();
+ doReturn("stack1").when(stack1).getName();
+ doReturn(heatConnector).when(mg.getContext()).getHeatConnector();
+ com.att.cdp.zones.model.Stack.Status stackStatus =
+ com.att.cdp.zones.model.Stack.Status.DELETED;
+ doReturn(stackStatus).when(stack1).getStatus();
+ doReturn(mg.getContext()).when(stack1).getContext();
+ List<Stack> stackList = new LinkedList<Stack>();
+ stackList.add(stack1);
+ doReturn(stackList).when(stackService).getStacks();
+ doReturn(stack1).when(stackService).getStack("stack1", "stack1");
+ doReturn(stackService).when(mg.getContext()).getStackService();
+ mg.getParams().put(ProviderAdapter.PROPERTY_STACK_ID, "stack1");
+ mg.getParams().put(ProviderAdapter.PROPERTY_INSTANCE_URL, "URL");
+ mg.getParams().put(ProviderAdapter.PROPERTY_PROVIDER_NAME, "NAME");
+ mg.getParams().put(ProviderAdapter.PROPERTY_INPUT_SNAPSHOT_ID, "SNAPSHOT_ID");
+ SubclassRestoreStack rbs = Mockito.spy(new SubclassRestoreStack());
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ Mockito.doReturn(stack1).when(rbs).lookupStack(Mockito.any(RequestContext.class), Mockito.any(Context.class),
+ Mockito.anyString());
+ Mockito.doReturn(mg.getContext()).when(rbs).resolveContext(Mockito.any(RequestContext.class), Mockito.anyMap(),
+ Mockito.anyString(), Mockito.anyString());
+ expectedEx.expect(SvcLogicException.class);
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ }
+
+ class SubclassRestoreStack extends RestoreStack {
+ @Override
+ protected Context resolveContext(RequestContext rc, Map<String, String> params, String appName, String vmUrl) {
+ return Mockito.mock(Context.class);
+ }
+ @Override
+ protected Stack lookupStack(RequestContext rc, Context context, String id) {
+ Stack stack = Mockito.mock(Stack.class);
+ return stack;
+ }
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestSnapshotStack.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestSnapshotStack.java
new file mode 100644
index 000000000..204af3de4
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestSnapshotStack.java
@@ -0,0 +1,71 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.openstack.connectors.HeatConnector;
+import com.att.cdp.zones.StackService;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Stack;
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.iaas.ProviderAdapter;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+
+public class TestSnapshotStack {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void snapshotStackTest() throws ZoneException, SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ HeatConnector heatConnector = Mockito.mock(HeatConnector.class);
+ StackService stackService = mock(StackService.class);
+ Stack stack1 = mock(Stack.class);
+ doReturn("stack1").when(stack1).getId();
+ doReturn("stack1").when(stack1).getName();
+ doReturn(heatConnector).when(mg.getContext()).getHeatConnector();
+ com.att.cdp.zones.model.Stack.Status stackStatus =
+ com.att.cdp.zones.model.Stack.Status.DELETED;
+ doReturn(stackStatus).when(stack1).getStatus();
+ doReturn(mg.getContext()).when(stack1).getContext();
+ List<Stack> stackList = new LinkedList<Stack>();
+ stackList.add(stack1);
+ doReturn(stackList).when(stackService).getStacks();
+ doReturn(stack1).when(stackService).getStack("stack1", "stack1");
+ doReturn(stackService).when(mg.getContext()).getStackService();
+ mg.getParams().put(ProviderAdapter.PROPERTY_STACK_ID, "stack1");
+ SnapshotStack rbs = new SnapshotStack();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ expectedEx.expect(SvcLogicException.class);
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestStartServer.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestStartServer.java
new file mode 100644
index 000000000..82009e13b
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestStartServer.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.mockito.Mockito.inOrder;
+
+public class TestStartServer {
+
+ @Test
+ public void startServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ StartServer rbs = new StartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during StartServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).resume();
+ }
+
+ @Test
+ public void startServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.PAUSED);
+ Server server = mg.getServer();
+ StartServer rbs = new StartServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during StartServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).unpause();
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestStopServer.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestStopServer.java
new file mode 100644
index 000000000..9247b090d
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestStopServer.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.mockito.Mockito.inOrder;
+
+public class TestStopServer {
+
+ @Test
+ public void stopServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ StopServer rbs = new StopServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during StopServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).resume();
+ }
+
+ @Test
+ public void stopServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.PAUSED);
+ Server server = mg.getServer();
+ StopServer rbs = new StopServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during StopServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).unpause();
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestTerminateServer.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestTerminateServer.java
new file mode 100644
index 000000000..ea5c5c6ee
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestTerminateServer.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.mockito.Mockito.inOrder;
+
+public class TestTerminateServer {
+
+ @Test
+ public void terminateServerSuspended() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ TerminateServer rbs = new TerminateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during TerminateServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).delete();
+ }
+
+ @Test
+ public void terminateServerRunning() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ TerminateServer rbs = new TerminateServer();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ int i = 5;
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during TerminateServer.executeProviderOperation");
+ }
+ InOrder inOrderTest = inOrder(server);
+ inOrderTest.verify(server).stop();
+ inOrderTest.verify(server).delete();
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestTerminateStack.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestTerminateStack.java
new file mode 100644
index 000000000..01655d7c6
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestTerminateStack.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.StackService;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Stack;
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.iaas.ProviderAdapter;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class TestTerminateStack {
+
+ @Test
+ public void terminateStack() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ StackService stackService = mock(StackService.class);
+ Stack stack1 = mock(Stack.class);
+ doReturn("stack1").when(stack1).getId();
+ doReturn("stack1").when(stack1).getName();
+ com.att.cdp.zones.model.Stack.Status stackStatus =
+ com.att.cdp.zones.model.Stack.Status.DELETED;
+ doReturn(stackStatus).when(stack1).getStatus();
+ doReturn(mg.getContext()).when(stack1).getContext();
+ List<Stack> stackList = new LinkedList<Stack>();
+ stackList.add(stack1);
+ doReturn(stackList).when(stackService).getStacks();
+ doReturn(stack1).when(stackService).getStack("stack1", "stack1");
+ doReturn(stackService).when(mg.getContext()).getStackService();
+ mg.getParams().put(ProviderAdapter.PROPERTY_STACK_ID, "stack1");
+
+ TerminateStack rbs = new TerminateStack();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ try {
+ rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during TerminateStack.executeProviderOperation");
+ }
+ verify(stackService).deleteStack(stack1);
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestVmStatuschecker.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestVmStatuschecker.java
new file mode 100644
index 000000000..ac80a0c65
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/TestVmStatuschecker.java
@@ -0,0 +1,124 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Modifications Copyright (C) 2019 IBM.
+ * =============================================================================
+ * 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.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl;
+
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.iaas.Constants;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.verify;
+
+public class TestVmStatuschecker {
+
+ @Test
+ public void vmStatuscheckerSuspended() {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = null;
+ try {
+ mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during VmStatuschecker.executeProviderOperation");
+ }
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "suspended");
+ }
+
+ @Test
+ public void vmStatuscheckerRunning() {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = null;
+ try {
+ mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during VmStatuschecker.executeProviderOperation");
+ }
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "running");
+ }
+
+ @Test
+ public void vmStatuscheckerError() {
+ MockGenerator mg = new MockGenerator(Status.ERROR);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = null;
+ try {
+ mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ } catch (SvcLogicException e) {
+ Assert.fail("Exception during VmStatuschecker.executeProviderOperation");
+ }
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "error");
+ }
+
+ @Test
+ public void vmDeletedStatuscheckerError() throws SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.DELETED);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "deleted");
+ }
+
+ @Test
+ public void vmReadyStatuscheckerError() throws SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.READY);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "ready");
+ }
+
+ @Test
+ public void vmPausedStatuscheckerError() throws SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.PAUSED);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "paused");
+ }
+
+ @Test
+ public void vmPendingStatuscheckerError() throws SvcLogicException {
+ MockGenerator mg = new MockGenerator(Status.PENDING);
+ Server server = mg.getServer();
+ VmStatuschecker rbs = new VmStatuschecker();
+ rbs.setProviderCache(mg.getProviderCacheMap());
+ ModelObject mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
+ verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "pending");
+ }
+} \ No newline at end of file
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderOperation.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderOperation.java
new file mode 100644
index 000000000..ca55f82d1
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderOperation.java
@@ -0,0 +1,338 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.base;
+
+import com.att.cdp.openstack.OpenStackContext;
+import com.att.cdp.zones.model.Server.Status;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.iaas.Constants;
+import org.onap.ccsdk.sli.core.utils.configuration.ConfigurationFactory;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.ProviderCache;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestContext;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestFailedException;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.TenantCache;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.VMURL;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.AttachVolumeServer;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.MockGenerator;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.utils.pool.Pool;
+import org.onap.ccsdk.sli.core.utils.pool.PoolDrainedException;
+import org.onap.ccsdk.sli.core.utils.pool.PoolExtensionException;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+
+public class TestProviderOperation {
+
+ ProviderServerOperation underTest = spy(new AttachVolumeServer());
+
+ @Test
+ public void testDoFailureRequestContextHttpStatusString() throws SvcLogicException {
+ RequestContext rc = mock(RequestContext.class);
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ HttpStatus code = HttpStatus.NOT_FOUND_404;
+ String message = "PALOS\n";
+ underTest.doFailure(rc, code, message);
+ verify(underTest).doFailure(rc, code, message, null);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testDoFailureRequestContextHttpStatusStringException() throws SvcLogicException {
+ RequestContext rc = mock(RequestContext.class);
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ HttpStatus code = spy(HttpStatus.NOT_FOUND_404);
+ doThrow(new RuntimeException("TEST")).when(code).getStatusCode();
+ String message = "PALOS\n";
+ underTest.doFailure(rc, code, message, new Throwable("TEST"));
+ verify(underTest).doFailure(rc, code, message, null);
+ }
+
+ @Test
+ public void testDoFailureRequestContextHttpStatusStringSvcLogicException() throws SvcLogicException {
+ RequestContext rc = mock(RequestContext.class);
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ HttpStatus code = HttpStatus.NOT_FOUND_404;
+ String message = "PALOS\n";
+ doThrow(new SvcLogicException("TEST")).when(underTest).doFailure(rc, code, message, null);
+ underTest.doFailure(rc, code, message);
+ verify(underTest).doFailure(rc, code, message, null);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testDoFailureRequestContextHttpStatusStringThrowableSvcLogicException() throws SvcLogicException {
+ RequestContext rc = mock(RequestContext.class);
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ HttpStatus code = HttpStatus.NOT_FOUND_404;
+ String message = "PALOS\n";
+ underTest.doFailure(rc, code, message, new Throwable());
+ }
+
+ @Test
+ public void testValidateVM() throws RequestFailedException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ RequestContext rc = mock(RequestContext.class);
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ assertTrue(underTest.validateVM(rc, "TEST", "TEST", null));
+ }
+
+ @Test
+ public void testGetContextNullVM() {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ assertNull(underTest.getContext(rc, "%£$%^$", "%£$%^$"));
+ verify(underTest).doFailure(Mockito.any(RequestContext.class), Mockito.any(HttpStatus.class),
+ Mockito.anyString());
+ }
+
+ @Test
+ public void testGetContextNullCache() {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ underTest.setProviderCache(mg.getProviderCacheMap());
+ assertNull(underTest.getContext(rc, "http://10.1.1.2:5000/v2/abc12345-1234-5678-890a-abcdefb12345/servers/"
+ + "abc12345-1234-5678-890a-abcdefb12345", "%£$%^$"));
+ verify(underTest).doFailure(Mockito.any(RequestContext.class), Mockito.any(HttpStatus.class),
+ Mockito.anyString());
+ }
+
+ @Test
+ public void testGetContextNullTenantCache() {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ Map<String, ProviderCache> providerCacheMap = mg.getProviderCacheMap();
+ providerCacheMap.put("TEST", mock(ProviderCache.class));
+ underTest.setProviderCache(mg.getProviderCacheMap());
+ assertNull(underTest.getContext(rc, "http://10.1.1.2:5000/v2/abc12345-1234-5678-890a-abcdefb12345/servers/"
+ + "abc12345-1234-5678-890a-abcdefb12345", "TEST"));
+ verify(underTest).doFailure(Mockito.any(RequestContext.class), Mockito.any(HttpStatus.class),
+ Mockito.anyString());
+ }
+
+ @Test
+ public void testGetContextPoolNullRegion() {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ Map<String, ProviderCache> providerCacheMap = mg.getProviderCacheMap();
+ TenantCache tenantCache = mock(TenantCache.class);
+ when(tenantCache.getTenantName()).thenReturn("TEST");
+ when(tenantCache.getTenantId()).thenReturn("TEST");
+ when(tenantCache.determineRegion(Mockito.anyObject())).thenReturn(null);
+ ProviderCache providerCache = mock(ProviderCache.class);
+ when(providerCache.getTenant(Mockito.anyString())).thenReturn(tenantCache);
+ providerCacheMap.put("TEST", providerCache);
+ underTest.setProviderCache(mg.getProviderCacheMap());
+ assertNull(underTest.getContext(rc, "http://10.1.1.2:5000/v2/abc12345-1234-5678-890a-abcdefb12345/servers/"
+ + "abc12345-1234-5678-890a-abcdefb12345", "TEST"));
+ verify(underTest).doFailure(Mockito.any(RequestContext.class), Mockito.any(HttpStatus.class),
+ Mockito.anyString());
+ }
+
+ @Test
+ public void testGetContextAttemptFailed() {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ underTest.setProviderCache(mg.getProviderCacheMap());
+ assertNull(underTest.getContext(rc,
+ "http://10.1.1.2:5000/v2/abc12345-1234-5678-890a-abcdefb12345/servers/"
+ + "abc12345-1234-5678-890a-abcdefb12345",
+ "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3"));
+ }
+
+ @Test
+ public void testGetContextRelogin() throws PoolExtensionException, PoolDrainedException {
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext svcLogicContext = mock(SvcLogicContext.class);
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ ProviderCache providerCache = mock(ProviderCache.class);
+ Map<String, ProviderCache> providerCacheMap = new HashMap<String, ProviderCache>();
+ providerCacheMap.put("http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3", providerCache);
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ OpenStackContext context = mock(OpenStackContext.class);
+ when(context.isStale()).thenReturn(true);
+ TenantCache tenantCache = mock(TenantCache.class);
+ doReturn("cloudowner_region").when(tenantCache).determineRegion(any(VMURL.class));
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantId();
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantName();
+ Pool pool = mock(Pool.class);
+ Map<String, Pool> tenantCachePools = new HashMap<String, Pool>();
+ tenantCachePools.put("cloudowner_region", pool);
+ doReturn(tenantCachePools).when(tenantCache).getPools();
+ when(providerCache.getTenant(Mockito.anyString())).thenReturn(tenantCache);
+ doReturn(tenantCache).when(providerCache).getTenant(Mockito.anyString());
+ doReturn(context).when(pool).reserve();
+ underTest.setProviderCache(providerCacheMap);
+ assertTrue(underTest.getContext(rc,
+ "http://10.1.1.2:5000/v2/abc12345-1234-5678-890a-abcdefb12345/servers/"
+ + "abc12345-1234-5678-890a-abcdefb12345",
+ "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3") instanceof OpenStackContext);
+ }
+
+ @Test
+ public void testGetContextPoolException() throws PoolExtensionException, PoolDrainedException {
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext svcLogicContext = mock(SvcLogicContext.class);
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ ProviderCache providerCache = mock(ProviderCache.class);
+ Map<String, ProviderCache> providerCacheMap = new HashMap<String, ProviderCache>();
+ providerCacheMap.put("http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3", providerCache);
+
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ OpenStackContext context = mock(OpenStackContext.class);
+ when(context.isStale()).thenReturn(true);
+ TenantCache tenantCache = mock(TenantCache.class);
+ doReturn("cloudowner_region").when(tenantCache).determineRegion(any(VMURL.class));
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantId();
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantName();
+ Pool pool = mock(Pool.class);
+ Map<String, Pool> tenantCachePools = new HashMap<String, Pool>();
+ tenantCachePools.put("cloudowner_region", pool);
+ doReturn(tenantCachePools).when(tenantCache).getPools();
+ when(providerCache.getTenant(Mockito.anyString())).thenReturn(tenantCache);
+ doReturn(tenantCache).when(providerCache).getTenant(Mockito.anyString());
+ doThrow(new PoolExtensionException("TEST")).when(pool).reserve();
+ underTest.setProviderCache(providerCacheMap);
+ underTest.getContext(rc,
+ "http://10.1.1.2:5000/v2/abc12345-1234-5678-890a-abcdefb12345/servers/"
+ + "abc12345-1234-5678-890a-abcdefb12345",
+ "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3");
+ verify(rc).delay();
+ }
+
+ @Test
+ public void testGetContextException() {
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext svcLogicContext = mock(SvcLogicContext.class);
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ ProviderCache providerCache = mock(ProviderCache.class);
+ Map<String, ProviderCache> providerCacheMap = new HashMap<String, ProviderCache>();
+ providerCacheMap.put("http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3", providerCache);
+
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ OpenStackContext context = mock(OpenStackContext.class);
+ when(context.isStale()).thenReturn(true);
+ TenantCache tenantCache = mock(TenantCache.class);
+ doReturn("cloudowner_region").when(tenantCache).determineRegion(any(VMURL.class));
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantId();
+ doReturn("abc12345-1234-5678-890a-abcdefb12345").when(tenantCache).getTenantName();
+ Pool pool = mock(Pool.class);
+ Map<String, Pool> tenantCachePools = new HashMap<String, Pool>();
+ tenantCachePools.put("cloudowner_region", pool);
+ doReturn(tenantCachePools).when(tenantCache).getPools();
+ when(providerCache.getTenant(Mockito.anyString())).thenReturn(tenantCache);
+ doReturn(tenantCache).when(providerCache).getTenant(Mockito.anyString());
+ doThrow(new RuntimeException("TEST")).when(rc).delay();
+ underTest.setProviderCache(providerCacheMap);
+ assertNull(underTest.getContext(rc,
+ "http://10.1.1.2:5000/v2/abc12345-1234-5678-890a-abcdefb12345/servers/"
+ + "abc12345-1234-5678-890a-abcdefb12345",
+ "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3"));
+ }
+
+ @Test
+ public void testValidateVMURLRequestFailedExceptionWellFormed() {
+ VMURL vm = mock(VMURL.class);
+ try {
+ underTest.validateVMURL(vm);
+ fail("Exception not thrown");
+ } catch (RequestFailedException rfe) {
+ assert (rfe.getMessage().startsWith("The value vm-id is not well formed"));
+ }
+ }
+
+ @Test
+ public void testValidateVMURLRequestFailedExceptionTenantId() throws RequestFailedException {
+ VMURL vm = mock(VMURL.class);
+ when(vm.toString()).thenReturn("192.168.0.1");
+ when(vm.getTenantId()).thenReturn("%£$%^$");
+ try {
+ underTest.validateVMURL(vm);
+ fail("Exception not thrown");
+ } catch (RequestFailedException rfe) {
+ assert (rfe.getMessage().startsWith("The value vm-id has an invalid tenantId"));
+ }
+ }
+
+ @Test
+ public void testValidateVMURLRequestFailedExceptionServerId() throws RequestFailedException {
+ VMURL vm = mock(VMURL.class);
+ when(vm.toString()).thenReturn("192.168.0.1");
+ when(vm.getTenantId()).thenReturn("0000000000000000000000000000000a");
+ when(vm.getServerId()).thenReturn("%£$%^$");
+ try {
+ underTest.validateVMURL(vm);
+ fail("Exception not thrown");
+ } catch (RequestFailedException rfe) {
+ assert (rfe.getMessage().startsWith("The value vm-id has an invalid serverId"));
+ }
+ }
+
+ @Test
+ public void testResolveContext() throws RequestFailedException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ RequestContext rc = mock(RequestContext.class);
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ assertNull(underTest.resolveContext(rc, new HashMap<String, String>(), "TEST", "TEST"));
+ }
+
+ @Test(expected = RequestFailedException.class)
+ public void testValidateParameters() throws RequestFailedException {
+ Properties properties = new Properties();
+ properties.putAll(ConfigurationFactory.getConfiguration().getProperties());
+ properties.put("TEST", "");
+ Map<String, String> propertyMap = new HashMap<String, String>();
+ for (String keys: properties.stringPropertyNames()) { propertyMap.put(keys, properties.getProperty(keys) );}
+ underTest.validateParametersExist(propertyMap, Constants.PROPERTY_APPLICATION_NAME, "TEST");
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderServerOperation.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderServerOperation.java
new file mode 100644
index 000000000..d098e1a5c
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderServerOperation.java
@@ -0,0 +1,592 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.base;
+
+import com.att.cdp.exceptions.ContextClosedException;
+import com.att.cdp.exceptions.ContextConnectionException;
+import com.att.cdp.exceptions.InvalidRequestException;
+import com.att.cdp.exceptions.NotLoggedInException;
+import com.att.cdp.exceptions.NotNavigableException;
+import com.att.cdp.exceptions.TimeoutException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.openstack.OpenStackContext;
+import com.att.cdp.zones.ComputeService;
+import com.att.cdp.zones.Context;
+import com.att.cdp.zones.ImageService;
+import com.att.cdp.zones.NetworkService;
+import com.att.cdp.zones.Provider;
+import com.att.cdp.zones.model.Hypervisor;
+import com.att.cdp.zones.model.Image;
+import com.att.cdp.zones.model.Network;
+import com.att.cdp.zones.model.Port;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Tenant;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestContext;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestFailedException;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.AttachVolumeServer;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.MockGenerator;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class TestProviderServerOperation {
+
+ ProviderServerOperation underTest = spy(AttachVolumeServer.class);
+
+ @Test
+ public void testHasImageAccess() throws NotLoggedInException {
+ RequestContext rc = mock(RequestContext.class);
+ ImageService imageService = mock(ImageService.class);
+ Context context = mock(OpenStackContext.class);
+ when(context.getImageService()).thenReturn(imageService);
+ assertTrue(underTest.hasImageAccess(rc, context));
+ }
+
+ @Test
+ public void testHasImageAccessZoneException() throws ZoneException {
+ RequestContext rc = mock(RequestContext.class);
+ ImageService imageService = mock(ImageService.class);
+ Context context = mock(OpenStackContext.class);
+ when(context.getImageService()).thenReturn(imageService);
+ when(imageService.getImageByName("CHECK_IMAGE_ACCESS")).thenThrow(new ZoneException("TEST_ZONE_EXCEPTION"));
+ assertFalse(underTest.hasImageAccess(rc, context));
+ }
+
+ @Test
+ public void testWaitForStateChangeRequestContextImageStatusArray() throws ZoneException {
+ Image image = mock(Image.class);
+ Image.Status imageStatus = Image.Status.ACTIVE;
+ image.setStatus(imageStatus);
+ RequestContext rc = mock(RequestContext.class);
+ ImageService imageService = mock(ImageService.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ when(image.getContext()).thenReturn(context);
+ when(rc.isFailed()).thenReturn(true);
+ when(context.getImageService()).thenReturn(imageService);
+ boolean requestFailedExceptionThrown = false;
+ try {
+ underTest.waitForStateChange(rc, image, imageStatus);
+ fail("Exception not thrown");
+ } catch (RequestFailedException requestFailedException) {
+ requestFailedExceptionThrown = (requestFailedException.getOperation().equals("Waiting for State Change"));
+ }
+ assertTrue(requestFailedExceptionThrown);
+ }
+
+ @Test
+ public void testWaitForStateChangeRequestContextImageStatusArrayTimeoutException() throws ZoneException,
+ NotNavigableException, InvalidRequestException, ContextClosedException, RequestFailedException {
+ Image image = mock(Image.class);
+ Image.Status imageStatus = Image.Status.ACTIVE;
+ image.setStatus(imageStatus);
+ RequestContext rc = mock(RequestContext.class);
+ ImageService imageService = mock(ImageService.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(context.getProvider()).thenReturn(provider);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ when(image.getContext()).thenReturn(context);
+ when(rc.isFailed()).thenReturn(false);
+ Tenant tenant = spy(new Tenant());
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ when(context.getTenant()).thenReturn(tenant);
+ when(context.getImageService()).thenReturn(imageService);
+ doThrow(new TimeoutException("TEST")).when(image).waitForStateChange(Mockito.anyInt(), Mockito.anyInt(),
+ Mockito.anyObject());
+ underTest.waitForStateChange(rc, image, imageStatus);
+ verify(rc, times(1)).delay();
+ }
+
+ @Test
+ public void testWaitForStateChangeRequestContextImageStatusArrayZoneException()
+ throws ZoneException, RequestFailedException {
+ Image image = mock(Image.class);
+ Image.Status imageStatus = Image.Status.ACTIVE;
+ image.setStatus(imageStatus);
+ RequestContext rc = mock(RequestContext.class);
+ ImageService imageService = mock(ImageService.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(context.getProvider()).thenReturn(provider);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ when(image.getContext()).thenReturn(context);
+ when(image.getName()).thenReturn("TEST_IMAGE_NAME");
+ when(image.getId()).thenReturn("TEST_IMAGE_ID");
+ when(image.getStatus()).thenReturn(imageStatus);
+ when(rc.isFailed()).thenReturn(false);
+ Tenant tenant = spy(new Tenant());
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ when(context.getTenant()).thenReturn(tenant).thenThrow(new ZoneException("TEST_ZONE_EXCEPTION"));
+ when(context.getImageService()).thenReturn(imageService);
+ doThrow(new TimeoutException("TEST")).when(image).waitForStateChange(Mockito.anyInt(), Mockito.anyInt(),
+ Mockito.anyObject());
+ underTest.waitForStateChange(rc, image, imageStatus);
+ verify(rc, times(1)).delay();
+ }
+
+ @Test
+ public void testWaitForStateChangeRequestContextServerStatusArray() throws NotLoggedInException {
+ Server server = mock(Server.class);
+ Status serverStatus = Status.RUNNING;
+ server.setStatus(serverStatus);
+ RequestContext rc = mock(RequestContext.class);
+ ImageService imageService = mock(ImageService.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(context.getProvider()).thenReturn(provider);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ when(server.getContext()).thenReturn(context);
+ when(rc.isFailed()).thenReturn(true);
+ boolean requestFailedExceptionThrown = false;
+ try {
+ when(context.getImageService()).thenReturn(imageService);
+ underTest.waitForStateChange(rc, server, serverStatus);
+ } catch (RequestFailedException requestFailedException) {
+ requestFailedExceptionThrown = (requestFailedException.getOperation().equals("Waiting for State Change"));
+ }
+ assertTrue(requestFailedExceptionThrown);
+ }
+
+ @Test
+ public void testWaitForStateChangeRequestContextServerStatusArrayTimeoutException()
+ throws ZoneException, RequestFailedException {
+ Server server = mock(Server.class);
+ Status serverStatus = Status.RUNNING;
+ server.setStatus(serverStatus);
+ when(server.getStatus()).thenReturn(serverStatus);
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(context.getProvider()).thenReturn(provider);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ when(server.getContext()).thenReturn(context);
+ when(rc.isFailed()).thenReturn(false);
+ Tenant tenant = spy(new Tenant());
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ when(context.getTenant()).thenReturn(tenant);
+ doThrow(new TimeoutException("TEST")).when(server).waitForStateChange(Mockito.anyInt(), Mockito.anyInt(),
+ Mockito.anyObject());
+ underTest.waitForStateChange(rc, server, serverStatus);
+ verify(rc, times(1)).delay();
+ }
+
+ @Test
+ public void testWaitForStateChangeRequestContextServerStatusArrayZoneException()
+ throws ZoneException, RequestFailedException {
+ Server server = mock(Server.class);
+ Status serverStatus = Status.RUNNING;
+ MockGenerator mg = new MockGenerator(serverStatus);
+ server.setStatus(serverStatus);
+ when(server.getStatus()).thenReturn(serverStatus);
+ RequestContext rc = mock(RequestContext.class);
+ ImageService imageService = mock(ImageService.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(context.getProvider()).thenReturn(provider);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ when(server.getContext()).thenReturn(context);
+ when(rc.isFailed()).thenReturn(false);
+ Tenant tenant = spy(new Tenant());
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ when(context.getTenant()).thenReturn(tenant).thenThrow(new ZoneException("TEST_ZONE_EXCEPTION"));
+ when(context.getImageService()).thenReturn(imageService);
+ doThrow(new TimeoutException("TEST")).when(server).waitForStateChange(Mockito.anyInt(), Mockito.anyInt(),
+ Mockito.anyObject());
+ underTest.waitForStateChange(rc, server, serverStatus);
+ verify(rc, times(1)).delay();
+ }
+
+ @Test
+ public void testLookupServer() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = mock(Server.class);
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(rc.isFailed()).thenReturn(true);
+ SvcLogicContext slc = new SvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(slc);
+ rc.setSvcLogicContext(slc);
+ String id = mg.SERVER_ID;
+ boolean requestFailedExceptionThrown = false;
+ try {
+ underTest.lookupServer(rc, context, id);
+ fail("Exception not thrown");
+ } catch (RequestFailedException requestFailedException) {
+ System.out.println(requestFailedException.getOperation());
+ requestFailedExceptionThrown = (requestFailedException.getOperation().equals("Lookup Server"));
+ }
+ assertTrue(requestFailedExceptionThrown);
+ }
+
+ @Test
+ public void testLookupServerContextConnectionException() throws ZoneException, RequestFailedException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ Tenant tenant = spy(new Tenant());
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ when(context.getTenant()).thenReturn(tenant);
+ doThrow(new ContextConnectionException("TEST")).when(computeService).getServer(Mockito.anyString());
+ assertNull(underTest.lookupServer(rc, context, mg.SERVER_ID));
+ verify(rc, times(1)).delay();
+ }
+
+ @Test
+ public void testResumeServer() throws ZoneException {
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(rc.isFailed()).thenReturn(true);
+ boolean requestFailedExceptionThrown = false;
+ try {
+ underTest.resumeServer(rc, server);
+ fail("Exception not thrown");
+ } catch (RequestFailedException requestFailedException) {
+ requestFailedExceptionThrown = (requestFailedException.getOperation().equals("Resume Server"));
+ }
+ assertTrue(requestFailedExceptionThrown);
+ }
+
+ @Test
+ public void testResumeServerContextConnectionException() throws ZoneException, RequestFailedException {
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ Tenant tenant = spy(new Tenant());
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ when(context.getTenant()).thenReturn(tenant);
+ doThrow(new ContextConnectionException("TEST")).when(server).resume();
+ underTest.resumeServer(rc, server);
+ verify(rc, times(1)).delay();
+ }
+
+ @Test
+ public void testStopServer() throws ZoneException {
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(rc.isFailed()).thenReturn(true);
+ boolean requestFailedExceptionThrown = false;
+ try {
+ underTest.stopServer(rc, server);
+ fail("Exception not thrown");
+ } catch (RequestFailedException requestFailedException) {
+ requestFailedExceptionThrown = (requestFailedException.getOperation().equals("Stop Server")) ? true : false;
+ }
+ assertTrue(requestFailedExceptionThrown);
+ }
+
+ @Test
+ public void testStopServerContextConnectionException() throws ZoneException, RequestFailedException {
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ Tenant tenant = spy(new Tenant());
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ when(context.getTenant()).thenReturn(tenant);
+ doThrow(new ContextConnectionException("TEST")).when(server).stop();
+ underTest.stopServer(rc, server);
+ verify(rc, times(1)).delay();
+ }
+
+ @Test
+ public void testStartServer() throws ZoneException {
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(rc.isFailed()).thenReturn(true);
+ boolean requestFailedExceptionThrown = false;
+ try {
+ underTest.startServer(rc, server);
+ fail("Exception not thrown");
+ } catch (RequestFailedException requestFailedException) {
+ System.out.println(requestFailedException.getOperation());
+ requestFailedExceptionThrown = (requestFailedException.getOperation().equals("Start Server"));
+ }
+ assertTrue(requestFailedExceptionThrown);
+ }
+
+ @Test
+ public void testStartServerContextConnectionException() throws ZoneException, RequestFailedException {
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ Tenant tenant = spy(new Tenant());
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ when(context.getTenant()).thenReturn(tenant);
+ doThrow(new ContextConnectionException("TEST")).when(server).start();
+ underTest.startServer(rc, server);
+ verify(rc, times(1)).delay();
+ }
+
+ @Test
+ public void testUnpauseServer() throws ZoneException {
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ when(rc.isFailed()).thenReturn(true);
+ boolean requestFailedExceptionThrown = false;
+ try {
+ underTest.unpauseServer(rc, server);
+ } catch (RequestFailedException requestFailedException) {
+ System.out.println(requestFailedException.getOperation());
+ requestFailedExceptionThrown = (requestFailedException.getOperation().equals("Unpause Server"));
+ }
+ assertTrue(requestFailedExceptionThrown);
+ }
+
+ @Test
+ public void testUnpauseServerContextConnectionException() throws ZoneException, RequestFailedException {
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mock(OpenStackContext.class);
+ Provider provider = mock(Provider.class);
+ when(context.getProvider()).thenReturn(provider);
+ when(server.getContext()).thenReturn(context);
+ when(provider.getName()).thenReturn("TEST Provider Name");
+ ComputeService computeService = mock(ComputeService.class);
+ when(context.getComputeService()).thenReturn(computeService);
+ when(computeService.getURL()).thenReturn("TEST URL");
+ Tenant tenant = spy(new Tenant());
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ when(context.getTenant()).thenReturn(tenant);
+ doThrow(new ContextConnectionException("TEST")).when(server).unpause();
+ underTest.unpauseServer(rc, server);
+ verify(rc, times(1)).delay();
+ }
+
+ @Test
+ public void testCheckVirtualMachineNetworkStatusOnlinePort() throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext slc = new SvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(slc);
+ rc.setSvcLogicContext(slc);
+ OpenStackContext context = mock(OpenStackContext.class);
+ NetworkService netSvc = mock(NetworkService.class);
+ when(context.getNetworkService()).thenReturn(netSvc);
+ String id = mg.SERVER_ID;
+ Network network = mock(Network.class);
+ Server server = mock(Server.class);
+ Port onlinePort = new Port();
+ onlinePort.setName("Online Port");
+ onlinePort.setPortState(Port.Status.ONLINE);
+ onlinePort.setNetwork("ONLINE Port Network");
+ List<Port> portList = Arrays.asList(onlinePort);
+ System.out.println(Arrays.toString(portList.toArray()));
+ boolean requestFailedExceptionThrown = false;
+ try {
+ when(netSvc.getNetworkById(Mockito.anyString())).thenReturn(network);
+ when(server.getPorts()).thenReturn(portList);
+ when(network.getStatus()).thenReturn(Network.Status.OFFLINE.toString());
+ underTest.checkVirtualMachineNetworkStatus(rc, server, context);
+ fail("Exception not thrown");
+ } catch (RequestFailedException requestFailedException) {
+ System.out.println(requestFailedException.getOperation());
+ requestFailedExceptionThrown = (requestFailedException.getOperation().equals("VM Server Network is DOWN"));
+ }
+ assertTrue(requestFailedExceptionThrown);
+
+ }
+
+ @Test
+ public void testCheckVirtualMachineNetworkStatusOfflinePort() throws ZoneException {
+ Port offlinePort = new Port();
+ offlinePort.setName("Offline Port");
+ offlinePort.setId("Offline Port");
+ offlinePort.setPortState(Port.Status.OFFLINE);
+ testCheckVirtualMachineNetworkStatusBaseTest("OFFLINE", offlinePort);
+ }
+
+ @Test
+ public void testCheckVirtualMachineNetworkStatusPendingPort() throws ZoneException {
+ Port pendingPort = new Port();
+ pendingPort.setName("Pending Port");
+ pendingPort.setId("Pending Port");
+ pendingPort.setPortState(Port.Status.PENDING);
+ testCheckVirtualMachineNetworkStatusBaseTest("PENDING", pendingPort);
+ }
+
+ @Test
+ public void testCheckVirtualMachineNetworkStatusUnkownPort() throws ZoneException {
+ Port unknownPort = new Port();
+ unknownPort.setName("Unknown Port");
+ unknownPort.setId("Unknown Port");
+ unknownPort.setPortState(Port.Status.UNKNOWN);
+ testCheckVirtualMachineNetworkStatusBaseTest("UNKNOWN", unknownPort);
+ }
+
+ private void testCheckVirtualMachineNetworkStatusBaseTest(String name, Port port) throws ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ RequestContext rc = mock(RequestContext.class);
+ SvcLogicContext slc = new SvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(slc);
+ rc.setSvcLogicContext(slc);
+ OpenStackContext context = mg.getContext();
+ String id = mg.SERVER_ID;
+ Server server = mock(Server.class);
+ List<Port> portList = Arrays.asList(port);
+ boolean requestFailedExceptionThrown = false;
+ try {
+ when(server.getPorts()).thenReturn(portList);
+ underTest.checkVirtualMachineNetworkStatus(rc, server, context);
+ fail("Exception not thrown");
+ } catch (RequestFailedException requestFailedException) {
+ requestFailedExceptionThrown = (requestFailedException.getOperation()
+ .equals("VM Server Port status is " + name)) ? true : false;
+ }
+ assertTrue(requestFailedExceptionThrown);
+ }
+
+ @Test
+ public void testCheckHypervisorDown() throws ZoneException {
+ testCheckHypervisorBaseTest(Hypervisor.State.DOWN, "Hypervisor status DOWN or NOT ENABLED");
+ }
+
+ @Test
+ public void testCheckHypervisorUnknown() throws ZoneException {
+ testCheckHypervisorBaseTest(null, "Unable to determine Hypervisor status");
+ }
+
+ public void testCheckHypervisorBaseTest(Hypervisor.State state, String expectedExceptionOperation) throws ZoneException {
+ Server server = mock(Server.class);
+ Hypervisor hypervisor = new Hypervisor();
+ hypervisor.setStatus(Hypervisor.Status.DISABLED);
+ hypervisor.setState(state);
+ when(server.getHypervisor()).thenReturn(hypervisor);
+ boolean requestFailedExceptionThrown = false;
+ try {
+ underTest.checkHypervisor(server);
+ fail("Exception not thrown");
+ } catch (RequestFailedException requestFailedException) {
+ requestFailedExceptionThrown = (requestFailedException.getOperation().equals(expectedExceptionOperation));
+ }
+ assertTrue(requestFailedExceptionThrown);
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderStackOperation.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderStackOperation.java
new file mode 100644
index 000000000..d0447de04
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/iaas/provider/operation/impl/base/TestProviderStackOperation.java
@@ -0,0 +1,199 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.base;
+
+import com.att.cdp.exceptions.ContextConnectionException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.openstack.v1.OpenStackStackService;
+import com.att.cdp.zones.Context;
+import com.att.cdp.zones.StackService;
+import com.att.cdp.zones.model.Server;
+import com.att.cdp.zones.model.Server.Status;
+import com.att.cdp.zones.model.Stack;
+import com.att.cdp.zones.model.Tenant;
+import com.att.cdp.zones.spi.AbstractService;
+import com.woorea.openstack.base.client.OpenStackBaseException;
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.iaas.ProviderAdapter;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestContext;
+import org.onap.ccsdk.sli.adaptors.iaas.impl.RequestFailedException;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.MockGenerator;
+import org.onap.ccsdk.sli.adaptors.iaas.provider.operation.impl.RestoreStack;
+import org.onap.ccsdk.sli.adaptors.openstack.heat.StackResource;
+import org.onap.ccsdk.sli.adaptors.openstack.heat.StackResource.ShowStack;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@Ignore
+public class TestProviderStackOperation {
+
+ ProviderStackOperation underTest = spy(RestoreStack.class);
+
+ @Test
+ public void testTrackRequest() {
+ MockGenerator mg = new MockGenerator(Server.Status.RUNNING);
+ Context context = mg.getContext();
+ AbstractService.State state = new OpenStackStackService(context).new State("STATE_NAME", "STATE_VALUE");
+ underTest.trackRequest(context, state);
+ verify(context).getPrincipal();
+ }
+
+ @Test
+ public void testWaitForStack() throws Exception{
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ StackService stackService = mock(StackService.class);
+ StackResource stackResource = mock(StackResource.class);
+ ShowStack showStack = mock(ShowStack.class);
+ Stack stack1 = mock(Stack.class);
+ com.woorea.openstack.heat.model.Stack openstackHeatModelStack = mock(
+ com.woorea.openstack.heat.model.Stack.class);
+ doReturn("stack1").when(stack1).getId();
+ doReturn("stack1").when(stack1).getName();
+ com.att.cdp.zones.model.Stack.Status stackStatus = com.att.cdp.zones.model.Stack.Status.DELETED;
+ doReturn(stackStatus).when(stack1).getStatus();
+ doReturn(mg.getContext()).when(stack1).getContext();
+ List<Stack> stackList = new LinkedList<Stack>();
+ stackList.add(stack1);
+ doReturn(stackList).when(stackService).getStacks();
+ doReturn(stack1).when(stackService).getStack("stack1", "stack1");
+ doReturn(showStack).when(stackResource).show(Mockito.anyString(), Mockito.anyString());
+ doReturn(openstackHeatModelStack).when(showStack).execute();
+ doReturn(stackService).when(mg.getContext()).getStackService();
+ doReturn("ONLINE").when(openstackHeatModelStack).getStackStatus();
+ mg.getParams().put(ProviderAdapter.PROPERTY_STACK_ID, "stack1");
+ underTest.setProviderCache(mg.getProviderCacheMap());
+ assertTrue(underTest.waitForStack(stack1, stackResource, "ONLINE"));
+ }
+
+ @Test
+ public void testWaitForStackFailed() throws ZoneException, OpenStackBaseException {
+ MockGenerator mg = new MockGenerator(Status.SUSPENDED);
+ StackService stackService = mock(StackService.class);
+ StackResource stackResource = mock(StackResource.class);
+ ShowStack showStack = mock(ShowStack.class);
+ Stack stack1 = mock(Stack.class);
+ com.woorea.openstack.heat.model.Stack openstackHeatModelStack = mock(
+ com.woorea.openstack.heat.model.Stack.class);
+ doReturn("stack1").when(stack1).getId();
+ doReturn("stack1").when(stack1).getName();
+ com.att.cdp.zones.model.Stack.Status stackStatus = com.att.cdp.zones.model.Stack.Status.DELETED;
+ doReturn(stackStatus).when(stack1).getStatus();
+ doReturn(mg.getContext()).when(stack1).getContext();
+ List<Stack> stackList = new LinkedList<Stack>();
+ stackList.add(stack1);
+ doReturn(stackList).when(stackService).getStacks();
+ doReturn(stack1).when(stackService).getStack("stack1", "stack1");
+ doReturn(showStack).when(stackResource).show(Mockito.anyString(), Mockito.anyString());
+ doReturn(openstackHeatModelStack).when(showStack).execute();
+ doReturn(stackService).when(mg.getContext()).getStackService();
+ doReturn("FAILED").when(openstackHeatModelStack).getStackStatus();
+ mg.getParams().put(ProviderAdapter.PROPERTY_STACK_ID, "stack1");
+ underTest.setProviderCache(mg.getProviderCacheMap());
+ assertFalse(underTest.waitForStack(stack1, stackResource, "ONLINE"));
+ }
+
+ @Test
+ public void testLookupStack() throws ZoneException, RequestFailedException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mg.getContext();
+ when(server.getContext()).thenReturn(context);
+ Tenant tenant = spy(new Tenant());
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ Stack stack1 = mock(Stack.class);
+ String id = mg.SERVER_ID;
+ when(stack1.getId()).thenReturn(id);
+ StackService stackService = mock(StackService.class);
+ List<Stack> stackList = new LinkedList<Stack>();
+ stackList.add(stack1);
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(context.getTenant()).thenReturn(tenant);
+ doReturn(stackList).when(stackService).getStacks();
+ doReturn(stackService).when(context).getStackService();
+ underTest.lookupStack(rc, context, id);
+ verify(rc, times(1)).isFailed();
+ }
+
+ @Test(expected = RequestFailedException.class)
+ public void testLookupStackRcFailed() throws RequestFailedException, ZoneException {
+ MockGenerator mg = new MockGenerator(Status.RUNNING);
+ Server server = spy(new Server());
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mg.getContext();
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ when(server.getContext()).thenReturn(context);
+ Tenant tenant = spy(new Tenant());
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.attempt()).thenReturn(true).thenReturn(false);
+ Stack stack1 = mock(Stack.class);
+ String id = mg.SERVER_ID;
+ when(stack1.getId()).thenReturn(id);
+ StackService stackService = mock(StackService.class);
+ List<Stack> stackList = new LinkedList<Stack>();
+ stackList.add(stack1);
+ when(tenant.getName()).thenReturn("TEST_TENANT_NAME");
+ when(tenant.getId()).thenReturn("TEST_TENANT_ID");
+ when(rc.isFailed()).thenReturn(true);
+ when(context.getTenant()).thenReturn(tenant);
+ doReturn(stackService).when(context).getStackService();
+ doThrow(new ContextConnectionException("TEST")).when(stackService).getStacks();
+ underTest.lookupStack(rc, context, id);
+ }
+
+ @Test
+ public void testWaitForStackStatus() throws ZoneException, RequestFailedException {
+ MockGenerator mg = new MockGenerator(Server.Status.ERROR);
+ RequestContext rc = mock(RequestContext.class);
+ Context context = mg.getContext();
+ Stack stack1 = mock(Stack.class);
+ String id = mg.SERVER_ID;
+ when(stack1.getId()).thenReturn(id);
+ StackService stackService = mock(StackService.class);
+ List<Stack> stackList = new LinkedList<Stack>();
+ stackList.add(stack1);
+ when(stack1.getContext()).thenReturn(context);
+ com.att.cdp.zones.model.Stack.Status stackStatus = com.att.cdp.zones.model.Stack.Status.FAILED;
+ doReturn(stackStatus).when(stack1).getStatus();
+ SvcLogicContext svcLogicContext = mg.getSvcLogicContext();
+ when(rc.getSvcLogicContext()).thenReturn(svcLogicContext);
+ doReturn(stackService).when(context).getStackService();
+ doReturn(stack1).when(stackService).getStack(Mockito.anyString(), Mockito.anyString());
+ assertFalse(underTest.waitForStackStatus(rc, stack1, Stack.Status.DELETED));
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestCreateSnapshotParams.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestCreateSnapshotParams.java
new file mode 100644
index 000000000..db37a2503
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestCreateSnapshotParams.java
@@ -0,0 +1,49 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class TestCreateSnapshotParams {
+ private CreateSnapshotParams createSnapshotParams;
+
+ @Before
+ public void setUp() {
+ createSnapshotParams=new CreateSnapshotParams();
+ }
+ @Test
+ public void testGetName() {
+ createSnapshotParams.setName("ABC");
+ assertNotNull(createSnapshotParams.getName());
+ assertEquals(createSnapshotParams.getName(),"ABC");
+ }
+
+ @Test
+ public void testToString_ReturnNonEmptyString() {
+ assertNotEquals(createSnapshotParams.toString(), "");
+ assertNotEquals(createSnapshotParams.toString(), null);
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestData.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestData.java
new file mode 100644
index 000000000..2bbefd119
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestData.java
@@ -0,0 +1,129 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Modifications Copyright (c) 2018-2019 IBM
+*=================================================================================
+* 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+public class TestData {
+ private Data data;
+ private Environment environment;
+ private Resources__ resources__;
+ private Template template;
+
+ @Before
+ public void setUp() {
+ data = new Data();
+ environment = new Environment();
+ resources__ = new Resources__();
+ template = new Template();
+ }
+
+ @Test
+ public void testGetStatus() {
+ data.setStatus("status");
+ assertNotNull(data.getStatus());
+ assertEquals("status", data.getStatus());
+ }
+
+ @Test
+ public void testGetName() {
+ data.setName("XYZ");
+ assertNotNull(data.getName());
+ assertEquals("XYZ", data.getName());
+ }
+
+ @Test
+ public void testGetStackUserProjectId() {
+ data.setStackUserProjectId("stackUserProjectId");
+ assertNotNull(data.getStackUserProjectId());
+ assertEquals("stackUserProjectId", data.getStackUserProjectId());
+ }
+
+ @Test
+ public void testGetAction() {
+ data.setAction("action");
+ assertNotNull(data.getAction());
+ assertEquals("action", data.getAction());
+ }
+
+ @Test
+ public void testGetProjectId() {
+ data.setProjectId("projectId");
+ assertNotNull(data.getProjectId());
+ assertEquals("projectId", data.getProjectId());
+ }
+
+ @Test
+ public void testGetId() {
+ data.setId("Id");
+ assertNotNull(data.getId());
+ assertEquals("Id", data.getId());
+ }
+
+ @Test
+ public void testToString_ReturnNonEmptyString() {
+ assertNotEquals("", data.toString());
+ assertNotEquals(null, data.toString());
+ }
+
+ @Test
+ public void testSetEnvironment() {
+ data.setEnvironment(environment);
+ assertNotNull(data.getEnvironment());
+ }
+
+ @Test
+ public void testGetEnvironment() {
+ data.setEnvironment(environment);
+ assertSame(environment, data.getEnvironment());
+ }
+
+ @Test
+ public void testSetTemplate() {
+ data.setTemplate(template);
+ assertNotNull(data.getTemplate());
+ }
+
+ @Test
+ public void testGetTemplate() {
+ data.setTemplate(template);
+ assertSame(template, data.getTemplate());
+ }
+
+ @Test
+ public void testSetResources__() {
+ data.setResources(resources__);
+ assertNotNull(data.getResources());
+ }
+
+ @Test
+ public void testGetResources__() {
+ data.setResources(resources__);
+ assertSame(resources__, data.getResources());
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestEnvironment.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestEnvironment.java
new file mode 100644
index 000000000..1d66e50d8
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestEnvironment.java
@@ -0,0 +1,62 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2019 IBM.
+ * ===================================================================
+ * 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+public class TestEnvironment {
+
+ private Environment environment;
+ private Parameters parameters;
+ private ResourceRegistry resourceRegistry;
+
+ @Before
+ public void setUp() {
+ environment = new Environment();
+ parameters = new Parameters();
+ resourceRegistry = new ResourceRegistry();
+ }
+
+ @Test
+ public void testGetParameters() {
+ environment.setParameters(parameters);
+ assertNotNull(environment.getParameters());
+ assertSame(parameters, environment.getParameters());
+ }
+
+ @Test
+ public void testGetResourceRegistry() {
+ environment.setResourceRegistry(resourceRegistry);
+ assertNotNull(environment.getResourceRegistry());
+ assertSame(resourceRegistry, environment.getResourceRegistry());
+ }
+
+ @Test
+ public void testToString() {
+ environment.setResourceRegistry(resourceRegistry);
+ assertNotNull(environment.toString());
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestMetadata.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestMetadata.java
new file mode 100644
index 000000000..8d33c1c69
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestMetadata.java
@@ -0,0 +1,43 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2019 IBM.
+ * ===================================================================
+ * 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+
+public class TestMetadata {
+
+ private Metadata metadata;
+
+ @Before
+ public void setUp() {
+ metadata = new Metadata();
+ }
+
+ @Test
+ public void testToString() {
+ assertNotNull(metadata.toString());
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestParameters.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestParameters.java
new file mode 100644
index 000000000..4b647d7b5
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestParameters.java
@@ -0,0 +1,43 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2019 IBM.
+ * ===================================================================
+ * 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+
+public class TestParameters {
+
+ private Parameters parameters;
+
+ @Before
+ public void setUp() {
+ parameters = new Parameters();
+ }
+
+ @Test
+ public void testToString() {
+ assertNotNull(parameters.toString());
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestProperties.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestProperties.java
new file mode 100644
index 000000000..84abf12a0
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestProperties.java
@@ -0,0 +1,49 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class TestProperties {
+ private Properties properties;
+
+ @Before
+ public void setUp() {
+ properties=new Properties();
+ }
+ @Test
+ public void testGetSize() {
+ properties.setSize(123);
+ assertNotNull(properties.getSize());
+ assertEquals(properties.getSize(),123);
+ }
+
+ @Test
+ public void testToString_ReturnNonEmptyString() {
+ assertNotEquals(properties.toString(), "");
+ assertNotEquals(properties.toString(), null);
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResourceData.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResourceData.java
new file mode 100644
index 000000000..1da7a0332
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResourceData.java
@@ -0,0 +1,48 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class TestResourceData {
+ private ResourceData resourceData;
+
+ @Before
+ public void setUp() {
+ resourceData=new ResourceData();
+ }
+ @Test
+ public void testGetBackupId() {
+ resourceData.setBackupId("111");
+ assertNotNull(resourceData.getBackupId());
+ assertEquals(resourceData.getBackupId(),"111");
+ }
+
+ @Test
+ public void testToString_ReturnNonEmptyString() {
+ assertNotEquals(resourceData.toString(), "");
+ assertNotEquals(resourceData.toString(), null);
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResourceRegistry.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResourceRegistry.java
new file mode 100644
index 000000000..48ce15f3d
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResourceRegistry.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 IBM.
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+
+public class TestResourceRegistry {
+
+ private ResourceRegistry resourceRegistry ;
+
+ @Before
+ public void setUp()
+ {
+ resourceRegistry= new ResourceRegistry();
+ }
+
+ @Test
+ public void testResources()
+ {
+ Resources resources = new Resources();
+ resourceRegistry.setResources(resources);
+ assertSame(resources, resourceRegistry.getResources());
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources.java
new file mode 100644
index 000000000..fb7b61139
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 IBM.
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class TestResources {
+
+ private Resources resources;
+
+ @Before
+ public void setUp() {
+ resources = new Resources();
+ }
+
+ @Test
+ public void testToString() {
+ assertTrue(resources.toString() instanceof String);
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources_.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources_.java
new file mode 100644
index 000000000..88eed294e
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources_.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 IBM.
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+public class TestResources_ {
+ private Resources_ resources;
+
+ @Before
+ public void setUp() {
+ resources = new Resources_();
+ }
+
+ @Test
+ public void testVolume() {
+ Volume volume = new Volume();
+ resources.setVolume(volume);
+ assertSame(volume, resources.getVolume());
+ }
+
+ @Test
+ public void testToString() {
+ assertTrue(resources.toString() instanceof String);
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources__.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources__.java
new file mode 100644
index 000000000..e74825e41
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestResources__.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 IBM.
+ * ================================================================================
+ * 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+public class TestResources__ {
+
+ public Resources__ resources;
+
+ @Before
+ public void setUp() {
+ resources = new Resources__();
+ }
+
+ @Test
+ public void testVolume() {
+ Volume_ volume = new Volume_();
+ resources.setVolume(volume);
+ assertSame(volume, resources.getVolume());
+
+ }
+
+ @Test
+ public void testtoString() {
+ assertTrue(resources.toString() instanceof String);
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshot.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshot.java
new file mode 100644
index 000000000..365ae208a
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshot.java
@@ -0,0 +1,86 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Modifications Copyright 2019 IBM.
+*=================================================================================
+* 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+public class TestSnapshot {
+ private Snapshot snapshot;
+
+ @Before
+ public void setUp() {
+ snapshot = new Snapshot();
+ }
+
+ @Test
+ public void testGetBackupId() {
+ snapshot.setId("222");
+ assertNotNull(snapshot.getId());
+ assertEquals(snapshot.getId(), "222");
+ }
+
+ @Test
+ public void testGetName() {
+ snapshot.setName("ABC");
+ assertNotNull(snapshot.getName());
+ assertEquals(snapshot.getName(), "ABC");
+ }
+
+ @Test
+ public void testGetStatus() {
+ snapshot.setStatus("status");
+ assertNotNull(snapshot.getStatus());
+ assertEquals(snapshot.getStatus(), "status");
+ }
+
+ @Test
+ public void testGetStatusReason() {
+ snapshot.setStatusReason("statusReason");
+ assertNotNull(snapshot.getStatusReason());
+ assertEquals(snapshot.getStatusReason(), "statusReason");
+ }
+
+ @Test
+ public void testGetCreationTime() {
+ snapshot.setCreationTime("01-March-2018");
+ assertEquals("01-March-2018",snapshot.getCreationTime());
+ }
+
+ @Test
+ public void testToString_ReturnNonEmptyString() {
+ assertNotEquals("",snapshot.toString());
+ assertNotEquals(null,snapshot.toString());
+ }
+
+ @Test
+ public void testData() {
+ Data data = new Data();
+ snapshot.setData(data);
+ assertSame(data, snapshot.getData());
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshotDetails.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshotDetails.java
new file mode 100644
index 000000000..7708a517e
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshotDetails.java
@@ -0,0 +1,53 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2019 IBM.
+ * ===================================================================
+ * 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+public class TestSnapshotDetails {
+
+ private SnapshotDetails snapshotDetails;
+ private Snapshot snapshot;
+
+ @Before
+ public void setUp() {
+ snapshotDetails = new SnapshotDetails();
+ snapshot = new Snapshot();
+ }
+
+ @Test
+ public void testGetSnapshot() {
+ snapshotDetails.setSnapshot(snapshot);
+ assertSame(snapshot, snapshotDetails.getSnapshot());
+ }
+
+ @Test
+ public void testToString() {
+ snapshotDetails.setSnapshot(snapshot);
+ assertNotNull(snapshotDetails.toString());
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshotRestoreResponse.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshotRestoreResponse.java
new file mode 100644
index 000000000..1e3b2cbc2
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestSnapshotRestoreResponse.java
@@ -0,0 +1,63 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class TestSnapshotRestoreResponse {
+ private SnapshotRestoreResponse snapshotRestoreResponse;
+
+ @Before
+ public void setUp() {
+ snapshotRestoreResponse = new SnapshotRestoreResponse();
+ }
+
+ @Test
+ public void testGetCode() {
+ snapshotRestoreResponse.setCode("200");
+ assertNotNull(snapshotRestoreResponse.getCode());
+ assertEquals(snapshotRestoreResponse.getCode(), "200");
+ }
+
+ @Test
+ public void testMessage() {
+ snapshotRestoreResponse.setMessage("Success");
+ assertNotNull(snapshotRestoreResponse.getMessage());
+ assertEquals(snapshotRestoreResponse.getMessage(), "Success");
+ }
+
+ @Test
+ public void testTitle() {
+ snapshotRestoreResponse.setTitle("A1");
+ assertNotNull(snapshotRestoreResponse.getTitle());
+ assertEquals(snapshotRestoreResponse.getTitle(), "A1");
+ }
+
+ @Test
+ public void testToString_ReturnNonEmptyString() {
+ assertNotEquals(snapshotRestoreResponse.toString(), "");
+ assertNotEquals(snapshotRestoreResponse.toString(), null);
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestTemplate.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestTemplate.java
new file mode 100644
index 000000000..79df1b389
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestTemplate.java
@@ -0,0 +1,58 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Modifications Copyright 2019 IBM.
+*=================================================================================
+* 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertSame;
+
+public class TestTemplate {
+ private Template template;
+
+ @Before
+ public void setUp() {
+ template = new Template();
+ }
+
+ @Test
+ public void testGetHeatTemplateVersion() {
+ template.setHeatTemplateVersion("1.0");
+ assertEquals("1.0", template.getHeatTemplateVersion());
+ }
+
+ @Test
+ public void testToString_ReturnNonEmptyString() {
+ assertNotEquals("",template.toString());
+ assertNotEquals(null,template.toString());
+ }
+
+ @Test
+ public void testResources() {
+ Resources_ resources = new Resources_();
+ template.setResources(resources);
+ assertSame(resources, template.getResources());
+ }
+
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestVolume.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestVolume.java
new file mode 100644
index 000000000..35c46b889
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestVolume.java
@@ -0,0 +1,60 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+* ================================================================================
+* Modifications Copyright (c) 2019 IBM
+* ================================================================================
+* 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertSame;
+
+public class TestVolume {
+ private Volume volume;
+ private Properties properties;
+
+ @Before
+ public void setUp() {
+ volume = new Volume();
+ properties = new Properties();
+ }
+
+ @Test
+ public void testGetType() {
+ volume.setType("A");
+ assertEquals("A",volume.getType());
+ }
+
+ @Test
+ public void testToString_ReturnNonEmptyString() {
+ assertNotEquals("",volume.toString());
+ assertNotEquals(null,volume.toString());
+ }
+
+ @Test
+ public void testGetProperties() {
+ properties.setSize(2);
+ volume.setProperties(properties);
+ assertEquals(2, volume.getProperties().getSize());
+ assertSame(properties, volume.getProperties());
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestVolume_.java b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestVolume_.java
new file mode 100644
index 000000000..f1dace977
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/openstack/heat/model/TestVolume_.java
@@ -0,0 +1,94 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Modifications Copyright (c) 2019 IBM
+* ================================================================================
+* 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.onap.ccsdk.sli.adaptors.openstack.heat.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+public class TestVolume_ {
+ private Volume_ volume_;
+ private Metadata metadata;
+ private ResourceData resourceData;
+
+ @Before
+ public void setUp() {
+ volume_ = new Volume_();
+ metadata = new Metadata();
+ resourceData = new ResourceData();
+ }
+
+ @Test
+ public void testGetStatus() {
+ volume_.setStatus("Success");
+ assertEquals("Success",volume_.getStatus());
+ }
+
+ @Test
+ public void testGetName() {
+ volume_.setName("XYZ");
+ assertNotNull(volume_.getName());
+ assertEquals("XYZ",volume_.getName());
+ }
+
+ @Test
+ public void testGetResourceId() {
+ volume_.setResourceId("333");
+ assertNotNull(volume_.getResourceId());
+ assertEquals("333",volume_.getResourceId());
+ }
+
+ @Test
+ public void testGetAction() {
+ volume_.setAction("action");
+ assertNotNull(volume_.getAction());
+ assertEquals("action",volume_.getAction());
+ }
+
+ @Test
+ public void testGetType() {
+ volume_.setType("A");
+ assertEquals("A",volume_.getType());
+ }
+
+ @Test
+ public void testToString_ReturnNonEmptyString() {
+ assertNotEquals("",volume_.toString());
+ assertNotEquals(null,volume_.toString());
+ }
+
+ @Test
+ public void testGetResourceData() {
+ volume_.setResourceData(resourceData);
+ assertSame(resourceData,volume_.getResourceData());
+ }
+
+ @Test
+ public void testGetMetadata() {
+ volume_.setMetadata(metadata);
+ assertSame(metadata,volume_.getMetadata());
+ }
+}
diff --git a/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/resources/default.properties b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/resources/default.properties
new file mode 100644
index 000000000..6ecf278ca
--- /dev/null
+++ b/adaptors/iaas-adaptor/iaas-adaptor-bundle/src/test/resources/default.properties
@@ -0,0 +1,112 @@
+###
+# ============LICENSE_START=======================================================
+# ONAP : APPC
+# ================================================================================
+# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Copyright (C) 2017 Amdocs
+# =============================================================================
+# 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=========================================================
+###
+
+#
+# Default properties for the APP-C Provider Adapter
+#
+# -------------------------------------------------------------------------------------------------
+#
+# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded
+# to supply configuration options
+org.onap.appc.bootstrap.file=appc.properties
+org.onap.appc.bootstrap.path=/opt/onap/appc/data/properties,${user.home},.
+
+appc.application.name=APPC
+
+#
+# Define the message resource bundle name to be loaded
+org.onap.appc.resources=org/onap/appc/i18n/MessageResources
+#
+# The name of the adapter.
+org.onap.appc.provider.adaptor.name=org.onap.appc.appc_provider_adapter
+#
+# Set up the logging environment
+#
+org.onap.appc.logging.file=org/onap/appc/logback.xml
+org.onap.appc.logging.path=${user.home};etc;../etc
+org.onap.appc.logger=org.onap.appc
+org.onap.appc.security.logger=org.onap.appc.security
+#
+# The minimum and maximum provider/tenant context pool sizes. Min=1 means that as soon
+# as the provider/tenant is referenced a Context is opened and added to the pool. Max=0
+# means that the upper bound on the pool is unbounded.
+org.onap.appc.provider.min.pool=1
+org.onap.appc.provider.max.pool=0
+
+#
+# The following properties are used to configure the retry logic for connection to the
+# IaaS provider(s). The retry delay property is the amount of time, in seconds, the
+# application waits between retry attempts. The retry limit is the number of retries
+# that are allowed before the request is failed.
+org.onap.appc.provider.retry.delay = 30
+org.onap.appc.provider.retry.limit = 10
+
+#
+# The trusted hosts list for SSL access when a certificate is not provided.
+#
+provider.trusted.hosts=*
+#
+# The amount of time, in seconds, to wait for a server state change (start->stop, stop->start, etc).
+# If the server does not change state to a valid state within the alloted time, the operation
+# fails.
+org.onap.appc.server.state.change.timeout=300
+#
+# The amount of time to wait, in seconds, between subsequent polls to the OpenStack provider
+# to refresh the status of a resource we are waiting on.
+#
+org.onap.appc.openstack.poll.interval=20
+#
+# The connection information to connect to the provider we are using. These properties
+# are "structured" properties, in that the name is a compound name, where the nodes
+# of the name can be ordered (1, 2, 3, ...). All of the properties with the same ordinal
+# position are defining the same entity. For example, provider1.type and provider1.name
+# are defining the same provider, whereas provider2.name and provider2.type are defining
+# the values for a different provider. Any number of providers can be defined in this
+# way.
+#
+
+
+# Don't change these 2 right now since they are hard coded in the DG
+provider1.type=appc
+provider1.name=appc
+
+#These you can change
+provider1.identity=http://localhost:9081/v2.0
+provider1.tenant1.name=appc
+provider1.tenant1.userid=appc
+provider1.tenant1.password=appc
+
+# After a change to the provider make sure to recheck these values with an api call to provider1.identity/tokens
+test.expected-regions=1
+test.expected-endpoints=1
+
+#Your OpenStack IP
+test.ip=192.168.1.2
+# Your OpenStack Platform's Keystone Port (default is 5000)
+test.port=5000
+test.tenantid=abcde12345fghijk6789lmnopq123rst
+test.vmid=abc12345-1234-5678-890a-abcdefg12345
+# Port 8774 below is default port for OpenStack's Nova API Service
+test.url=http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345
+test.version=v2
+