aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test')
-rw-r--r--adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java54
-rw-r--r--adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java252
-rw-r--r--adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java413
-rwxr-xr-xadapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/TestApplication.java38
-rw-r--r--adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java562
-rw-r--r--adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/resources/application.yaml61
6 files changed, 1380 insertions, 0 deletions
diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java
new file mode 100644
index 0000000000..01749fa749
--- /dev/null
+++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java
@@ -0,0 +1,54 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import java.net.URI;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.http.RequestEntity;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = TestApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+public class HealthCheckTest {
+
+ @LocalServerPort
+ private int port;
+
+ private final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
+
+ @Test
+ public void testHealthcheck() throws Exception {
+ final RequestEntity<Void> request =
+ RequestEntity.get(new URI("http://localhost:" + port + "/manage/health")).build();
+ final ResponseEntity<Void> response = restTemplate.exchange(request, Void.class);
+ assertEquals(200, response.getStatusCode().value());
+ }
+
+}
diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java
new file mode 100644
index 0000000000..5a2c5d0fc8
--- /dev/null
+++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java
@@ -0,0 +1,252 @@
+/*-
+ * ============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 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.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+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.GenericVnfs;
+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.grant.model.GrantRequest;
+import org.onap.so.adapters.vnfmadapter.grant.model.GrantRequest.OperationEnum;
+import org.onap.so.adapters.vnfmadapter.grant.model.GrantsAddResources;
+import org.onap.so.adapters.vnfmadapter.grant.model.GrantsAddResources.TypeEnum;
+import org.onap.so.adapters.vnfmadapter.grant.model.GrantsLinks;
+import org.onap.so.adapters.vnfmadapter.grant.model.GrantsLinksVnfLcmOpOcc;
+import org.onap.so.adapters.vnfmadapter.grant.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.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.web.client.RestTemplate;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = TestApplication.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;
+
+ @MockBean
+ private AAIResourcesClient aaiResourcesClient;
+
+ @Autowired
+ private Sol003GrantController controller;
+
+ @Before
+ public void setUp() throws Exception {
+ setUpVimInMockAai();
+ }
+
+ @Test
+ public void grantRequest_ValidRequestInstantiate_GrantApproved() {
+ final 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());
+ assertNull(response.getBody().getRemoveResources());
+
+ assertEquals(vimConnectionId, response.getBody().getAddResources().get(0).getVimConnectionId());
+ assertEquals("myTestVnfIdOnVnfm", response.getBody().getVnfInstanceId());
+ assertEquals("123456", response.getBody().getVnfLcmOpOccId());
+
+ final 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() {
+ final GrantRequest grantRequest = createGrantRequest("TERMINATE");
+ setUpGenericVnfWithVnfmRelationshipInMockAai("vnfmType", "vnfm1");
+ final ResponseEntity<InlineResponse201> response = controller.grantsPost(grantRequest);
+
+ assertEquals(HttpStatus.CREATED, response.getStatusCode());
+ assertNull(response.getBody().getAddResources());
+ assertEquals(1, response.getBody().getRemoveResources().size());
+ assertEquals(vimConnectionId, response.getBody().getRemoveResources().get(0).getVimConnectionId());
+ assertEquals("myTestVnfIdOnVnfm", response.getBody().getVnfInstanceId());
+ assertEquals("123456", response.getBody().getVnfLcmOpOccId());
+
+ final 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(final String operation) {
+ final GrantRequest grantRequest = new GrantRequest();
+ grantRequest.setVnfInstanceId("myTestVnfIdOnVnfm");
+ grantRequest.setVnfLcmOpOccId("123456");
+ grantRequest.links(new GrantsLinks()
+ .vnfInstance(new GrantsLinksVnfLcmOpOcc().href("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")));
+ if (operation == "INSTANTIATE") {
+ grantRequest.setOperation(OperationEnum.INSTANTIATE);
+ final GrantsAddResources resource = new GrantsAddResources();
+ resource.setId("123");
+ resource.setType(TypeEnum.COMPUTE);
+ grantRequest.addAddResourcesItem(resource);
+ } else if (operation == "TERMINATE") {
+ grantRequest.setOperation(OperationEnum.TERMINATE);
+ final 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")));
+
+ final List<GenericVnf> listOfGenericVnfs = new ArrayList<>();
+ listOfGenericVnfs.add(genericVnf);
+ final GenericVnfs genericVnfs = new GenericVnfs();
+ genericVnfs.getGenericVnf().addAll(listOfGenericVnfs);
+ doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher(
+ "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm")));
+ }
+
+ 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/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java
new file mode 100644
index 0000000000..f44bf8778f
--- /dev/null
+++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java
@@ -0,0 +1,413 @@
+/*-
+ * ============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 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 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 javax.inject.Inject;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.hamcrest.MockitoHamcrest;
+import org.onap.aai.domain.yang.EsrSystemInfoList;
+import org.onap.aai.domain.yang.EsrVnfm;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.GenericVnfs;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipData;
+import org.onap.aai.domain.yang.RelationshipList;
+import org.onap.aai.domain.yang.Vserver;
+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.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201Links;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201LinksSelf;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo;
+import org.onap.so.adapters.vnfmadapter.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs;
+import org.onap.so.adapters.vnfmadapter.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs.ChangeTypeEnum;
+import org.onap.so.adapters.vnfmadapter.lcn.model.LcnVnfLcmOperationOccurrenceNotificationComputeResource;
+import org.onap.so.adapters.vnfmadapter.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinks;
+import org.onap.so.adapters.vnfmadapter.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance;
+import org.onap.so.adapters.vnfmadapter.lcn.model.VnfIdentifierCreationNotification;
+import org.onap.so.adapters.vnfmadapter.lcn.model.VnfLcmOperationOccurrenceNotification;
+import org.onap.so.adapters.vnfmadapter.lcn.model.VnfLcmOperationOccurrenceNotification.OperationEnum;
+import org.onap.so.adapters.vnfmadapter.lcn.model.VnfLcmOperationOccurrenceNotification.OperationStateEnum;
+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.MediaType;
+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 com.google.gson.Gson;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = TestApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+public class Sol003LcnControllerTest {
+
+ private static final String CLOUD_OWNER = "myTestCloudOwner";
+ private static final String REGION = "myTestRegion";
+ private static final String TENANT_ID = "myTestTenantId";
+
+ @LocalServerPort
+ private int port;
+ @Autowired
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE)
+ private RestTemplate testRestTemplate;
+ private MockRestServiceServer mockRestServer;
+
+ @MockBean
+ private AAIResourcesClient aaiResourcesClient;
+
+ @Autowired
+ private Sol003LcnContoller controller;
+ private final Gson gson = new Gson();
+
+ @Inject
+ private AaiHelper aaiHelper;
+
+ @Before
+ public void setUp() throws Exception {
+ mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
+ }
+
+ @Test
+ public void lcnNotification_IdentifierCreated_Returns204() throws URISyntaxException, InterruptedException {
+ final VnfIdentifierCreationNotification vnfIdentifierCreationNotification =
+ new VnfIdentifierCreationNotification();
+ final ResponseEntity<Void> response =
+ controller.lcnVnfIdentifierCreationNotificationPost(vnfIdentifierCreationNotification);
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+ }
+
+ @Test
+ public void lcnNotification_IdentifierDeleted_Returns204() throws URISyntaxException, InterruptedException {
+ final VnfIdentifierCreationNotification vnfIdentifierCreationNotification =
+ new VnfIdentifierCreationNotification();
+ final ResponseEntity<Void> response =
+ controller.lcnVnfIdentifierCreationNotificationPost(vnfIdentifierCreationNotification);
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+ }
+
+ @Test
+ public void lcnNotification_InstantiateStartingOrProcessing_NoAction()
+ throws URISyntaxException, InterruptedException {
+ final VnfLcmOperationOccurrenceNotification startingNotification = new VnfLcmOperationOccurrenceNotification();
+ startingNotification.setOperation(OperationEnum.INSTANTIATE);
+ startingNotification.setOperationState(OperationStateEnum.STARTING);
+
+ ResponseEntity<Void> response = controller.lcnVnfLcmOperationOccurrenceNotificationPost(startingNotification);
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+
+ verifyZeroInteractions(aaiResourcesClient);
+
+ final VnfLcmOperationOccurrenceNotification processingNotification =
+ new VnfLcmOperationOccurrenceNotification();
+ processingNotification.setOperation(OperationEnum.INSTANTIATE);
+ processingNotification.setOperationState(OperationStateEnum.STARTING);
+
+ response = controller.lcnVnfLcmOperationOccurrenceNotificationPost(processingNotification);
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+
+ verifyZeroInteractions(aaiResourcesClient);
+ }
+
+ @Test
+ public void lcnNotification_InstantiateCompleted_AaiUpdated() throws URISyntaxException, InterruptedException {
+ final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification =
+ createNotification(OperationEnum.INSTANTIATE);
+ addVnfcsToNotification(vnfLcmOperationOccurrenceNotification, ChangeTypeEnum.ADDED);
+ final InlineResponse201 vnfInstance = createVnfInstance();
+
+ mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
+ .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON));
+
+ final GenericVnf genericVnf = createGenericVnf("vnfmType1");
+ addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
+ final List<GenericVnf> listOfGenericVnfs = new ArrayList<>();
+ listOfGenericVnfs.add(genericVnf);
+ final GenericVnfs genericVnfs = new GenericVnfs();
+ genericVnfs.getGenericVnf().addAll(listOfGenericVnfs);
+ doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher(
+ "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm")));
+ EsrVnfm vnfm = new EsrVnfm();
+ vnfm.setVnfmId("vnfm1");
+ final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
+ vnfm.setEsrSystemInfoList(esrSystemInfoList);
+ doReturn(Optional.of(vnfm)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest
+ .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1")));
+
+ final ResponseEntity<Void> response =
+ controller.lcnVnfLcmOperationOccurrenceNotificationPost(vnfLcmOperationOccurrenceNotification);
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+
+ final ArgumentCaptor<Object> bodyArgument1 = ArgumentCaptor.forClass(Object.class);
+ final ArgumentCaptor<AAIResourceUri> uriArgument1 = ArgumentCaptor.forClass(AAIResourceUri.class);
+
+ verify(aaiResourcesClient, timeout(1000)).update(uriArgument1.capture(), bodyArgument1.capture());
+
+ assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId",
+ uriArgument1.getAllValues().get(0).build().toString());
+ final GenericVnf updatedGenericVnf = (GenericVnf) bodyArgument1.getAllValues().get(0);
+ assertEquals("10.10.10.10", updatedGenericVnf.getIpv4OamAddress());
+ assertEquals("Created", updatedGenericVnf.getOrchestrationStatus());
+
+ final ArgumentCaptor<Object> bodyArgument2 = ArgumentCaptor.forClass(Object.class);
+ final ArgumentCaptor<AAIResourceUri> uriArgument2 = ArgumentCaptor.forClass(AAIResourceUri.class);
+ verify(aaiResourcesClient, timeout(1000)).create(uriArgument2.capture(), bodyArgument2.capture());
+
+ assertEquals(
+ "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/"
+ + TENANT_ID + "/vservers/vserver/myVnfc1",
+ uriArgument2.getAllValues().get(0).build().toString());
+
+ final Vserver vserver = (Vserver) bodyArgument2.getAllValues().get(0);
+ assertEquals("myVnfc1", vserver.getVserverId());
+
+ final ArgumentCaptor<AAIResourceUri> uriArgument1Connect = ArgumentCaptor.forClass(AAIResourceUri.class);
+ final ArgumentCaptor<AAIResourceUri> uriArgument2Connect = ArgumentCaptor.forClass(AAIResourceUri.class);
+ verify(aaiResourcesClient, timeout(1000)).connect(uriArgument1Connect.capture(), uriArgument2Connect.capture());
+ assertEquals(
+ "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/"
+ + TENANT_ID + "/vservers/vserver/myVnfc1",
+ uriArgument1Connect.getAllValues().get(0).build().toString());
+ assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId",
+ uriArgument2Connect.getAllValues().get(0).build().toString());
+ }
+
+ @Test
+ public void lcnNotification_TerminateCompleted_AaiUpdated() throws URISyntaxException, InterruptedException {
+ final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification =
+ createNotification(OperationEnum.TERMINATE);
+ addVnfcsToNotification(vnfLcmOperationOccurrenceNotification, ChangeTypeEnum.REMOVED);
+
+ final InlineResponse201 vnfInstance = createVnfInstance();
+
+ mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
+ .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON));
+
+ mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
+ .andRespond(withStatus(HttpStatus.NO_CONTENT).contentType(MediaType.APPLICATION_JSON));
+
+ final GenericVnf genericVnf = createGenericVnf("vnfmType1");
+ addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
+ genericVnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
+ final List<GenericVnf> listOfGenericVnfs = new ArrayList<>();
+ listOfGenericVnfs.add(genericVnf);
+ final GenericVnfs genericVnfs = new GenericVnfs();
+ genericVnfs.getGenericVnf().addAll(listOfGenericVnfs);
+ addRelationshipFromGenericVnfToVserver(genericVnf, "myVnfc1");
+
+ doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher(
+ "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm")));
+ EsrVnfm vnfm = new EsrVnfm();
+ vnfm.setVnfmId("vnfm1");
+ final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
+ vnfm.setEsrSystemInfoList(esrSystemInfoList);
+ doReturn(Optional.of(vnfm)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest
+ .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1")));
+
+ final ResponseEntity<Void> response =
+ controller.lcnVnfLcmOperationOccurrenceNotificationPost(vnfLcmOperationOccurrenceNotification);
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+
+ final ArgumentCaptor<GenericVnf> genericVnfArgument = ArgumentCaptor.forClass(GenericVnf.class);
+ final ArgumentCaptor<AAIResourceUri> updateUriArgument = ArgumentCaptor.forClass(AAIResourceUri.class);
+ verify(aaiResourcesClient, timeout(10000000)).update(updateUriArgument.capture(), genericVnfArgument.capture());
+ assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", updateUriArgument.getValue().build().toString());
+ assertEquals("Assigned", genericVnfArgument.getValue().getOrchestrationStatus());
+
+ final ArgumentCaptor<AAIResourceUri> deleteUriArgument = ArgumentCaptor.forClass(AAIResourceUri.class);
+
+ verify(aaiResourcesClient, timeout(10000000)).delete(deleteUriArgument.capture());
+
+ assertEquals(
+ "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/"
+ + TENANT_ID + "/vservers/vserver/myVnfc1",
+ deleteUriArgument.getAllValues().get(0).build().toString());
+ }
+
+ private VnfLcmOperationOccurrenceNotification createNotification(final OperationEnum operation) {
+ final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification();
+ notification.setOperation(operation);
+ notification.setOperationState(OperationStateEnum.COMPLETED);
+
+ final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance linkToVnfInstance =
+ new LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance()
+ .href("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
+ final LcnVnfLcmOperationOccurrenceNotificationLinks operationLinks =
+ new LcnVnfLcmOperationOccurrenceNotificationLinks().vnfInstance(linkToVnfInstance);
+ notification.setLinks(operationLinks);
+
+ return notification;
+ }
+
+ private void addVnfcsToNotification(final VnfLcmOperationOccurrenceNotification notification,
+ final ChangeTypeEnum changeType) {
+ final List<LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs> affectedVnfcs = new ArrayList<>();;
+ final LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs vnfc =
+ new LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs();
+ vnfc.changeType(changeType);
+ final LcnVnfLcmOperationOccurrenceNotificationComputeResource computeResource =
+ new LcnVnfLcmOperationOccurrenceNotificationComputeResource();
+ computeResource.setResourceId("myVnfc1");
+ computeResource.setVimConnectionId(CLOUD_OWNER + "_" + REGION);
+ vnfc.setComputeResource(computeResource);
+ affectedVnfcs.add(vnfc);
+ notification.setAffectedVnfcs(affectedVnfcs);
+ }
+
+ 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();
+ VnfInstancelinks.setSelf(selfLink);
+ vnfInstance.setLinks(VnfInstancelinks);
+
+ final Map<String, String> vnfConfigurableProperties = new HashMap<>();
+ vnfConfigurableProperties.put("vnfIpAddress", "10.10.10.10");
+ vnfInstance.setVnfConfigurableProperties(vnfConfigurableProperties);
+
+ final List<InlineResponse201VimConnectionInfo> vimConnectionInfo = new ArrayList<>();;
+ final InlineResponse201VimConnectionInfo vimConnection = new InlineResponse201VimConnectionInfo();
+ vimConnection.setVimId(CLOUD_OWNER + "_" + REGION);
+ vimConnection.setId(CLOUD_OWNER + "_" + REGION);
+ final AccessInfo accessInfo = new AccessInfo();
+ accessInfo.setProjectId(TENANT_ID);
+ vimConnection.setAccessInfo(accessInfo);
+ vimConnectionInfo.add(vimConnection);
+ vnfInstance.setVimConnectionInfo(vimConnectionInfo);
+
+ final OamIpAddressSource oamIpAddressSource =
+ new OamIpAddressSource(OamIpAddressType.CONFIGURABLE_PROPERTY, "vnfIpAddress");
+ aaiHelper.setOamIpAddressSource("myTestVnfIdOnVnfm", oamIpAddressSource);
+ return vnfInstance;
+ }
+
+ private GenericVnf createGenericVnf(final String type) {
+ final GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("myTestVnfId");
+ genericVnf.setNfType(type);
+ return genericVnf;
+ }
+
+ private void addRelationshipFromGenericVnfToVnfm(final GenericVnf genericVnf, final String vnfmId) {
+ final Relationship relationshipToVnfm = new Relationship();
+ relationshipToVnfm.setRelatedLink("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/" + vnfmId);
+ relationshipToVnfm.setRelatedTo("esr-vnfm");
+ final RelationshipData relationshipData = new RelationshipData();
+ relationshipData.setRelationshipKey("esr-vnfm.vnfm-id");
+ relationshipData.setRelationshipValue(vnfmId);
+ relationshipToVnfm.getRelationshipData().add(relationshipData);
+
+ if (genericVnf.getRelationshipList() == null) {
+ final RelationshipList relationshipList = new RelationshipList();
+ genericVnf.setRelationshipList(relationshipList);
+ }
+ genericVnf.getRelationshipList().getRelationship().add(relationshipToVnfm);
+ }
+
+ private void addRelationshipFromGenericVnfToVserver(final GenericVnf genericVnf, final String vserverId) {
+ final Relationship relationshipToVserver = new Relationship();
+ relationshipToVserver.setRelatedTo("vserver");
+ final RelationshipData relationshipData1 = new RelationshipData();
+ relationshipData1.setRelationshipKey("vserver.vserver-id");
+ relationshipData1.setRelationshipValue(vserverId);
+ relationshipToVserver.getRelationshipData().add(relationshipData1);
+ final RelationshipData relationshipData2 = new RelationshipData();
+ relationshipData2.setRelationshipKey("cloud-region.cloud-owner");
+ relationshipData2.setRelationshipValue(CLOUD_OWNER);
+ relationshipToVserver.getRelationshipData().add(relationshipData2);
+ final RelationshipData relationshipData3 = new RelationshipData();
+ relationshipData3.setRelationshipKey("cloud-region.cloud-region-id");
+ relationshipData3.setRelationshipValue(REGION);
+ relationshipToVserver.getRelationshipData().add(relationshipData3);
+ final RelationshipData relationshipData4 = new RelationshipData();
+ relationshipData4.setRelationshipKey("tenant.tenant-id");
+ relationshipData4.setRelationshipValue(TENANT_ID);
+ relationshipToVserver.getRelationshipData().add(relationshipData4);
+
+ if (genericVnf.getRelationshipList() == null) {
+ final RelationshipList relationshipList = new RelationshipList();
+ genericVnf.setRelationshipList(relationshipList);
+ }
+ genericVnf.getRelationshipList().getRelationship().add(relationshipToVserver);
+ }
+
+ 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/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/TestApplication.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/TestApplication.java
new file mode 100755
index 0000000000..152d3136f1
--- /dev/null
+++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/TestApplication.java
@@ -0,0 +1,38 @@
+/*-
+ * ============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 org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
+import org.springframework.cache.annotation.EnableCaching;
+
+@EnableCaching
+@SpringBootApplication(scanBasePackages = {"org.onap.so"})
+@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class})
+public class TestApplication {
+
+ public static void main(final String[] args) {
+ new SpringApplication(TestApplication.class).run(args);
+ }
+
+}
diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java
new file mode 100644
index 0000000000..9fbea38f65
--- /dev/null
+++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java
@@ -0,0 +1,562 @@
+/*-
+ * ============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 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.timeout;
+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;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+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.EsrVnfm;
+import org.onap.aai.domain.yang.EsrVnfmList;
+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.extclients.SdcPackageProvider;
+import org.onap.so.adapters.vnfmadapter.lcn.JSON;
+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.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201Links;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201LinksSelf;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.AAIVersion;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
+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.vnfmadapter.v1.model.Tenant;
+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.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.RequestEntity;
+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 org.threeten.bp.LocalDateTime;
+import org.threeten.bp.OffsetDateTime;
+import org.threeten.bp.ZoneOffset;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = TestApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+
+public class VnfmAdapterControllerTest {
+
+ private static final OffsetDateTime JAN_1_2019_12_00 =
+ OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 12, 0), ZoneOffset.UTC);
+ private static final OffsetDateTime JAN_1_2019_1_00 =
+ OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 1, 0), ZoneOffset.UTC);
+ private static final String CLOUD_OWNER = "myTestCloudOwner";
+ private static final String REGION = "myTestRegion";
+ private static final String TENANT_ID = "myTestTenantId";
+
+ @LocalServerPort
+ private int port;
+ @Autowired
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE)
+ private RestTemplate testRestTemplate;
+ private MockRestServiceServer mockRestServer;
+
+ @MockBean
+ AAIResourcesClient aaiResourcesClient;
+
+ @MockBean
+ SdcPackageProvider sdcPackageProvider;
+
+ @Autowired
+ VnfmAdapterController controller;
+ Gson gson = new JSON().getGson();
+
+ @Before
+ public void setUp() throws Exception {
+ mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
+ }
+
+ @Test
+ public void createVnf_ValidRequest_Returns202AndJobId() throws Exception {
+ final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
+ setUpGenericVnfInMockAai("vnfmType2");
+ setUpVnfmsInMockAai();
+ setUpVimInMockAai();
+
+ final String expectedsubscriptionRequest =
+ "{\"filter\":{\"vnfInstanceSubscriptionFilter\":{\"vnfInstanceIds\":[\"vnfId\"]},\"notificationTypes\":[\"VnfLcmOperationOccurrenceNotification\"]},\"callbackUri\":\"https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/lcn/VnfLcmOperationOccurrenceNotification\",\"authentication\":{\"authType\":[\"OAUTH2_CLIENT_CREDENTIALS\", \"BASIC\", \"TLS_CERT\"],\"paramsOauth2ClientCredentials\":{\"clientId\":\"vnfm\",\"clientPassword\":\"password1$\",\"tokenEndpoint\":\"https://so-vnfm-adapter.onap:30406/oauth/token\"},\"paramsBasic\":{\"userName\":\"vnfm\",\"password\":\"password1$\"}}}";
+ 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://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);
+ mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_lcm_op_occs/123456"))
+ .andRespond(withSuccess(gson.toJson(firstOperationQueryResponse), MediaType.APPLICATION_JSON));
+
+ final InlineResponse200 secondOperationQueryReponse = createOperationQueryResponse(
+ org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.INSTANTIATE,
+ org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.COMPLETED);
+ mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_lcm_op_occs/123456"))
+ .andRespond(withSuccess(gson.toJson(secondOperationQueryReponse), MediaType.APPLICATION_JSON));
+
+ // Invoke the create request
+
+ final ResponseEntity<CreateVnfResponse> createVnfResponse =
+ controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
+ assertEquals(HttpStatus.ACCEPTED, createVnfResponse.getStatusCode());
+ assertNotNull(createVnfResponse.getBody().getJobId());
+
+ final ArgumentCaptor<GenericVnf> genericVnfArgument = ArgumentCaptor.forClass(GenericVnf.class);
+ final ArgumentCaptor<AAIResourceUri> uriArgument = ArgumentCaptor.forClass(AAIResourceUri.class);
+
+ verify(aaiResourcesClient).update(uriArgument.capture(), genericVnfArgument.capture());
+
+ assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", uriArgument.getValue().build().toString());
+
+ assertEquals("myTestVnfId", genericVnfArgument.getValue().getVnfId());
+
+ final ArgumentCaptor<AAIResourceUri> uriArgument1Connect = ArgumentCaptor.forClass(AAIResourceUri.class);
+ final ArgumentCaptor<AAIResourceUri> uriArgument2Connect = ArgumentCaptor.forClass(AAIResourceUri.class);
+ verify(aaiResourcesClient, timeout(1000)).connect(uriArgument1Connect.capture(), uriArgument2Connect.capture());
+ assertEquals("/external-system/esr-vnfm-list/esr-vnfm/vnfm2",
+ uriArgument1Connect.getAllValues().get(0).build().toString());
+ assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId",
+ uriArgument2Connect.getAllValues().get(0).build().toString());
+
+ // check the job status
+
+ final ResponseEntity<QueryJobResponse> firstJobQueryResponse =
+ controller.jobQuery(createVnfResponse.getBody().getJobId(), "", "so", "1213");
+ assertEquals(OperationEnum.INSTANTIATE, firstJobQueryResponse.getBody().getOperation());
+ assertEquals(OperationStateEnum.PROCESSING, firstJobQueryResponse.getBody().getOperationState());
+ assertEquals(JAN_1_2019_12_00, firstJobQueryResponse.getBody().getStartTime());
+ assertEquals(JAN_1_2019_1_00, firstJobQueryResponse.getBody().getStateEnteredTime());
+
+ final ResponseEntity<QueryJobResponse> secondJobQueryResponse =
+ controller.jobQuery(createVnfResponse.getBody().getJobId(), "", "so", "1213");
+ assertEquals(OperationEnum.INSTANTIATE, secondJobQueryResponse.getBody().getOperation());
+ assertEquals(OperationStateEnum.COMPLETED, secondJobQueryResponse.getBody().getOperationState());
+ assertEquals(JAN_1_2019_12_00, secondJobQueryResponse.getBody().getStartTime());
+ assertEquals(JAN_1_2019_1_00, secondJobQueryResponse.getBody().getStateEnteredTime());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void createVnf_VnfAlreadyExistsOnVnfm_ThrowsIllegalArgumentException() throws Exception {
+ final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
+ final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1");
+ addSelfLinkToGenericVnf(genericVnf);
+ addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
+ setUpVnfmsInMockAai();
+
+ final InlineResponse201 reponse = new InlineResponse201();
+ mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
+ .andRespond(withSuccess(gson.toJson(reponse), MediaType.APPLICATION_JSON));
+
+ controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
+ }
+
+ @Test(expected = VnfmNotFoundException.class)
+ public void createVnf_NoMatchingVnfmFound_ThrowsException() throws Exception {
+ final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
+ setUpGenericVnfInMockAai("anotherType");
+ setUpVnfmsInMockAai();
+
+ controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
+ }
+
+ @Test
+ public void createVnf_VnfmAlreadyAssociatedWithVnf_Returns202AndJobId() throws Exception {
+ final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
+ final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType2");
+ addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm2");
+ 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://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 ResponseEntity<CreateVnfResponse> response =
+ controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
+ assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
+ assertNotNull(response.getBody().getJobId());
+ }
+
+ @Test
+ @Ignore
+ public void createVnf_UnauthorizedUser_Returns401() throws Exception {
+ final TestRestTemplate restTemplateWrongPassword = new TestRestTemplate("test", "wrongPassword");
+ final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
+ final RequestEntity<CreateVnfRequest> request =
+ RequestEntity.post(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId"))
+ .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
+ .header("X-ONAP-RequestId", "myRequestId").header("X-ONAP-InvocationID", "myInvocationId")
+ .body(createVnfRequest);
+ final ResponseEntity<CreateVnfResponse> response =
+ restTemplateWrongPassword.exchange(request, CreateVnfResponse.class);
+ assertEquals(401, response.getStatusCode().value());
+ }
+
+ @Test
+ public void deleteVnf_ValidRequest_Returns202AndJobId() throws Exception {
+ final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
+
+ final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1");
+ addSelfLinkToGenericVnf(genericVnf);
+ addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
+ setUpVnfmsInMockAai();
+
+ mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate"))
+ .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON)
+ .location(new URI("http://vnfm1:8080/vnf_lcm_op_occs/1234567")));
+
+ final InlineResponse200 firstOperationQueryResponse = createOperationQueryResponse(
+ org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.TERMINATE,
+ org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.PROCESSING);
+ mockRestServer.expect(requestTo("http://vnfm1: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://vnfm1: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")
+ .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
+ final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
+ restTemplate.exchange(request, DeleteVnfResponse.class);
+ assertEquals(202, deleteVnfResponse.getStatusCode().value());
+ assertNotNull(deleteVnfResponse.getBody().getJobId());
+
+ final ResponseEntity<QueryJobResponse> firstJobQueryResponse =
+ controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213");
+ assertEquals(OperationEnum.TERMINATE, firstJobQueryResponse.getBody().getOperation());
+ assertEquals(OperationStateEnum.PROCESSING, firstJobQueryResponse.getBody().getOperationState());
+ assertEquals(JAN_1_2019_12_00, firstJobQueryResponse.getBody().getStartTime());
+ assertEquals(JAN_1_2019_1_00, firstJobQueryResponse.getBody().getStateEnteredTime());
+
+ final ResponseEntity<QueryJobResponse> secondJobQueryResponse =
+ controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213");
+ assertEquals(OperationEnum.TERMINATE, secondJobQueryResponse.getBody().getOperation());
+ assertEquals(OperationStateEnum.PROCESSING, secondJobQueryResponse.getBody().getOperationState());
+ assertEquals(JAN_1_2019_12_00, secondJobQueryResponse.getBody().getStartTime());
+ assertEquals(JAN_1_2019_1_00, secondJobQueryResponse.getBody().getStateEnteredTime());
+ }
+
+ @Test
+ public void deleteVnf_VnfAlreadyTerminated_Returns202AndJobId() throws Exception {
+ final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
+
+ final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1");
+ addSelfLinkToGenericVnf(genericVnf);
+ addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
+ setUpVnfmsInMockAai();
+
+ mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate"))
+ .andRespond(withStatus(HttpStatus.CONFLICT).contentType(MediaType.APPLICATION_JSON));
+
+ final InlineResponse201 reponse = new InlineResponse201();
+ reponse.setInstantiationState(InstantiationStateEnum.NOT_INSTANTIATED);
+ mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
+ .andRespond(withSuccess(gson.toJson(reponse), MediaType.APPLICATION_JSON));
+
+ mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"))
+ .andRespond(withStatus(HttpStatus.NO_CONTENT).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")
+ .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
+ final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
+ restTemplate.exchange(request, DeleteVnfResponse.class);
+ assertEquals(202, deleteVnfResponse.getStatusCode().value());
+ assertNotNull(deleteVnfResponse.getBody().getJobId());
+
+ final ResponseEntity<QueryJobResponse> jobQueryResponse =
+ controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213");
+ assertEquals(OperationStateEnum.COMPLETED, jobQueryResponse.getBody().getOperationState());
+ }
+
+ @Test
+ public void deleteVnf_GenericVnfNotFound_Returns404() throws Exception {
+ final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
+
+ final RequestEntity<Void> request = RequestEntity
+ .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myNonExistingVnfId"))
+ .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
+ .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
+ final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
+ restTemplate.exchange(request, DeleteVnfResponse.class);
+ assertEquals(404, deleteVnfResponse.getStatusCode().value());
+ assertNull(deleteVnfResponse.getBody().getJobId());
+ }
+
+ @Test
+ public void deleteVnf_NoAssignedVnfm_Returns400() throws Exception {
+ final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
+
+ setUpGenericVnfInMockAai("vnfmType");
+
+ 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")
+ .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
+ final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
+ restTemplate.exchange(request, DeleteVnfResponse.class);
+ assertEquals(400, deleteVnfResponse.getStatusCode().value());
+ assertNull(deleteVnfResponse.getBody().getJobId());
+ }
+
+ @Test
+ public void deleteVnf_ErrorStatusCodeFromVnfm_Returns500() throws Exception {
+ final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
+
+ final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1");
+ addSelfLinkToGenericVnf(genericVnf);
+ addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1");
+ setUpVnfmsInMockAai();
+
+ 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")
+ .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build();
+ final ResponseEntity<DeleteVnfResponse> deleteVnfResponse =
+ restTemplate.exchange(request, DeleteVnfResponse.class);
+ assertEquals(500, deleteVnfResponse.getStatusCode().value());
+ assertNull(deleteVnfResponse.getBody().getJobId());
+
+ }
+
+ private InlineResponse200 createOperationQueryResponse(
+ final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum operation,
+ final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum operationState) {
+ final InlineResponse200 response = new InlineResponse200();
+ response.setId("9876");
+ response.setOperation(operation);
+ response.setOperationState(operationState);
+ response.setStartTime(JAN_1_2019_12_00);
+ response.setStateEnteredTime(JAN_1_2019_1_00);
+ response.setVnfInstanceId("myVnfInstanceId");
+ return response;
+ }
+
+ private GenericVnf createGenericVnf(final String type) {
+ final GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("myTestVnfId");
+ genericVnf.setNfType(type);
+ return genericVnf;
+ }
+
+ private GenericVnf setUpGenericVnfInMockAai(final String type) {
+ final GenericVnf genericVnf = createGenericVnf(type);
+
+ doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId")));
+ return genericVnf;
+ }
+
+ private void addSelfLinkToGenericVnf(final GenericVnf vnf) {
+ vnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
+ }
+
+ private void addRelationshipFromGenericVnfToVnfm(final GenericVnf genericVnf, final String vnfmId) {
+ final Relationship relationshipToVnfm = new Relationship();
+ relationshipToVnfm
+ .setRelatedLink("/aai/" + AAIVersion.LATEST + "/external-system/esr-vnfm-list/esr-vnfm/" + vnfmId);
+ relationshipToVnfm.setRelatedTo("esr-vnfm");
+ final RelationshipData relationshipData = new RelationshipData();
+ relationshipData.setRelationshipKey("esr-vnfm.vnfm-id");
+ relationshipData.setRelationshipValue(vnfmId);
+ relationshipToVnfm.getRelationshipData().add(relationshipData);
+
+ final RelationshipList relationshipList = new RelationshipList();
+ relationshipList.getRelationship().add(relationshipToVnfm);
+ genericVnf.setRelationshipList(relationshipList);
+ }
+
+ private void setUpVnfmsInMockAai() {
+ final EsrSystemInfo esrSystemInfo1 = new EsrSystemInfo();
+ esrSystemInfo1.setServiceUrl("http://vnfm1:8080");
+ esrSystemInfo1.setType("vnfmType1");
+ esrSystemInfo1.setSystemType("VNFM");
+ final EsrSystemInfoList esrSystemInfoList1 = new EsrSystemInfoList();
+ esrSystemInfoList1.getEsrSystemInfo().add(esrSystemInfo1);
+
+ final EsrVnfm esrVnfm1 = new EsrVnfm();
+ esrVnfm1.setVnfmId("vnfm1");
+ esrVnfm1.setEsrSystemInfoList(esrSystemInfoList1);
+ esrVnfm1.setResourceVersion("1234");
+
+ final EsrSystemInfo esrSystemInfo2 = new EsrSystemInfo();
+ esrSystemInfo2.setServiceUrl("http://vnfm2:8080");
+ esrSystemInfo2.setType("vnfmType2");
+ esrSystemInfo2.setSystemType("VNFM");
+ final EsrSystemInfoList esrSystemInfoList2 = new EsrSystemInfoList();
+ esrSystemInfoList2.getEsrSystemInfo().add(esrSystemInfo2);
+
+ final EsrVnfm esrVnfm2 = new EsrVnfm();
+ esrVnfm2.setVnfmId("vnfm2");
+ esrVnfm2.setEsrSystemInfoList(esrSystemInfoList2);
+ esrVnfm2.setResourceVersion("1234");
+
+ final EsrVnfmList esrVnfmList = new EsrVnfmList();
+ esrVnfmList.getEsrVnfm().add(esrVnfm1);
+ esrVnfmList.getEsrVnfm().add(esrVnfm2);
+
+ doReturn(Optional.of(esrVnfm1)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest
+ .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1")));
+
+ doReturn(Optional.of(esrVnfm2)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest
+ .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm2?depth=1")));
+
+ doReturn(Optional.of(esrVnfmList)).when(aaiResourcesClient).get(eq(EsrVnfmList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list")));
+
+ doReturn(Optional.of(esrSystemInfoList1)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher(
+ "/external-system/esr-vnfm-list/esr-vnfm/vnfm1/esr-system-info-list")));
+ doReturn(Optional.of(esrSystemInfoList2)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher(
+ "/external-system/esr-vnfm-list/esr-vnfm/vnfm2/esr-system-info-list")));
+ }
+
+ 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 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;
+
+ 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/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/resources/application.yaml b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/resources/application.yaml
new file mode 100644
index 0000000000..cdb6662191
--- /dev/null
+++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/resources/application.yaml
@@ -0,0 +1,61 @@
+# Copyright © 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.
+spring:
+ security:
+ usercredentials:
+ - username: test
+ password: '$2a$12$Zi3AuYcZoZO/gBQyUtST2.F5N6HqcTtaNci2Et.ufsQhski56srIu'
+ role: BPEL-Client
+ - username: vnfm
+ password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke'
+ role: BPEL-Client
+ main:
+ allow-bean-definition-overriding: true
+
+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
+
+
+#Actuator
+management:
+ endpoints:
+ web:
+ base-path: /manage
+ exposure:
+ include: "*"
+ metrics:
+ se-global-registry: false
+ export:
+ prometheus:
+ enabled: true # Whether exporting of metrics to Prometheus is enabled.
+ step: 1m # Step size (i.e. reporting frequency) to use.
+
+etsi-catalog-manager:
+ vnfpkgm:
+ endpoint: http://msb-iag.onap:80/api/vnfpkgm/v1