diff options
Diffstat (limited to 'adapters/mso-openstack-adapters/src/test')
7 files changed, 263 insertions, 6 deletions
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java index 2a4564bcb2..6123415b41 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java @@ -142,7 +142,7 @@ public class NetworkAdapterRestTest extends BaseRestTestUtils { ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); - + CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( new File("src/test/resources/__files/CreateNetworkResponse2.json"), CreateNetworkResponse.class); @@ -150,6 +150,8 @@ public class NetworkAdapterRestTest extends BaseRestTestUtils { assertThat(response.getBody(), sameBeanAs(expectedResponse)); } + + @Test public void testDeleteNetwork() throws IOException{ @@ -267,6 +269,33 @@ public class NetworkAdapterRestTest extends BaseRestTestUtils { assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } + @Test + public void testCreateNetworkCNRC_JSON() throws JSONException, JsonParseException, JsonMappingException, IOException { + + mockOpenStackResponseAccess(wireMockPort); + + mockOpenStackPostPublicUrlWithBodyFile_200(); + + mockOpenStackGetStackCreatedAppC_200(); + + mockOpenStackGetStackAppC_404(); + + headers.add("Content-Type", MediaType.APPLICATION_JSON); + headers.add("Accept", MediaType.APPLICATION_JSON); + + String request = readJsonFileAsString("src/test/resources/CreateNetwork3.json"); + HttpEntity<String> entity = new HttpEntity<String>(request, headers); + + ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); + + CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateNetworkResponse3.json"), CreateNetworkResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + @Override protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{ return new String(Files.readAllBytes(Paths.get(fileLocation))); 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 b21f1f3db2..77ef8d4776 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 @@ -7,9 +7,9 @@ * 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. @@ -20,15 +20,31 @@ 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; @@ -36,11 +52,15 @@ 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 { @@ -52,6 +72,53 @@ 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); @@ -88,18 +155,52 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { new Holder<VnfRollback>()); } - @Test + /* @Test public void createVfModule_INSTANTIATED() throws Exception { mockOpenStackResponseAccess(wireMockPort); mockOpenStackGetStackVfModule_200(); + MsoRequest msoRequest = getMsoRequest(); Map<String, String> map = new HashMap<>(); map.put("key1", "value1"); - msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, + 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_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/java/org/onap/so/bpmn/mock/StubOpenStack.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java index 98d5f7eb5f..569a845caa 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java @@ -49,6 +49,12 @@ public class StubOpenStack { .withStatus(HttpStatus.SC_OK))); } + public static void mockOpenStackResponseAccessMulticloud(int port) throws IOException { + stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_AccessMulticloud.json", port, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + } + public static void mockOpenStackResponseAccessQueryNetwork(int port) throws IOException { stubFor(post(urlPathEqualTo("/v2.0/tokens")) .withRequestBody(containing("tenantId")) diff --git a/adapters/mso-openstack-adapters/src/test/resources/CreateNetwork3.json b/adapters/mso-openstack-adapters/src/test/resources/CreateNetwork3.json new file mode 100644 index 0000000000..accd9e9a54 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/resources/CreateNetwork3.json @@ -0,0 +1,42 @@ +{ + "createNetworkRequest": { + "skipAAI": true, + "messageId": "c4c44af4-4310-4d8b-a1eb-656fc99fe709", + "synchronous": true, + "cloudSiteId": "mtn13", + "tenantId": "ba38bc24a2ef4fb2ad2810c894f1938f", + "networkId": "da886914-efb2-4917-b335-c8381528d90b", + "networkName": "APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3", + "networkType": "CONTRAIL30_BASIC", + "modelCustomizationUuid": "3bdbb104-ffff-483e-9f8b-c095b3d30844", + "networkTechnology": "NEUTRON", + "subnets": [{ + "subnetName": "APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3_subnet_1", + "subnetId": "da60501d-9aa8-48d2-99b7-26644fa01093", + "cidr": "20", + "gatewayIp": "", + "ipVersion": "4", + "enableDHCP": false, + "addrFromStart": true, + "hostRoutes": [] + }], + "providerVlanNetwork": { + "physicalNetworkName": "FALSE", + "vlans": [] + }, + "contrailNetwork": { + "shared": "false", + "external": "false", + "routeTargets": [], + "policyFqdns": [], + "routeTableFqdns": [] + }, + "failIfExists": true, + "backout": false, + "msoRequest": { + "requestId": "5349f419-b3e9-4546-b3a1-094bd568d6b7", + "serviceInstanceId": "cf965caf-a003-4189-abf9-e0ed77056dd6" + }, + "contrailRequest": false + } +}
\ No newline at end of file diff --git a/adapters/mso-openstack-adapters/src/test/resources/__files/CreateNetworkResponse3.json b/adapters/mso-openstack-adapters/src/test/resources/__files/CreateNetworkResponse3.json new file mode 100644 index 0000000000..2e5517cebb --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/resources/__files/CreateNetworkResponse3.json @@ -0,0 +1,25 @@ +{ + "createNetworkResponse": { + "networkId": "da886914-efb2-4917-b335-c8381528d90b", + "neutronNetworkId": null, + "networkStackId": "stackname/stackId", + "networkFqdn": null, + "networkCreated": true, + "subnetMap": { + + }, + "rollback": { + "networkStackId": "stackname/stackId", + "tenantId": "ba38bc24a2ef4fb2ad2810c894f1938f", + "cloudId": "mtn13", + "networkType": "CONTRAIL30_BASIC", + "modelCustomizationUuid": "3bdbb104-ffff-483e-9f8b-c095b3d30844", + "networkCreated": true, + "msoRequest": { + "requestId": "5349f419-b3e9-4546-b3a1-094bd568d6b7", + "serviceInstanceId": "cf965caf-a003-4189-abf9-e0ed77056dd6" + } + }, + "messageId": "c4c44af4-4310-4d8b-a1eb-656fc99fe709" + } +}
\ No newline at end of file diff --git a/adapters/mso-openstack-adapters/src/test/resources/__files/OpenstackResponse_AccessMulticloud.json b/adapters/mso-openstack-adapters/src/test/resources/__files/OpenstackResponse_AccessMulticloud.json new file mode 100644 index 0000000000..23fbe840e4 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/resources/__files/OpenstackResponse_AccessMulticloud.json @@ -0,0 +1,40 @@ +{ + "access": { + "token": { + "id": "tokenId1234", + "issued_at": null, + "expires": "1517418429142", + "tenant": null + }, + "serviceCatalog": [ + { + "type": "orchestration", + "name": null, + "endpoints": [ + { + "region": "MTN13", + "publicURL": "port", + "internalURL": null, + "adminURL": null + } + ], + "endpointsLinks": null + }, + { + "type": "network", + "name": null, + "endpoints": [ + { + "region": "MTN13", + "publicURL": "port", + "internalURL": null, + "adminURL": null + } + ], + "endpointsLinks": null + } + ], + "user": null, + "metadata": null + } +} diff --git a/adapters/mso-openstack-adapters/src/test/resources/data.sql b/adapters/mso-openstack-adapters/src/test/resources/data.sql index d16ca4528c..960f483e46 100644 --- a/adapters/mso-openstack-adapters/src/test/resources/data.sql +++ b/adapters/mso-openstack-adapters/src/test/resources/data.sql @@ -71,6 +71,20 @@ insert into network_resource_customization(model_customization_uuid, model_insta ('3bdbb104-476c-483e-9f8b-c095b3d30844', 'CONTRAIL30_BASIC', '', 'CONTRAIL30_BASIC', '', '', '2017-04-19 14:28:32', '10b36f65-f4e6-4be6-ae49-9596dc1c4789'), ('3bdbb104-476c-483e-9f8b-c095b3d3068c', 'CONTRAIL31_BASIC', '', 'CONTRAIL31_BASIC', '', '', '2017-04-19 14:28:32', '10b36f65-f4e6-4be6-ae49-9596dc1c4790'); +insert into instance_group(model_uuid, model_name, model_invariant_uuid, model_version, tosca_node_type, role, object_type, cr_model_uuid, instance_group_type) values +('21e43a7c-d823-4f5b-a427-5235f63035ff', 'dror_cr_network_resource_1806..NetworkCollection..0', '81c94263-c01e-4046-b0c7-51878d658eab', '1', 'org.openecomp.groups.NetworkCollection', 'SUB_INTERFACE', 'L3_NETWORK', '5e3fca45-e2d8-4987-bef1-016d9bda1a8c', 'L3_NETWORK'); + +insert into collection_resource(model_uuid, model_name, model_invariant_uuid, model_version, tosca_node_type, description) values +('5e3fca45-e2d8-4987-bef1-016d9bda1a8c', 'Dror_CR_Network_Resource_1806', 'fe243154-ac18-405f-94c2-ef629d26b8bb', '2.0', 'org.openecomp.resource.cr.DrorCrNetworkResource1806', 'Creation date: 07/25/18'); + +insert into collection_resource_customization(model_customization_uuid, model_instance_name, role, object_type, function, collection_resource_type, cr_model_uuid) values +('c51096a4-6081-41f4-a540-3ed015a8064a', 'Dror_CR_Network_Resource_1806', 'Dror2', 'NetworkCollection', 'Dror1', 'Dror3', '5e3fca45-e2d8-4987-bef1-016d9bda1a8c'); + +insert into collection_network_resource_customization(model_customization_uuid, model_instance_name, network_technology, network_type, network_role, network_scope, network_resource_model_uuid, instance_group_model_uuid, crc_model_customization_uuid) values +('3bdbb104-ffff-483e-9f8b-c095b3d30844', 'ExtVL 0', 'CONTRAIL', 'L3-NETWORK', '', '', '10b36f65-f4e6-4be6-ae49-9596dc1c4789', '21e43a7c-d823-4f5b-a427-5235f63035ff', 'c51096a4-6081-41f4-a540-3ed015a8064a'), +('3bdbb104-ffff-483e-9f8b-c095b3d3068c', 'ExtVL 0', 'CONTRAIL', 'L3-NETWORK', '', '', '10b36f65-f4e6-4be6-ae49-9596dc1c4790', '21e43a7c-d823-4f5b-a427-5235f63035ff', 'c51096a4-6081-41f4-a540-3ed015a8064a'); + + insert into vnf_resource(orchestration_mode, description, creation_timestamp, model_uuid, aic_version_min, aic_version_max, model_invariant_uuid, model_version, model_name, tosca_node_type, heat_template_artifact_uuid) values ('HEAT', '1607 vSAMP10a - inherent network', '2017-04-14 21:46:28', 'ff2ae348-214a-11e7-93ae-92361f002672', '', '', '2fff5b20-214b-11e7-93ae-92361f002671', '2.0', 'vSAMP10a', 'VF', null); |