diff options
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test')
5 files changed, 352 insertions, 68 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java index c25d8257d8..07c471ec87 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java @@ -20,8 +20,6 @@ package org.onap.so.adapters.vnfmadapter.rest; -import static org.junit.Assert.assertEquals; -import java.net.URI; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; @@ -33,6 +31,8 @@ import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import java.net.URI; +import static org.junit.Assert.assertEquals; @RunWith(SpringRunner.class) @SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java new file mode 100644 index 0000000000..b7f5e96eab --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java @@ -0,0 +1,240 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.so.adapters.vnfmadapter.rest; + +import com.google.gson.Gson; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.hamcrest.MockitoHamcrest; +import org.onap.aai.domain.yang.EsrSystemInfo; +import org.onap.aai.domain.yang.EsrSystemInfoList; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.aai.domain.yang.RelationshipList; +import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest.OperationEnum; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources.TypeEnum; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201VimConnections; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.web.client.RestTemplate; +import java.util.Optional; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class Sol003GrantControllerTest { + + private static final String CLOUD_OWNER = "myTestCloudOwner"; + private static final String REGION = "myTestRegion"; + private static final String TENANT_ID = "myTestTenantId"; + private static final String SEPARATOR = "_"; + private static final String vimConnectionId = CLOUD_OWNER + SEPARATOR + REGION; + + @LocalServerPort + private int port; + @Autowired + @Qualifier(CONFIGURABLE_REST_TEMPLATE) + private RestTemplate testRestTemplate; + private MockRestServiceServer mockRestServer; + + @MockBean + private AAIResourcesClient aaiResourcesClient; + + @Autowired + private Sol003GrantController controller; + private final Gson gson = new Gson(); + + @Before + public void setUp() throws Exception { + mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build(); + setUpVimInMockAai(); + } + + @Test + public void grantRequest_ValidRequestInstantiate_GrantApproved() { + GrantRequest grantRequest = createGrantRequest("INSTANTIATE"); + setUpGenericVnfWithVnfmRelationshipInMockAai("vnfmType", "vnfm1"); + final ResponseEntity<InlineResponse201> response = controller.grantsPost(grantRequest); + assertEquals(HttpStatus.CREATED, response.getStatusCode()); + assertEquals(1, response.getBody().getAddResources().size()); + + assertEquals(vimConnectionId, response.getBody().getAddResources().get(0).getVimConnectionId()); + assertEquals("myTestVnfId", response.getBody().getVnfInstanceId()); + assertEquals("123456", response.getBody().getVnfLcmOpOccId()); + + InlineResponse201VimConnections vimConnections = response.getBody().getVimConnections().get(0); + assertEquals(vimConnectionId, vimConnections.getVimId()); + assertEquals("OPENSTACK", vimConnections.getVimType()); + assertNotNull(vimConnections.getAccessInfo()); + assertNotNull(vimConnections.getInterfaceInfo()); + assertEquals("INSTANTIATE", grantRequest.getOperation().toString()); + } + + @Test + public void getGrant_notSupported_returns501() { + final ResponseEntity<InlineResponse201> response2 = controller.grantsGrantIdGet("myTestGrantId"); + assertEquals(HttpStatus.NOT_IMPLEMENTED, response2.getStatusCode()); + } + + @Test + public void grantRequest_ValidRequestTerminate_GrantApproved() { + GrantRequest grantRequest = createGrantRequest("TERMINATE"); + setUpGenericVnfWithVnfmRelationshipInMockAai("vnfmType", "vnfm1"); + final ResponseEntity<InlineResponse201> response = controller.grantsPost(grantRequest); + + assertEquals(HttpStatus.CREATED, response.getStatusCode()); + assertEquals(1, response.getBody().getAddResources().size()); + assertEquals(vimConnectionId, response.getBody().getAddResources().get(0).getVimConnectionId()); + assertEquals("myTestVnfId", response.getBody().getVnfInstanceId()); + assertEquals("123456", response.getBody().getVnfLcmOpOccId()); + + InlineResponse201VimConnections vimConnections = response.getBody().getVimConnections().get(0); + assertEquals(vimConnectionId, vimConnections.getVimId()); + assertEquals("OPENSTACK", vimConnections.getVimType()); + assertNotNull(vimConnections.getAccessInfo()); + assertNotNull(vimConnections.getInterfaceInfo()); + assertEquals("TERMINATE", grantRequest.getOperation().toString()); + + } + + private GrantRequest createGrantRequest(String operation) { + GrantRequest grantRequest = new GrantRequest(); + grantRequest.setVnfInstanceId("myTestVnfId"); + grantRequest.setVnfLcmOpOccId("123456"); + if (operation == "INSTANTIATE") { + grantRequest.setOperation(OperationEnum.INSTANTIATE); + GrantsAddResources resource = new GrantsAddResources(); + resource.setId("123"); + resource.setType(TypeEnum.COMPUTE); + grantRequest.addAddResourcesItem(resource); + } else if (operation == "TERMINATE") { + grantRequest.setOperation(OperationEnum.TERMINATE); + GrantsAddResources resource = new GrantsAddResources(); + resource.setId("123"); + resource.setType(TypeEnum.COMPUTE); + grantRequest.addRemoveResourcesItem(resource); + } + + return grantRequest; + } + + private void setUpVimInMockAai() { + final EsrSystemInfo esrSystemInfo = new EsrSystemInfo(); + esrSystemInfo.setServiceUrl("http://myVim:8080"); + esrSystemInfo.setType("OPENSTACK"); + esrSystemInfo.setSystemType("VIM"); + esrSystemInfo.setCloudDomain("myDomain"); + esrSystemInfo.setUserName("myUser"); + esrSystemInfo.setPassword("myPassword"); + + final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList(); + esrSystemInfoList.getEsrSystemInfo().add(esrSystemInfo); + + doReturn(Optional.of(esrSystemInfoList)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class), + MockitoHamcrest.argThat(new AaiResourceUriMatcher("/cloud-infrastructure/cloud-regions/cloud-region/" + + CLOUD_OWNER + "/" + REGION + "/esr-system-info-list"))); + } + + private GenericVnf createGenericVnf(final String type) { + final GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("myTestVnfId"); + genericVnf.setNfType(type); + return genericVnf; + } + + private void setUpGenericVnfWithVnfmRelationshipInMockAai(final String type, final String vnfmId) { + final GenericVnf genericVnf = createGenericVnf(type); + + final Relationship relationshipToVnfm = new Relationship(); + relationshipToVnfm.setRelatedTo("tenant"); + final RelationshipData relationshipData1 = new RelationshipData(); + final RelationshipData relationshipData2 = new RelationshipData(); + final RelationshipData relationshipData3 = new RelationshipData(); + + relationshipData1.setRelationshipKey("cloud-region.cloud-owner"); + relationshipData1.setRelationshipValue(CLOUD_OWNER); + relationshipData2.setRelationshipKey("cloud-region.cloud-region-id"); + relationshipData2.setRelationshipValue(REGION); + relationshipData3.setRelationshipKey("tenant.tenant-id"); + relationshipData3.setRelationshipValue(TENANT_ID); + + relationshipToVnfm.getRelationshipData().add(relationshipData1); + relationshipToVnfm.getRelationshipData().add(relationshipData2); + relationshipToVnfm.getRelationshipData().add(relationshipData3); + + final RelationshipList relationshipList = new RelationshipList(); + relationshipList.getRelationship().add(relationshipToVnfm); + genericVnf.setRelationshipList(relationshipList); + + doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class), + MockitoHamcrest.argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId"))); + } + + private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> { + + final String uriAsString; + + public AaiResourceUriMatcher(final String uriAsString) { + this.uriAsString = uriAsString; + } + + @Override + public boolean matches(final Object item) { + if (item instanceof AAIResourceUri) { + if (uriAsString.endsWith("...")) { + return ((AAIResourceUri) item).build().toString() + .startsWith(uriAsString.substring(0, uriAsString.indexOf("..."))); + } + return ((AAIResourceUri) item).build().toString().equals(uriAsString); + } + return false; + } + + @Override + public void describeTo(final Description description) {} + + } + +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java index a8455f85db..66e8e99f72 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java @@ -20,24 +20,7 @@ package org.onap.so.adapters.vnfmadapter.rest; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; import com.google.gson.Gson; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Before; @@ -49,6 +32,9 @@ import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.Vserver; import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; +import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiHelper; +import org.onap.so.adapters.vnfmadapter.extclients.aai.OamIpAddressSource; +import org.onap.so.adapters.vnfmadapter.extclients.aai.OamIpAddressSource.OamIpAddressType; import org.onap.so.adapters.vnfmadapter.extclients.vim.model.AccessInfo; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs.ChangeTypeEnum; @@ -78,7 +64,24 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; - +import javax.inject.Inject; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @RunWith(SpringRunner.class) @SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) @@ -103,6 +106,9 @@ public class Sol003LcnControllerTest { private Sol003LcnContoller controller; private final Gson gson = new Gson(); + @Inject + private AaiHelper aaiHelper; + @Before public void setUp() throws Exception { mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build(); @@ -270,6 +276,7 @@ public class Sol003LcnControllerTest { private InlineResponse201 createVnfInstance() { final InlineResponse201 vnfInstance = new InlineResponse201(); + vnfInstance.setId("myTestVnfIdOnVnfm"); final InlineResponse201LinksSelf selfLink = new InlineResponse201LinksSelf(); selfLink.setHref("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"); final InlineResponse201Links VnfInstancelinks = new InlineResponse201Links(); @@ -289,6 +296,10 @@ public class Sol003LcnControllerTest { vimConnection.setAccessInfo(accessInfo); vimConnectionInfo.add(vimConnection); vnfInstance.setVimConnectionInfo(vimConnectionInfo); + + final OamIpAddressSource oamIpAddressSource = + new OamIpAddressSource(OamIpAddressType.CONFIGURABLE_PROPERTY, "vnfIpAddress"); + aaiHelper.setOamIpAddressSource("myTestVnfIdOnVnfm", oamIpAddressSource); return vnfInstance; } @@ -324,5 +335,4 @@ public class Sol003LcnControllerTest { } - } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java index 78b2116311..20a074b2ba 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java @@ -20,21 +20,7 @@ package org.onap.so.adapters.vnfmadapter.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; import com.google.gson.Gson; -import java.net.URI; -import java.util.Optional; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Before; @@ -50,20 +36,24 @@ import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.RelationshipList; -import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse2001; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; -import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException; -import org.onap.so.client.aai.AAIResourcesClient; -import org.onap.so.client.aai.entities.uri.AAIResourceUri; -import org.onap.vnfmadapter.v1.model.CreateVnfRequest; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201Links; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201LinksSelf; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; import org.onap.vnfmadapter.v1.model.OperationEnum; import org.onap.vnfmadapter.v1.model.OperationStateEnum; import org.onap.vnfmadapter.v1.model.QueryJobResponse; +import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; +import org.onap.so.adapters.vnfmadapter.extclients.SdcPackageProvider; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.*; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.Tenant; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse2001; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; @@ -82,7 +72,18 @@ import org.springframework.web.client.RestTemplate; import org.threeten.bp.LocalDateTime; import org.threeten.bp.OffsetDateTime; import org.threeten.bp.ZoneOffset; - +import java.net.URI; +import java.util.Optional; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.*; @RunWith(SpringRunner.class) @SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) @@ -108,6 +109,9 @@ public class VnfmAdapterControllerTest { @MockBean AAIResourcesClient aaiResourcesClient; + @MockBean + SdcPackageProvider sdcPackageProvider; + @Autowired VnfmAdapterController controller; Gson gson = new Gson(); @@ -129,15 +133,19 @@ public class VnfmAdapterControllerTest { final String expectedsubscriptionRequest = "{\"filter\":{\"vnfInstanceSubscriptionFilter\":{\"vnfInstanceIds\":[\"vnfId\"]},\"notificationTypes\":[\"VnfLcmOperationOccurrenceNotification\"]},\"callbackUri\":\"https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/lcn/VnfLcmOperationOccurrenceNotification\",\"authentication\":{\"authType\":[\"BASIC\"],\"paramsBasic\":{\"userName\":\"vnfm\",\"password\":\"$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke\"}}}"; final InlineResponse2001 subscriptionResponse = new InlineResponse2001(); + + final InlineResponse201 createResponse = createCreateResponse(); + mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances")) + .andRespond(withSuccess(gson.toJson(createResponse), MediaType.APPLICATION_JSON)); + mockRestServer.expect(requestTo("http://vnfm2:8080/subscriptions")) .andExpect(content().json(expectedsubscriptionRequest)) .andRespond(withSuccess(gson.toJson(subscriptionResponse), MediaType.APPLICATION_JSON)); - mockRestServer.expect(requestTo("http://dummy.value/until/create/implememted/vnfId/instantiate")) + mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances/vnfId/instantiate")) .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON) .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/123456"))); - final InlineResponse200 firstOperationQueryResponse = createOperationQueryResponse( org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.INSTANTIATE, org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.PROCESSING); @@ -165,12 +173,20 @@ public class VnfmAdapterControllerTest { assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", uriArgument.getValue().build().toString()); assertEquals("myTestVnfId", genericVnfArgument.getValue().getVnfId()); - assertEquals(1, genericVnfArgument.getValue().getRelationshipList().getRelationship().size()); - final Relationship createdRelationship = + assertEquals(2, genericVnfArgument.getValue().getRelationshipList().getRelationship().size()); + final Relationship vnfmRelationship = genericVnfArgument.getValue().getRelationshipList().getRelationship().get(0); - assertEquals("esr-vnfm", createdRelationship.getRelatedTo()); - assertEquals("tosca.relationships.DependsOn", createdRelationship.getRelationshipLabel()); - assertEquals("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/vnfm2", createdRelationship.getRelatedLink()); + assertEquals("esr-vnfm", vnfmRelationship.getRelatedTo()); + assertEquals("tosca.relationships.DependsOn", vnfmRelationship.getRelationshipLabel()); + assertEquals("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/vnfm2", vnfmRelationship.getRelatedLink()); + + final Relationship tenantRelationship = + genericVnfArgument.getValue().getRelationshipList().getRelationship().get(1); + assertEquals("tenant", tenantRelationship.getRelatedTo()); + assertEquals( + "/aai/v15/cloud-infrastructure/cloud-regions/cloud-region/myTestCloudOwner/myTestRegion/tenants/tenant/myTestTenantId", + tenantRelationship.getRelatedLink()); + // check the job status @@ -225,9 +241,13 @@ public class VnfmAdapterControllerTest { setUpVnfmsInMockAai(); setUpVimInMockAai(); + final InlineResponse201 createResponse = createCreateResponse(); + mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances")) + .andRespond(withSuccess(gson.toJson(createResponse), MediaType.APPLICATION_JSON)); + mockRestServer.expect(requestTo("http://vnfm2:8080/subscriptions")).andRespond(withBadRequest()); - mockRestServer.expect(requestTo("http://dummy.value/until/create/implememted/vnfId/instantiate")) + mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances/vnfId/instantiate")) .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON) .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/123456"))); @@ -271,14 +291,12 @@ public class VnfmAdapterControllerTest { mockRestServer.expect(requestTo("http://vnfm:8080/vnf_lcm_op_occs/1234567")) .andRespond(withSuccess(gson.toJson(firstOperationQueryResponse), MediaType.APPLICATION_JSON)); - final InlineResponse200 secondOperationQueryReponse = createOperationQueryResponse( org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.TERMINATE, org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.COMPLETED); mockRestServer.expect(requestTo("http://vnfm:8080/vnf_lcm_op_occs/1234567")) .andRespond(withSuccess(gson.toJson(secondOperationQueryReponse), MediaType.APPLICATION_JSON)); - final RequestEntity<Void> request = RequestEntity .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId")) .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId") @@ -288,7 +306,6 @@ public class VnfmAdapterControllerTest { assertEquals(202, deleteVnfResponse.getStatusCode().value()); assertNotNull(deleteVnfResponse.getBody().getJobId()); - final EsrSystemInfo esrSystemInfo = new EsrSystemInfo(); esrSystemInfo.setServiceUrl("http://vnfm:8080"); esrSystemInfo.setType("vnfmType"); @@ -299,7 +316,6 @@ public class VnfmAdapterControllerTest { doReturn(Optional.of(esrSystemInfoList)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class), MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/..."))); - final ResponseEntity<QueryJobResponse> firstJobQueryResponse = controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213"); assertEquals(OperationEnum.TERMINATE, firstJobQueryResponse.getBody().getOperation()); @@ -356,7 +372,6 @@ public class VnfmAdapterControllerTest { mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate")) .andRespond(withStatus(HttpStatus.BAD_REQUEST).contentType(MediaType.APPLICATION_JSON)); - final RequestEntity<Void> request = RequestEntity .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId")) .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId") @@ -476,6 +491,19 @@ public class VnfmAdapterControllerTest { + CLOUD_OWNER + "/" + REGION + "/esr-system-info-list"))); } + private InlineResponse201 createCreateResponse() { + final InlineResponse201 createResponse = new InlineResponse201(); + createResponse.setVnfdId("myTestVnfd"); + final InlineResponse201Links links = new InlineResponse201Links(); + final InlineResponse201LinksSelf self = new InlineResponse201LinksSelf(); + self.setHref("http://vnfm2:8080/vnf_instances/vnfId"); + links.setSelf(self); + createResponse.setLinks(links); + createResponse.setId("vnfId"); + return createResponse; + } + + private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> { final String uriAsString; @@ -501,5 +529,4 @@ public class VnfmAdapterControllerTest { } - } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application-test.yaml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application-test.yaml index e69e90173d..3afc542a1b 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application-test.yaml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application-test.yaml @@ -14,20 +14,27 @@ spring: security: usercredentials: - - username: test - password: '$2a$12$Zi3AuYcZoZO/gBQyUtST2.F5N6HqcTtaNci2Et.ufsQhski56srIu' - role: BPEL-Client - - username: vnfm - password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' - role: BPEL-Client - + - username: test + password: '$2a$12$Zi3AuYcZoZO/gBQyUtST2.F5N6HqcTtaNci2Et.ufsQhski56srIu' + role: BPEL-Client + - username: vnfm + password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' + role: BPEL-Client + mso: key: 07a7159d3bf51a0e53be7a8f89699be7 - + aai: auth: 2A11B07DB6214A839394AA1EC5844695F5114FC407FF5422625FB00175A3DCB8A1FF745F22867EFA72D5369D599BBD88DA8BED4233CF5586 endpoint: https://aai.onap:8443 version: v15 - + +sdc: + username: sdcUser + password: sdcPassword + key: adadadadad + endpoint: http://sdc.onap/1234A + + vnfmadapter: - endpoint: https://so-vnfm-adapter.onap:30406
\ No newline at end of file + endpoint: https://so-vnfm-adapter.onap:30406 |