Search in sources :

Example 1 with UserVmService

use of com.cloud.vm.UserVmService in project cloudstack by apache.

the class UpdateVmNicIpTest method testFailure.

@Test
public void testFailure() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    UserVmService userVmService = Mockito.mock(UserVmService.class);
    updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class);
    Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(null);
    updateVmNicIpCmd._userVmService = userVmService;
    updateVmNicIpCmd._responseGenerator = responseGenerator;
    try {
        updateVmNicIpCmd.execute();
    } catch (ServerApiException exception) {
        Assert.assertEquals("Failed to update ip address on vm NIC. Refer to server logs for details.", exception.getDescription());
    }
}
Also used : UserVmService(com.cloud.vm.UserVmService) ServerApiException(org.apache.cloudstack.api.ServerApiException) UpdateVmNicIpCmd(org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd) Test(org.junit.Test)

Example 2 with UserVmService

use of com.cloud.vm.UserVmService in project cloudstack by apache.

the class ScaleVMCmdTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    UserVmService userVmService = Mockito.mock(UserVmService.class);
    UserVm userVm = Mockito.mock(UserVm.class);
    try {
        Mockito.when(userVmService.upgradeVirtualMachine(scaleVMCmd)).thenReturn(userVm);
    } catch (Exception e) {
        Assert.fail("Received exception when success expected " + e.getMessage());
    }
    ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class);
    scaleVMCmd._responseGenerator = responseGenerator;
    UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
    //List<UserVmResponse> list = Mockito.mock(UserVmResponse.class);
    //list.add(userVmResponse);
    //LinkedList<UserVmResponse> mockedList = Mockito.mock(LinkedList.class);
    //Mockito.when(mockedList.get(0)).thenReturn(userVmResponse);
    List<UserVmResponse> list = new LinkedList<UserVmResponse>();
    list.add(userVmResponse);
    Mockito.when(responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm)).thenReturn(list);
    scaleVMCmd._userVmService = userVmService;
    scaleVMCmd.execute();
}
Also used : UserVm(com.cloud.uservm.UserVm) UserVmService(com.cloud.vm.UserVmService) ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ExpectedException(org.junit.rules.ExpectedException) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with UserVmService

use of com.cloud.vm.UserVmService in project cloudstack by apache.

the class ScaleVMCmdTest method testCreateFailure.

@Test
public void testCreateFailure() {
    UserVmService userVmService = Mockito.mock(UserVmService.class);
    try {
        Mockito.when(userVmService.upgradeVirtualMachine(scaleVMCmd)).thenReturn(null);
    } catch (Exception e) {
        Assert.fail("Received exception when success expected " + e.getMessage());
    }
    scaleVMCmd._userVmService = userVmService;
    try {
        scaleVMCmd.execute();
    } catch (ServerApiException exception) {
        Assert.assertEquals("Failed to scale vm", exception.getDescription());
    }
}
Also used : UserVmService(com.cloud.vm.UserVmService) ServerApiException(org.apache.cloudstack.api.ServerApiException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 4 with UserVmService

use of com.cloud.vm.UserVmService in project cloudstack by apache.

the class UpdateVmNicIpTest method testSuccess.

@Test
public void testSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    UserVmService userVmService = Mockito.mock(UserVmService.class);
    updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class);
    UserVm userVm = Mockito.mock(UserVm.class);
    Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(userVm);
    updateVmNicIpCmd._userVmService = userVmService;
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    List<UserVmResponse> list = new LinkedList<UserVmResponse>();
    UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
    list.add(userVmResponse);
    Mockito.when(responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm)).thenReturn(list);
    updateVmNicIpCmd._responseGenerator = responseGenerator;
    updateVmNicIpCmd.execute();
}
Also used : UserVm(com.cloud.uservm.UserVm) UserVmService(com.cloud.vm.UserVmService) ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) UpdateVmNicIpCmd(org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

UserVmService (com.cloud.vm.UserVmService)4 Test (org.junit.Test)4 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 UserVm (com.cloud.uservm.UserVm)2 LinkedList (java.util.LinkedList)2 ResponseGenerator (org.apache.cloudstack.api.ResponseGenerator)2 UpdateVmNicIpCmd (org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd)2 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)2 ExpectedException (org.junit.rules.ExpectedException)2