aboutsummaryrefslogtreecommitdiffstats
path: root/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test
diff options
context:
space:
mode:
authorAndrewLamb <andrew.a.lamb@est.tech>2019-10-03 12:02:53 +0100
committerAndrewLamb <andrew.a.lamb@est.tech>2019-10-04 15:38:16 +0100
commitfa9bb10f04035acb0621dd0f0a204b97cdd002fb (patch)
treefa2a7a52b534ffc159be4978b722d676f7943aa6 /plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test
parent72b4bc7eb109847c023ffed5d26b0a832730dea5 (diff)
Move the VNFM Simulator into CSIT
Change-Id: I7335be1a0adb033813fa5405526e95460134d9a6 Issue-ID: SO-1952 Signed-off-by: AndrewLamb <andrew.a.lamb@est.tech>
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test')
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSvnfmController.java183
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/InstantiateOperatorProgressorTest.java169
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/SvnfmServiceTest.java203
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/TerminateOperationProgressorTest.java157
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/VnfmHelperTest.java104
5 files changed, 816 insertions, 0 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSvnfmController.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSvnfmController.java
new file mode 100644
index 00000000..84a34623
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSvnfmController.java
@@ -0,0 +1,183 @@
+/*-
+ * ============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.svnfm.simulator.controllers;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
+import org.onap.so.svnfm.simulator.constants.Constant;
+import org.onap.so.svnfm.simulator.controller.SvnfmController;
+import org.onap.so.svnfm.simulator.repository.VnfmCacheRepository;
+import org.onap.so.svnfm.simulator.services.SvnfmService;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.test.web.servlet.ResultActions;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestSvnfmController {
+
+ private static final String VNF_INSTANCES_URL = "/vnf_instances/";
+ private static final String VNFD_ID = "vnfdId";
+ private static final String VNF_INSTANCE_NAME = "vnfInstanceName";
+ private static final String VNF_INSTANCE_DESCRIPTION = "vnfInstanceDescription";
+ private static final String VNF_INSTANCE_ID = "vnfInstanceId";
+ private static final String VNF_OPERATION_ID = "vnfOperationId";
+ private static final String VNF_INSTANTIATE_URL = "/instantiate";
+ private static final String VNF_TERMINATE_URL = "/terminate";
+ private static final String VNF_LCM_OP_OCC_ID = "vnfLcmOpOccId";
+ private static final String VNF_OPERATION_STATUS_URL = "/vnf_lcm_op_occs/";
+ private static final String SUBSCRIPTIONS_URL = "/subscriptions";
+
+ @InjectMocks
+ private SvnfmController svnfmController;
+
+ private MockMvc mockMvc;
+
+ @Mock
+ private SvnfmService svnfmService;
+
+ @Mock
+ private VnfmCacheRepository vnfmCacheRepository;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ this.mockMvc = MockMvcBuilders.standaloneSetup(svnfmController).build();
+ }
+
+ @Test
+ public void createVnfInstanceTest() throws Exception {
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest();
+
+ createVnfRequest.setVnfdId(VNFD_ID);
+ createVnfRequest.setVnfInstanceName(VNF_INSTANCE_NAME);
+ createVnfRequest.setVnfInstanceDescription(VNF_INSTANCE_DESCRIPTION);
+
+ when(vnfmCacheRepository.createVnf(eq(createVnfRequest), anyString())).thenReturn(new InlineResponse201());
+
+ final String body = (new ObjectMapper()).valueToTree(createVnfRequest).toString();
+ this.mockMvc
+ .perform(post(Constant.BASE_URL + VNF_INSTANCES_URL).content(body)
+ .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON));
+ }
+
+ @Test
+ public void test_getVnf_usingValidVnfInstanceId_vnfInstanceRetrievedSuccessfully() throws Exception {
+ final InlineResponse201 inlineResponse201 = new InlineResponse201();
+ inlineResponse201.setId(VNF_INSTANCE_ID);
+ inlineResponse201.setVnfInstanceName(VNF_INSTANCE_NAME);
+
+ when(vnfmCacheRepository.getVnf(VNF_INSTANCE_ID)).thenReturn(inlineResponse201);
+
+ final ResultActions resultActions = this.mockMvc
+ .perform(get(Constant.BASE_URL + VNF_INSTANCES_URL + VNF_INSTANCE_ID)
+ .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
+
+ final MvcResult result = resultActions.andReturn();
+ final String content = result.getResponse().getContentAsString();
+ final InlineResponse201 response201 = new ObjectMapper().readValue(content, InlineResponse201.class);
+ assertThat(response201.getId()).isEqualTo(VNF_INSTANCE_ID);
+ assertThat(response201.getVnfInstanceName()).isEqualTo(VNF_INSTANCE_NAME);
+ }
+
+ @Test
+ public void test_instantiateVnf_usingValidVnfInstanceId_returnsHttpStatusAccepted() throws Exception {
+ when(svnfmService.instantiateVnf(VNF_INSTANCE_ID)).thenReturn(VNF_OPERATION_ID);
+
+ this.mockMvc
+ .perform(post(Constant.BASE_URL + VNF_INSTANCES_URL + VNF_INSTANCE_ID + VNF_INSTANTIATE_URL)
+ .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isAccepted()).andExpect(content().contentType(MediaType.APPLICATION_JSON));
+ }
+
+ @Test
+ public void test_deleteVnf_usingValidVnfInstanceId_returnsHttpStatusNoContent() throws Exception {
+ this.mockMvc
+ .perform(delete(Constant.BASE_URL + VNF_INSTANCES_URL + VNF_INSTANCE_ID)
+ .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNoContent()).andExpect(content().contentType(MediaType.APPLICATION_JSON));
+ }
+
+ @Test
+ public void test_terminateVnf_usingValidVnfInstanceId_returnsHttpStatusIsAccepted() throws Exception {
+ when(svnfmService.terminateVnf(VNF_INSTANCE_ID)).thenReturn(VNF_OPERATION_ID);
+
+ this.mockMvc
+ .perform(post(Constant.BASE_URL + VNF_INSTANCES_URL + VNF_INSTANCE_ID + VNF_TERMINATE_URL)
+ .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isAccepted()).andExpect(content().contentType(MediaType.APPLICATION_JSON));
+ }
+
+ @Test
+ public void test_getOperationStatus_usingValidOperationId_operationStatusRetrievedSuccessfully() throws Exception {
+ final InlineResponse200 inlineResponse200 = new InlineResponse200();
+ inlineResponse200.setId(VNF_LCM_OP_OCC_ID);
+ inlineResponse200.setOperation(OperationEnum.INSTANTIATE);
+
+ when(svnfmService.getOperationStatus(VNF_LCM_OP_OCC_ID)).thenReturn(inlineResponse200);
+
+ final ResultActions resultActions = this.mockMvc
+ .perform(get(Constant.BASE_URL + VNF_OPERATION_STATUS_URL + VNF_LCM_OP_OCC_ID)
+ .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
+
+ final MvcResult result = resultActions.andReturn();
+ final String content = result.getResponse().getContentAsString();
+ final InlineResponse200 response200 = new ObjectMapper().readValue(content, InlineResponse200.class);
+ assertThat(response200.getId()).isEqualTo(VNF_LCM_OP_OCC_ID);
+ assertThat(response200.getOperation()).isEqualTo(OperationEnum.INSTANTIATE);
+ }
+
+ @Test
+ public void test_subscribeForNotifications_usingValidSubscriptionRequest_returnsHttpStatusCreated()
+ throws Exception {
+ final LccnSubscriptionRequest lccnSubscriptionRequest = new LccnSubscriptionRequest();
+ final String body = (new ObjectMapper()).valueToTree(lccnSubscriptionRequest).toString();
+
+ this.mockMvc
+ .perform(post(Constant.BASE_URL + SUBSCRIPTIONS_URL).content(body)
+ .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON));
+ }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/InstantiateOperatorProgressorTest.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/InstantiateOperatorProgressorTest.java
new file mode 100644
index 00000000..71709cb2
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/InstantiateOperatorProgressorTest.java
@@ -0,0 +1,169 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Nokia.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.svnfm.simulator.services;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201AddResources;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201VimConnections;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoVnfcResourceInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
+import org.onap.so.svnfm.simulator.model.Vnfds;
+import org.onap.so.svnfm.simulator.model.Vnfds.Vnfc;
+import org.onap.so.svnfm.simulator.model.Vnfds.Vnfd;
+import org.onap.so.svnfm.simulator.config.ApplicationConfig;
+import org.onap.so.svnfm.simulator.model.VnfOperation;
+
+public class InstantiateOperatorProgressorTest {
+
+ private static final String VNF_ID = "vnfTestId";
+ private static final String CALLBACK_URI = "/lcn/uritest";
+ private static final String VNFC_TYPE = "COMPUTE";
+ private static final String RESOURCE_TEMPLATE_ID = "resTempIdTest";
+ private static final String VDU_ID = "vduIdTest";
+ private static final String VNF_INSTANCE_ID = "vnfInstanceId";
+ private static final String VNFC_ID = "vnfcIdTest";
+ private static final String RESOURCE_DEFINITION_ID = "resDefTestId";
+ private static final String VIM_CONNECTION_ID = "vimConnTestId";
+
+ private SvnfmService svnfmServiceMock;
+
+ private InstantiateOperationProgressor testedObject;
+
+ @Before
+ public void setup() {
+ svnfmServiceMock = mock(SvnfmService.class);
+ VnfOperation vnfOperation = new VnfOperation();
+ vnfOperation.setVnfInstanceId(VNF_INSTANCE_ID);
+ vnfOperation.setOperation(OperationEnum.OPERATE);
+ testedObject = new InstantiateOperationProgressor(vnfOperation, svnfmServiceMock, null, new ApplicationConfig(),
+ createVnfds(), createSubscriptionService());
+ }
+
+ @Test
+ public void getAddResources_vnfIdFound() {
+ List<GrantsAddResources> result = testedObject.getAddResources(VNF_ID);
+ assertThat(result).hasSize(1);
+ GrantsAddResources grantsAddResourceResult = result.get(0);
+ assertThat(grantsAddResourceResult.getType()).hasToString(VNFC_TYPE);
+ assertThat(grantsAddResourceResult.getResourceTemplateId()).isEqualTo(RESOURCE_TEMPLATE_ID);
+ assertThat(grantsAddResourceResult.getVduId()).isEqualTo(VDU_ID);
+ }
+
+ @Test
+ public void getAddResources_vnfIdNotFound() {
+ List<GrantsAddResources> result = testedObject.getAddResources("otherVnfId");
+ assertThat(result).isEmpty();
+ }
+
+ @Test
+ public void handleGrantResponse_VnfdObjectsAvailable() {
+ when(svnfmServiceMock.getVnf(VNF_INSTANCE_ID)).thenReturn(createInlineResponse201());
+
+ InlineResponse201VimConnections inlineResponse201VimConnections = new InlineResponse201VimConnections();
+ List<InlineResponse201VimConnections> listOfVimConnection = new ArrayList<>();
+ listOfVimConnection.add(inlineResponse201VimConnections);
+
+ InlineResponse201AddResources inlineResponse201AddResources = new InlineResponse201AddResources();
+ inlineResponse201AddResources.setResourceDefinitionId(RESOURCE_DEFINITION_ID);
+ inlineResponse201AddResources.setVimConnectionId(VIM_CONNECTION_ID);
+ List<InlineResponse201AddResources> listOfResources = new ArrayList<>();
+ listOfResources.add(inlineResponse201AddResources);
+
+ InlineResponse201 inlineResponse201 = new InlineResponse201();
+ inlineResponse201.setVimConnections(listOfVimConnection);
+ inlineResponse201.setAddResources(listOfResources);
+ List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> resultList =
+ testedObject.handleGrantResponse(inlineResponse201);
+
+ assertThat(resultList).hasSize(1);
+ InlineResponse201InstantiatedVnfInfoVnfcResourceInfo resultObject = resultList.get(0);
+ assertThat(resultObject.getId()).isEqualTo(VNFC_ID);
+ assertThat(resultObject.getVduId()).isEqualTo(VDU_ID);
+ assertThat(resultObject.getComputeResource().getVimConnectionId()).isEqualTo(VIM_CONNECTION_ID);
+ }
+
+ @Test
+ public void getVnfcChangeType_enumAdded() {
+ assertThat(testedObject.getVnfcChangeType().getValue()).isEqualTo("ADDED");
+ }
+
+ @Test
+ public void getRemoveResourcesShouldReturnEmptyList() {
+ assertThat(testedObject.getRemoveResources("anyVnfId")).isEmpty();
+ }
+
+ @Test
+ public void test_buildGrantRequest_usingValidVnfInstanceId_grantRequestRetrievedSuccessfully() {
+ when(svnfmServiceMock.getVnf(Mockito.eq(VNF_INSTANCE_ID))).thenReturn(createInlineResponse201());
+ GrantRequest grantRequest = testedObject.buildGrantRequest();
+ assertThat(grantRequest.getVnfdId().equals(VNF_ID));
+ }
+
+ private Vnfds createVnfds() {
+ Vnfd vnfd = new Vnfd();
+ vnfd.setVnfdId(VNF_ID);
+ List<Vnfc> vnfcList = new ArrayList<>();
+ vnfcList.add(createVnfc());
+ vnfd.setVnfcList(vnfcList);
+ List<Vnfd> vnfdList = new ArrayList<>();
+ vnfdList.add(vnfd);
+
+ Vnfds vnfds = new Vnfds();
+ vnfds.setVnfdList(vnfdList);
+ return vnfds;
+ }
+
+ private Vnfc createVnfc() {
+ Vnfc vnfc = new Vnfc();
+ vnfc.setVnfcId(VNFC_ID);
+ vnfc.setType(VNFC_TYPE);
+ vnfc.setResourceTemplateId(RESOURCE_TEMPLATE_ID);
+ vnfc.setVduId(VDU_ID);
+ vnfc.setGrantResourceId(RESOURCE_DEFINITION_ID);
+ return vnfc;
+ }
+
+ private SubscriptionService createSubscriptionService() {
+ SubscriptionService subscriptionService = new SubscriptionService();
+ LccnSubscriptionRequest lccnSubscriptionRequest = new LccnSubscriptionRequest();
+ lccnSubscriptionRequest.setCallbackUri(CALLBACK_URI);
+ subscriptionService.registerSubscription(lccnSubscriptionRequest);
+ return subscriptionService;
+ }
+
+ private org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201 createInlineResponse201() {
+ org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201 inlineResponse201 =
+ new org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201();
+ inlineResponse201.setVnfdId(VNF_ID);
+ return inlineResponse201;
+ }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/SvnfmServiceTest.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/SvnfmServiceTest.java
new file mode 100644
index 00000000..7e441ab8
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/SvnfmServiceTest.java
@@ -0,0 +1,203 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Nokia.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.svnfm.simulator.services;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.svnfm.simulator.model.Vnfds;
+import org.onap.so.svnfm.simulator.config.ApplicationConfig;
+import org.onap.so.svnfm.simulator.constants.Constant;
+import org.onap.so.svnfm.simulator.model.VnfInstance;
+import org.onap.so.svnfm.simulator.model.VnfOperation;
+import org.onap.so.svnfm.simulator.repository.VnfOperationRepository;
+import org.onap.so.svnfm.simulator.repository.VnfmRepository;
+import org.springframework.cache.Cache;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.support.SimpleValueWrapper;
+
+public class SvnfmServiceTest {
+
+ private static final String VNFD_ID = "vnfdId";
+ private static final String VNF_INSTANCE_NAME = "vnfInstanceName";
+ private static final String VNF_INSTANCE_ID = "vnfInstanceId";
+ private static final String OPERATION_ID = "operationId";
+ private SvnfmService testedObject;
+ private CacheManager cacheManagerMock;
+ private VnfmHelper vnfmHelperMock;
+ private VnfmRepository vnfmRepositoryMock;
+ private VnfOperationRepository vnfOperationRepositoryMock;
+
+ @Before
+ public void setup() {
+ vnfmRepositoryMock = mock(VnfmRepository.class);
+ vnfOperationRepositoryMock = mock(VnfOperationRepository.class);
+ vnfmHelperMock = mock(VnfmHelper.class);
+ ApplicationConfig applicationConfigMock = mock(ApplicationConfig.class);
+ cacheManagerMock = mock(CacheManager.class);
+ Vnfds vnfdsMock = mock(Vnfds.class);
+ SubscriptionService subscriptionServiceMock = mock(SubscriptionService.class);
+
+ testedObject = new SvnfmService(vnfmRepositoryMock, vnfOperationRepositoryMock, vnfmHelperMock,
+ applicationConfigMock, cacheManagerMock, vnfdsMock, subscriptionServiceMock);
+ }
+
+ @Test
+ public void getVnfSuccessful() {
+ // given
+ Cache cacheMock = mock(Cache.class);
+ SimpleValueWrapper simpleValueWrapperMock = mock(SimpleValueWrapper.class);
+ when(cacheManagerMock.getCache(Constant.IN_LINE_RESPONSE_201_CACHE)).thenReturn(cacheMock);
+ when(cacheMock.get(VNF_INSTANCE_ID)).thenReturn(simpleValueWrapperMock);
+ when(simpleValueWrapperMock.get()).thenReturn(getInlineResponse(VNFD_ID, VNF_INSTANCE_NAME));
+ // when
+ InlineResponse201 result = testedObject.getVnf(VNF_INSTANCE_ID);
+ // then
+ assertThat(result.getVnfdId()).isEqualTo(VNFD_ID);
+ assertThat(result.getVnfInstanceName()).isEqualTo(VNF_INSTANCE_NAME);
+ }
+
+ @Test
+ public void getVnf_ifCacheNullThenReturnNull() {
+ // given
+ when(cacheManagerMock.getCache(Constant.IN_LINE_RESPONSE_201_CACHE)).thenReturn(null);
+ // then
+ assertThat(testedObject.getVnf("any")).isNull();
+ }
+
+ @Test
+ public void getVnf_ifWrapperNullThenReturnNull() {
+ // given
+ Cache cacheMock = mock(Cache.class);
+ when(cacheManagerMock.getCache(Constant.IN_LINE_RESPONSE_201_CACHE)).thenReturn(cacheMock);
+ when(cacheMock.get(VNF_INSTANCE_ID)).thenReturn(null);
+ // then
+ assertThat(testedObject.getVnf(VNF_INSTANCE_ID)).isNull();
+ }
+
+ @Test
+ public void getVnf_ifResultIsNullThenReturnNull() {
+ // when
+ Cache cacheMock = mock(Cache.class);
+ SimpleValueWrapper simpleValueWrapperMock = mock(SimpleValueWrapper.class);
+ when(cacheManagerMock.getCache(Constant.IN_LINE_RESPONSE_201_CACHE)).thenReturn(cacheMock);
+ when(cacheMock.get(VNF_INSTANCE_ID)).thenReturn(simpleValueWrapperMock);
+ when(simpleValueWrapperMock.get()).thenReturn(null);
+ // then
+ assertThat(testedObject.getVnf(VNF_INSTANCE_ID)).isNull();
+ }
+
+ @Test
+ public void test_createVnf_usingValidCreateVnfRequest_vnfInstanceCreatedSuccessfully() throws Exception {
+ // given
+ final CreateVnfRequest createVnfRequest = getCreateVnfRequest();
+ final VnfInstance vnfInstance = getVnfInstance();
+ final InlineResponse201 inlineResponse201 = getInlineResponse(VNFD_ID, VNF_INSTANCE_NAME);
+ when(vnfmHelperMock.createVnfInstance(createVnfRequest, VNF_INSTANCE_ID)).thenReturn(vnfInstance);
+ when(vnfmRepositoryMock.save(vnfInstance)).thenReturn(vnfInstance);
+ when(vnfmHelperMock.getInlineResponse201(vnfInstance)).thenReturn(inlineResponse201);
+ // when
+ final InlineResponse201 result = testedObject.createVnf(createVnfRequest, VNF_INSTANCE_ID);
+ // then
+ assertThat(result.getVnfdId()).isEqualTo(VNFD_ID);
+ assertThat(result.getVnfInstanceName()).isEqualTo(VNF_INSTANCE_NAME);
+ }
+
+ @Test
+ public void test_createVnf_illegalAccessExceptionThrown_returnsNull() throws Exception {
+ // given
+ final CreateVnfRequest createVnfRequest = getCreateVnfRequest();
+ final VnfInstance vnfInstance = getVnfInstance();
+ when(vnfmHelperMock.createVnfInstance(createVnfRequest, VNF_INSTANCE_ID)).thenReturn(vnfInstance);
+ when(vnfmRepositoryMock.save(vnfInstance)).thenReturn(vnfInstance);
+ when(vnfmHelperMock.getInlineResponse201(vnfInstance)).thenThrow(new IllegalAccessException());
+ // when
+ final InlineResponse201 result = testedObject.createVnf(createVnfRequest, VNF_INSTANCE_ID);
+ // then
+ assertNull(result);
+ }
+
+ @Test
+ public void test_getOperationStatus_usingValidOperationId_operationStatusRetrievedSuccessfully() {
+ // given
+ final OperationEnum operationEnum = OperationEnum.OPERATE;
+ final VnfOperation vnfOperation = getVnfOperation(OPERATION_ID, operationEnum);
+ final List<VnfOperation> vnfOperations = new ArrayList<>();
+ vnfOperations.add(vnfOperation);
+ when(vnfOperationRepositoryMock.findAll()).thenReturn(vnfOperations);
+ // when
+ final InlineResponse200 result = testedObject.getOperationStatus(OPERATION_ID);
+ // then
+ assertThat(result.getId()).isEqualTo(OPERATION_ID);
+ assertThat(result.getOperation()).isEqualTo(operationEnum);
+ }
+
+ @Test
+ public void test_getOperationStatus_usingInvalidOperationId_returnsNull() {
+ // given
+ final OperationEnum operationEnum = OperationEnum.OPERATE;
+ final VnfOperation vnfOperation = getVnfOperation(OPERATION_ID, operationEnum);
+ final List<VnfOperation> vnfOperations = new ArrayList<>();
+ vnfOperations.add(vnfOperation);
+ when(vnfOperationRepositoryMock.findAll()).thenReturn(vnfOperations);
+ // when
+ InlineResponse200 result = testedObject.getOperationStatus("invalidOperationId");
+ // then
+ assertNull(result);
+ }
+
+ private InlineResponse201 getInlineResponse(String vnfdId, String vnfInstanceName) {
+ InlineResponse201 response201 = new InlineResponse201();
+ response201.setVnfdId(vnfdId);
+ response201.vnfInstanceName(vnfInstanceName);
+ return response201;
+ }
+
+ private CreateVnfRequest getCreateVnfRequest() {
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest();
+ createVnfRequest.setVnfdId(VNFD_ID);
+ createVnfRequest.setVnfInstanceName(VNF_INSTANCE_NAME);
+ return createVnfRequest;
+ }
+
+ private VnfInstance getVnfInstance() {
+ final VnfInstance vnfInstance = new VnfInstance();
+ vnfInstance.setVnfdId(VNFD_ID);
+ vnfInstance.setVnfInstanceName(VNF_INSTANCE_NAME);
+ return vnfInstance;
+ }
+
+ private VnfOperation getVnfOperation(String operationId, OperationEnum operationEnum) {
+ final VnfOperation vnfOperation = new VnfOperation();
+ vnfOperation.setId(operationId);
+ vnfOperation.setOperation(operationEnum);
+ return vnfOperation;
+ }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/TerminateOperationProgressorTest.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/TerminateOperationProgressorTest.java
new file mode 100644
index 00000000..0b1ded4d
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/TerminateOperationProgressorTest.java
@@ -0,0 +1,157 @@
+/*-
+ * ============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.svnfm.simulator.services;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoResourceHandle;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoVnfcResourceInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
+import org.onap.so.svnfm.simulator.model.Vnfds;
+import org.onap.so.svnfm.simulator.model.Vnfds.Vnfc;
+import org.onap.so.svnfm.simulator.model.Vnfds.Vnfd;
+import org.onap.so.svnfm.simulator.config.ApplicationConfig;
+import org.onap.so.svnfm.simulator.model.VnfOperation;
+
+public class TerminateOperationProgressorTest {
+
+ private static final String VNFD_ID = "vnfdId";
+ private static final String VNFC_TYPE = "COMPUTE";
+ private static final String VDU_ID = "vduId";
+ private static final String VNF_INSTANCE_ID = "vnfInstanceId";
+
+ @Mock
+ private SvnfmService svnfmService;
+
+ private TerminateOperationProgressor testedObject;
+
+ @Before
+ public void setup() {
+ svnfmService = mock(SvnfmService.class);
+ VnfOperation vnfOperation = new VnfOperation();
+ vnfOperation.setVnfInstanceId(VNF_INSTANCE_ID);
+ vnfOperation.setOperation(OperationEnum.OPERATE);
+ testedObject = new TerminateOperationProgressor(vnfOperation, svnfmService, null, new ApplicationConfig(),
+ createVnfds(), createSubscriptionService());
+ }
+
+ @Test
+ public void test_getAddResources_usingValidVnfdId_returnsEmptyList() {
+ List<GrantsAddResources> results = testedObject.getAddResources(VNFD_ID);
+ assertThat(results.isEmpty());
+ }
+
+ @Test
+ public void test_getRemoveResources_usingValidVnfdId_retrievesGrantsAddResourcesSuccessfully() {
+ // given
+ InlineResponse201 inlineResponse201 = createInlineResponse201();
+ InlineResponse201InstantiatedVnfInfo inlineResponse201InstantiatedVnfInfo =
+ setupInlineResponseInstantiatedVnfInfo();
+ inlineResponse201.setInstantiatedVnfInfo(inlineResponse201InstantiatedVnfInfo);
+
+ when(svnfmService.getVnf(VNF_INSTANCE_ID)).thenReturn(inlineResponse201);
+
+ // when
+ List<GrantsAddResources> result = testedObject.getRemoveResources(VNFD_ID);
+
+ // then
+ assertThat(result).hasSize(1);
+ GrantsAddResources grantsAddResourcesResult = result.get(0);
+ assertThat(grantsAddResourcesResult.getType()).hasToString(VNFC_TYPE);
+ assertThat(grantsAddResourcesResult.getVduId()).isEqualTo(VDU_ID);
+ }
+
+ @Test
+ public void test_getVnfcChangeType_isEnumRemoved() {
+ assertThat(testedObject.getVnfcChangeType().getValue()).isEqualTo("REMOVED");
+ }
+
+ private Vnfds createVnfds() {
+ Vnfd vnfd = new Vnfd();
+ vnfd.setVnfdId(VNFD_ID);
+ List<Vnfc> vnfcList = new ArrayList<>();
+ vnfcList.add(createVnfc());
+ vnfd.setVnfcList(vnfcList);
+ List<Vnfd> vnfdList = new ArrayList<>();
+ vnfdList.add(vnfd);
+
+ Vnfds vnfds = new Vnfds();
+ vnfds.setVnfdList(vnfdList);
+ return vnfds;
+ }
+
+ private Vnfc createVnfc() {
+ Vnfc vnfc = new Vnfc();
+ String vnfcId = "vnfcId";
+ vnfc.setVnfcId(vnfcId);
+ vnfc.setType(VNFC_TYPE);
+ String resourceTemplateId = "resTempId";
+ vnfc.setResourceTemplateId(resourceTemplateId);
+ vnfc.setVduId(VDU_ID);
+ String resourceDefinitionId = "resourceDefinitionId";
+ vnfc.setGrantResourceId(resourceDefinitionId);
+ return vnfc;
+ }
+
+ private SubscriptionService createSubscriptionService() {
+ SubscriptionService subscriptionService = new SubscriptionService();
+ LccnSubscriptionRequest lccnSubscriptionRequest = new LccnSubscriptionRequest();
+ String callbackUri = "/lcn/uriest";
+ lccnSubscriptionRequest.setCallbackUri(callbackUri);
+ subscriptionService.registerSubscription(lccnSubscriptionRequest);
+ return subscriptionService;
+ }
+
+ private InlineResponse201 createInlineResponse201() {
+ InlineResponse201 inlineResponse201 = new InlineResponse201();
+ inlineResponse201.setVnfdId(VNFD_ID);
+ return inlineResponse201;
+ }
+
+ private InlineResponse201InstantiatedVnfInfo setupInlineResponseInstantiatedVnfInfo() {
+ InlineResponse201InstantiatedVnfInfo inlineResponse201InstantiatedVnfInfo =
+ new InlineResponse201InstantiatedVnfInfo();
+ List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> resultList = new ArrayList<>();
+ InlineResponse201InstantiatedVnfInfoVnfcResourceInfo resourceInfo =
+ new InlineResponse201InstantiatedVnfInfoVnfcResourceInfo();
+ String resourceInfoId = "resourceInfoId";
+ resourceInfo.setId(resourceInfoId);
+ resourceInfo.setVduId((VDU_ID));
+ InlineResponse201InstantiatedVnfInfoResourceHandle resourceHandle =
+ new InlineResponse201InstantiatedVnfInfoResourceHandle();
+ resourceInfo.setComputeResource(resourceHandle);
+ resultList.add(resourceInfo);
+ inlineResponse201InstantiatedVnfInfo.setVnfcResourceInfo(resultList);
+ String flavourId = "flavourId";
+ inlineResponse201InstantiatedVnfInfo.setFlavourId(flavourId);
+ return inlineResponse201InstantiatedVnfInfo;
+ }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/VnfmHelperTest.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/VnfmHelperTest.java
new file mode 100644
index 00000000..da538994
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/services/VnfmHelperTest.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Nokia.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.svnfm.simulator.services;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest;
+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.InlineResponse201LinksSelf;
+import org.onap.so.svnfm.simulator.config.ApplicationConfig;
+import org.onap.so.svnfm.simulator.constants.Constant;
+import org.onap.so.svnfm.simulator.model.VnfInstance;
+
+public class VnfmHelperTest {
+
+ private static final String VNF_INSTANCE_ID = "vnfInstanceTestId";
+ private static final String VNFD_ID = "vnfdTestId";
+ private static final String VNF_INSTANCE_NAME = "vnfInsNameTest";
+ private static final String VNF_INSTANCE_DESCRIPTION = "vnfInstTestDescr";
+ private static final String APPLICATION_CONFIG_BASE_URL = "appConfUrl";
+ private VnfmHelper testedObject;
+ private ApplicationConfig applicationConfigMock;
+
+ @Before
+ public void setup() {
+ applicationConfigMock = mock(ApplicationConfig.class);
+ testedObject = new VnfmHelper(applicationConfigMock);
+ }
+
+ @Test
+ public void createVnfInstance() {
+ // when
+ VnfInstance result = testedObject.createVnfInstance(createVnfRequest(), VNF_INSTANCE_ID);
+ // then
+ assertThat(result.getId()).isEqualTo(VNF_INSTANCE_ID);
+ assertThat(result.getVnfdId()).isEqualTo(VNFD_ID);
+ assertThat(result.getVnfInstanceName()).isEqualTo(VNF_INSTANCE_NAME);
+ assertThat(result.getVnfInstanceDescription()).isEqualTo(VNF_INSTANCE_DESCRIPTION);
+ assertThat(result.getVnfProvider()).isEqualTo(Constant.VNF_PROVIDER);
+ assertThat(result.getVnfProductName()).isEqualTo(Constant.VNF_PROVIDER_NAME);
+ }
+
+ @Test
+ public void getInlineResponse201() throws Exception {
+ // given
+ when(applicationConfigMock.getBaseUrl()).thenReturn(APPLICATION_CONFIG_BASE_URL);
+ // when
+ InlineResponse201 result = testedObject.getInlineResponse201(prepareVnfInstance());
+ // then
+ assertThat(result.getVnfdVersion()).isEqualTo(Constant.VNFD_VERSION);
+ assertThat(result.getVnfSoftwareVersion()).isEqualTo(Constant.VNF_SOFTWARE_VERSION);
+ assertThat(result.getInstantiationState()).isEqualByComparingTo(InstantiationStateEnum.NOT_INSTANTIATED);
+ verifyAdditionalPropertyInlineResponse201(result);
+ }
+
+ private CreateVnfRequest createVnfRequest() {
+ CreateVnfRequest createVnfRequest = new CreateVnfRequest();
+ createVnfRequest.setVnfdId(VNFD_ID);
+ createVnfRequest.setVnfInstanceName(VNF_INSTANCE_NAME);
+ createVnfRequest.setVnfInstanceDescription(VNF_INSTANCE_DESCRIPTION);
+ return createVnfRequest;
+ }
+
+ private VnfInstance prepareVnfInstance() {
+ VnfInstance vnfInstance = new VnfInstance();
+ vnfInstance.setId(VNF_INSTANCE_ID);
+ return vnfInstance;
+ }
+
+ private void verifyAdditionalPropertyInlineResponse201(InlineResponse201 result) {
+ InlineResponse201LinksSelf expectedVnfInstancesLinksSelf = new InlineResponse201LinksSelf();
+ expectedVnfInstancesLinksSelf
+ .setHref(APPLICATION_CONFIG_BASE_URL + "/vnflcm/v1/vnf_instances/" + VNF_INSTANCE_ID);
+ assertThat(result.getLinks().getSelf()).isEqualTo(expectedVnfInstancesLinksSelf);
+
+ InlineResponse201LinksSelf expectedVnfInstancesLinksSelfInstantiate = new InlineResponse201LinksSelf();
+ expectedVnfInstancesLinksSelfInstantiate.setHref(
+ (APPLICATION_CONFIG_BASE_URL + "/vnflcm/v1/vnf_instances/" + VNF_INSTANCE_ID + "/instantiate"));
+ assertThat(result.getLinks().getInstantiate()).isEqualTo(expectedVnfInstancesLinksSelfInstantiate);
+ }
+
+}