summaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-adapter-utils/src/test')
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/AllTestsTestSuite.java32
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java32
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java76
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java37
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoKeystoneUtilsTest.java32
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java43
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoNeutronUtilsTest.java22
7 files changed, 175 insertions, 99 deletions
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/AllTestsTestSuite.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/AllTestsTestSuite.java
new file mode 100644
index 0000000000..a74dbf614b
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/AllTestsTestSuite.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 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.so;
+import org.junit.runner.RunWith;
+
+import com.googlecode.junittoolbox.SuiteClasses;
+import com.googlecode.junittoolbox.WildcardPatternSuite;
+
+@RunWith(WildcardPatternSuite.class)
+@SuiteClasses("**/*Test.class")
+public class AllTestsTestSuite {
+ // the class remains empty,
+ // used only as a holder for the above annotations
+}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java
index 9cfdf53094..82b18d86ed 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java
@@ -23,7 +23,16 @@
package org.onap.so;
-import com.github.tomakehurst.wiremock.client.WireMock;
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+import javax.ws.rs.core.MediaType;
+
import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
import org.junit.After;
@@ -33,20 +42,15 @@ 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.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
-import javax.ws.rs.core.MediaType;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-
-import static com.github.tomakehurst.wiremock.client.WireMock.*;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.WireMock;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@@ -56,10 +60,12 @@ public abstract class BaseTest extends TestDataSetup {
@Value("${wiremock.server.port}")
protected int wireMockPort;
+ @Autowired
+ protected WireMockServer wireMockServer;
@After
public void after() {
- WireMock.reset();
+ wireMockServer.resetAll();
}
protected static String getBody(String body, int port, String urlPath) throws IOException {
@@ -74,15 +80,15 @@ public abstract class BaseTest extends TestDataSetup {
}
private void mockCloud(CloudIdentity identity, CloudSite cloudSite) throws IOException {
- stubFor(get(urlPathEqualTo("/cloudSite/MTN13")).willReturn(aResponse()
+ wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/MTN13")).willReturn(aResponse()
.withBody(getBody(mapper.writeValueAsString(cloudSite),wireMockPort, ""))
.withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.withStatus(HttpStatus.SC_OK)));
- stubFor(get(urlPathEqualTo("/cloudSite/DEFAULT")).willReturn(aResponse()
+ wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/DEFAULT")).willReturn(aResponse()
.withBody(getBody(mapper.writeValueAsString(cloudSite),wireMockPort, ""))
.withHeader(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON)
.withStatus(HttpStatus.SC_OK)));
- stubFor(get(urlPathEqualTo("/cloudIdentity/mtn13")).willReturn(aResponse()
+ wireMockServer.stubFor(get(urlPathEqualTo("/cloudIdentity/mtn13")).willReturn(aResponse()
.withBody(getBody(mapper.writeValueAsString(identity),wireMockPort, ""))
.withHeader(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON)
.withStatus(HttpStatus.SC_OK)));
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java
index 0820076c66..ae3fb8271a 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java
@@ -27,38 +27,40 @@ 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.put;
-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;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
+
import org.apache.http.HttpStatus;
+import com.github.tomakehurst.wiremock.WireMockServer;
+
public class StubOpenStack {
- public static void mockOpenStackResponseAccess(int port) throws IOException {
- stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+ public static void mockOpenStackResponseAccess(WireMockServer wireMockServer, int port) throws IOException {
+ wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl"))
.withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackResponseUnauthorized(int port) throws IOException {
- stubFor(
+ public static void mockOpenStackResponseUnauthorized(WireMockServer wireMockServer, int port) throws IOException {
+ wireMockServer.stubFor(
post(urlPathEqualTo("/v2.0/tokens"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl"))
.withStatus(HttpStatus.SC_UNAUTHORIZED)));
}
- public static void mockOpenStackDelete(String id) {
- stubFor(delete(urlMatching("/mockPublicUrl/stacks/" + id)).willReturn(aResponse()
+ public static void mockOpenStackDelete(WireMockServer wireMockServer, String id) {
+ wireMockServer.stubFor(delete(urlMatching("/mockPublicUrl/stacks/" + id)).willReturn(aResponse()
.withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackGet(String id) {
- stubFor(
+ public static void mockOpenStackGet(WireMockServer wireMockServer, String id) {
+ wireMockServer.stubFor(
get(urlPathEqualTo("/mockPublicUrl/stacks/" + id))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBodyFile("OpenstackResponse_Stack_Created.json")
@@ -66,82 +68,82 @@ public class StubOpenStack {
}
- public static void mockOpenStackPostStack_200(String filename) {
- stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse()
+ public static void mockOpenStackPostStack_200(WireMockServer wireMockServer, String filename) {
+ wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackPostTenantWithBodyFile_200() throws IOException {
- stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants"))
+ public static void mockOpenStackPostTenantWithBodyFile_200(WireMockServer wireMockServer) throws IOException {
+ wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants"))
.willReturn(aResponse().withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackGetTenantByName(String tenantName) throws IOException {
- stubFor(get(urlMatching("/mockPublicUrl/tenants/[?]name=" + tenantName))
+ public static void mockOpenStackGetTenantByName(WireMockServer wireMockServer, String tenantName) throws IOException {
+ wireMockServer.stubFor(get(urlMatching("/mockPublicUrl/tenants/[?]name=" + tenantName))
.willReturn(aResponse().withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackGetTenantById(String tenantId) throws IOException {
- stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/tenantId"))
+ public static void mockOpenStackGetTenantById(WireMockServer wireMockServer, String tenantId) throws IOException {
+ wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/tenantId"))
.willReturn(aResponse().withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackDeleteTenantById_200(String tenantId) {
- stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse()
+ public static void mockOpenStackDeleteTenantById_200(WireMockServer wireMockServer, String tenantId) {
+ wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse()
.withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackGetUserById(String user) {
- stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user)).willReturn(aResponse()
+ public static void mockOpenStackGetUserById(WireMockServer wireMockServer, String user) {
+ wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user)).willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackGetUserByName(String userName) {
- stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)).willReturn(aResponse()
+ public static void mockOpenStackGetUserByName(WireMockServer wireMockServer, String userName) {
+ wireMockServer.stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)).willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackGetUserByName_500(String userName) {
- stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)).willReturn(aResponse()
+ public static void mockOpenStackGetUserByName_500(WireMockServer wireMockServer, String userName) {
+ wireMockServer.stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)).willReturn(aResponse()
.withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
}
- public static void mockOpenStackGetRoles_200(String roleFor) {
- stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles")).willReturn(aResponse()
+ public static void mockOpenStackGetRoles_200(WireMockServer wireMockServer, String roleFor) {
+ wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles")).willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile("OpenstackResponse_Roles.json").withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenstackPostNetwork(String responseFile) {
- stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
+ public static void mockOpenstackPostNetwork(WireMockServer wireMockServer, String responseFile) {
+ wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile(responseFile)
.withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenstackPutNetwork(String responseFile, String networkId) {
- stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse()
+ public static void mockOpenstackPutNetwork(WireMockServer wireMockServer, String responseFile, String networkId) {
+ wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBodyFile(responseFile)
.withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackGetNeutronNetwork(String filename,String networkId) {
- stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId))
+ public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String filename,String networkId) {
+ wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
}
- public static void mockOpenStackGetNeutronNetwork_500(String networkId) {
- stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId))
+ public static void mockOpenStackGetNeutronNetwork_500(WireMockServer wireMockServer, String networkId) {
+ wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId))
.willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
}
- public static void mockOpenStackDeleteNeutronNetwork(String networkId) {
- stubFor(delete(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId))
+ public static void mockOpenStackDeleteNeutronNetwork(WireMockServer wireMockServer, String networkId) {
+ wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId))
.willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
index c771a75976..925365f00e 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
@@ -24,19 +24,17 @@ package org.onap.so.openstack.utils;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.shazam.shazamcrest.MatcherAssert.assertThat;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
import static org.junit.Assert.assertNotNull;
-import com.woorea.openstack.heat.Heat;
-import com.woorea.openstack.heat.model.CreateStackParam;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import org.apache.http.HttpStatus;
import org.junit.Assert;
import org.junit.Test;
@@ -59,6 +57,9 @@ import org.onap.so.openstack.exceptions.MsoIOException;
import org.onap.so.openstack.exceptions.MsoOpenstackException;
import org.springframework.beans.factory.annotation.Autowired;
+import com.woorea.openstack.heat.Heat;
+import com.woorea.openstack.heat.model.CreateStackParam;
+
public class MsoHeatUtilsTest extends BaseTest{
@Autowired
@@ -94,10 +95,10 @@ public class MsoHeatUtilsTest extends BaseTest{
Map<String, Object> inputs = new HashMap<>();
boolean rollbackOnFailure = true;
- StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
- StubOpenStack.mockOpenStackPostStack_200("OpenstackResponse_Stack_Created.json");
+ StubOpenStack.mockOpenStackResponseAccess(wireMockServer, wireMockPort);
+ StubOpenStack.mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack_Created.json");
- stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/instanceName/stackId"))
+ wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/instanceName/stackId"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBodyFile("OpenstackResponse_StackId.json")
.withStatus(HttpStatus.SC_OK)));
@@ -123,10 +124,10 @@ public class MsoHeatUtilsTest extends BaseTest{
cloudInfo.setTenantId("tenantId");
String instanceId = "instanceId";
- StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
- StubOpenStack.mockOpenStackPostStack_200("OpenstackResponse_Stack_Created.json");
+ StubOpenStack.mockOpenStackResponseAccess(wireMockServer, wireMockPort);
+ StubOpenStack.mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack_Created.json");
- stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/instanceId"))
+ wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/instanceId"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBodyFile("OpenstackResponse_StackId.json")
.withStatus(HttpStatus.SC_OK)));
@@ -152,10 +153,10 @@ public class MsoHeatUtilsTest extends BaseTest{
int timeoutInMinutes = 1;
- StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
- stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/instanceId")).willReturn(aResponse().withBodyFile("OpenstackResponse_StackId.json").withStatus(HttpStatus.SC_OK)));
- StubOpenStack.mockOpenStackDelete("name/da886914-efb2-4917-b335-c8381528d90b");
- stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/name/da886914-efb2-4917-b335-c8381528d90b")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_DeleteComplete.json").withStatus(HttpStatus.SC_OK)));
+ StubOpenStack.mockOpenStackResponseAccess(wireMockServer, wireMockPort);
+ wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/instanceId")).willReturn(aResponse().withBodyFile("OpenstackResponse_StackId.json").withStatus(HttpStatus.SC_OK)));
+ StubOpenStack.mockOpenStackDelete(wireMockServer, "name/da886914-efb2-4917-b335-c8381528d90b");
+ wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/name/da886914-efb2-4917-b335-c8381528d90b")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_DeleteComplete.json").withStatus(HttpStatus.SC_OK)));
VduInstance actual = heatUtils.deleteVdu(cloudInfo, instanceId, timeoutInMinutes);
@@ -195,7 +196,7 @@ public class MsoHeatUtilsTest extends BaseTest{
@Test
public final void getHeatClientSuccessTest() throws MsoException, IOException {
CloudSite cloudSite = getCloudSite(getCloudIdentity());
- StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
+ StubOpenStack.mockOpenStackResponseAccess(wireMockServer, wireMockPort);
Heat heatClient = heatUtils.getHeatClient(cloudSite, "TEST-tenant");
assertNotNull(heatClient);
}
@@ -210,7 +211,7 @@ public class MsoHeatUtilsTest extends BaseTest{
@Test(expected = MsoAdapterException.class)
public final void getHeatClientOpenStackResponseException401Test() throws MsoException, IOException {
CloudSite cloudSite = getCloudSite(getCloudIdentity());
- StubOpenStack.mockOpenStackResponseUnauthorized(wireMockPort);
+ StubOpenStack.mockOpenStackResponseUnauthorized(wireMockServer, wireMockPort);
heatUtils.getHeatClient(cloudSite, "TEST-tenant");
}
@@ -226,9 +227,9 @@ public class MsoHeatUtilsTest extends BaseTest{
@Test
public final void createStackSuccessTest() throws MsoException, IOException {
CloudSite cloudSite = getCloudSite(getCloudIdentity());
- StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
- StubOpenStack.mockOpenStackPostStack_200("OpenstackResponse_Stack_Created.json");
- StubOpenStack.mockOpenStackGet("TEST-stack/stackId");
+ StubOpenStack.mockOpenStackResponseAccess(wireMockServer, wireMockPort);
+ StubOpenStack.mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack_Created.json");
+ StubOpenStack.mockOpenStackGet(wireMockServer, "TEST-stack/stackId");
StackInfo stackInfo = heatUtils.createStack(cloudSite.getId(), "CloudOwner", "tenantId", "TEST-stack", null,
"TEST-heat", new HashMap<>(), false, 1, "TEST-env",
new HashMap<>(), new HashMap<>(), false);
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoKeystoneUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoKeystoneUtilsTest.java
index 5100407633..3526a68ef6 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoKeystoneUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoKeystoneUtilsTest.java
@@ -39,15 +39,15 @@ public class MsoKeystoneUtilsTest extends BaseTest {
@Before
public void before() throws IOException {
- StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
+ StubOpenStack.mockOpenStackResponseAccess(wireMockServer, wireMockPort);
}
@Test
public void createTenantTest() throws Exception {
- StubOpenStack.mockOpenStackPostTenantWithBodyFile_200();
+ StubOpenStack.mockOpenStackPostTenantWithBodyFile_200(wireMockServer);
- StubOpenStack.mockOpenStackGetUserById("john");
- StubOpenStack.mockOpenStackGetRoles_200("OS-KSADM");
+ StubOpenStack.mockOpenStackGetUserById(wireMockServer, "john");
+ StubOpenStack.mockOpenStackGetRoles_200(wireMockServer, "OS-KSADM");
String response = msoKeystoneUtils.createTenant("tenant", "MTN13", new HashMap<>(), true);
Assert.assertEquals("tenantId", response);
@@ -55,10 +55,10 @@ public class MsoKeystoneUtilsTest extends BaseTest {
@Test
public void createTenantTest_FindUserByName() throws Exception {
- StubOpenStack.mockOpenStackPostTenantWithBodyFile_200();
+ StubOpenStack.mockOpenStackPostTenantWithBodyFile_200(wireMockServer);
- StubOpenStack.mockOpenStackGetUserByName("john");
- StubOpenStack.mockOpenStackGetRoles_200("OS-KSADM");
+ StubOpenStack.mockOpenStackGetUserByName(wireMockServer, "john");
+ StubOpenStack.mockOpenStackGetRoles_200(wireMockServer, "OS-KSADM");
String response = msoKeystoneUtils.createTenant("tenant", "MTN13", new HashMap<>(), true);
Assert.assertEquals("tenantId", response);
@@ -67,15 +67,15 @@ public class MsoKeystoneUtilsTest extends BaseTest {
@Test
public void createTenantTest_Exception() throws Exception {
expectedException.expect(MsoException.class);
- StubOpenStack.mockOpenStackPostTenantWithBodyFile_200();
- StubOpenStack.mockOpenStackGetUserByName_500("john");
- StubOpenStack.mockOpenStackGetRoles_200("OS-KSADM");
+ StubOpenStack.mockOpenStackPostTenantWithBodyFile_200(wireMockServer);
+ StubOpenStack.mockOpenStackGetUserByName_500(wireMockServer, "john");
+ StubOpenStack.mockOpenStackGetRoles_200(wireMockServer, "OS-KSADM");
msoKeystoneUtils.createTenant("tenant", "Test", new HashMap<>(), true);
}
@Test
public void queryTenantTest() throws Exception {
- StubOpenStack.mockOpenStackGetTenantById("tenantId");
+ StubOpenStack.mockOpenStackGetTenantById(wireMockServer, "tenantId");
MsoTenant msoTenant = msoKeystoneUtils.queryTenant("tenantId", "MTN13");
@@ -84,7 +84,7 @@ public class MsoKeystoneUtilsTest extends BaseTest {
@Test
public void queryTenantByNameTest() throws Exception {
- StubOpenStack.mockOpenStackGetTenantByName("tenant");
+ StubOpenStack.mockOpenStackGetTenantByName(wireMockServer, "tenant");
MsoTenant msoTenant = msoKeystoneUtils.queryTenantByName("tenant", "MTN13");
@@ -93,8 +93,8 @@ public class MsoKeystoneUtilsTest extends BaseTest {
@Test
public void deleteTenantTest() throws Exception {
- StubOpenStack.mockOpenStackGetTenantById("tenantId");
- StubOpenStack.mockOpenStackDeleteTenantById_200("tenantId");
+ StubOpenStack.mockOpenStackGetTenantById(wireMockServer, "tenantId");
+ StubOpenStack.mockOpenStackDeleteTenantById_200(wireMockServer, "tenantId");
boolean result = msoKeystoneUtils.deleteTenant("tenantId", "MTN13");
Assert.assertTrue(result);
@@ -102,8 +102,8 @@ public class MsoKeystoneUtilsTest extends BaseTest {
@Test
public void deleteTenantByNameTest() throws Exception {
- StubOpenStack.mockOpenStackGetTenantByName("tenant");
- StubOpenStack.mockOpenStackDeleteTenantById_200("tenantId");
+ StubOpenStack.mockOpenStackGetTenantByName(wireMockServer, "tenant");
+ StubOpenStack.mockOpenStackDeleteTenantById_200(wireMockServer, "tenantId");
boolean result = msoKeystoneUtils.deleteTenantByName("tenant", "MTN13");
Assert.assertTrue(result);
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java
index b2a69ded46..8b0efd8ade 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2019 Samsung Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* 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
@@ -22,25 +24,31 @@ package org.onap.so.openstack.utils;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
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.urlPathEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.HashMap;
import java.util.Optional;
+
import org.apache.http.HttpStatus;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.onap.so.BaseTest;
+import org.onap.so.adapters.vdu.CloudInfo;
+import org.onap.so.adapters.vdu.VduException;
+import org.onap.so.adapters.vdu.VduInstance;
import org.onap.so.adapters.vdu.VduModelInfo;
+import org.onap.so.adapters.vdu.VduStateType;
import org.onap.so.cloud.CloudConfig;
import org.onap.so.db.catalog.beans.CloudIdentity;
import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.openstack.beans.HeatStatus;
import org.onap.so.openstack.beans.StackInfo;
import org.onap.so.openstack.exceptions.MsoException;
import org.springframework.beans.factory.annotation.Autowired;
@@ -61,7 +69,7 @@ public class MsoMulticloudUtilsTest extends BaseTest {
@Test
public void createStackSuccess() throws MsoException, IOException {
- stubFor(post(urlPathEqualTo("/v2.0"))
+ wireMockServer.stubFor(post(urlPathEqualTo("/v2.0"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBody(CREATE_STACK_RESPONSE)
.withStatus(HttpStatus.SC_CREATED)));
@@ -73,6 +81,33 @@ public class MsoMulticloudUtilsTest extends BaseTest {
}
@Test
+ public void deleteStack() throws MsoException {
+ StackInfo result = multicloudUtils.deleteStack("MTN13", "CloudOwner", "TEST-tenant", "instanceId");
+ assertNotNull(result);
+ assertTrue(HeatStatus.NOTFOUND == result.getStatus());
+ }
+
+ @Test
+ public void queryStack() throws MsoException {
+ StackInfo result = multicloudUtils.queryStack("MTN13", "CloudOwner", "TEST-tenant", "instanceId");
+ assertTrue(HeatStatus.NOTFOUND == result.getStatus());
+ }
+
+ @Test(expected = VduException.class)
+ public void updateVdu() throws MsoException {
+ multicloudUtils.updateVdu(new CloudInfo(), "instanceId", new HashMap<>(), new VduModelInfo(),
+ false);
+ }
+
+ @Test
+ public void deleteVdu() throws VduException {
+ CloudInfo cloudInfo = new CloudInfo("cloudSiteId", "cloudOwner", "tenantId", "tenantName");
+ VduInstance vduInstance = multicloudUtils.deleteVdu(cloudInfo, "instanceId", 3);
+ assertNotNull(vduInstance);
+ assertTrue(VduStateType.DELETED == vduInstance.getStatus().getState());
+ }
+
+ @Test
public void createStackMulticloudClientIsNull() {
try {
multicloudUtilsMock.cloudConfig = cloudConfigMock;
@@ -93,7 +128,7 @@ public class MsoMulticloudUtilsTest extends BaseTest {
@Test
public void createStackBadRequest() {
try {
- stubFor(post(urlPathEqualTo("/v2.0"))
+ wireMockServer.stubFor(post(urlPathEqualTo("/v2.0"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withStatus(HttpStatus.SC_BAD_REQUEST)));
multicloudUtils.createStack("MTN13", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(),
@@ -108,7 +143,7 @@ public class MsoMulticloudUtilsTest extends BaseTest {
@Test
public void createStackEmptyResponseEntity() throws MsoException {
- stubFor(post(urlPathEqualTo("/v2.0"))
+ wireMockServer.stubFor(post(urlPathEqualTo("/v2.0"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withStatus(HttpStatus.SC_CREATED)));
StackInfo result = multicloudUtils.createStack("MTN13", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(),
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoNeutronUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoNeutronUtilsTest.java
index f679e1f776..8c337865df 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoNeutronUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoNeutronUtilsTest.java
@@ -44,7 +44,7 @@ public class MsoNeutronUtilsTest extends BaseTest{
public void before() throws IOException {
vlans = new ArrayList<>();
vlans.add(3014);
- StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
+ StubOpenStack.mockOpenStackResponseAccess(wireMockServer, wireMockPort);
}
@Test
@@ -56,7 +56,7 @@ public class MsoNeutronUtilsTest extends BaseTest{
@Test
public void createNetworkTest_NetworkTypeAsMultiProvider() throws Exception {
- StubOpenStack.mockOpenstackPostNetwork("OpenstackCreateNeutronNetworkResponse.json");
+ StubOpenStack.mockOpenstackPostNetwork(wireMockServer, "OpenstackCreateNeutronNetworkResponse.json");
NetworkInfo networkInfo = msoNeutronUtils.createNetwork("MTN13", "tenantId",
MsoNeutronUtils.NetworkType.MULTI_PROVIDER,"networkName","PROVIDER", vlans);
@@ -65,7 +65,7 @@ public class MsoNeutronUtilsTest extends BaseTest{
@Test
public void createNetworkTest() throws Exception {
- StubOpenStack.mockOpenstackPostNetwork("OpenstackCreateNeutronNetworkResponse.json");
+ StubOpenStack.mockOpenstackPostNetwork(wireMockServer, "OpenstackCreateNeutronNetworkResponse.json");
NetworkInfo networkInfo = msoNeutronUtils.createNetwork("MTN13", "tenantId",
MsoNeutronUtils.NetworkType.PROVIDER,"networkName","PROVIDER", vlans);
@@ -74,7 +74,7 @@ public class MsoNeutronUtilsTest extends BaseTest{
@Test
public void queryNetworkTest() throws Exception {
- StubOpenStack.mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
+ StubOpenStack.mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
NetworkInfo networkInfo = msoNeutronUtils.queryNetwork("43173f6a-d699-414b-888f-ab243dda6dfe", "tenantId","MTN13");
Assert.assertEquals("net1",networkInfo.getName());
@@ -89,15 +89,15 @@ public class MsoNeutronUtilsTest extends BaseTest{
@Test
public void queryNetworkTest_500() throws Exception {
expectedException.expect(MsoException.class);
- StubOpenStack.mockOpenStackGetNeutronNetwork_500("43173f6a-d699-414b-888f-ab243dda6dfe");
+ StubOpenStack.mockOpenStackGetNeutronNetwork_500(wireMockServer, "43173f6a-d699-414b-888f-ab243dda6dfe");
msoNeutronUtils.queryNetwork("43173f6a-d699-414b-888f-ab243dda6dfe", "tenantId","MTN13");
}
@Test
public void deleteNetworkkTest() throws Exception {
- StubOpenStack.mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
- StubOpenStack.mockOpenStackDeleteNeutronNetwork("43173f6a-d699-414b-888f-ab243dda6dfe");
+ StubOpenStack.mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
+ StubOpenStack.mockOpenStackDeleteNeutronNetwork(wireMockServer, "43173f6a-d699-414b-888f-ab243dda6dfe");
Boolean result = msoNeutronUtils.deleteNetwork("43173f6a-d699-414b-888f-ab243dda6dfe", "tenantId","MTN13");
Assert.assertTrue(result);
@@ -105,8 +105,8 @@ public class MsoNeutronUtilsTest extends BaseTest{
@Test
public void updateNetworkTest() throws Exception {
- StubOpenStack.mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
- StubOpenStack.mockOpenstackPutNetwork("OpenstackCreateNeutronNetworkResponse.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
+ StubOpenStack.mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
+ StubOpenStack.mockOpenstackPutNetwork(wireMockServer, "OpenstackCreateNeutronNetworkResponse.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
NetworkInfo networkInfo = msoNeutronUtils.updateNetwork("MTN13", "tenantId",
"43173f6a-d699-414b-888f-ab243dda6dfe",MsoNeutronUtils.NetworkType.PROVIDER,"PROVIDER", vlans);
@@ -115,8 +115,8 @@ public class MsoNeutronUtilsTest extends BaseTest{
@Test
public void updateNetworkTest_NetworkTypeAsMultiProvider() throws Exception {
- StubOpenStack.mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
- StubOpenStack.mockOpenstackPutNetwork("OpenstackCreateNeutronNetworkResponse.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
+ StubOpenStack.mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
+ StubOpenStack.mockOpenstackPutNetwork(wireMockServer, "OpenstackCreateNeutronNetworkResponse.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
NetworkInfo networkInfo = msoNeutronUtils.updateNetwork("MTN13", "tenantId",
"43173f6a-d699-414b-888f-ab243dda6dfe",MsoNeutronUtils.NetworkType.MULTI_PROVIDER,"PROVIDER", vlans);