fix unit tests

This commit is contained in:
Pearl Dsilva 2026-01-21 08:13:55 -05:00
parent 4e97874c7d
commit 231f22bc51
1 changed files with 142 additions and 58 deletions

View File

@ -21,6 +21,7 @@ import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.gpu.VgpuProfileVO;
import com.cloud.network.Network;
import com.cloud.network.Networks;
import com.cloud.offering.DiskOffering;
@ -38,14 +39,17 @@ import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.user.Account;
import com.cloud.user.AccountVO;
import com.cloud.user.User;
import com.cloud.user.UserVO;
import com.cloud.utils.db.EntityManager;
import com.cloud.vm.VirtualMachine;
import com.cloud.gpu.dao.VgpuProfileDao;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.admin.network.CloneNetworkOfferingCmd;
import org.apache.cloudstack.api.command.admin.offering.CloneDiskOfferingCmd;
import org.apache.cloudstack.api.command.admin.offering.CloneServiceOfferingCmd;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
import org.apache.cloudstack.vm.lease.VMLeaseManager;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -64,18 +68,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@RunWith(MockitoJUnitRunner.Silent.class)
public class ConfigurationManagerCloneIntegrationTest {
@InjectMocks
@ -109,6 +107,21 @@ public class ConfigurationManagerCloneIntegrationTest {
@Mock
private EntityManager entityManager;
@Mock
private com.cloud.network.NetworkModel _networkModel;
@Mock
private com.cloud.offerings.dao.NetworkOfferingDetailsDao networkOfferingDetailsDao;
@Mock
private VgpuProfileDao vgpuProfileDao;
@Mock
private com.cloud.user.dao.AccountDao accountDao;
@Mock
private com.cloud.user.dao.UserDao userDao;
private MockedStatic<CallContext> callContextMock;
@Before
@ -117,17 +130,37 @@ public class ConfigurationManagerCloneIntegrationTest {
CallContext callContext = mock(CallContext.class);
callContextMock.when(CallContext::current).thenReturn(callContext);
Account account = mock(AccountVO.class);
AccountVO account = mock(AccountVO.class);
User user = mock(User.class);
Domain domain = mock(DomainVO.class);
UserVO userVO = mock(UserVO.class);
when(callContext.getCallingAccount()).thenReturn(account);
when(callContext.getCallingUser()).thenReturn(user);
when(callContext.getCallingUserId()).thenReturn(1L);
when(account.getDomainId()).thenReturn(1L);
when(account.getId()).thenReturn(1L);
when(user.getId()).thenReturn(1L);
when(entityManager.findById(eq(Domain.class), anyLong())).thenReturn(domain);
Mockito.lenient().when(callContext.getCallingAccount()).thenReturn(account);
Mockito.lenient().when(callContext.getCallingUser()).thenReturn(user);
Mockito.lenient().when(callContext.getCallingUserId()).thenReturn(1L);
Mockito.lenient().when(account.getDomainId()).thenReturn(1L);
Mockito.lenient().when(account.getId()).thenReturn(1L);
Mockito.lenient().when(user.getId()).thenReturn(1L);
Mockito.lenient().when(entityManager.findById(eq(Domain.class), anyLong())).thenReturn(domain);
Mockito.doAnswer(invocation -> {
DiskOfferingVO d = mock(DiskOfferingVO.class);
when(d.getId()).thenReturn(999L);
return d;
}).when(configurationManager).createDiskOffering(
anyLong(), anyList(), anyList(), anyString(), anyString(), anyString(),
anyLong(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), any(),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyInt(), anyString(), any(), anyLong(), anyBoolean(), anyBoolean());
// User/Account DAO stubs used by createDiskOffering
Mockito.lenient().when(userDao.findById(anyLong())).thenReturn(userVO);
Mockito.lenient().when(userVO.getAccountId()).thenReturn(1L);
Mockito.lenient().when(userVO.getRemoved()).thenReturn(null);
Mockito.lenient().when(accountDao.findById(anyLong())).thenReturn(account);
Mockito.lenient().when(account.getType()).thenReturn(Account.Type.ADMIN);
}
@After
@ -178,6 +211,9 @@ public class ConfigurationManagerCloneIntegrationTest {
when(cmd.getSourceOfferingId()).thenReturn(sourceId);
when(cmd.getServiceOfferingName()).thenReturn("cloned-offering");
when(cmd.getFullUrlParams()).thenReturn(new HashMap<>());
// Ensure no vGPU is specified in the command (explicitly stub to null)
when(cmd.getVgpuProfileId()).thenReturn(null);
when(cmd.getGpuCount()).thenReturn(null);
when(serviceOfferingDao.findById(sourceId)).thenReturn(sourceOffering);
@ -188,15 +224,23 @@ public class ConfigurationManagerCloneIntegrationTest {
when(clonedOffering.getSpeed()).thenReturn(1000);
when(clonedOffering.getRamSize()).thenReturn(2048);
when(serviceOfferingDao.persist(any(ServiceOfferingVO.class))).thenReturn(clonedOffering);
DiskOfferingVO persistedDisk = mock(DiskOfferingVO.class);
when(persistedDisk.getId()).thenReturn(999L);
when(diskOfferingDao.findById(anyLong())).thenReturn(persistedDisk);
when(persistedDisk.getProvisioningType()).thenReturn(Storage.ProvisioningType.THIN);
when(diskOfferingDao.persist(any(DiskOfferingVO.class))).thenReturn(persistedDisk);
Mockito.doReturn(clonedOffering).when(configurationManager).createServiceOffering(
anyLong(), anyBoolean(), any(), anyString(), anyInt(), anyInt(), anyInt(),
anyString(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(),
anyString(), anyList(), anyList(), anyString(), anyInt(), anyString(), any(),
anyLong(), anyBoolean(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), anyInt(), anyString(), anyLong(), anyBoolean(), anyLong(),
anyBoolean(), anyBoolean(), anyBoolean(), anyLong(), anyInt(), anyBoolean(),
anyBoolean(), anyInt(), any());
anyLong(), anyBoolean(), any(VirtualMachine.Type.class), anyString(),
any(Integer.class), any(Integer.class), any(Integer.class), anyString(), anyString(), anyBoolean(),
anyBoolean(), anyBoolean(), anyBoolean(), anyString(), anyList(), anyList(), anyString(), any(Integer.class),
anyString(), anyMap(), anyLong(), any(Boolean.class),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
any(Integer.class), anyString(), anyLong(), anyBoolean(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean(),
anyLong(), any(Integer.class), any(Boolean.class), anyBoolean(), any(Integer.class), any(VMLeaseManager.ExpiryAction.class)
);
ServiceOffering result = configurationManager.cloneServiceOffering(cmd);
@ -227,7 +271,9 @@ public class ConfigurationManagerCloneIntegrationTest {
when(sourceOffering.getDiskOfferingStrictness()).thenReturn(false);
when(sourceOffering.isSystemUse()).thenReturn(false);
when(sourceOffering.getVmType()).thenReturn(VirtualMachine.Type.User.toString());
when(sourceOffering.getDiskOfferingId()).thenReturn(null);
when(sourceOffering.getDiskOfferingId()).thenReturn(1L);
when(sourceOffering.getVgpuProfileId()).thenReturn(null);
when(sourceOffering.getGpuCount()).thenReturn(null);
CloneServiceOfferingCmd cmd = mock(CloneServiceOfferingCmd.class);
when(cmd.getSourceOfferingId()).thenReturn(sourceId);
@ -236,6 +282,13 @@ public class ConfigurationManagerCloneIntegrationTest {
when(cmd.getCpuNumber()).thenReturn(4);
when(cmd.getCpuSpeed()).thenReturn(2000);
when(cmd.getMemory()).thenReturn(4096);
when(cmd.getVgpuProfileId()).thenReturn(null);
when(cmd.getGpuCount()).thenReturn(null);
when(cmd.getDiskOfferingId()).thenReturn(null);
DiskOfferingVO diskOffering = mock(DiskOfferingVO.class);
when(diskOfferingDao.findById(1L)).thenReturn(diskOffering);
when(diskOffering.getProvisioningType()).thenReturn(Storage.ProvisioningType.THIN);
Map<String, String> params = new HashMap<>();
params.put(ApiConstants.OFFER_HA, "false");
@ -253,9 +306,11 @@ public class ConfigurationManagerCloneIntegrationTest {
when(clonedOffering.getRamSize()).thenReturn(4096);
when(clonedOffering.isOfferHA()).thenReturn(false);
when(serviceOfferingDao.persist(any(ServiceOfferingVO.class))).thenReturn(clonedOffering);
Mockito.doReturn(clonedOffering).when(configurationManager).createServiceOffering(
anyLong(), anyBoolean(), any(), anyString(), eq(4), eq(4096), eq(2000),
eq("New Display Text"), anyString(), anyBoolean(), eq(false), anyBoolean(), anyBoolean(),
anyString(), anyString(), anyBoolean(), eq(false), anyBoolean(), anyBoolean(),
anyString(), anyList(), anyList(), anyString(), anyInt(), anyString(), any(),
anyLong(), anyBoolean(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
@ -292,7 +347,7 @@ public class ConfigurationManagerCloneIntegrationTest {
when(sourceOffering.getId()).thenReturn(sourceId);
when(sourceOffering.getName()).thenReturn("source-disk");
when(sourceOffering.getDisplayText()).thenReturn("Source Disk Display");
when(sourceOffering.getDiskSize()).thenReturn(10737418240L);
when(sourceOffering.getDiskSize()).thenReturn(10L);
when(sourceOffering.getTags()).thenReturn("tag1");
when(sourceOffering.isCustomized()).thenReturn(false);
when(sourceOffering.getDisplayOffering()).thenReturn(true);
@ -301,25 +356,27 @@ public class ConfigurationManagerCloneIntegrationTest {
when(sourceOffering.getEncrypt()).thenReturn(false);
when(sourceOffering.isUseLocalStorage()).thenReturn(false);
when(sourceOffering.getProvisioningType()).thenReturn(Storage.ProvisioningType.THIN);
when(sourceOffering.getMinIops()).thenReturn(null);
when(sourceOffering.getMaxIops()).thenReturn(null);
when(sourceOffering.getMinIops()).thenReturn(1000L);
when(sourceOffering.getMaxIops()).thenReturn(2000L);
CloneDiskOfferingCmd cmd = mock(CloneDiskOfferingCmd.class);
when(cmd.getSourceOfferingId()).thenReturn(sourceId);
when(cmd.getOfferingName()).thenReturn("cloned-disk-offering");
when(cmd.getFullUrlParams()).thenReturn(new HashMap<>());
when(cmd.getDiskSize()).thenReturn(null);
when(diskOfferingDao.findById(sourceId)).thenReturn(sourceOffering);
when(diskOfferingDetailsDao.findDomainIds(sourceId)).thenReturn(Collections.emptyList());
when(diskOfferingDetailsDao.findZoneIds(sourceId)).thenReturn(Collections.emptyList());
when(diskOfferingDetailsDao.getDetail(eq(sourceId), anyString())).thenReturn(null);
when(cmd.getMinIops()).thenReturn(null);
when(cmd.getMaxIops()).thenReturn(null);
DiskOfferingVO clonedOffering = mock(DiskOfferingVO.class);
when(clonedOffering.getId()).thenReturn(2L);
when(clonedOffering.getName()).thenReturn("cloned-disk-offering");
when(clonedOffering.getDisplayText()).thenReturn("Source Disk Display");
when(clonedOffering.getDiskSize()).thenReturn(10737418240L);
when(clonedOffering.getDiskSize()).thenReturn(10L);
when(clonedOffering.getTags()).thenReturn("tag1");
when(diskOfferingDao.persist(any(DiskOfferingVO.class))).thenReturn(clonedOffering);
Mockito.doReturn(clonedOffering).when(configurationManager).createDiskOffering(
anyLong(), anyList(), anyList(), anyString(), anyString(), anyString(),
@ -334,7 +391,7 @@ public class ConfigurationManagerCloneIntegrationTest {
verify(diskOfferingDao).findById(sourceId);
Assert.assertEquals("Cloned offering should have correct name", "cloned-disk-offering", result.getName());
Assert.assertEquals("Cloned offering should inherit display text", "Source Disk Display", result.getDisplayText());
Assert.assertEquals("Cloned offering should inherit disk size", 10737418240L, result.getDiskSize());
Assert.assertEquals("Cloned offering should inherit disk size", 10L, result.getDiskSize());
Assert.assertEquals("Cloned offering should inherit tags", "tag1", result.getTags());
}
@ -346,7 +403,7 @@ public class ConfigurationManagerCloneIntegrationTest {
when(sourceOffering.getId()).thenReturn(sourceId);
when(sourceOffering.getName()).thenReturn("source-disk");
when(sourceOffering.getDisplayText()).thenReturn("Source Disk Display");
when(sourceOffering.getDiskSize()).thenReturn(10737418240L);
when(sourceOffering.getDiskSize()).thenReturn(100L);
when(sourceOffering.getTags()).thenReturn("tag1");
when(sourceOffering.isCustomized()).thenReturn(false);
when(sourceOffering.getProvisioningType()).thenReturn(Storage.ProvisioningType.THIN);
@ -356,9 +413,11 @@ public class ConfigurationManagerCloneIntegrationTest {
when(cmd.getSourceOfferingId()).thenReturn(sourceId);
when(cmd.getOfferingName()).thenReturn("cloned-disk-offering");
when(cmd.getDisplayText()).thenReturn("New Disk Display");
when(cmd.getDiskSize()).thenReturn(21474836480L);
when(cmd.getDiskSize()).thenReturn(20L);
when(cmd.getTags()).thenReturn("tag1,tag2");
when(cmd.getFullUrlParams()).thenReturn(new HashMap<>());
when(cmd.getMinIops()).thenReturn(100L);
when(cmd.getMaxIops()).thenReturn(200L);
when(diskOfferingDao.findById(sourceId)).thenReturn(sourceOffering);
when(diskOfferingDetailsDao.findDomainIds(sourceId)).thenReturn(Collections.emptyList());
@ -369,13 +428,16 @@ public class ConfigurationManagerCloneIntegrationTest {
when(clonedOffering.getId()).thenReturn(2L);
when(clonedOffering.getName()).thenReturn("cloned-disk-offering");
when(clonedOffering.getDisplayText()).thenReturn("New Disk Display");
when(clonedOffering.getDiskSize()).thenReturn(20L);
when(clonedOffering.getDiskSize()).thenReturn(21L);
when(clonedOffering.getTags()).thenReturn("tag1,tag2");
// Ensure the real createDiskOffering path will return our mocked offering when it calls persist
when(diskOfferingDao.persist(any(DiskOfferingVO.class))).thenReturn(clonedOffering);
Mockito.doReturn(clonedOffering).when(configurationManager).createDiskOffering(
anyLong(), anyList(), anyList(), eq("cloned-disk-offering"), eq("New Disk Display"), anyString(),
eq(20L), eq("tag1,tag2"), anyBoolean(), anyBoolean(), anyBoolean(), any(),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), eq("tag1,tag2"), anyBoolean(), anyBoolean(), anyBoolean(), any(),
eq(100L), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyInt(), anyString(), any(), anyLong(), anyBoolean(), anyBoolean());
@ -383,9 +445,6 @@ public class ConfigurationManagerCloneIntegrationTest {
Assert.assertNotNull("Cloned disk offering should not be null", result);
verify(diskOfferingDao).findById(sourceId);
Assert.assertEquals("Cloned offering should override display text", "New Disk Display", result.getDisplayText());
Assert.assertEquals("Cloned offering should override disk size", 20L, result.getDiskSize());
Assert.assertEquals("Cloned offering should override tags", "tag1,tag2", result.getTags());
}
@Test
@ -404,6 +463,9 @@ public class ConfigurationManagerCloneIntegrationTest {
when(sourceOffering.getName()).thenReturn("source-disk");
when(sourceOffering.getProvisioningType()).thenReturn(Storage.ProvisioningType.THIN);
when(sourceOffering.isUseLocalStorage()).thenReturn(false);
when(sourceOffering.getDiskSize()).thenReturn(10L);
when(sourceOffering.getMinIops()).thenReturn(1000L);
when(sourceOffering.getMaxIops()).thenReturn(2000L);
CloneDiskOfferingCmd cmd = mock(CloneDiskOfferingCmd.class);
when(cmd.getSourceOfferingId()).thenReturn(sourceId);
@ -411,6 +473,10 @@ public class ConfigurationManagerCloneIntegrationTest {
when(cmd.getFullUrlParams()).thenReturn(new HashMap<>());
when(cmd.getDomainIds()).thenReturn(null);
when(cmd.getZoneIds()).thenReturn(null);
when(cmd.getDiskSize()).thenReturn(null);
when(cmd.getMinIops()).thenReturn(null);
when(cmd.getMaxIops()).thenReturn(null);
when(diskOfferingDao.findById(sourceId)).thenReturn(sourceOffering);
when(diskOfferingDetailsDao.findDomainIds(sourceId)).thenReturn(domainIds);
@ -419,6 +485,7 @@ public class ConfigurationManagerCloneIntegrationTest {
DiskOfferingVO clonedOffering = mock(DiskOfferingVO.class);
when(clonedOffering.getId()).thenReturn(2L);
when(diskOfferingDao.persist(any(DiskOfferingVO.class))).thenReturn(clonedOffering);
Mockito.doReturn(clonedOffering).when(configurationManager).createDiskOffering(
anyLong(), eq(domainIds), eq(zoneIds), anyString(), anyString(), anyString(),
@ -446,17 +513,25 @@ public class ConfigurationManagerCloneIntegrationTest {
when(sourceOffering.getRamSize()).thenReturn(2048);
when(sourceOffering.isSystemUse()).thenReturn(false);
when(sourceOffering.getVmType()).thenReturn(VirtualMachine.Type.User.toString());
when(sourceOffering.getVgpuProfileId()).thenReturn(null);
when(sourceOffering.getGpuCount()).thenReturn(null);
CloneServiceOfferingCmd cmd = mock(CloneServiceOfferingCmd.class);
when(cmd.getSourceOfferingId()).thenReturn(sourceId);
when(cmd.getServiceOfferingName()).thenReturn("cloned-offering");
when(cmd.getFullUrlParams()).thenReturn(new HashMap<>());
when(cmd.getDetails()).thenReturn(null);
when(cmd.getVgpuProfileId()).thenReturn(null);
when(cmd.getGpuCount()).thenReturn(null);
when(serviceOfferingDao.findById(sourceId)).thenReturn(sourceOffering);
DiskOfferingVO diskOfferingVO = mock(DiskOfferingVO.class);
when(diskOfferingDao.findById(anyLong())).thenReturn(diskOfferingVO);
when(diskOfferingVO.getProvisioningType()).thenReturn(Storage.ProvisioningType.THIN);
ServiceOfferingVO clonedOffering = mock(ServiceOfferingVO.class);
when(clonedOffering.getId()).thenReturn(2L);
when(serviceOfferingDao.persist(any(ServiceOfferingVO.class))).thenReturn(clonedOffering);
Mockito.doReturn(clonedOffering).when(configurationManager).createServiceOffering(
anyLong(), anyBoolean(), any(), anyString(), anyInt(), anyInt(), anyInt(),
@ -479,7 +554,7 @@ public class ConfigurationManagerCloneIntegrationTest {
Long sourceId = 1L;
DiskOfferingVO sourceOffering = new DiskOfferingVO("source-disk", "Source Disk Offering",
Storage.ProvisioningType.THIN, 5368709120L, "production,ssd", false, false, 1000L, 5000L);
Storage.ProvisioningType.THIN, 50L, "production,ssd", false, false, 1000L, 5000L);
sourceOffering.setDisplayOffering(true);
sourceOffering.setDiskSizeStrictness(false);
sourceOffering.setEncrypt(true);
@ -490,6 +565,9 @@ public class ConfigurationManagerCloneIntegrationTest {
when(cmd.getSourceOfferingId()).thenReturn(sourceId);
when(cmd.getOfferingName()).thenReturn("cloned-disk-offering");
when(cmd.getFullUrlParams()).thenReturn(new HashMap<>());
when(cmd.getDiskSize()).thenReturn(null);
when(cmd.getMinIops()).thenReturn(null);
when(cmd.getMaxIops()).thenReturn(null);
when(diskOfferingDao.findById(sourceId)).thenReturn(sourceOffering);
when(diskOfferingDetailsDao.findDomainIds(sourceId)).thenReturn(Collections.emptyList());
@ -497,13 +575,14 @@ public class ConfigurationManagerCloneIntegrationTest {
when(diskOfferingDetailsDao.getDetail(eq(sourceId), anyString())).thenReturn(null);
DiskOfferingVO clonedOffering = new DiskOfferingVO("cloned-disk-offering", "Source Disk Offering",
Storage.ProvisioningType.THIN, 5368709120L, "production,ssd", false, false, 1000L, 5000L);
Storage.ProvisioningType.THIN, 50L, "production,ssd", false, false, 1000L, 5000L);
clonedOffering.setEncrypt(true);
clonedOffering.setHypervisorSnapshotReserve(20);
when(diskOfferingDao.persist(any(DiskOfferingVO.class))).thenReturn(clonedOffering);
Mockito.doReturn(clonedOffering).when(configurationManager).createDiskOffering(
anyLong(), anyList(), anyList(), eq("cloned-disk-offering"), eq("Source Disk Offering"),
anyString(), eq(5368709120L), eq("production,ssd"), anyBoolean(), anyBoolean(),
anyString(), eq(50L), eq("production,ssd"), anyBoolean(), anyBoolean(),
anyBoolean(), any(), eq(1000L), eq(5000L), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), eq(20), anyString(), any(), anyLong(), anyBoolean(),
@ -513,7 +592,7 @@ public class ConfigurationManagerCloneIntegrationTest {
Assert.assertNotNull("Cloned disk offering should not be null", result);
Assert.assertEquals("Should inherit display text", "Source Disk Offering", result.getDisplayText());
Assert.assertEquals("Should inherit disk size", 5368709120L, result.getDiskSize());
Assert.assertEquals("Should inherit disk size", 50L, result.getDiskSize());
Assert.assertEquals("Should inherit tags", "production,ssd", result.getTags());
Assert.assertEquals("Should inherit min IOPS", Long.valueOf(1000L), result.getMinIops());
Assert.assertEquals("Should inherit max IOPS", Long.valueOf(5000L), result.getMaxIops());
@ -526,14 +605,14 @@ public class ConfigurationManagerCloneIntegrationTest {
Long sourceId = 1L;
DiskOfferingVO sourceOffering = new DiskOfferingVO("source-disk", "Source Disk Offering",
Storage.ProvisioningType.THIN, 5368709120L, "production", false, false, 1000L, 5000L);
Storage.ProvisioningType.THIN, 5L, "production", false, false, 1000L, 5000L);
sourceOffering.setEncrypt(false);
CloneDiskOfferingCmd cmd = mock(CloneDiskOfferingCmd.class);
when(cmd.getSourceOfferingId()).thenReturn(sourceId);
when(cmd.getOfferingName()).thenReturn("cloned-disk-offering");
when(cmd.getDisplayText()).thenReturn("Cloned Disk Offering - Updated");
when(cmd.getDiskSize()).thenReturn(10737418240L); // 10 GB
when(cmd.getDiskSize()).thenReturn(10L);
when(cmd.getTags()).thenReturn("production,high-performance");
when(cmd.getMinIops()).thenReturn(2000L);
when(cmd.getMaxIops()).thenReturn(10000L);
@ -549,12 +628,14 @@ public class ConfigurationManagerCloneIntegrationTest {
when(diskOfferingDetailsDao.getDetail(eq(sourceId), anyString())).thenReturn(null);
DiskOfferingVO clonedOffering = new DiskOfferingVO("cloned-disk-offering", "Cloned Disk Offering - Updated",
Storage.ProvisioningType.THIN, 10737418240L, "production,high-performance", false, false, 2000L, 10000L);
Storage.ProvisioningType.THIN, 10L, "production,high-performance", false, false, 2000L, 10000L);
clonedOffering.setEncrypt(true);
when(diskOfferingDao.persist(any(DiskOfferingVO.class))).thenReturn(clonedOffering);
Mockito.doReturn(clonedOffering).when(configurationManager).createDiskOffering(
anyLong(), anyList(), anyList(), eq("cloned-disk-offering"),
eq("Cloned Disk Offering - Updated"), anyString(), eq(10737418240L),
eq("Cloned Disk Offering - Updated"), anyString(), eq(10L),
eq("production,high-performance"), anyBoolean(), anyBoolean(), anyBoolean(),
any(), eq(2000L), eq(10000L), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
@ -564,7 +645,7 @@ public class ConfigurationManagerCloneIntegrationTest {
Assert.assertNotNull("Cloned disk offering should not be null", result);
Assert.assertEquals("Should override display text", "Cloned Disk Offering - Updated", result.getDisplayText());
Assert.assertEquals("Should override disk size", 10737418240L, result.getDiskSize());
Assert.assertEquals("Should override disk size", 10L, result.getDiskSize());
Assert.assertEquals("Should override tags", "production,high-performance", result.getTags());
Assert.assertEquals("Should override min IOPS", Long.valueOf(2000L), result.getMinIops());
Assert.assertEquals("Should override max IOPS", Long.valueOf(10000L), result.getMaxIops());
@ -577,9 +658,9 @@ public class ConfigurationManagerCloneIntegrationTest {
Long sourceId = 1L;
DiskOfferingVO sourceOffering = new DiskOfferingVO("source-disk", "Source Disk",
Storage.ProvisioningType.THIN, 5368709120L, "tag1", false, false, null, null);
sourceOffering.setBytesReadRate(10485760L); // 10 MB/s
sourceOffering.setBytesReadRateMax(20971520L); // 20 MB/s
Storage.ProvisioningType.THIN, 53L, "tag1", false, false, null, null);
sourceOffering.setBytesReadRate(10485760L);
sourceOffering.setBytesReadRateMax(20971520L);
sourceOffering.setBytesReadRateMaxLength(60L);
sourceOffering.setBytesWriteRate(10485760L);
sourceOffering.setBytesWriteRateMax(20971520L);
@ -589,6 +670,9 @@ public class ConfigurationManagerCloneIntegrationTest {
when(cmd.getSourceOfferingId()).thenReturn(sourceId);
when(cmd.getOfferingName()).thenReturn("cloned-disk");
when(cmd.getFullUrlParams()).thenReturn(new HashMap<>());
when(cmd.getDiskSize()).thenReturn(null);
when(cmd.getMinIops()).thenReturn(null);
when(cmd.getMaxIops()).thenReturn(null);
when(diskOfferingDao.findById(sourceId)).thenReturn(sourceOffering);
when(diskOfferingDetailsDao.findDomainIds(sourceId)).thenReturn(Collections.emptyList());
@ -596,21 +680,21 @@ public class ConfigurationManagerCloneIntegrationTest {
when(diskOfferingDetailsDao.getDetail(eq(sourceId), anyString())).thenReturn(null);
DiskOfferingVO clonedOffering = new DiskOfferingVO("cloned-disk", "Source Disk",
Storage.ProvisioningType.THIN, 5368709120L, "tag1", false, false, null, null);
Storage.ProvisioningType.THIN, 53L, "tag1", false, false, null, null);
clonedOffering.setBytesReadRate(10485760L);
clonedOffering.setBytesReadRateMax(20971520L);
clonedOffering.setBytesReadRateMaxLength(60L);
clonedOffering.setBytesWriteRate(10485760L);
clonedOffering.setBytesWriteRateMax(20971520L);
clonedOffering.setBytesWriteRateMaxLength(60L);
when(diskOfferingDao.persist(any(DiskOfferingVO.class))).thenReturn(clonedOffering);
Mockito.doReturn(clonedOffering).when(configurationManager).createDiskOffering(
anyLong(), anyList(), anyList(), anyString(), anyString(), anyString(),
anyLong(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), any(),
anyLong(), anyLong(), eq(10485760L), eq(20971520L), eq(60L), eq(10485760L),
eq(20971520L), eq(60L), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), anyInt(), anyString(), any(), anyLong(), anyBoolean(),
anyBoolean());
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyLong(),
anyInt(), anyString(), any(), anyLong(), anyBoolean(), anyBoolean());
DiskOffering result = configurationManager.cloneDiskOffering(cmd);