summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-openstack-adapters/src/test')
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java16
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java123
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java102
-rw-r--r--adapters/mso-openstack-adapters/src/test/resources/__files/MulticloudResponse_Stack.json5
-rw-r--r--adapters/mso-openstack-adapters/src/test/resources/__files/MulticloudResponse_Stack_Create.json16
5 files changed, 153 insertions, 109 deletions
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java
index a2f57ef06f..9ead28b577 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java
@@ -77,7 +77,10 @@ public class BaseRestTestUtils {
private int port;
public ObjectMapper mapper;
-
+
+ public String orchestrator = "orchestrator";
+ public String cloudEndpoint = "/v2.0";
+
protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{
ObjectMapper mapper = new ObjectMapper();
@@ -111,7 +114,6 @@ public class BaseRestTestUtils {
public void setUp() throws Exception {
reset();
mapper = new ObjectMapper();
-
CloudIdentity identity = new CloudIdentity();
identity.setId("MTN13");
identity.setMsoId("m93945");
@@ -119,7 +121,8 @@ public class BaseRestTestUtils {
identity.setAdminTenant("admin");
identity.setMemberRole("admin");
identity.setTenantMetadata(new Boolean(true));
- identity.setIdentityUrl("http://localhost:"+wireMockPort+"/v2.0");
+ identity.setIdentityUrl("http://localhost:" + wireMockPort + cloudEndpoint);
+
identity.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
CloudSite cloudSite = new CloudSite();
@@ -127,12 +130,10 @@ public class BaseRestTestUtils {
cloudSite.setCloudVersion("3.0");
cloudSite.setClli("MDT13");
cloudSite.setRegionId("mtn13");
- cloudSite.setOrchestrator("orchestrator" +
- "");
+ cloudSite.setOrchestrator(orchestrator);
identity.setIdentityServerType(ServerType.KEYSTONE);
cloudSite.setIdentityService(identity);
-
stubFor(get(urlPathEqualTo("/cloudSite/MTN13")).willReturn(aResponse()
.withBody(getBody(mapper.writeValueAsString(cloudSite),wireMockPort, ""))
.withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
@@ -145,8 +146,7 @@ public class BaseRestTestUtils {
.withBody(getBody(mapper.writeValueAsString(identity),wireMockPort, ""))
.withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON)
.withStatus(HttpStatus.SC_OK)));
- cloudConfig.getCloudSite("MTN13").get().getIdentityService().setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
-
+ cloudConfig.getCloudSite("MTN13").get().getIdentityService().setIdentityUrl("http://localhost:" + wireMockPort + cloudEndpoint);
}
protected static String getBody(String body, int port, String urlPath) throws IOException {
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java
new file mode 100644
index 0000000000..07fa47df42
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java
@@ -0,0 +1,123 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Intel Corp. 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.so.adapters.vnf;
+
+import org.apache.http.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.adapters.openstack.MsoOpenstackAdaptersApplication;
+import org.onap.so.adapters.vnf.exceptions.VnfException;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.entity.MsoRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.embedded.LocalServerPort;
+
+import javax.xml.ws.Holder;
+import java.util.HashMap;
+import java.util.Map;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.delete;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+
+public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Autowired
+ private MsoVnfPluginAdapterImpl instance;
+
+ @Autowired
+ private CloudConfig cloudConfig;
+
+ @Before
+ public void before() throws Exception {
+ super.orchestrator = "multicloud";
+ super.cloudEndpoint = "/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload";
+ super.setUp();
+ }
+
+ @Test
+ public void createVfModule() throws Exception {
+ //expectedException.expect(VnfException.class);
+ Map<String, String> stackInputs = new HashMap<>();
+ stackInputs.put("oof_directives", "{oofDIRECTIVES}");
+ stackInputs.put("sdnc_directives", "{sdncDIRECTIVES}");
+ stackInputs.put("generic_vnf_id", "genVNFID");
+ stackInputs.put("vf_module_id", "vfMODULEID");
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/vfname")).willReturn(aResponse()
+ //.withHeader()
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+
+ stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/vfname/outputs")).willReturn(aResponse()
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+
+ stubFor(post(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload")).willReturn(aResponse()
+ .withBodyFile("MulticloudResponse_Stack_Create.json")
+ .withStatus(HttpStatus.SC_CREATED)));
+
+ instance.createVfModule("MTN13", "123", "vf", "v1", "vfname", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
+ }
+
+ @Test
+ public void deleteVfModule() throws Exception {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
+ .withBodyFile("MulticloudResponse_Stack.json")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(delete(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
+ .withStatus(HttpStatus.SC_NO_CONTENT)));
+
+ instance.deleteVfModule("MTN13", "123", "workload-id", msoRequest, new Holder<>());
+ }
+
+ @Test
+ public void queryVfModule() throws Exception {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
+ .withBodyFile("MulticloudResponse_Stack.json")
+ .withStatus(HttpStatus.SC_OK)));
+
+ instance.queryVnf("MTN13", "123", "workload-id", msoRequest, new Holder<>(), new Holder<>(), new Holder<>(), new Holder<>());
+ }
+
+ // TODO Error Tests
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java
index 77ef8d4776..936bce5b5c 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java
@@ -20,31 +20,15 @@
package org.onap.so.adapters.vnf;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.github.tomakehurst.wiremock.client.WireMock;
import org.apache.http.HttpStatus;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.mockito.MockitoAnnotations;
-import org.onap.so.adapters.vdu.CloudInfo;
-import org.onap.so.adapters.vdu.VduInstance;
-import org.onap.so.adapters.vdu.VduStateType;
-import org.onap.so.adapters.vdu.VduStatus;
import org.onap.so.adapters.vnf.exceptions.VnfException;
-import org.onap.so.db.catalog.beans.AuthenticationType;
-import org.onap.so.db.catalog.beans.CloudIdentity;
-import org.onap.so.db.catalog.beans.CloudSite;
-import org.onap.so.db.catalog.beans.ServerType;
import org.onap.so.entity.MsoRequest;
-import org.onap.so.openstack.beans.HeatStatus;
-import org.onap.so.openstack.beans.StackInfo;
import org.onap.so.openstack.beans.VnfRollback;
-import org.onap.so.openstack.utils.MsoMulticloudUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import javax.ws.rs.core.MediaType;
import javax.xml.ws.Holder;
import java.util.HashMap;
import java.util.Map;
@@ -52,15 +36,11 @@ import java.util.Map;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.delete;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.reset;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
-import static org.mockito.Mockito.when;
import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_404;
import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
-import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccessMulticloud;
-import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenstackGetWithResponse;
public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils {
@@ -72,53 +52,6 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils {
String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
- /***
- * Before each test execution, updating IdentityUrl port value to the ramdom wireMockPort
- * Since URL will be used as a rest call and required to be mocked in unit tests
- */
- @Before
- public void setUp() throws Exception {
- reset();
- mapper = new ObjectMapper();
-
- CloudIdentity identity = new CloudIdentity();
- identity.setId("MTN13");
- identity.setMsoId("m93945");
- identity.setMsoPass("93937EA01B94A10A49279D4572B48369");
- identity.setAdminTenant("admin");
- identity.setMemberRole("admin");
- identity.setTenantMetadata(new Boolean(true));
- identity.setIdentityUrl("http://localhost:"+wireMockPort+"/v2.0");
- identity.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
-
- CloudSite cloudSite = new CloudSite();
- cloudSite.setId("MTN13");
- cloudSite.setCloudVersion("3.0");
- cloudSite.setClli("MDT13");
- cloudSite.setRegionId("MTN13");
- cloudSite.setOrchestrator("multicloud" +
- "");
- identity.setIdentityServerType(ServerType.KEYSTONE);
- cloudSite.setIdentityService(identity);
-
-
-
- stubFor(get(urlPathEqualTo("/cloudSite/MTN13")).willReturn(aResponse()
- .withBody(getBody(mapper.writeValueAsString(cloudSite),wireMockPort, ""))
- .withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .withStatus(HttpStatus.SC_OK)));
- stubFor(get(urlPathEqualTo("/cloudSite/DEFAULT")).willReturn(aResponse()
- .withBody(getBody(mapper.writeValueAsString(cloudSite),wireMockPort, ""))
- .withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON)
- .withStatus(HttpStatus.SC_OK)));
- stubFor(get(urlPathEqualTo("/cloudIdentity/MTN13")).willReturn(aResponse()
- .withBody(getBody(mapper.writeValueAsString(identity),wireMockPort, ""))
- .withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON)
- .withStatus(HttpStatus.SC_OK)));
- cloudConfig.getCloudSite("MTN13").get().getIdentityService().setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
-
- }
-
@Test
public void createVfModule_ModelCustUuidIsNull() throws Exception {
expectedException.expect(VnfException.class);
@@ -155,7 +88,7 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils {
new Holder<VnfRollback>());
}
- /* @Test
+ @Test
public void createVfModule_INSTANTIATED() throws Exception {
mockOpenStackResponseAccess(wireMockPort);
mockOpenStackGetStackVfModule_200();
@@ -167,40 +100,7 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils {
null, "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
new Holder<VnfRollback>());
- }*/
-
- @Test
- public void createVfModule_INSTANTIATED_Multicloud() throws Exception {
- mockOpenStackResponseAccessMulticloud(wireMockPort);
- mockOpenStackGetStackVfModule_200();
-
- MsoRequest msoRequest = getMsoRequest();
- Map<String, String> map = new HashMap<>();
- map.put("key1", "value1");
- msoVnfPluginAdapter.createVfModule("MTN13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
- null, "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
- Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
- new Holder<VnfRollback>());
- }
-
- /*
- @Test
- public void createVfModule_Multicloud() throws Exception {
- expectedException.expect(VnfException.class);
- mockOpenStackResponseAccessMulticloud(wireMockPort);
- mockOpenStackGetStackVfModule_404();
-
- MsoRequest msoRequest = getMsoRequest();
- Map<String, String> map = new HashMap<>();
- map.put("key1", "value1");
- map.put("oof_directives", "{ abc: 123 }");
- map.put("sdnc_directives", "{ def: 456 }");
- msoVnfPluginAdapter.createVfModule("MTN13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
- null, "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
- Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
- new Holder<VnfRollback>());
}
- */
@Test
public void createVfModule_queryVduNotFoundWithVolumeGroupId() throws Exception {
diff --git a/adapters/mso-openstack-adapters/src/test/resources/__files/MulticloudResponse_Stack.json b/adapters/mso-openstack-adapters/src/test/resources/__files/MulticloudResponse_Stack.json
new file mode 100644
index 0000000000..068cb83a33
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/resources/__files/MulticloudResponse_Stack.json
@@ -0,0 +1,5 @@
+{
+ "template_type":"heat",
+ "workload_id": "vfname",
+ "workload_status":"STATUS"
+ } \ No newline at end of file
diff --git a/adapters/mso-openstack-adapters/src/test/resources/__files/MulticloudResponse_Stack_Create.json b/adapters/mso-openstack-adapters/src/test/resources/__files/MulticloudResponse_Stack_Create.json
new file mode 100644
index 0000000000..b6092bfbe0
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/resources/__files/MulticloudResponse_Stack_Create.json
@@ -0,0 +1,16 @@
+{
+ "template_type": "heat",
+ "workload_id": "workload-id",
+ "template_response":
+ {
+ "stack": {
+ "id": "abcdef00-1234-abcd-5678-ef9123456789",
+ "links": [
+ {
+ "href": "http://localhost:1234/v1/id12345678/stacks/workload-id/abcdef00-1234-abcd-5678-ef9123456789",
+ "rel": "self"
+ }
+ ]
+ }
+ }
+}