use of com.cloud.legacymodel.communication.command.BackupSnapshotCommand in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testBackupSnapshotCommandLibvirtException.
@Test
public void testBackupSnapshotCommandLibvirtException() {
// Simple test used to make sure the flow (LibvirtComputingResource => Request => CommandWrapper) is working.
// The code is way to big and complex. Will finish the refactor and come back to this to add more cases.
final StoragePool pool = Mockito.mock(StoragePool.class);
final String secondaryStorageUrl = "nfs:/127.0.0.1/storage/secondary";
final long accountId = 1l;
final String volumePath = "/123/vol";
final String vmName = "Test";
final int wait = 0;
final long snapshotId = 1l;
final String snapshotName = "snap";
final Long dcId = 1l;
final Long volumeId = 1l;
final Long secHostId = 1l;
final String snapshotUuid = "9a0afe7c-26a7-4585-bf87-abf82ae106d9";
final String prevBackupUuid = "003a0cc2-2e04-417a-bee0-534ef1724561";
final boolean isVolumeInactive = false;
final String prevSnapshotUuid = "1791efae-f22d-474b-87c6-92547d6c5877";
final BackupSnapshotCommand command = new BackupSnapshotCommand(secondaryStorageUrl, dcId, accountId, volumeId, snapshotId, secHostId, volumePath, pool, snapshotUuid, snapshotName, prevSnapshotUuid, prevBackupUuid, isVolumeInactive, vmName, wait);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
// final Connect conn = Mockito.mock(Connect.class);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
Aggregations