/** * Sets the timeout for server connections. * * @param timeout the timeout to be used for connecting * @return true, if the operation was successful */ public boolean setTimeout(int timeout) { if (serviceInstance != null) { ServerConnection serverConnection = serviceInstance.getServerConnection(); if (serverConnection != null) { VimPortType vimService = serverConnection.getVimService(); if (vimService != null) { WSClient wsClient = vimService.getWsc(); if (wsClient != null) { wsClient.setConnectTimeout(timeout); wsClient.setReadTimeout(timeout); return true; } } } } return false; }
/** * Disconnects from the server. */ public void disconnect() { if (serviceInstance == null) { // not connected return; } else { ServerConnection serverConnection = serviceInstance.getServerConnection(); if (serverConnection == null) { // not connected return; } else { serviceInstance.getServerConnection().logout(); } } }
/** * Sets the timeout for server connections. * * @param timeout the timeout to be used for connecting * @return true, if the operation was successful */ public boolean setTimeout(int timeout) { if (m_serviceInstance != null) { ServerConnection serverConnection = m_serviceInstance.getServerConnection(); if (serverConnection != null) { VimPortType vimService = serverConnection.getVimService(); if (vimService != null) { WSClient wsClient = vimService.getWsc(); if (wsClient != null) { wsClient.setConnectTimeout(timeout); wsClient.setReadTimeout(timeout); return true; } } } } return false; }
/** * Disconnects from the server. */ public void disconnect() { if (m_serviceInstance == null) { // not connected return; } else { ServerConnection serverConnection = m_serviceInstance.getServerConnection(); if (serverConnection == null) { // not connected return; } else { m_serviceInstance.getServerConnection().logout(); } } }
@Test public void vSphereLocationSupplierTest() throws IOException { ServerConnection serverConnection = PowerMock.createMock(ServerConnection.class); WSClient wsClient = PowerMock.createMock(WSClient.class); ManagedObjectReference managedObjectReference = PowerMock.createMock(ManagedObjectReference.class); ServiceInstance serviceInstance = PowerMock.createMock(ServiceInstance.class); CreateAndConnectVSphereClient supplier = PowerMock.createMock(CreateAndConnectVSphereClient.class); VSphereServiceInstance vSphereServiceInstance = PowerMock.createMock(VSphereServiceInstance.class); Folder rootFolder = PowerMock.createMock(Folder.class); expect(supplier.get()).andReturn(vSphereServiceInstance); expect(vSphereServiceInstance.getInstance()).andReturn(serviceInstance); expect(serviceInstance.getRootFolder()).andReturn(rootFolder); expect(rootFolder.getServerConnection()).andReturn(serverConnection).anyTimes(); expect(rootFolder.getMOR()).andReturn(managedObjectReference); expect(serverConnection.getServiceInstance()).andReturn(serviceInstance).anyTimes(); expect(serverConnection.getVimService()).andReturn(new VimPortType(wsClient)).anyTimes(); AboutInfo aboutInfo = new AboutInfo(); aboutInfo.setApiVersion("5.1"); expect(serviceInstance.getPropertyCollector()).andReturn(new PropertyCollector(serverConnection, managedObjectReference)); expect(serviceInstance.getAboutInfo()).andReturn(aboutInfo); vSphereServiceInstance.close(); replay(supplier, vSphereServiceInstance, serviceInstance, rootFolder, serverConnection); VSphereLocationSupplier vSphereLocationSupplier = new VSphereLocationSupplier(supplier); Set<? extends Location> location = vSphereLocationSupplier.get(); Assert.assertEquals(1, location.size()); for (Location l : location) { Assert.assertEquals("default", l.getId()); } verify(supplier, vSphereServiceInstance, serviceInstance, rootFolder, serverConnection); }
@Test public void applyTest() { HostSystemToVSphereHost hostSystemToVSphereHost = new HostSystemToVSphereHost(); Assert.assertNull(hostSystemToVSphereHost.apply(null)); HostSystem vm = PowerMock.createMock(HostSystem.class); ServiceInstance si = PowerMock.createMock(ServiceInstance.class); ServerConnection sc = PowerMock.createMock(ServerConnection.class); expect(vm.getServerConnection()).andReturn(sc).anyTimes(); expect(sc.getServiceInstance()).andReturn(si).anyTimes(); replay(vm, sc, ServerConnection.class); Assert.assertNotNull(hostSystemToVSphereHost.apply(vm)); }