Search in sources :

Example 16 with NetworkUsageCommand

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

the class XcpServerWrapperTest method testNetworkUsageCommandCreate.

@Test
public void testNetworkUsageCommandCreate() {
    final Connection conn = Mockito.mock(Connection.class);
    final String privateIP = "192.168.0.10";
    final String domRName = "dom";
    final String option = "create";
    final boolean forVpc = true;
    final NetworkUsageCommand usageCommand = new NetworkUsageCommand(privateIP, domRName, option, forVpc);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(XcpServerResource.getConnection()).thenReturn(conn);
    when(XcpServerResource.networkUsage(conn, usageCommand.getPrivateIP(), "create", null)).thenReturn("success");
    final Answer answer = wrapper.execute(usageCommand, XcpServerResource);
    verify(XcpServerResource, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) Connection(com.xensource.xenapi.Connection) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) Test(org.junit.Test)

Example 17 with NetworkUsageCommand

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

the class XcpServerWrapperTest method testNetworkUsageCommandExceptiopn.

@Test
public void testNetworkUsageCommandExceptiopn() {
    final Connection conn = Mockito.mock(Connection.class);
    final String privateIP = "192.168.0.10";
    final String domRName = "dom";
    final String option = null;
    final boolean forVpc = true;
    final NetworkUsageCommand usageCommand = new NetworkUsageCommand(privateIP, domRName, option, forVpc);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(XcpServerResource.getConnection()).thenReturn(conn);
    when(XcpServerResource.networkUsage(conn, usageCommand.getPrivateIP(), "create", null)).thenThrow(new CloudRuntimeException("FAILED"));
    final Answer answer = wrapper.execute(usageCommand, XcpServerResource);
    verify(XcpServerResource, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) Test(org.junit.Test)

Aggregations

NetworkUsageCommand (com.cloud.legacymodel.communication.command.NetworkUsageCommand)17 Answer (com.cloud.legacymodel.communication.answer.Answer)13 Test (org.junit.Test)13 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)6 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)6 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)6 Connection (com.xensource.xenapi.Connection)5 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)3 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)3 Network (com.cloud.legacymodel.network.Network)3 UserStatisticsVO (com.cloud.user.UserStatisticsVO)3 DomainRouterVO (com.cloud.vm.DomainRouterVO)3 ExecutionResult (com.cloud.legacymodel.ExecutionResult)2 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)2 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)2 Nic (com.cloud.legacymodel.network.Nic)2 VpcVO (com.cloud.network.vpc.VpcVO)2 ConfigurationException (javax.naming.ConfigurationException)2 Commands (com.cloud.agent.manager.Commands)1 NetworkUsageAnswer (com.cloud.legacymodel.communication.answer.NetworkUsageAnswer)1