Search in sources :

Example 1 with GetVmIpAddressCommand

use of com.cloud.legacymodel.communication.command.GetVmIpAddressCommand in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testGetVmIpAddressCommand.

@Test
public void testGetVmIpAddressCommand() throws XenAPIException, XmlRpcException {
    final Connection conn = Mockito.mock(Connection.class);
    final VM vm = Mockito.mock(VM.class);
    final VMGuestMetrics mtr = Mockito.mock(VMGuestMetrics.class);
    final VMGuestMetrics.Record rec = Mockito.mock(VMGuestMetrics.Record.class);
    final Map<String, String> vmIpsMap = new HashMap<>();
    vmIpsMap.put("Test", "127.0.0.1");
    rec.networks = vmIpsMap;
    final GetVmIpAddressCommand getVmIpAddrCmd = new GetVmIpAddressCommand("Test", "127.0.0.1/24", false);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(this.citrixResourceBase.getConnection()).thenReturn(conn);
    when(this.citrixResourceBase.getVM(conn, getVmIpAddrCmd.getVmName())).thenReturn(vm);
    when(vm.getGuestMetrics(conn)).thenReturn(mtr);
    when(mtr.getRecord(conn)).thenReturn(rec);
    final Answer answer = wrapper.execute(getVmIpAddrCmd, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) VMGuestMetrics(com.xensource.xenapi.VMGuestMetrics) HashMap(java.util.HashMap) GetVmIpAddressCommand(com.cloud.legacymodel.communication.command.GetVmIpAddressCommand) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)1 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 GetVmIpAddressCommand (com.cloud.legacymodel.communication.command.GetVmIpAddressCommand)1 Connection (com.xensource.xenapi.Connection)1 VM (com.xensource.xenapi.VM)1 VMGuestMetrics (com.xensource.xenapi.VMGuestMetrics)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1