@Test public void listVMsAndTemplatesEmptyMap() throws Exception { whenNew(MorObjectHandler.class).withNoArguments().thenReturn(morObjectHandlerMock); Map<String, ManagedObjectReference> vmsMap = new HashMap<>(); when(morObjectHandlerMock.getSpecificObjectsMap(any(ConnectionResources.class), anyString())).thenReturn(vmsMap); whenNew(ResponseHelper.class).withArguments(any(ConnectionResources.class), any(ManagedObjectReference.class)) .thenReturn(getResponseHelper(connectionResourcesMock, taskMorMock, true)); Map<String, String> results = new VmService().listVMsAndTemplates(httpInputsMock, new VmInputs.VmInputsBuilder().build(), ""); verify(morObjectHandlerMock, times(1)).getSpecificObjectsMap(any(ConnectionResources.class), anyString()); assertNotNull(results); assertEquals(-1, Integer.parseInt(results.get("returnCode"))); assertEquals("No VM found in datacenter.", results.get("returnResult")); }
public Map<String, String> listVMsAndTemplates(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { Map<String, ManagedObjectReference> virtualMachinesMorMap = new MorObjectHandler() .getSpecificObjectsMap(connectionResources, ManagedObjectType.VIRTUAL_MACHINE.getValue()); Set<String> virtualMachineNamesList = virtualMachinesMorMap.keySet(); if (virtualMachineNamesList.size() > 0) { return ResponseUtils.getResultsMap(ResponseUtils .getResponseStringFromCollection(virtualMachineNamesList, delimiter), Outputs.RETURN_CODE_SUCCESS); } else { return ResponseUtils.getResultsMap("No VM found in datacenter.", Outputs.RETURN_CODE_FAILURE); } } catch (Exception ex) { return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE); } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } }
VmService { public Map<String, String> listVMsAndTemplates(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { Map<String, ManagedObjectReference> virtualMachinesMorMap = new MorObjectHandler() .getSpecificObjectsMap(connectionResources, ManagedObjectType.VIRTUAL_MACHINE.getValue()); Set<String> virtualMachineNamesList = virtualMachinesMorMap.keySet(); if (virtualMachineNamesList.size() > 0) { return ResponseUtils.getResultsMap(ResponseUtils .getResponseStringFromCollection(virtualMachineNamesList, delimiter), Outputs.RETURN_CODE_SUCCESS); } else { return ResponseUtils.getResultsMap("No VM found in datacenter.", Outputs.RETURN_CODE_FAILURE); } } catch (Exception ex) { return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE); } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } } }
VmService { public Map<String, String> listVMsAndTemplates(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { Map<String, ManagedObjectReference> virtualMachinesMorMap = new MorObjectHandler() .getSpecificObjectsMap(connectionResources, ManagedObjectType.VIRTUAL_MACHINE.getValue()); Set<String> virtualMachineNamesList = virtualMachinesMorMap.keySet(); if (virtualMachineNamesList.size() > 0) { return ResponseUtils.getResultsMap(ResponseUtils .getResponseStringFromCollection(virtualMachineNamesList, delimiter), Outputs.RETURN_CODE_SUCCESS); } else { return ResponseUtils.getResultsMap("No VM found in datacenter.", Outputs.RETURN_CODE_FAILURE); } } catch (Exception ex) { return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE); } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } }  }
VmService { public Map<String, String> listVMsAndTemplates(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { Map<String, ManagedObjectReference> virtualMachinesMorMap = new MorObjectHandler() .getSpecificObjectsMap(connectionResources, ManagedObjectType.VIRTUAL_MACHINE.getValue()); Set<String> virtualMachineNamesList = virtualMachinesMorMap.keySet(); if (virtualMachineNamesList.size() > 0) { return ResponseUtils.getResultsMap(ResponseUtils .getResponseStringFromCollection(virtualMachineNamesList, delimiter), Outputs.RETURN_CODE_SUCCESS); } else { return ResponseUtils.getResultsMap("No VM found in datacenter.", Outputs.RETURN_CODE_FAILURE); } } catch (Exception ex) { return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE); } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } }  Map<String, String> getOsDescriptors(HttpInputs httpInputs, VmInputs vmInputs, String delimiter); Map<String, String> createVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> deleteVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> powerOnVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> powerOffVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> listVMsAndTemplates(HttpInputs httpInputs, VmInputs vmInputs, String delimiter); Map<String, String> getVMDetails(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> updateVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> cloneVM(HttpInputs httpInputs, VmInputs vmInputs); }
VmService { public Map<String, String> listVMsAndTemplates(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { Map<String, ManagedObjectReference> virtualMachinesMorMap = new MorObjectHandler() .getSpecificObjectsMap(connectionResources, ManagedObjectType.VIRTUAL_MACHINE.getValue()); Set<String> virtualMachineNamesList = virtualMachinesMorMap.keySet(); if (virtualMachineNamesList.size() > 0) { return ResponseUtils.getResultsMap(ResponseUtils .getResponseStringFromCollection(virtualMachineNamesList, delimiter), Outputs.RETURN_CODE_SUCCESS); } else { return ResponseUtils.getResultsMap("No VM found in datacenter.", Outputs.RETURN_CODE_FAILURE); } } catch (Exception ex) { return ResponseUtils.getResultsMap(ex.toString(), Outputs.RETURN_CODE_FAILURE); } finally { if (httpInputs.isCloseSession()) { connectionResources.getConnection().disconnect(); clearConnectionFromContext(httpInputs.getGlobalSessionObject()); } } }  Map<String, String> getOsDescriptors(HttpInputs httpInputs, VmInputs vmInputs, String delimiter); Map<String, String> createVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> deleteVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> powerOnVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> powerOffVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> listVMsAndTemplates(HttpInputs httpInputs, VmInputs vmInputs, String delimiter); Map<String, String> getVMDetails(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> updateVM(HttpInputs httpInputs, VmInputs vmInputs); Map<String, String> cloneVM(HttpInputs httpInputs, VmInputs vmInputs);  }