use of com.cloud.legacymodel.communication.command.CreatePrivateTemplateFromVolumeCommand in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromVolumeCommand.
@Test
public void testCreatePrivateTemplateFromVolumeCommand() {
// 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 templateId = 1l;
final long accountId = 1l;
final String userSpecifiedName = "User";
final String uniqueName = "Unique";
final String volumePath = "/123/vol";
final String vmName = "Test";
final int wait = 0;
final CreatePrivateTemplateFromVolumeCommand command = new CreatePrivateTemplateFromVolumeCommand(pool, secondaryStorageUrl, templateId, accountId, userSpecifiedName, uniqueName, volumePath, vmName, wait);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool secondaryStorage = Mockito.mock(KvmStoragePool.class);
// final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl)).thenReturn(secondaryStorage);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPrimaryStoragePoolNameLabel())).thenThrow(new CloudRuntimeException("error"));
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByUri(secondaryStorageUrl);
verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), command.getPrimaryStoragePoolNameLabel());
}
Aggregations