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());
}
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations