Search in sources :

Example 11 with ResponseGenerator

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

the class CreateSnapshotCmdTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    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);
    Snapshot snapshot = Mockito.mock(Snapshot.class);
    try {
        Mockito.when(volumeApiService.takeSnapshot(anyLong(), anyLong(), anyLong(), any(Account.class), anyBoolean(), isNull(Snapshot.LocationType.class))).thenReturn(snapshot);
    } catch (Exception e) {
        Assert.fail("Received exception when success expected " + e.getMessage());
    }
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    SnapshotResponse snapshotResponse = Mockito.mock(SnapshotResponse.class);
    Mockito.when(responseGenerator.createSnapshotResponse(snapshot)).thenReturn(snapshotResponse);
    Mockito.doNothing().when(snapshotResponse).setAccountName(anyString());
    createSnapshotCmd._accountService = accountService;
    createSnapshotCmd._responseGenerator = responseGenerator;
    createSnapshotCmd._volumeService = volumeApiService;
    try {
        createSnapshotCmd.execute();
    } catch (Exception e) {
        Assert.fail("Received exception when success expected " + e.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) Snapshot(com.cloud.storage.Snapshot) ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) SnapshotResponse(org.apache.cloudstack.api.response.SnapshotResponse) 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)

Aggregations

ResponseGenerator (org.apache.cloudstack.api.ResponseGenerator)11 Test (org.junit.Test)7 Before (org.junit.Before)4 ResourceService (com.cloud.resource.ResourceService)3 ManagementService (com.cloud.server.ManagementService)2 UserVm (com.cloud.uservm.UserVm)2 UserVmService (com.cloud.vm.UserVmService)2 LinkedList (java.util.LinkedList)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)2 ExpectedException (org.junit.rules.ExpectedException)2 ConfigurationService (com.cloud.configuration.ConfigurationService)1 NetworkService (com.cloud.network.NetworkService)1 Cluster (com.cloud.org.Cluster)1 ImageStore (com.cloud.storage.ImageStore)1 Snapshot (com.cloud.storage.Snapshot)1 StorageService (com.cloud.storage.StorageService)1 VolumeApiService (com.cloud.storage.VolumeApiService)1 Account (com.cloud.user.Account)1 AccountService (com.cloud.user.AccountService)1