From 287362502adc4485fc43f9364fd1829adec55ab6 Mon Sep 17 00:00:00 2001 From: Eric Multanen Date: Tue, 9 Apr 2019 23:18:19 -0700 Subject: Update multicloud plugin GET handling Supports multicloud API query by workload name or id. Gets workload details e.g. stack outputs, etc. To be used to fill in inputs for vfmodule that has a volume group or base module. Change-Id: If45783e82c2a209d3385be1b689a02a05baf9922 Issue-ID: SO-1445 Signed-off-by: Eric Multanen --- .../so/openstack/utils/MsoMulticloudUtilsTest.java | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'adapters/mso-adapter-utils/src/test/java/org/onap') 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 0d8f451a6d..995db522e9 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 @@ -21,9 +21,11 @@ package org.onap.so.openstack.utils; 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.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -34,7 +36,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.Optional; import org.apache.http.HttpStatus; -import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.mockito.InjectMocks; @@ -64,38 +65,36 @@ public class MsoMulticloudUtilsTest extends BaseTest { @Mock private CloudConfig cloudConfigMock; - private static final String CREATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": " + private static final String CREATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": " + "\"TEST-workload\", \"template_response\": {\"stack\": {\"id\": \"TEST-stack\", \"links\": []}}}"; private static final String UPDATE_STACK_RESPONSE = - "{\"template_type\": \"TEST-template\", \"workload_id\": " + "\"TEST-workload\"}"; - private static final String GET_CREATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": " - + "\"TEST-workload\", \"workload_status\": \"CREATE_COMPLETE\"}"; - private static final String GET_UPDATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": " - + "\"TEST-workload\", \"workload_status\": \"UPDATE_COMPLETE\"}"; + "{\"template_type\": \"heat\", \"workload_id\": " + "\"TEST-workload\"}"; private static final String MULTICLOUD_CREATE_PATH = "/api/multicloud/v1/CloudOwner/MTN14/infra_workload"; private static final String MULTICLOUD_UPDATE_PATH = "/api/multicloud/v1/CloudOwner/MTN14/infra_workload/TEST-workload"; private static final String MULTICLOUD_GET_PATH = "/api/multicloud/v1/CloudOwner/MTN14/infra_workload/TEST-workload"; + private static final String MULTICLOUD_DELETE_PATH = + "/api/multicloud/v1/CloudOwner/MTN14/infra_workload/TEST-workload"; @Test public void createStackSuccess() throws MsoException, IOException { wireMockServer - .stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)).inScenario("CREATE") + .stubFor(post(urlEqualTo(MULTICLOUD_CREATE_PATH)).inScenario("CREATE") .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(CREATE_STACK_RESPONSE).withStatus(HttpStatus.SC_CREATED)) .willSetStateTo("CREATING")); wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH)).inScenario("CREATE") .whenScenarioStateIs("CREATING").willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(GET_CREATE_STACK_RESPONSE).withStatus(HttpStatus.SC_OK))); + .withBodyFile("MulticloudGetCreateResponse.json").withStatus(HttpStatus.SC_OK))); wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_UPDATE_PATH)) .inScenario("CREATE").willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(UPDATE_STACK_RESPONSE).withStatus(HttpStatus.SC_ACCEPTED)) .willSetStateTo("UPDATING")); - wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH)).inScenario("CREATE") - .whenScenarioStateIs("UPDATING").willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(GET_UPDATE_STACK_RESPONSE).withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlEqualTo(MULTICLOUD_GET_PATH)).inScenario("CREATE").whenScenarioStateIs("UPDATING") + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("MulticloudGetUpdateResponse.json").withStatus(HttpStatus.SC_OK))); StackInfo result = multicloudUtils.createStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(), "TEST-heat", new HashMap<>(), true, 200, "TEST-env", new HashMap<>(), new HashMap<>(), false); @@ -106,7 +105,13 @@ public class MsoMulticloudUtilsTest extends BaseTest { @Test public void deleteStack() throws MsoException { - StackInfo result = multicloudUtils.deleteStack("MTN13", "CloudOwner", "TEST-tenant", "instanceId"); + wireMockServer.stubFor(delete(urlEqualTo(MULTICLOUD_DELETE_PATH)).willReturn( + aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NO_CONTENT))); + wireMockServer.stubFor(get(urlEqualTo(MULTICLOUD_GET_PATH)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("MulticloudGetDeleteResponse.json").withStatus(HttpStatus.SC_OK))); + StackInfo result = + multicloudUtils.deleteStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack/TEST-workload"); assertNotNull(result); assertTrue(HeatStatus.NOTFOUND == result.getStatus()); } @@ -123,7 +128,7 @@ public class MsoMulticloudUtilsTest extends BaseTest { .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(CREATE_STACK_RESPONSE) .withStatus(HttpStatus.SC_OK))); - StackInfo result = multicloudUtils.queryStack("MTN13", "CloudOwner", "TEST-tenant", "instanceId"); + StackInfo result = multicloudUtils.queryStack("MTN13", "CloudOwner", "TEST-tenant", "instanceName/instanceId"); assertTrue(HeatStatus.FAILED == result.getStatus()); assertEquals(MULTICLOUD_QUERY_BODY_NULL, result.getStatusMessage()); } -- cgit 1.2.3-korg