@Test public void getOsDescriptorsException() throws Exception { whenNew(ResponseHelper.class).withArguments(any(ConnectionResources.class), any(ManagedObjectReference.class)) .thenReturn(getResponseHelper(connectionResourcesMock, taskMorMock, true)); when(connectionResourcesMock.getMoRefHandler()).thenReturn(moRefHandlerMock); when(moRefHandlerMock.entityProps(any(ManagedObjectReference.class), any(String[].class))).thenReturn(entityPropsMock); when(entityPropsMock.get(anyString())).thenReturn(environmentBrowserMorMock); when(vimPortMock.queryConfigOption(any(ManagedObjectReference.class), anyString(), any(ManagedObjectReference.class))) .thenReturn(null); List<GuestOsDescriptor> guestOSDescriptors = new ArrayList<>(); populateOsDescriptorsList(guestOSDescriptors, "firstDescriptorToBeTested"); populateOsDescriptorsList(guestOSDescriptors, "secondDescriptorToBeTested"); when(configOptionsMock.getGuestOSDescriptor()).thenReturn(guestOSDescriptors); Map<String, String> results = new VmService().getOsDescriptors(httpInputsMock, new VmInputs.VmInputsBuilder().withDataCenterName("datacenter").withHostname("hostname").build(), ""); verify(connectionResourcesMock, times(1)).getMoRefHandler(); verify(moRefHandlerMock, times(1)).entityProps(any(ManagedObjectReference.class), any(String[].class)); verify(entityPropsMock, times(1)).get(anyString()); verify(connectionResourcesMock, times(1)).getVimPortType(); verify(vimPortMock, times(1)).queryConfigOption(any(ManagedObjectReference.class), anyString(), any(ManagedObjectReference.class)); verify(configOptionsMock, never()).getGuestOSDescriptor(); assertNotNull(results); assertEquals(-1, Integer.parseInt(results.get("returnCode"))); assertEquals("java.lang.NullPointerException", results.get("returnResult")); }
public Map<String, String> getOsDescriptors(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { ManagedObjectReference environmentBrowserMor = new MorObjectHandler() .getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue()); VirtualMachineConfigOption configOptions = connectionResources.getVimPortType() .queryConfigOption(environmentBrowserMor, null, connectionResources.getHostMor()); List<GuestOsDescriptor> guestOSDescriptors = configOptions.getGuestOSDescriptor(); return ResponseUtils.getResultsMap(ResponseUtils.getResponseStringFromCollection(guestOSDescriptors, delimiter), Outputs.RETURN_CODE_SUCCESS); } 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> getOsDescriptors(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { ManagedObjectReference environmentBrowserMor = new MorObjectHandler() .getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue()); VirtualMachineConfigOption configOptions = connectionResources.getVimPortType() .queryConfigOption(environmentBrowserMor, null, connectionResources.getHostMor()); List<GuestOsDescriptor> guestOSDescriptors = configOptions.getGuestOSDescriptor(); return ResponseUtils.getResultsMap(ResponseUtils.getResponseStringFromCollection(guestOSDescriptors, delimiter), Outputs.RETURN_CODE_SUCCESS); } 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> getOsDescriptors(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { ManagedObjectReference environmentBrowserMor = new MorObjectHandler() .getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue()); VirtualMachineConfigOption configOptions = connectionResources.getVimPortType() .queryConfigOption(environmentBrowserMor, null, connectionResources.getHostMor()); List<GuestOsDescriptor> guestOSDescriptors = configOptions.getGuestOSDescriptor(); return ResponseUtils.getResultsMap(ResponseUtils.getResponseStringFromCollection(guestOSDescriptors, delimiter), Outputs.RETURN_CODE_SUCCESS); } 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> getOsDescriptors(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { ManagedObjectReference environmentBrowserMor = new MorObjectHandler() .getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue()); VirtualMachineConfigOption configOptions = connectionResources.getVimPortType() .queryConfigOption(environmentBrowserMor, null, connectionResources.getHostMor()); List<GuestOsDescriptor> guestOSDescriptors = configOptions.getGuestOSDescriptor(); return ResponseUtils.getResultsMap(ResponseUtils.getResponseStringFromCollection(guestOSDescriptors, delimiter), Outputs.RETURN_CODE_SUCCESS); } 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> getOsDescriptors(HttpInputs httpInputs, VmInputs vmInputs, String delimiter) throws Exception { ConnectionResources connectionResources = new ConnectionResources(httpInputs, vmInputs); try { ManagedObjectReference environmentBrowserMor = new MorObjectHandler() .getEnvironmentBrowser(connectionResources, ManagedObjectType.ENVIRONMENT_BROWSER.getValue()); VirtualMachineConfigOption configOptions = connectionResources.getVimPortType() .queryConfigOption(environmentBrowserMor, null, connectionResources.getHostMor()); List<GuestOsDescriptor> guestOSDescriptors = configOptions.getGuestOSDescriptor(); return ResponseUtils.getResultsMap(ResponseUtils.getResponseStringFromCollection(guestOSDescriptors, delimiter), Outputs.RETURN_CODE_SUCCESS); } 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);  }