### Question:
SDNCQueryTasks { public void queryVfModule(BuildingBlockExecution execution) throws BBObjectNotFoundException { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); String selfLink = "restconf/config/GENERIC-RESOURCE-API:services/service/" + serviceInstance.getServiceInstanceId() + "/service-data/vnfs/vnf/" + genericVnf.getVnfId() + "/vnf-data/vf-modules/vf-module/" + vfModule.getVfModuleId() + "/vf-module-data/vf-module-topology/"; try { if (vfModule.getSelflink() == null || (vfModule.getSelflink() != null && vfModule.getSelflink().isEmpty())) { vfModule.setSelflink(selfLink); } if (vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) { String response = sdncVfModuleResources.queryVfModule(vfModule); execution.setVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId(), response); } else { throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value"); } } catch (BadResponseException ex) { logger.error("Exception occurred for BadResponse ", ex); if (!ex.getMessage().equals(NO_RESPONSE_FROM_SDNC)) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, ONAPComponents.SDNC); } else { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, ONAPComponents.SO); } } catch (Exception ex) { logger.error("Exception occurred", ex); exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } }  void queryVnf(BuildingBlockExecution execution); void queryVfModule(BuildingBlockExecution execution); void queryVfModuleForVolumeGroup(BuildingBlockExecution execution); static final String SDNCQUERY_RESPONSE; }### Answer:
@Test public void queryVfModuleTest() throws Exception { String sdncQueryResponse = "response"; vfModule.setSelflink("vfModuleSelfLink"); doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule); assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId())); sdncQueryTasks.queryVfModule(execution); assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId())); verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule); }
@Test public void queryVfModuleBadResponseExceptionTest() throws Exception { BadResponseException exception = new BadResponseException("Error received from SDNC"); doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); expectedException.expect(BpmnError.class); sdncQueryTasks.queryVfModule(execution); verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, ONAPComponents.SDNC); }
@Test public void queryVfModuleResponseExceptionNoResponseTest() throws Exception { BadResponseException exception = new BadResponseException("Error did not receive a response from SDNC."); doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); expectedException.expect(BpmnError.class); sdncQueryTasks.queryVfModule(execution); verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, ONAPComponents.SO); }