Search in sources :

Example 1 with VolumeApiService

use of com.cloud.storage.VolumeApiService 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(nullable(Long.class), nullable(Long.class), nullable(Long.class), nullable(Account.class), nullable(Boolean.class), nullable(Snapshot.LocationType.class), nullable(Boolean.class), anyObject())).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 123", exception.getDescription());
    }
}
Also used : Account(com.cloud.user.Account) ServerApiException(org.apache.cloudstack.api.ServerApiException) VolumeApiService(com.cloud.storage.VolumeApiService) Matchers.anyLong(org.mockito.Matchers.anyLong) AccountService(com.cloud.user.AccountService) ServerApiException(org.apache.cloudstack.api.ServerApiException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 2 with VolumeApiService

use of com.cloud.storage.VolumeApiService 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(nullable(Long.class), nullable(Long.class), isNull(), nullable(Account.class), nullable(Boolean.class), nullable(Snapshot.LocationType.class), nullable(Boolean.class), nullable(Map.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) Matchers.anyLong(org.mockito.Matchers.anyLong) AccountService(com.cloud.user.AccountService) HashMap(java.util.HashMap) Map(java.util.Map) ServerApiException(org.apache.cloudstack.api.ServerApiException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Aggregations

VolumeApiService (com.cloud.storage.VolumeApiService)2 Account (com.cloud.user.Account)2 AccountService (com.cloud.user.AccountService)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 Test (org.junit.Test)2 ExpectedException (org.junit.rules.ExpectedException)2 Matchers.anyLong (org.mockito.Matchers.anyLong)2 Snapshot (com.cloud.storage.Snapshot)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ResponseGenerator (org.apache.cloudstack.api.ResponseGenerator)1 SnapshotResponse (org.apache.cloudstack.api.response.SnapshotResponse)1