aboutsummaryrefslogtreecommitdiffstats
path: root/vnfm-simulator
diff options
context:
space:
mode:
authorAndrewLamb <andrew.a.lamb@est.tech>2019-09-19 13:43:32 +0100
committerAndrewLamb <andrew.a.lamb@est.tech>2019-09-27 11:47:07 +0100
commit0f5d4b5e7df6d80684d612e27ce32f0cae6f6b6c (patch)
tree3e91c4655a9d4778ef66e52032cf8cc88bbd95cb /vnfm-simulator
parent5323b7150d0c4df4b0c38e0537c78fc011c0fb9b (diff)
Unit test cases for SVNFM Simulator
Change-Id: Ibc6e4d47007fb14dbcad97b27d47cdd808251c9d Issue-ID: SO-1853 Signed-off-by: AndrewLamb <andrew.a.lamb@est.tech>
Diffstat (limited to 'vnfm-simulator')
-rw-r--r--vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/controllers/TestSvnfmController.java108
-rw-r--r--vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/InstantiateOperatorProgressorTest.java12
-rw-r--r--vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/SvnfmServiceTest.java127
-rw-r--r--vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/TerminateOperationProgressorTest.java157
4 files changed, 381 insertions, 23 deletions
diff --git a/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/controllers/TestSvnfmController.java b/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/controllers/TestSvnfmController.java
index 9cb0702ee0..0818ea363f 100644
--- a/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/controllers/TestSvnfmController.java
+++ b/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/controllers/TestSvnfmController.java
@@ -20,9 +20,12 @@
package org.onap.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;
@@ -35,18 +38,35 @@ 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.svnfm.simulator.constants.Constant;
import org.onap.svnfm.simulator.controller.SvnfmController;
import org.onap.svnfm.simulator.repository.VnfmCacheRepository;
import org.onap.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;
@@ -68,18 +88,96 @@ public class TestSvnfmController {
public void createVnfInstanceTest() throws Exception {
final CreateVnfRequest createVnfRequest = new CreateVnfRequest();
- createVnfRequest.setVnfdId("123456798");
- createVnfRequest.setVnfInstanceName("createVnfInstanceTest");
- createVnfRequest.setVnfInstanceDescription("createVnfInstanceTest");
+ 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").content(body)
+ .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/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/InstantiateOperatorProgressorTest.java b/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/InstantiateOperatorProgressorTest.java
index 46030e94d3..b74cd689c8 100644
--- a/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/InstantiateOperatorProgressorTest.java
+++ b/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/InstantiateOperatorProgressorTest.java
@@ -21,16 +21,20 @@
package org.onap.svnfm.simulator.services;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
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.svnfm.simulator.config.ApplicationConfig;
@@ -60,6 +64,7 @@ public class InstantiateOperatorProgressorTest {
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());
}
@@ -117,6 +122,13 @@ public class InstantiateOperatorProgressorTest {
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);
diff --git a/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/SvnfmServiceTest.java b/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/SvnfmServiceTest.java
index ed77775421..2eca37ba6c 100644
--- a/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/SvnfmServiceTest.java
+++ b/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/SvnfmServiceTest.java
@@ -21,13 +21,21 @@
package org.onap.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.svnfm.simulator.config.ApplicationConfig;
import org.onap.svnfm.simulator.constants.Constant;
+import org.onap.svnfm.simulator.model.VnfInstance;
+import org.onap.svnfm.simulator.model.VnfOperation;
import org.onap.svnfm.simulator.model.Vnfds;
import org.onap.svnfm.simulator.repository.VnfOperationRepository;
import org.onap.svnfm.simulator.repository.VnfmRepository;
@@ -37,14 +45,21 @@ 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() {
- VnfmRepository vnfmRepositoryMock = mock(VnfmRepository.class);
- VnfOperationRepository vnfOperationRepositoryMock = mock(VnfOperationRepository.class);
- VnfmHelper vnfmHelperMock = mock(VnfmHelper.class);
+ 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);
@@ -57,18 +72,16 @@ public class SvnfmServiceTest {
@Test
public void getVnfSuccessful() {
// given
- String vnfId = "vnfId";
- String vnfInstanceName = "testVnf";
Cache cacheMock = mock(Cache.class);
SimpleValueWrapper simpleValueWrapperMock = mock(SimpleValueWrapper.class);
when(cacheManagerMock.getCache(Constant.IN_LINE_RESPONSE_201_CACHE)).thenReturn(cacheMock);
- when(cacheMock.get(vnfId)).thenReturn(simpleValueWrapperMock);
- when(simpleValueWrapperMock.get()).thenReturn(prepareInlineResponse(vnfId, vnfInstanceName));
+ when(cacheMock.get(VNF_INSTANCE_ID)).thenReturn(simpleValueWrapperMock);
+ when(simpleValueWrapperMock.get()).thenReturn(getInlineResponse(VNFD_ID, VNF_INSTANCE_NAME));
// when
- InlineResponse201 result = testedObject.getVnf(vnfId);
+ InlineResponse201 result = testedObject.getVnf(VNF_INSTANCE_ID);
// then
- assertThat(result.getVnfdId()).isEqualTo(vnfId);
- assertThat(result.getVnfInstanceName()).isEqualTo(vnfInstanceName);
+ assertThat(result.getVnfdId()).isEqualTo(VNFD_ID);
+ assertThat(result.getVnfInstanceName()).isEqualTo(VNF_INSTANCE_NAME);
}
@Test
@@ -82,31 +95,109 @@ public class SvnfmServiceTest {
@Test
public void getVnf_ifWrapperNullThenReturnNull() {
// given
- String vnfId = "vnfId";
Cache cacheMock = mock(Cache.class);
when(cacheManagerMock.getCache(Constant.IN_LINE_RESPONSE_201_CACHE)).thenReturn(cacheMock);
- when(cacheMock.get(vnfId)).thenReturn(null);
+ when(cacheMock.get(VNF_INSTANCE_ID)).thenReturn(null);
// then
- assertThat(testedObject.getVnf(vnfId)).isNull();
+ assertThat(testedObject.getVnf(VNF_INSTANCE_ID)).isNull();
}
@Test
public void getVnf_ifResultIsNullThenReturnNull() {
// when
- String vnfId = "vnfId";
Cache cacheMock = mock(Cache.class);
SimpleValueWrapper simpleValueWrapperMock = mock(SimpleValueWrapper.class);
when(cacheManagerMock.getCache(Constant.IN_LINE_RESPONSE_201_CACHE)).thenReturn(cacheMock);
- when(cacheMock.get(vnfId)).thenReturn(simpleValueWrapperMock);
+ when(cacheMock.get(VNF_INSTANCE_ID)).thenReturn(simpleValueWrapperMock);
when(simpleValueWrapperMock.get()).thenReturn(null);
// then
- assertThat(testedObject.getVnf(vnfId)).isNull();
+ assertThat(testedObject.getVnf(VNF_INSTANCE_ID)).isNull();
}
- private InlineResponse201 prepareInlineResponse(String vnfId, String vnfInstanceName) {
+ @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(vnfId);
+ 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/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/TerminateOperationProgressorTest.java b/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/services/TerminateOperationProgressorTest.java
new file mode 100644
index 0000000000..c7237a860c
--- /dev/null
+++ b/vnfm-simulator/vnfm-service/src/test/java/org/onap/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.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.svnfm.simulator.config.ApplicationConfig;
+import org.onap.svnfm.simulator.model.VnfOperation;
+import org.onap.svnfm.simulator.model.Vnfds;
+import org.onap.svnfm.simulator.model.Vnfds.Vnfc;
+import org.onap.svnfm.simulator.model.Vnfds.Vnfd;
+
+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;
+ }
+}