### Question:
VnfmAdapterServiceProviderImpl implements VnfmAdapterServiceProvider { @Override public Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, final CreateVnfRequest request) { try { final String url = urlProvider.getCreateInstantiateUrl(vnfId); final ResponseEntity<CreateVnfResponse> response = httpServiceProvider.postHttpRequest(request, url, CreateVnfResponse.class); final HttpStatus httpStatus = response.getStatusCode(); if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) { LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value()); return Optional.absent(); } if (!response.hasBody()) { LOGGER.error(RECEIVED_RESPONSE_WITHOUT_BODY, response); return Optional.absent(); } final CreateVnfResponse createVnfResponse = response.getBody(); if (createVnfResponse.getJobId() == null || createVnfResponse.getJobId().isEmpty()) { LOGGER.error("Received invalid instantiation response: {}", response); return Optional.absent(); } return Optional.of(createVnfResponse); } catch (final RestProcessingException | InvalidRestRequestException | HttpResouceNotFoundException httpInvocationException) { LOGGER.error("Unexpected error while processing create and instantiation request", httpInvocationException); return Optional.absent(); } } @Autowired  VnfmAdapterServiceProviderImpl(final VnfmAdapterUrlProvider urlProvider,
            final HttpRestServiceProvider httpServiceProvider); @Override Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId,
            final CreateVnfRequest request); @Override Optional<DeleteVnfResponse> invokeDeleteRequest(final String vnfId); @Override Optional<QueryJobResponse> getInstantiateOperationJobStatus(final String jobId); static final String RECEIVED_RESPONSE_WITHOUT_BODY; }### Answer:
@Test public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusAcceptedWithBody_validResponse() { when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), eq(CreateVnfResponse.class))).thenReturn(mockedResponseEntity); when(mockedResponseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); when(mockedResponseEntity.hasBody()).thenReturn(true); final CreateVnfResponse response = getCreateVnfResponse(DUMMY_JOB_ID); when(mockedResponseEntity.getBody()).thenReturn(response); final VnfmAdapterServiceProvider objUnderTest = new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); final Optional<CreateVnfResponse> actual = objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); assertTrue(actual.isPresent()); assertEquals(actual.get(), response); }
@Test public void testInvokeCreateInstantiationRequest_httpServiceProviderThrowException_httpRestServiceProviderNotNull() { when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), eq(CreateVnfResponse.class))).thenThrow(RestProcessingException.class); final VnfmAdapterServiceProvider objUnderTest = new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); final Optional<CreateVnfResponse> actual = objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); assertFalse(actual.isPresent()); }