package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification;
import com.google.gson.*;
-import com.nokia.cbam.lcm.v32.ApiException;
import com.nokia.cbam.lcm.v32.model.*;
-import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
public class TestLifecycleChangeNotificationManager extends TestBase {
- public static final String OPERATION_EXECUTION_ID = "myOperationExecutionId";
-
@InjectMocks
private LifecycleChangeNotificationManager lifecycleChangeNotificationManager;
private VnfLifecycleChangeNotification recievedLcn = new VnfLifecycleChangeNotification();
recievedLcn.setLifecycleOperationOccurrenceId("instantiationOperationExecutionId");
healOperation.setStartTime(OffsetDateTime.now().plusDays(1));
recievedLcn.setVnfInstanceId(VNF_ID);
- when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(operationExecutions);
+ when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationExecutions));
prepOperation(instantiationOperation);
prepOperation(scaleOperation);
prepOperation(healOperation);
VimInfo vimInfo = new VimInfo();
vimInfo.setId(VIM_ID);
instantiateVnfRequest.getVims().add(vimInfo);
- when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(new Gson().toJsonTree(instantiateVnfRequest));
- when(vnfApi.vnfsGet(NOKIA_LCM_API_VERSION)).thenReturn(vnfs);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperation.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(new Gson().toJsonTree(instantiateVnfRequest)));
+ when(vnfApi.vnfsGet(NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfs));
vnfs.add(vnf);
vnf.setId(VNF_ID);
VnfProperty prop = new VnfProperty();
prop.setValue(VNFM_ID);
vnf.setExtensions(new ArrayList<>());
vnf.getExtensions().add(prop);
- when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnf));
}
- private void prepOperation(OperationExecution operationExecution) throws ApiException {
+ private void prepOperation(OperationExecution operationExecution) {
addEmptyModifiedConnectionPoints(operationExecution);
JsonElement root = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + JOB_ID + "\"}}");
operationExecution.setOperationParams(root);
case TERMINATE:
root.getAsJsonObject().addProperty("terminationType", "GRACEFULL");
}
- when(operationExecutionApi.operationExecutionsOperationExecutionIdGet(operationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(operationExecution);
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdGet(operationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(operationExecution));
operationExecutions.add(operationExecution);
}
*/
@Test
public void testInstantiationSufficesTheLastInstantiation() {
- DateTime baseTime = DateTime.now();
+ OffsetDateTime baseTime = OffsetDateTime.now();
List<OperationExecution> operations = new ArrayList<>();
OperationExecution operation = buildOperation(OffsetDateTime.now(), INSTANTIATE);
*/
@Test
public void testNoInstantiation() {
- DateTime baseTime = DateTime.now();
+ OffsetDateTime baseTime = OffsetDateTime.now();
List<OperationExecution> operations = new ArrayList<>();
OperationExecution operation = buildOperation(OffsetDateTime.now(), TERMINATE);
*/
@Test
public void testUnableToListVnfs() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsGet(NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//when
try {
*/
@Test
public void testUnableToQueryVnf() throws Exception {
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//when
try {
public void testUnableToQueryCurrentOperation() throws Exception {
recievedLcn.setOperation(OperationType.TERMINATE);
recievedLcn.setStatus(OperationStatus.FINISHED);
- ApiException expectedException = new ApiException();
+ RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
//when
try {
} catch (Exception e) {
//verify
assertEquals(expectedException, e.getCause());
- verify(logger).error("Unable to retrieve the current VNF myVnfId", e.getCause());
+ verify(logger).error("Unable to retrieve the operation executions for the VNF myVnfId", e.getCause());
}
}