Search in sources :

Example 56 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class AddNetworkServiceProviderCmdTest method testCreateProviderToPhysicalNetworkFailure.

@Test
public void testCreateProviderToPhysicalNetworkFailure() throws ResourceAllocationException {
    NetworkService networkService = Mockito.mock(NetworkService.class);
    addNetworkServiceProviderCmd._networkService = networkService;
    Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn(null);
    try {
        addNetworkServiceProviderCmd.create();
    } catch (ServerApiException exception) {
        Assert.assertEquals("Failed to add service provider entity to physical network", exception.getDescription());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkService(com.cloud.network.NetworkService) Test(org.junit.Test)

Example 57 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class AddSecondaryStorageCmdTest method testExecuteForNullResult.

@Test
public void testExecuteForNullResult() throws Exception {
    StorageService resourceService = Mockito.mock(StorageService.class);
    addImageStoreCmd._storageService = resourceService;
    Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map) anyObject())).thenReturn(null);
    try {
        addImageStoreCmd.execute();
    } catch (ServerApiException exception) {
        Assert.assertEquals("Failed to add secondary storage", exception.getDescription());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageService(com.cloud.storage.StorageService) Test(org.junit.Test)

Example 58 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class CreateSnapshotCmdTest method testCreateFailure.

@Test
public void testCreateFailure() {
    AccountService accountService = Mockito.mock(AccountService.class);
    Account account = Mockito.mock(Account.class);
    Mockito.when(accountService.getAccount(anyLong())).thenReturn(account);
    VolumeApiService volumeApiService = Mockito.mock(VolumeApiService.class);
    try {
        Mockito.when(volumeApiService.takeSnapshot(anyLong(), anyLong(), anyLong(), any(Account.class), anyBoolean(), isNull(Snapshot.LocationType.class))).thenReturn(null);
    } catch (Exception e) {
        Assert.fail("Received exception when success expected " + e.getMessage());
    }
    createSnapshotCmd._accountService = accountService;
    createSnapshotCmd._volumeService = volumeApiService;
    try {
        createSnapshotCmd.execute();
    } catch (ServerApiException exception) {
        Assert.assertEquals("Failed to create snapshot due to an internal error creating snapshot for volume 1", exception.getDescription());
    }
}
Also used : Account(com.cloud.user.Account) ServerApiException(org.apache.cloudstack.api.ServerApiException) VolumeApiService(com.cloud.storage.VolumeApiService) AccountService(com.cloud.user.AccountService) ServerApiException(org.apache.cloudstack.api.ServerApiException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 59 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class RegionCmdTest method testCreateFailure.

@Test
public void testCreateFailure() {
    RegionService regionService = Mockito.mock(RegionService.class);
    Region region = Mockito.mock(Region.class);
    Mockito.when(regionService.addRegion(Matchers.anyInt(), Matchers.anyString(), Matchers.anyString())).thenReturn(null);
    addRegionCmd._regionService = regionService;
    try {
        addRegionCmd.execute();
    } catch (ServerApiException exception) {
        Assert.assertEquals("Failed to add Region", exception.getDescription());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) Region(org.apache.cloudstack.region.Region) RegionService(org.apache.cloudstack.region.RegionService) Test(org.junit.Test)

Example 60 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException 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)

Aggregations

ServerApiException (org.apache.cloudstack.api.ServerApiException)513 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)125 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)116 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)61 ArrayList (java.util.ArrayList)58 UserVm (com.cloud.uservm.UserVm)44 ListResponse (org.apache.cloudstack.api.response.ListResponse)44 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)42 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)39 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)33 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)26 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)25 Account (com.cloud.user.Account)24 Host (com.cloud.host.Host)20 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)18 Volume (com.cloud.storage.Volume)16 Test (org.junit.Test)16 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)15 VolumeResponse (org.apache.cloudstack.api.response.VolumeResponse)15 UserAccount (com.cloud.user.UserAccount)13